/** * @param $model * @return Comment */ public function processRequestSpec($model) { Yii::import('application.modules.users.models.User'); Yii::import('application.modules.catalog.models.Spec'); $comment = new CommentSpec; if(Yii::app()->request->getPost('CommentSpec')) { $comment->attributes = Yii::app()->request->getPost('CommentSpec'); $ratingAjax = null; if(isset($_POST['CommentSpec']['rating'])){ $ratingAjax = (int)$_POST['CommentSpec']['rating']; if($ratingAjax == 0) $ratingAjax = null; } $comment->rating = $ratingAjax; if(!Yii::app()->user->isGuest) { $comment->name = Yii::app()->user->username; $comment->email = Yii::app()->user->email; } $comment->status = CommentSpec::STATUS_WAITING; 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==CommentSpec::STATUS_WAITING) { $url.='#'; Yii::app()->user->setFlash('messages', 'Ваш комментарий успешно добавлен. '); } elseif($comment->status==CommentSpec::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; }
public function actionAddReviewSpec($id) { $id = (int)$id; $review = Spec::model()->active()->findByPk($id); if(!$review) Yii::app()->end(); if(isset($_POST['CommentSpec'])) { $model = new CommentSpec; $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', CommentSpec::STATUS_APPROVED); $this->performAjaxValidation($model, 'comments-form'); $model->attributes=$_POST['CommentSpec']; 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(); }
/* array( 'name' => 'name', 'type' => 'raw', 'value' => 'CHtml::link(CHtml::encode($data->name), array("update", "id"=>$data->id))', ), array( 'name'=>'email', ), */ array( 'header' => 'Отзыв', 'name'=>'text', // 'value'=>'Comment::truncate($data, 100)' ), array( 'name'=>'status', 'filter'=>CommentSpec::getStatuses(), 'value'=>'$data->statusTitle', ), array( 'header' => 'Оценка', 'name'=>'rating', 'filter'=>false ), array( 'header' => 'Специалист', 'type'=>'raw', 'value'=>'CHtml::link($data->getOwner_title(), $data->getViewUrlAdmin(), array("target"=>"_blank"))', 'filter'=>false ),
public function loadModel($id) { $model=CommentSpec::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
<div class="col-md-11 col-sm-10"> <?php echo $form->textArea($model, 'text', array( 'class'=>'form-control', 'rows'=>5, 'placeholder'=>'Отзыв' )); ?> </div> </div> <!-- / .form-group --> <div class="form-group"> <?php echo $form->label($model, 'status', array('class'=>'col-md-1 col-sm-2 control-label')); ?> <div class="col-md-11 col-sm-10"> <?php echo $form->dropDownList($model, 'status', CommentSpec::getStatuses(), array( 'encode'=>false, // 'empty'=>'Выбрать', 'class'=>'form-control', )); ?> </div> </div> <div style="margin-bottom: 0;" class="form-group"> <div class="col-md-offset-1 col-md-11 col-sm-offset-2 col-sm-10"> <button class="btn btn-primary" type="submit"><?php echo $model->isNewRecord ? 'Создать' : 'Сохранить'; ?></button>
<?php /** * @var $this Controller * @var $form CActiveForm */ // Load module $module = Yii::app()->getModule('comments'); // Validate and save comment on post request $comment = $module->processRequestSpec($model); // Load model comments $comments = CommentSpec::getObjectComments($model); $themeUrl = Yii::app()->theme->baseUrl; ?> <!-- Modal --> <div id="leave_comment" class="modal fade" tabindex="-1" role="dialog" style="display:none;"> <div class="modal-dialog"> <div class="modal-content"> <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'comment-create-form', 'action'=>'#comment-create-form', 'htmlOptions'=>array( 'role'=>'form'), 'enableAjaxValidation'=>true, 'enableClientValidation'=>false, 'errorMessageCssClass'=>'in-bl-error',
?> <div class="vote text-right c9 active" style="margin-top:10px;" id="vote<?php echo $model->id; ?>"> <span class="c-gray f-11" style="margin-right:5px;">Полезен ли отзыв?</span> <span class="user_votes"><span onclick="toVoteSpec(<?php echo $model->id; ?>, 1);" class="user_pro"><i class="md md-thumb-up"></i></span> <span class="user_num"><?php echo $model->yes?$model->yes:' '; ?></span> <span class="user_contra" onclick="toVoteSpec(<?php echo $model->id; ?>, 0);"><i class="md md-thumb-down"></i></span> <span class="user_contra-num"><?php echo $model->no?$model->no:' '; ?></span></span></div> <?php } ?> </div> </div> <div class="row"> <div class="col-xs-12"> <?php if($showcommenttext == true){ $comments = new CommentSpec('search'); $comments->unsetAttributes(); if(!empty($model->user_id)){ $user_name = $model->user->fullname; } else { $user_name = $model->name; } if(!empty($_GET['CommentSpec'])) $comments->attributes = $_GET['CommentSpec']; $criteria = new CDbCriteria; $criteria->limit = 3; $criteria->with = array('user'); $criteria->condition = 't.object_pk='.$org_id.' and t.id_parent='.$model->id.' and t.status='.CommentSpec::STATUS_APPROVED; $dataProviderComments = new CActiveDataProvider('CommentSpec', array(