Пример #1
0
 /**
  * @param $id
  * @return string
  */
 public function actionView($id)
 {
     /** @var Post $post */
     $post = Post::findOne(['id' => $id]);
     /** @var Topic $topic */
     $topic = Topic::find()->where(['id' => $post->topic_id])->one();
     if (!$topic) {
         throw new NotFoundHttpException();
     }
     $topic->updateCounters(['number_views' => 1]);
     $topic->save();
     if (!Yii::$app->getUser()->getIsGuest()) {
         $userMentions = UserMention::findAll(['post_id' => $id, 'mention_user_id' => Yii::$app->getUser()->getId(), 'status' => UserMention::MENTION_SATUS_UNVIEWED]);
         foreach ($userMentions as $userMention) {
             $userMention->status = UserMention::MENTION_SATUS_VIEWED;
             $userMention->save();
         }
     }
     $dataProvider = Post::getDataProviderByTopic($topic->id);
     $dataProvider->pagination->route = '/topic/default/view';
     $dataProvider->pagination->params = ['id' => $topic->id, 'page' => $this->getPostPage($post)];
     $posts = $dataProvider->getModels();
     $model = new PostForm();
     return $this->render('/default/view', ['dataProvider' => $dataProvider, 'model' => $model, 'topic' => $topic, 'posts' => $posts]);
 }
Пример #2
0
 /**
  * @param $id topic identificator.
  * @return string
  */
 public function actionView($id)
 {
     /** @var Topic $topic */
     $topic = Topic::find()->where(['id' => $id])->one();
     if (!$topic) {
         throw new NotFoundHttpException();
     }
     $topic->updateCounters(['number_views' => 1]);
     $topic->save();
     $dataProvider = Post::getDataProviderByTopic($topic->id);
     $posts = $dataProvider->getModels();
     if (!Yii::$app->getUser()->getIsGuest()) {
         $userMentions = UserMention::findAll(['topic_id' => $id, 'mention_user_id' => Yii::$app->getUser()->getId(), 'status' => UserMention::MENTION_SATUS_UNVIEWED]);
         // user mention update
         foreach ($userMentions as $userMention) {
             $userMention->status = UserMention::MENTION_SATUS_VIEWED;
             $userMention->save();
         }
         $model = new PostForm();
         if ($model->load(Yii::$app->getRequest()->post()) && $model->create($topic)) {
             $this->redirect(['/topic/post/view', 'id' => $model->post->id, '#' => 'p' . $model->post->id]);
         }
         return $this->render('view', ['dataProvider' => $dataProvider, 'model' => $model, 'topic' => $topic, 'posts' => $posts]);
     } else {
         return $this->render('view', ['dataProvider' => $dataProvider, 'topic' => $topic, 'posts' => $posts]);
     }
 }