Exemple #1
0
 /**
  * Refreshes the thread's meta infos
  * 
  * @return void
  */
 public function refresh()
 {
     $forumPost = ForumPost::whereThreadId($this->id)->orderBy('created_at', 'desc')->firstOrFail();
     $postsCount = ForumPost::whereThreadId($this->id)->count();
     $this->posts_count = $postsCount;
     $this->updated_at = $forumPost->updated_at;
     $this->forceSave();
 }
 /**
  * Shows the latest posts of a user
  * 
  * @param int The id of the user
  */
 public function showUserPosts($userId)
 {
     $user = User::findOrFail($userId);
     $forumPosts = ForumPost::where('forum_posts.creator_id', '=', $userId)->isAccessible($user)->orderBy('updated_at', 'DESC')->paginate(10)->setPath(Request::url());
     $this->pageView('forums::show_user_posts', compact('forumPosts'));
 }
 /**
  * Deletes a thread
  * 
  * @param int The id of the thread
  */
 public function delete($id)
 {
     $forumPost = ForumPost::isAccessible()->findOrFail($id);
     $forumThread = ForumThread::findOrFail($id);
     $forum = $forumThread->forum;
     ForumPost::whereThreadId($forumThread->id)->delete();
     /*
      * Updates the users posts counter
      */
     $query = DB::table('forum_posts')->whereThreadId(DB::raw($forumThread->id))->groupBy('creator_id')->select('creator_id', DB::raw('COUNT(creator_id) AS count'))->toSql();
     DB::table('users')->join(DB::raw('(' . $query . ') AS sq'), 'id', '=', 'creator_id')->update(['posts_count' => DB::raw('posts_count - count')]);
     $forumThread->delete();
     $forum->refresh();
 }
 /**
  * Reports a post
  * 
  * @param int The id of the post
  */
 public function report($id)
 {
     $forumPost = ForumPost::isAccessible()->findOrFail($id);
     $forumReport = ForumReport::whereCreatorId(user()->id)->wherePostId($id)->first();
     if ($forumReport) {
         $this->alertFlash(trans('forums::already_reported'));
     } else {
         $forumReport = new ForumReport(['forum_post_id' => $id]);
         $forumReport->creator_id = user()->id;
         $forumReport->save();
         $this->alertFlash(trans('forums::reported'));
     }
     return Redirect::to('forums/threads/' . $forumPost->thread->id . '/' . $forumPost->thread->slug);
 }