FluxBB\Models\Category::allForGroup PHP Method

allForGroup() public static method

public static allForGroup ( $group_id )
    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;
    }

Usage Example

Example #1
0
 public function get_index()
 {
     // TODO: Get list of forums and topics with new posts since last visit & get all topics that were marked as read
     // Fetch the categories and forums
     $categories = Category::allForGroup(User::current()->group_id);
     $view = \View::make('fluxbb::index');
     $view['categories'] = $categories;
     return $view;
 }
All Usage Examples Of FluxBB\Models\Category::allForGroup