Пример #1
0
 /**
  * Get comment children based on comment ID.
  *
  * @param int $id
  *
  * @return array|null
  */
 protected function getChildren($id)
 {
     /* @var $models \common\models\PostComment[] */
     $comments = [];
     $models = Comment::find()->select(['id', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_date', 'comment_content'])->andWhere(['comment_parent' => $id])->andWhere(['comment_post_id' => $this->model->id])->andWhere(['comment_approved' => 'approved'])->orderBy(['id' => $this->commentOrder])->all();
     if (empty($models)) {
         $comments = null;
     } else {
         foreach ($models as $model) {
             $comments[$model->id] = $model;
             $comments[$model->id]['child'] = $this->getChildren($model->id);
         }
     }
     return $comments;
 }
Пример #2
0
 /**
  * Show user count, post count, post-comment count on index (dashboard).
  *
  * @return string
  */
 public function actionIndex()
 {
     $userQuery = User::find()->andWhere(['blocked_at' => null, 'confirmed_at' => 'is not null']);
     $userCloneQuery = clone $userQuery;
     $userCount = $userCloneQuery->count();
     $users = $userQuery->limit(12)->orderBy(['id' => SORT_DESC])->all();
     $postQuery = Post::find()->andWhere(['post_status' => 'publish']);
     $postCloneQuery = clone $postQuery;
     $postCount = $postCloneQuery->count();
     $posts = $postQuery->limit(10)->orderBy(['id' => SORT_DESC])->all();
     $commentQuery = PostComment::find()->andWhere(['comment_approved' => 'approved']);
     $commentCloneQuery = clone $commentQuery;
     $commentCount = $commentCloneQuery->count();
     $comments = $commentQuery->limit(5)->orderBy(['id' => SORT_DESC])->all();
     return $this->render('index', ['users' => $users, 'posts' => $posts, 'comments' => $comments, 'userCount' => $userCount, 'postCount' => $postCount, 'commentCount' => $commentCount]);
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array    $params
  *
  * @param int      $post_type
  * @param int|null $post_id
  *
  * @return ActiveDataProvider
  */
 public function search($params, $post_type, $post_id = null)
 {
     $query = PostCommentModel::find();
     $query->innerJoinWith(['commentPost' => function ($query) {
         /* @var $query \yii\db\ActiveQuery */
         return $query->from(['post' => Post::tableName()]);
     }]);
     $query->andWhere(['post.post_type' => $post_type]);
     if ($post_id) {
         $query->andWhere(['post.id' => $post_id]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'comment_post_id' => $this->comment_post_id, 'comment_parent' => $this->comment_parent, 'comment_user_id' => $this->comment_user_id]);
     $query->andFilterWhere(['like', 'comment_author', $this->comment_author])->andFilterWhere(['like', 'comment_author_email', $this->comment_author_email])->andFilterWhere(['like', 'comment_author_url', $this->comment_author_url])->andFilterWhere(['like', 'comment_author_ip', $this->comment_author_ip])->andFilterWhere(['like', 'comment_content', $this->comment_content])->andFilterWhere(['like', 'comment_approved', $this->comment_approved])->andFilterWhere(['like', 'comment_agent', $this->comment_agent])->andFilterWhere(['like', 'comment_date', $this->comment_date])->andFilterWhere(['like', 'post.post_title', $this->post_title]);
     return $dataProvider;
 }