コード例 #1
0
 /**
  * Создаёт новый комментарий
  * @return bool
  */
 public function actionCreate()
 {
     $model = new Comment('guest');
     if ($user = \Yii::app()->getModule('comments')->loadUser()) {
         $model->setScenario('authorized');
         $model->user_id = $user->{$user->tableSchema->primaryKey};
     }
     $this->performAjaxValidation($model);
     if (!isset($_POST['pendalf89_yii_commentator_models_Comment'])) {
         return false;
     }
     $model->attributes = $_POST['pendalf89_yii_commentator_models_Comment'];
     $model->ip = CHelper::getRealIP();
     $model->setStatus();
     if (!$model->save()) {
         return false;
     }
     \Yii::app()->session["commentHash_{$model->id}"] = $model->getHash();
     $widget = new CommentsWidget();
     $widget->models = Comment::model()->page($model->url)->approved()->findAll();
     $widget->init();
     if (\Yii::app()->getModule('comments')->notifyAdmin) {
         $this->sendAdminNotify($model);
     }
     $this->sendUserNotifies($model);
     echo json_encode(array('id' => $model->id, 'premoderate' => \Yii::app()->getModule('comments')->getPremoderateStatus(), 'tree' => $widget->getTree(), 'count' => count($widget->models), 'modal' => $this->getModal(array('title' => '<i class="fa fa-comments"></i> Комментарий успешно отправлен!', 'content' => '<strong>Спасибо за комментарий!</strong> Он появится после проверки модератором.'))));
 }