/** * @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]); }
/** * @param integer $id post identificator. * @return string */ public function actionView($id) { /** @var Post $post */ $post = Post::findOne(['id' => $id]); if (!$post) { throw new NotFoundHttpException(); } return $this->run('/topic/default/view', ['id' => $post->topic_id, 'page' => $this->getPageByPost($post)]); }
/** * @param integer $id * @return boolean */ public function update($id) { /** @var Post $post */ $post = Post::findOne(['id' => $id]); if (!$post && !Yii::$app->getUser()->can('updatePost', ['post' => $post])) { return false; } $post->message = $this->message; $post->edited_at = time(); $post->edited_by = Yii::$app->getUser()->getIdentity()->getId(); if ($post->save()) { $this->_post = $post; return true; } return false; }
/** * @return string */ public function actionUpdate() { if (Yii::$app->getRequest()->getIsAjax()) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $text = Yii::$app->getRequest()->post('text'); $id = substr(Yii::$app->getRequest()->post('id'), 1); /** @var Post $post */ $post = Post::findOne(['id' => $id]); if (!$post || !Yii::$app->getUser()->can('updatePost', ['post' => $post])) { throw new NotFoundHttpException(); } $model = new PostForm(); $model->message = $text; if ($model->validate()) { $post->message = $text; $post->edited_at = time(); $post->edited_by = Yii::$app->getUser()->getIdentity()->getId(); $post->save(); } return $post->displayMessage; } throw new NotFoundHttpException(); }
/** * This action render the markdown helper page. * @return string */ public function actionMarkdown() { $post = Post::findOne(['id' => 450994]); return $this->render('markdown', ['post' => $post]); }