/** * Stores a post * * @param int The id of the thread */ public function store($id) { $forumPost = new ForumPost(Input::all()); $forumPost->creator_id = user()->id; $forumPost->thread_id = $id; $forumThread = ForumThread::isAccessible()->findOrFail($id); if ($forumThread->closed) { $this->alertError(trans('forums::closed_info')); return; } $valid = $forumPost->save(); if (!$valid) { return Redirect::to('forums/threads/create')->withInput()->withErrors($forumPost->getErrors()); } $forumThread->posts_count++; $forumThread->forceSave(); $user = user(); $user->posts_count++; $user->save(); $this->alertFlash(trans('app.created', ['Post'])); return Redirect::to($forumPost->paginatedPostUrl()); }
/** * Refreshes the forum's meta infos * * @return void */ public function refresh() { if (!$this->forum_id) { return; // Root forums (level = 0) do not need refreshes } $forumThread = ForumThread::whereForumId($this->id)->orderBy('created_at', 'desc')->first(); $threadsCount = ForumThread::whereForumId($this->id)->count(); $childThreadsCount = 0; foreach ($this->forums as $forum) { $childThreadsCount += $forum->threads_count; } $this->latest_thread_id = null; if ($forumThread) { $this->latest_thread_id = $forumThread->id; } $this->threads_count = $threadsCount + $childThreadsCount; $this->forceSave(); /* * Every forum has to call the refresh method of its parent forum, * because their meta infos all depend on their child forums. * Therefore we do a cascading method call. */ if ($this->forum_id) { $this->forum->refresh(); } }
public function render($parameters = array()) { $limit = isset($parameters['limit']) ? (int) $parameters['limit'] : self::LIMIT; $forumThreads = ForumThread::isAccessible()->orderBy('forum_threads.updated_at', 'DESC')->take($limit)->get(); return View::make('forums::widget_latest_threads', compact('forumThreads'))->render(); }
public function globalSearch($subject) { $forumThreads = ForumThread::isAccessible()->where('forum_threads.title', 'LIKE', '%' . $subject . '%')->get(); $results = array(); foreach ($forumThreads as $forumThread) { $results[$forumThread->title] = URL::to('forums/threads/' . $forumThread->id . '/' . $forumThread->slug); } return $results; }
public function render($parameters = array()) { $forumThreads = ForumThread::isAccessible()->orderBy('forum_threads.updated_at', 'DESC')->take(5)->get(); return View::make('forums::widget_latest_threads', compact('forumThreads'))->render(); }