示例#1
0
 /**
  * Quote the original post in the reply (reply to a post)
  * @param $id integer post_id
  */
 public function actionQuote($id = null)
 {
     $id = $id ?: \Yii::$app->request->get('id');
     $quoted = BbiiPost::findOne($id);
     if ($quoted === null) {
         throw new HttpException(404, Yii::t('BbiiModule.bbii', 'The requested post does not exist.'));
     }
     $forum = BbiiForum::findOne($quoted->forum_id);
     $topic = BbiiTopic::findOne($quoted->topic_id);
     if (\Yii::$app->request->post('BbiiPost')) {
         $post = new BbiiPost();
         $post->load(\Yii::$app->request->post());
         $post->user_id = \Yii::$app->user->identity->id;
         $post->create_time = date('Y-m-d H:m:i');
         if ($forum->moderated) {
             $post->approved = 0;
         } else {
             $post->approved = 1;
         }
         if ($post->validate() && $post->save()) {
             if ($post->approved) {
                 $forum->updateCounters(array('num_posts' => 1));
                 $topic->updateCounters(array('num_replies' => 1));
                 $topic->last_post_id = $post->id;
                 $forum->last_post_id = $post->id;
                 $topic->update();
                 $forum->update();
                 $post->poster->updateCounters(array('posts' => 1));
                 $this->assignMembergroup(\Yii::$app->user->identity->id);
             } else {
                 \Yii::$app->session->addFlash('moderation', Yii::t('BbiiModule.bbii', 'Your post has been saved. It has been placed in a queue and is now waiting for approval by a moderator before it will appear on the forum. Thank you for your contribution to the forum.'));
             }
             return \Yii::$app->response->redirect(array('forum/forum/topic', 'id' => $post->topic_id, 'nav' => 'last'));
         } else {
             echo '<pre>';
             print_r($post->getErrors());
             echo '</pre>';
             exit;
         }
     } else {
         $post = new BbiiPost();
         $quote = $quoted->poster->member_name . ' ' . Yii::t('BbiiModule.bbii', 'wrote') . ' ' . Yii::t('BbiiModule.bbii', 'on') . ' ' . \Yii::$app->formatter->asDatetime($quoted->create_time);
         $post->content = '<blockquote cite = "' . $quote . '"><p class = "blockquote-header"><strong>' . $quote . '</strong></p>' . $quoted->content . '</blockquote><p></p>';
         $post->subject = $quoted->subject;
         $post->forum_id = $quoted->forum_id;
         $post->topic_id = $quoted->topic_id;
     }
     return $this->render('reply', array('forum' => $forum, 'post' => $post, 'topic' => $topic));
 }