예제 #1
0
 public function actionFollowing()
 {
     $query = Topic::find()->innerJoinWith('authorFollowedBy')->where([Favorite::tableName() . '.source_id' => Yii::$app->getUser()->id, Favorite::tableName() . '.type' => Favorite::TYPE_USER]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(1), 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']);
     $topics = $query->select([Topic::tableName() . '.id'])->orderBy([Topic::tableName() . '.id' => SORT_DESC])->offset($pages->offset)->with(['topic.author', 'topic.node', 'topic.lastReply'])->limit($pages->limit)->all();
     return $this->render('following', ['topics' => Util::convertModelToArray($topics), 'pages' => $pages]);
 }
예제 #2
0
 public function actionReply($id)
 {
     $request = Yii::$app->getRequest();
     $me = Yii::$app->getUser()->getIdentity();
     $topic = $this->findTopicModel($id, ['node', 'author']);
     if (!$me->canReply($topic)) {
         throw new ForbiddenHttpException('您没有权限回复或此主题已关闭回复。');
     }
     $model = new Comment();
     if ($model->load($request->post()) && $model->validate()) {
         $model->user_id = $me->id;
         $cid = new \app\models\Commentid(['id' => null]);
         $cid->save(false);
         $model->id = $cid->id;
         $model->link('topic', $topic);
         $this->redirect(Topic::getRedirectUrl($id, $model->position));
     }
     return $this->render('add', ['comment' => $model, 'topic' => Util::convertModelToArray($topic)]);
 }
예제 #3
0
 public function actionView($id)
 {
     $topic = Topic::getTopicFromView($id);
     $pages = new Pagination(['totalCount' => $topic->comment_count, 'pageSize' => intval($this->settings['comment_pagesize']), 'pageParam' => 'p']);
     return $this->render('view', ['topic' => Util::convertModelToArray($topic), 'comments' => Comment::getCommentsFromView($id, $pages), 'pages' => $pages]);
 }