public static function allForGroup($group_id) { $categories = static::all(); $forums = Forum::allForGroup($group_id); /*usort($forums, function($forum1, $forum2) { if ($forum1->cat_id == $forum2->cat_id) { // Same category: forum's disp_position value decides return $forum1->disp_position - $forum2->disp_position; } else { // ...else the categories' disp_position values are compared return $categories[$forum1->cat_id]->disp_position - $categories[$forum2->cat_id]->disp_position; } });*/ // TODO: Handle sorting! // FIXME: Yuck!!! $forums_by_cat = array(); foreach ($forums as $forum) { if (!isset($forums_by_cat[$forum->cat_id])) { $forums_by_cat[$forum->cat_id] = array('category' => $categories[$forum->cat_id], 'forums' => array()); } $forums_by_cat[$forum->cat_id]['forums'][] = $forum; } return $forums_by_cat; }
protected function handleRequest(Request $request) { $fid = \Route::input('id'); $forum = Forum::with('perms')->findOrFail($fid); $this->data['forum'] = $forum; $this->data['action'] = trans('fluxbb::forum.post_topic'); }
protected function handleRequest(Request $request) { $fid = \Route::input('id'); $this->forum = Forum::with('perms')->findOrFail($fid); $this->subject = $request->input('req_subject'); $this->message = $request->input('req_message'); }
public static function forumsForGroup($group_id) { return Cache::remember('fluxbb.forums_for_group.' . $group_id, 7 * 24 * 60, function () use($group_id) { $disallowed = ForumPerms::where('group_id', '=', $group_id)->where('read_forum', '=', 0)->lists('forum_id'); $all_forum_ids = Forum::ids(); return array_diff($all_forum_ids, $disallowed); }); }
public function get_forum($fid, $page = 1) { $page = intval($page); // Fetch some info about the forum $forum = Forum::with('perms')->where('id', '=', $fid)->first(); if ($forum === NULL) { return \Event::first('404'); } $disp_topics = $this->user()->dispTopics(); $num_pages = ceil(($forum->num_topics + 1) / $disp_topics); $page = $page <= 1 || $page > $num_pages ? 1 : intval($page); $start_from = $disp_topics * ($page - 1); // FIXME: Do we have to fetch just IDs first (performance)? // TODO: If logged in, with "the dot" subquery // Fetch topic data $topics = Topic::where('forum_id', '=', $fid)->orderBy('sticky', 'DESC')->orderBy($forum->sortColumn(), $forum->sortDirection())->orderBy('id', 'DESC')->skip($start_from)->take($disp_topics)->get(); return \View::make('fluxbb::viewforum')->with('forum', $forum)->with('topics', $topics)->with('start_from', $start_from); }
public function put_topic($fid) { $forum = Forum::with(array('perms'))->where('id', '=', $fid)->first(); if ($forum === NULL) { return \Event::first('404'); } // TODO: Flood protection $rules = array('req_subject' => 'required|max:70', 'req_message' => 'required'); // TODO: More validation if (\Auth::isGuest()) { if (Config::enabled('p_force_guest_email') || \Input::get('email') != '') { $rules['req_email'] = 'required|email'; } // TODO: banned email } $validation = $this->make_validator(Input::all(), $rules); if ($validation->fails()) { return \Redirect::to_action('fluxbb::posting@topic', array($fid))->with_input()->with_errors($validation); } $topic_data = array('poster' => User::current()->username, 'subject' => \Input::get('req_subject'), 'posted' => \Request::time(), 'last_post' => \Request::time(), 'last_poster' => User::current()->username, 'sticky' => \Input::get('stick_topic') ? '1' : '0', 'forum_id' => $fid); if (\Auth::isGuest()) { $topic_data['poster'] = $topic_data['last_poster'] = \Input::get('req_username'); } // Create the topic $topic = Topic::create($topic_data); // To subscribe or not to subscribe $topic->subscribe(\Input::get('subscribe')); $post_data = array('poster' => User::current()->username, 'poster_id' => User::current()->id, 'poster_ip' => \Request::ip(), 'message' => \Input::get('req_message'), 'hide_smilies' => \Input::get('hide_smilies') ? '1' : '0', 'posted' => \Request::time(), 'topic_id' => $topic->id); if (\Auth::isGuest()) { $post_data['poster'] = \Input::get('req_username'); $post_data['poster_email'] = Config::enabled('p_force_guest_email') ? \Input::get('req_email') : \Input::get('email'); } // Create the post ("topic post") $post = Post::create($post_data); // Update the topic with last_post_id $topic->last_post_id = $topic->first_post_id = $post->id; $topic->save(); // Update forum (maybe $forum->update_forum() ?) $forum->num_posts += 1; $forum->num_topics += 1; $forum->last_post = $topic->last_post; $forum->last_post_id = $topic->last_post_id; $forum->last_poster = $topic->last_poster; $forum->save(); // TODO: update_search_index(); // If the posting user is logged in, increment his/her post count $user = User::current(); if (\Auth::isAuthed()) { $user->num_posts += 1; $user->last_post = \Request::time(); $user->save(); // TODO: Promote this user to a new group if enabled } else { $user->online()->update(array('last_post' => \Request::time())); } return \Redirect::to_action('fluxbb::topic', array($topic->id))->with('message', trans('fluxbb::topic.topic_added')); }
public static function ids() { return Cache::remember('FluxBB.forum_ids', 7 * 24 * 60, function () { return Forum::lists('id'); }); }
protected function handleRequest(Request $request) { $fid = \Route::input('id'); // Fetch some info about the topic $this->data['forum'] = Forum::findOrFail($fid); }