Esempio n. 1
0
 /**
  * @param Post  $post
  * @param Topic $topic
  */
 public function movePostToTopic(Post $post, Topic $topic)
 {
     $post->topic->decrement('num_posts');
     $post->topic->forum->decrement('num_posts');
     $post->topic_id = $topic->id;
     $post->save();
     $topic->increment('num_posts');
     $topic->forum->increment('num_posts');
     $topic->update(['last_post_id' => $post->id]);
     $topic->forum->update(['last_post_id' => $post->id, 'last_post_user_id' => $post->author->id]);
 }
Esempio n. 2
0
 /**
  * Add a post to a topic.
  *
  * @param Topic $topic       The topic to add a post to.
  * @param array $postDetails The details of the post to add.
  *
  * @return mixed
  */
 public function addPostToTopic(Topic $topic, array $postDetails)
 {
     $postDetails = array_merge(['user_id' => $this->guard->user()->id, 'username' => null, 'content' => '', 'content_parsed' => ''], $postDetails);
     $postDetails['content_parsed'] = $this->formatter->parse($postDetails['content'], [MessageFormatter::ME_USERNAME => $this->guard->user()->name]);
     // TODO: Parser options...
     if ($postDetails['user_id'] > 0) {
         $postDetails['username'] = User::find($postDetails['user_id'])->name;
     } else {
         $postDetails['user_id'] = null;
         if ($postDetails['username'] == trans('general.guest')) {
             $postDetails['username'] = null;
         }
     }
     $post = $topic->posts()->create($postDetails);
     if ($post !== false) {
         $topic->increment('num_posts');
         $topic->update(['last_post_id' => $post['id']]);
         $topic->forum->increment('num_posts');
         $topic->forum->update(['last_post_id' => $post->id, 'last_post_user_id' => $postDetails['user_id']]);
     }
     if ($post->user_id > 0) {
         $post->author->increment('num_posts');
     }
     return $post;
 }