public function actionReply($username, $page = null) { $this->title = $username . '发布的回复 - ' . Yii::$app->name; $this->description = ''; $user = $this->findModel($username); $query = Reply::find()->where(['user_id' => $user->id]); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $model = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('reply', ['model' => $model, 'user' => $user, 'pagination' => $pagination]); }
public function actionReply($username, $page = null) { $this->title = $username . '发布的回复 - ' . Yii::$app->name; $this->description = ''; $this->canonical = Yii::$app->params['domain'] . 'member/' . $username . '/reply'; $user = $this->findModel($username); $query = (new Query())->select('reply.*, topic.title, node.enname, node.name, user.username, user.avatar')->from(Reply::tableName())->leftJoin(Topic::tableName(), 'topic.id = reply.topic_id')->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName(), 'user.id = topic.user_id')->where(['node.is_hidden' => 0])->andWhere(['reply.user_id' => $user->id]); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $model = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('reply', ['model' => $model, 'user' => $user, 'pagination' => $pagination]); }
public function actionIndex() { //今天注册用户 $model['userToday'] = User::find()->where(['between', 'created_at', strtotime(date('Y-m-d', time())), strtotime(date('Y-m-d', time())) + 86400])->count(); //今天主题 $model['topicToday'] = Topic::find()->where(['between', 'created', strtotime(date('Y-m-d', time())), strtotime(date('Y-m-d', time())) + 86400])->count(); //今天回复 $model['replyToday'] = Reply::find()->where(['between', 'created', strtotime(date('Y-m-d', time())), strtotime(date('Y-m-d', time())) + 86400])->count(); //7天内注册用户 $model['user7day'] = User::find()->where(['between', 'created_at', strtotime(date('Y-m-d', time())) - 86400 * 7, strtotime(date('Y-m-d', time()))])->count(); //7天内主题 $model['topic7day'] = Topic::find()->where(['between', 'created', strtotime(date('Y-m-d', time())) - 86400 * 7, strtotime(date('Y-m-d', time()))])->count(); //7天内回复 $model['reply7day'] = Reply::find()->where(['between', 'created', strtotime(date('Y-m-d', time())) - 86400 * 7, strtotime(date('Y-m-d', time()))])->count(); //30天内注册用户 $model['user30day'] = User::find()->where(['between', 'created_at', strtotime(date('Y-m-d', time())) - 86400 * 30, strtotime(date('Y-m-d', time()))])->count(); //30天内主题 $model['topic30day'] = Topic::find()->where(['between', 'created', strtotime(date('Y-m-d', time())) - 86400 * 30, strtotime(date('Y-m-d', time()))])->count(); //30天内回复 $model['reply30day'] = Reply::find()->where(['between', 'created', strtotime(date('Y-m-d', time())) - 86400 * 30, strtotime(date('Y-m-d', time()))])->count(); return $this->render('index', ['model' => $model]); }
/** * @return \yii\db\ActiveQuery */ public function getReplyList() { return $this->hasMany(Reply::className(), ['topic_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getReplyList() { return $this->hasMany(Reply::className(), ['user_id' => 'id'])->orderBy(['id' => SORT_DESC])->limit(10); }
/** * Displays a single Topic model. * @param integer $id * @return mixed * @throws BadRequestHttpException * @throws NotFoundHttpException * @throws \Exception */ public function actionView($id) { $model = $this->findModel($id); if ($model->need_login == 1 && Yii::$app->user->isGuest) { Yii::$app->getSession()->setFlash('danger', '你访问的主题需要登陆之后才能查看'); return $this->redirect('/account/login?next=/topic/' . $id); } if (!empty($model->node->bg) && $model->node->use_bg == 1) { $this->bg = $model->node->bg; } if (!empty($model->node->bg_color)) { $this->bg_color = $model->node->bg_color; } if (isset($model->content->content)) { $this->description = $model->node->name . ' - ' . $model->user->username . ' - ' . Helper::truncateUtf8String($model->content->content, 200); } else { $this->description = $model->node->name . ' - ' . $model->user->username . Helper::truncateUtf8String($model->title, 200); } $replyQuery = Reply::find()->where(['topic_id' => $model->id]); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $replyQuery->count()]); $replyList = $replyQuery->offset($pagination->offset)->limit($pagination->limit)->all(); $reply = new Reply(); if (!Yii::$app->user->isGuest) { $model->updateCounters(['click' => 1]); $reply = new Reply(); if ($reply->load(Yii::$app->request->post()) && $reply->save()) { $this->redirect('/topic/' . $id . '#Reply'); } return $this->render('view', ['model' => $model, 'reply' => $reply, 'replyList' => $replyList, 'pagination' => $pagination]); } else { return $this->render('view', ['model' => $model, 'reply' => $reply, 'replyList' => $replyList, 'pagination' => $pagination]); } }
/** * Displays a single Topic model. * @param integer $id * @return mixed * @throws BadRequestHttpException * @throws NotFoundHttpException * @throws \Exception */ public function actionView($id) { $model = $this->findModel($id); if ($model->need_login == 1 && Yii::$app->user->isGuest) { Yii::$app->getSession()->setFlash('danger', '你访问的建议需要登陆之后才能查看'); return $this->redirect('/account/login?next=/topic/' . $id); } if (!empty($model->node->bg) && $model->node->use_bg == 1) { $this->bg = $model->node->bg; } if (!empty($model->node->bg_color)) { $this->bg_color = $model->node->bg_color; } $this->title = $model->title . ' - ' . Yii::$app->name; if (isset($model->content->content)) { $this->description = $model->node->name . ' - ' . $model->user->username . ' - ' . Helper::truncateUtf8String($model->content->content, 200); } else { $this->description = $model->node->name . ' - ' . $model->user->username . Helper::truncateUtf8String($model->title, 200); } $this->canonical = Yii::$app->params['domain'] . 'topic/' . $id; $replyQuery = (new Query())->select('reply.*, user.username, user.avatar, user.role')->from(Reply::tableName())->leftJoin(User::tableName(), 'user.id = reply.user_id')->where(['reply.topic_id' => $id]); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['ReplyPageSize'], 'totalCount' => $replyQuery->count()]); $replyList = $replyQuery->offset($pagination->offset)->limit($pagination->limit)->all(); $reply = new Reply(); if (!Yii::$app->user->isGuest) { $model->updateCounters(['click' => 1]); $reply = new Reply(); if ($reply->load(Yii::$app->request->post()) && $reply->save()) { Yii::$app->cache->delete('ReplyCount'); $this->redirect('/topic/' . $id . '#Reply'); } return $this->render('view', ['model' => $model, 'reply' => $reply, 'replyList' => $replyList, 'pagination' => $pagination]); } else { return $this->render('view', ['model' => $model, 'reply' => $reply, 'replyList' => $replyList, 'pagination' => $pagination]); } }
/** * @return \yii\db\ActiveQuery */ public function getReplies() { return $this->hasMany(Reply::className(), ['comment_id' => 'id']); }
static function Count() { return Reply::find()->count(); }
<section> <div class="block-header">统计 </div> <div class="block-content"> 会员 <b><?php echo \common\models\User::Count(); ?> </b> <div class="mt5"></div> 主题 <b><?php echo \common\models\Topic::TopicStat(); ?> </b> <div class="mt5"></div> 回复 <b><?php echo \common\models\Reply::Count(); ?> </b> </div> </section>
static function ReplyCount() { if (!($ReplyCount = Yii::$app->cache->get('ReplyCount'))) { $ReplyCount = Reply::find()->count(); Yii::$app->cache->set('ReplyCount', $ReplyCount, 86400); } return $ReplyCount; }
/** * @return \yii\db\ActiveQuery */ public function getReplyList() { return (new Query())->select('reply.*, topic.title, node.enname, node.name, user.username, user.avatar')->from(Reply::tableName())->leftJoin(Topic::tableName(), 'topic.id = reply.topic_id')->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName() . ' user', 'user.id = reply.user_id')->where(['node.is_hidden' => 0])->andWhere(['reply.user_id' => $this->id])->orderBy(['id' => SORT_DESC])->limit(10)->all(); }