示例#1
0
 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]);
 }
示例#2
0
 /**
  * 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]);
     }
 }
示例#3
0
 /**
  * @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();
 }