/** * Display all categories in a section * * @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'), 'group' => Request::getState($this->_option . '.' . $this->_controller . '.group', 'group', -1, 'int'), 'section_id' => Request::getState($this->_option . '.' . $this->_controller . '.section_id', 'section_id', -1, '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; } $this->view->filters['admin'] = true; // Load the current section $this->view->section = new Section($this->database); if (!$this->view->filters['section_id'] || $this->view->filters['section_id'] <= 0) { // No section? Load a default blank section $this->view->section->loadDefault(); } else { $this->view->section->load($this->view->filters['section_id']); } $this->view->sections = array(); if ($this->view->filters['scopeinfo']) { $this->view->sections = $this->view->section->getRecords(array('scope' => $this->view->filters['scope'], 'scope_id' => $this->view->filters['scope_id'], 'sort' => 'title', 'sort_Dir' => 'ASC')); } $model = new Category($this->database); // Get a record count $this->view->total = $model->getCount($this->view->filters); // Get records $this->view->results = $model->getRecords($this->view->filters); $this->view->forum = new Manager($this->view->filters['scope'], $this->view->filters['scope_id']); // Output the HTML $this->view->display(); }
/** * Deletes one or more records and redirects to listing * * @return void */ public function removeTask() { // Check for request forgeries Request::checkToken(); // Incoming $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; // Do we have any IDs? if (count($ids) > 0) { // Loop through each ID foreach ($ids as $id) { $id = intval($id); $section = new Tables\Section($this->database); $section->load($id); // Get the categories in this section $cModel = new Tables\Category($this->database); $categories = $cModel->getRecords(array('section_id' => $section->id)); // Loop through each category foreach ($categories as $category) { // Remove the posts in this category $tModel = new Tables\Post($this->database); if (!$tModel->deleteByCategory($category->id)) { throw new Exception($tModel->getError(), 500); } // Remove this category if (!$cModel->delete($category->id)) { throw new Exception($cModel->getError(), 500); } } // Remove this section if (!$section->delete()) { throw new Exception($section->getError(), 500); } } } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '§ion_id=' . Request::getInt('section_id', 0), false), Lang::txt('COM_FORUM_SECTIONS_DELETED')); }
/** * Get a count or list of categories * * @param string $rtrn Data type to return? * @param array $filters Filters to apply to query * @param boolean $clear Clear cached data? * @return mixed */ public function categories($rtrn = '', $filters = array(), $clear = false) { $filters['section_id'] = isset($filters['section_id']) ? $filters['section_id'] : (int) $this->get('id'); $filters['state'] = isset($filters['state']) ? $filters['state'] : self::APP_STATE_PUBLISHED; $filters['scope'] = isset($filters['scope']) ? $filters['scope'] : (string) $this->get('scope'); $filters['scope_id'] = isset($filters['scope_id']) ? $filters['scope_id'] : (int) $this->get('scope_id'); switch (strtolower($rtrn)) { case 'count': if (!isset($this->_cache['categories_count']) || $clear) { $tbl = new Tables\Category($this->_db); $this->_cache['categories_count'] = (int) $tbl->getCount($filters); } return $this->_cache['categories_count']; break; case 'first': return $this->categories('list', $filters)->first(); break; case 'list': case 'results': default: if (!$this->_cache['categories'] instanceof ItemList || $clear) { $tbl = new Tables\Category($this->_db); if ($results = $tbl->getRecords($filters)) { foreach ($results as $key => $result) { $results[$key] = new Category($result, $this->get('id'), $this->get('scope'), $this->get('group_id')); $results[$key]->set('section_alias', $this->get('alias')); } } else { $results = array(); } $this->_cache['categories'] = new ItemList($results); } return $this->_cache['categories']; break; } }