/** * Display a list of sections and their categories * * @return void */ public function displayTask() { // Get authorization $this->_authorize('section'); $this->_authorize('category'); $forum = new Manager('site', 0); // Filters $filters = array('scope' => $forum->get('scope'), 'scope_id' => $forum->get('scope_id'), 'state' => Section::STATE_PUBLISHED, 'search' => '', 'access' => User::getAuthorisedViewLevels()); // Flag to indicate if a section is being put into edit mode $edit = null; if ($this->getTask() == 'edit' && $this->config->get('access-edit-section')) { $edit = Request::getVar('section', ''); } $sections = $forum->sections($filters); if (!$sections->count() && $this->config->get('access-create-section') && Request::getWord('action') == 'populate') { if (!$forum->setup()) { $this->setError($forum->getError()); } $sections = $forum->sections($filters); } // Set the page title App::get('document')->setTitle(Lang::txt(strtoupper($this->_option))); // Set the pathway Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option); $this->view->set('filters', $filters)->set('config', $this->config)->set('forum', $forum)->set('sections', $sections)->set('edit', $edit)->display(); }
/** * Display all sections * * @return void */ public function displayTask() { // Filters $this->view->filters = array('limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'id'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'scopeinfo' => Request::getState($this->_option . '.' . $this->_controller . '.scopeinfo', 'scopeinfo', '')); if (strstr($this->view->filters['scopeinfo'], ':')) { $bits = explode(':', $this->view->filters['scopeinfo']); $this->view->filters['scope'] = $bits[0]; $this->view->filters['scope_id'] = intval(end($bits)); } else { $this->view->filters['scope'] = ''; $this->view->filters['scope_id'] = -1; } $model = new Manager($this->view->filters['scope'], $this->view->filters['scope_id']); // Get a record count $this->view->total = $model->sections('count', $this->view->filters); // Get records $this->view->results = $model->sections('list', $this->view->filters); $this->view->forum = $model; // Output the HTML $this->view->display(); }
/** * Display a list of sections * * @apiMethod GET * @apiUri /forum/sections * @apiParameter { * "name": "scope", * "description": "Scope (site, groups, members, etc.)", * "type": "string", * "required": false, * "default": "site" * } * @apiParameter { * "name": "scope_id", * "description": "Scope ID", * "type": "integer", * "required": false, * "default": 0 * } * @return void */ public function sectionsTask() { $filters = array('scope' => Request::getWord('scope', 'site'), 'scope_id' => Request::getInt('scope_id', 0), 'state' => Section::STATE_PUBLISHED, 'access' => User::getAuthorisedViewLevels()); if ($filters['scope'] == 'group') { $group = \Hubzero\User\Group::getInstance($filters['scope_id']); if ($group && in_array(User::get('id'), $group->get('members'))) { $filters['access'][] = 5; // Private } } $model = new Manager($filters['scope'], $filters['scope_id']); $response = new stdClass(); $response->sections = array(); $sections = $model->sections(array('state' => $filters['state'], 'access' => User::getAuthorisedViewLevels()))->ordered()->rows(); $response->total = $sections->count(); if ($response->total) { $base = rtrim(Request::base(), '/'); foreach ($sections as $section) { $obj = new stdClass(); $obj->id = $section->get('id'); $obj->title = $section->get('title'); $obj->alias = $section->get('alias'); $obj->created = with(new Date($section->get('created')))->format('Y-m-d\\TH:i:s\\Z'); $obj->scope = $section->get('scope'); $obj->scope_id = $section->get('scope_id'); $obj->categories = $section->categories()->whereEquals('state', $filters['state'])->whereIn('access', $filters['access'])->total(); $obj->url = str_replace('/api', '', $base . '/' . ltrim(Route::url($section->link('base')), '/')); $response->sections[] = $obj; } } $response->success = true; $this->send($response); }