/** * @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]); } }