예제 #1
0
 public function run()
 {
     $model = new Comment();
     $model->scenario = Yii::$app->user->isGuest ? Comment::SCENARIO_GUEST : Comment::SCENARIO_USER;
     $model->load(Yii::$app->getRequest()->post());
     if ($model->save()) {
         if (Yii::$app->user->isGuest) {
             $cookie = new Cookie(['name' => "username", 'value' => $model->username, 'expire' => time() + 86400 * 365]);
             Yii::$app->getResponse()->getCookies()->add($cookie);
             $cookie = new Cookie(['name' => "email", 'value' => $model->email, 'expire' => time() + 86400 * 365]);
             Yii::$app->getResponse()->getCookies()->add($cookie);
         }
         $content = CommentsList::widget(["entity" => $model->entity, "entity_id" => $model->entity_id, "dataProvider" => new ActiveDataProvider(['query' => Comment::find()->where(['comment_id' => $model->comment_id])]), "nestedLevel" => Yii::$app->getRequest()->post("nestedLevel") + 1]);
         return $this->controller->renderJsonMessage(true, $content);
     }
     return $this->controller->renderJsonMessage(false, $model->formatErrors());
 }
예제 #2
0
 public function run()
 {
     $order = $this->parent_id ? SORT_ASC : SORT_DESC;
     if ($this->dataProvider == null) {
         $this->dataProvider = new ActiveDataProvider(['query' => Comment::find()->where(['entity' => $this->entity, 'entity_id' => $this->entity_id, 'parent_id' => $this->parent_id, 'status' => EntityStatusEnum::STATUS_PUBLISHED])->orderBy(['comment_id' => $order]), 'pagination' => ['pageSize' => 10]]);
     }
     return $this->render('list', ['entity' => $this->entity, 'entity_id' => $this->entity_id, 'dataProvider' => $this->dataProvider, 'nestedLevel' => $this->nestedLevel, "maxNestedLevel" => $this->maxNestedLevel]);
 }
예제 #3
0
 public function afterDelete()
 {
     $entity = $this->getEntityClass();
     $entity_id = $this->getEntityId();
     CommentInfo::deleteAll(['entity' => $entity, 'entity_id' => $entity_id]);
     Comment::deleteAll(['entity' => $entity, 'entity_id' => $entity_id]);
 }
예제 #4
0
 /**
  * Get count of active comments by $model and $entity_id
  *
  * @param string $model
  * @param int $entity_id
  * @return int
  */
 public static function activeCount($entity, $entity_id = NULL)
 {
     return Comment::find()->where(['entity' => $entity, 'entity_id' => $entity_id, "status" => 1])->count();
 }