public function run() { $orderDirection = $this->parent_id ? CommentsModule::getInstance()->nestedOrderDirection : CommentsModule::getInstance()->orderDirection; $pageSize = $this->parent_id ? 0 : CommentsModule::getInstance()->commentsPerPage; $dataProvider = new ActiveDataProvider(['query' => Comment::find()->where(['model' => $this->model, 'model_id' => $this->model_id, 'parent_id' => $this->parent_id, 'status' => Comment::STATUS_PUBLISHED]), 'pagination' => ['pageSize' => $pageSize, 'pageParam' => 'comment-page', 'pageSizeParam' => 'comments-per-page'], 'sort' => ['defaultOrder' => ['id' => $orderDirection]]]); return $this->render('list', ['dataProvider' => $dataProvider, 'comment' => $this->comment, 'nested_level' => $this->nested_level]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['status' => $this->status !== NULL ? $this->status : 1]); $query->andFilterWhere(['id' => $this->id, 'model_id' => $this->model_id, 'user_id' => $this->user_id, 'parent_id' => $this->parent_id, 'updated_at' => $this->updated_at]); switch ($this->created_at_operand) { case '=': $query->andFilterWhere(['>=', 'created_at', strtotime($this->created_at)]); $query->andFilterWhere(['<=', 'created_at', strtotime($this->created_at . ' 23:59:59')]); break; case '>': $query->andFilterWhere(['>', 'created_at', strtotime($this->created_at . ' 23:59:59')]); break; case '<': $query->andFilterWhere(['<', 'created_at', strtotime($this->created_at)]); break; default: break; } $query->andFilterWhere(['like', 'model', $this->model])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user_ip', $this->user_ip]); return $dataProvider; }
public function run() { if (!$this->options) { $this->options = $this->getDefaultOptions(); } if (User::hasPermission('viewComments')) { $searchModel = new CommentSearch(); $formName = $searchModel->formName(); $recentComments = Comment::find()->active()->orderBy(['id' => SORT_DESC])->limit($this->recentLimit)->all(); foreach ($this->options as &$option) { $count = Comment::find()->filterWhere($option['filterWhere'])->count(); $option['count'] = $count; $option['url'] = [$this->commentIndexAction, $formName => $option['filterWhere']]; } return $this->render('comments', ['height' => $this->height, 'width' => $this->width, 'position' => $this->position, 'comments' => $this->options, 'recentComments' => $recentComments]); } }
public function run() { $commentsAsset = CommentsAsset::register($this->getView()); CommentModule::getInstance()->commentsAssetUrl = $commentsAsset->baseUrl; $model = $this->model; $model_id = $this->model_id; $comment = new Comment(compact('model', 'model_id')); $comment->scenario = Yii::$app->user->isGuest ? Comment::SCENARIO_GUEST : Comment::SCENARIO_USER; if ((!CommentModule::getInstance()->onlyRegistered || !Yii::$app->user->isGuest) && $comment->load(Yii::$app->getRequest()->post())) { if ($comment->validate() && Yii::$app->getRequest()->validateCsrfToken() && Yii::$app->getRequest()->getCsrfToken(true) && $comment->checkSpam() && $comment->save()) { if (Yii::$app->user->isGuest) { CommentsHelper::setCookies(['username' => $comment->username, 'email' => $comment->email]); } Yii::$app->getResponse()->redirect(Yii::$app->request->referrer); return; } } $dataProvider = new ActiveDataProvider(['query' => Comment::find(true)->where(['model' => $model, 'model_id' => $model_id, 'parent_id' => NULL, 'status' => Comment::STATUS_PUBLISHED]), 'pagination' => ['pageSize' => CommentsModule::getInstance()->commentsPerPage, 'pageParam' => 'comment-page', 'pageSizeParam' => 'comments-per-page'], 'sort' => ['defaultOrder' => ['created_at' => CommentsModule::getInstance()->orderDirection]]]); return $this->render('comments', compact('model', 'model_id', 'comment', 'dataProvider')); }
/** * Get count of active comments by $model and $model_id * * @param string $model * @param int $model_id * @return int */ public static function activeCount($model, $model_id = NULL) { return Comment::find()->where(['model' => $model, 'model_id' => $model_id])->active()->count(); }
public function getCommentsCount() { try { return Comment::find()->where(['model' => Trip::className()])->andWhere(['model_id' => $this->primaryKey])->andWhere(['status' => Comment::STATUS_APPROVED])->count(); } catch (Exception $exc) { return 0; } }
public function run() { $recentComments = Comment::find()->active()->orderBy(['created_at' => SORT_DESC])->limit($this->recentLimit)->all(); return $this->render($this->layout, ['recentComments' => $recentComments, 'commentTemplate' => $this->commentTemplate]); }