public function actionIndex() { $topics = Post::find()->limit(20)->where(['status' => 2])->orderBy(['created_at' => SORT_DESC])->all(); $users = UserService::findActiveUser(12); $statistics = array(); $statistics['post_count'] = Post::find()->count(); $statistics['comment_count'] = PostComment::find()->count(); $statistics['online_count'] = Session::find()->where(['>', 'expire', time()])->count(); return $this->render('index', ['topics' => $topics, 'users' => $users, 'statistics' => $statistics]); }
public function actionIndex() { $topics = Post::find()->limit(20)->where(['status' => 2])->orderBy(['created_at' => SORT_DESC])->all(); $users = UserService::findActiveUser(12); $headline = Arr::getColumn(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_HEADLINE])->all(), 'content'); $statistics = []; $statistics['post_count'] = Post::find()->count(); $statistics['comment_count'] = PostComment::find()->count(); $statistics['online_count'] = Session::find()->where(['>', 'expire', time()])->count(); return $this->render('index', ['topics' => $topics, 'users' => $users, 'statistics' => $statistics, 'headline' => Arr::arrayRandomAssoc($headline)]); }
/** * 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; }
public function actionPost() { $update = Topic::updateAll(['last_comment_time' => new Expression('created_at')], ['and', ['type' => Topic::TYPE], ['or', ['last_comment_username' => ''], ['last_comment_username' => null]]]); $this->stdout("同步最后回复时间,同步{$update}条数据\n"); $subQuery = new Query(); $subQuery->from(PostComment::tableName())->where(['status' => PostComment::STATUS_ACTIVE])->orderBy(['created_at' => SORT_DESC]); $comment = PostComment::find()->from(['tmpA' => $subQuery])->groupBy('post_id')->all(); Topic::updateAll(['comment_count' => 0], ['type' => Topic::TYPE]); $updateComment = []; foreach ($comment as $value) { $commentCount = PostComment::find()->where(['post_id' => $value->post_id, 'status' => PostComment::STATUS_ACTIVE])->count(); $updateComment[] = Topic::updateAll(['last_comment_time' => $value->created_at, 'last_comment_username' => $value->user->username, 'comment_count' => $commentCount], ['id' => $value->post_id, 'type' => Topic::TYPE]); } $this->stdout("校正最后回复时间和回复会员还有评论条数,校正" . count($updateComment) . "条数据\n"); }
/** * Show user count, post count, post-comment count on index (dashboard). * * @return string */ public function actionIndex() { $userQuery = User::find()->andWhere(['status' => '10']); $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]); }
/** * Show user count, post count, post-comment count on index (dashboard). * * @return string */ public function actionIndex() { // Get list User model $userQuery = User::find()->andWhere(['status' => '10']); $userCloneQuery = clone $userQuery; $userCount = $userCloneQuery->count(); $users = $userQuery->limit(8)->orderBy(['id' => SORT_DESC])->all(); // Get list Post model $postQuery = Post::find()->andWhere(['status' => 'publish'])->andWhere(['<=', 'date', date('Y-m-d H:i:s')]); $postCloneQuery = clone $postQuery; $postCount = $postCloneQuery->count(); $posts = $postQuery->limit(5)->orderBy(['id' => SORT_DESC])->all(); // Get list PostComment model $commentQuery = PostComment::find()->andWhere(['status' => 'approved']); $commentCloneQuery = clone $commentQuery; $commentCount = $commentCloneQuery->count(); $comments = $commentQuery->limit(3)->orderBy(['id' => SORT_DESC])->all(); return $this->render('index', ['users' => $users, 'posts' => $posts, 'comments' => $comments, 'userCount' => $userCount, 'postCount' => $postCount, 'commentCount' => $commentCount]); }
/** * 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()) { 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; }
protected function comment($userId) { return new ActiveDataProvider(['query' => PostComment::find()->where(['user_id' => $userId, 'status' => 1])->orderBy(['created_at' => SORT_DESC])]); }