public function actionAddReviewArticle($id) { $id = (int)$id; $review = Article::model()->active()->findByPk($id); if(!$review) Yii::app()->end(); if(isset($_POST['CommentArticle'])) { $model = new CommentArticle; $model->scenario = 'subcomment'; $model->object_pk = $review->id; if(!Yii::app()->user->isGuest) { $model->user_id = Yii::app()->user->id; } else { Yii::app()->end(); } $model->setAttribute('status', CommentArticle::STATUS_APPROVED); $this->performAjaxValidation($model, 'comments-form'); $model->attributes=$_POST['CommentArticle']; if(empty($model->id_parent)) $model->id_parent = null; if($model->validate()){ if($model->save()){ if(isset($_POST['type']) && $_POST['type']==1){ $this->renderPartial('_comment_super',array('model'=>$model,'supermodel'=>$review)); } else{ // $this->renderPartial('_comment',array('model'=>$model)); } } } } Yii::app()->end(); }
/** * @param $model * @return Comment */ public function processRequestArticle($model) { Yii::import('application.modules.users.models.User'); Yii::import('application.modules.catalog.models.Article'); $comment = new CommentArticle; if(Yii::app()->request->getPost('CommentArticle')) { $comment->attributes = Yii::app()->request->getPost('CommentArticle'); if(!Yii::app()->user->isGuest) { $comment->name = Yii::app()->user->username; $comment->email = Yii::app()->user->email; } $comment->status = CommentArticle::STATUS_APPROVED; if($comment->validate()) { // $pkAttr = $model->getObjectPkAttribute(); // $comment->class_name = $model->getClassName(); $comment->object_pk = $model->id; $comment->user_id = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id; if(!$comment->save()){ // VarDumper::dump($comment->errors); die(); // Ctrl + X Delete line } $url = Yii::app()->getRequest()->getUrl(); // if($comment->rating) { // $this->starRating($comment->object_pk, $comment->rating); // } if($comment->status==CommentArticle::STATUS_WAITING) { $url.='#'; Yii::app()->user->setFlash('messages', 'Ваш комментарий успешно добавлен. '); } elseif($comment->status==CommentArticle::STATUS_APPROVED){ $url.='#comment_'.$comment->id; } if(Yii::app()->request->isAjaxRequest){ echo '[]'; Yii::app()->end(); } else { // Refresh page Yii::app()->request->redirect($url, true); } } } return $comment; }
protected function beforeDelete() { parent::beforeDelete(); ArticleVote::model()->deleteAllByAttributes(array('article'=>$this->id)); $this->getDeleteFileFolder(); // all comments remove CommentArticle::model()->deleteAllByAttributes(array( 'object_pk'=>$this->id )); return true; }
<?php /** * @var $this Controller * @var $form CActiveForm */ // Load module //$module = Yii::app()->getModule('comments'); // Validate and save comment on post request //$comment = $module->processRequestArticle($model); // Load model comments $provider = CommentArticle::getObjectComments($model); $themeUrl = Yii::app()->theme->baseUrl; // Display comments if($provider) { ?> <div class="clearfix"></div> <div id="comment_module" class="woocommerce" style="margin-top:20px;margin-bottom:0px;"> <div id="reviews"> <div id="comments"> <?php $ip = MHelper::Ip()->getIp(); $this->widget('zii.widgets.CListView', array( 'dataProvider'=>$provider, 'ajaxUpdate'=>true, 'template'=>"{items}\n{pager}", 'itemView'=>'application.modules.comments.views.comment._item', 'itemsTagName'=>'ol',
$themeUrl = Yii::app()->theme->baseUrl; ?> <div class="row"> <div class="col-xs-12"> <?php if($showcommenttext == true){ $comments = new CommentArticle('search'); $comments->unsetAttributes(); if(!empty($model->user_id)){ $user_name = $model->user->fullname; } else { $user_name = $model->name; } if(!empty($_GET['CommentArticle'])) $comments->attributes = $_GET['CommentArticle']; $criteria = new CDbCriteria; $criteria->limit = 3; $criteria->with = array('user'); $criteria->condition = 't.object_pk='.$org_id.' and t.status='.CommentArticle::STATUS_APPROVED; $dataProviderComments = new CActiveDataProvider('CommentArticle', array(
public static function getAllComments(CActiveRecord $model) { $users_adv = Products::model() ->active() ->findAllByAttributes(array( 'user_id'=>$model->id )); $ids=array(); foreach($users_adv as $adv): $ids[]=$adv->id; endforeach; // $criteria = new CDbCriteria(); // $criteria->addInCondition("object_pk", $ids); return CommentArticle::model() ->approved() ->orderByCreatedDesc() ->findAllByAttributes(array('object_pk'=>$ids)); }