/** * Display all categories in a section * * @return void */ public function displayTask() { // Filters $filters = array('state' => Request::getState($this->_option . '.' . $this->_controller . '.state', 'state', -1, 'int'), 'access' => Request::getState($this->_option . '.' . $this->_controller . '.access', 'access', -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'), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''), 'scopeinfo' => Request::getState($this->_option . '.' . $this->_controller . '.scopeinfo', 'scopeinfo', '')); if (strstr($filters['scopeinfo'], ':')) { $bits = explode(':', $filters['scopeinfo']); $filters['scope'] = $bits[0]; $filters['scope_id'] = intval(end($bits)); } else { $filters['scope'] = ''; $filters['scope_id'] = -1; } $filters['admin'] = true; // Load the current section if (!$filters['section_id'] || $filters['section_id'] <= 0) { // No section? Load a default blank section $section = Section::blank(); } else { $section = Section::oneOrFail($filters['section_id']); $filters['scope'] = $section->get('scope'); $filters['scope_id'] = $section->get('scope_id'); $filters['scopeinfo'] = $filters['scope'] . ':' . $filters['scope_id']; } $sections = array(); if ($filters['scope_id'] >= 0) { $sections = Section::all()->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id'])->ordered('title', 'ASC')->rows(); } $entries = Category::all()->including(['posts', function ($post) { $post->select('id')->select('category_id'); }]); if ($filters['search']) { $entries->whereLike('title', strtolower((string) $filters['search'])); } if ($filters['scope']) { $entries->whereEquals('scope', $filters['scope']); } if ($filters['scope_id'] >= 0) { $entries->whereEquals('scope_id', (int) $filters['scope_id']); } if ($filters['state'] >= 0) { $entries->whereEquals('state', (int) $filters['state']); } if ($filters['access'] >= 0) { $entries->whereEquals('access', (int) $filters['access']); } if ($filters['section_id'] > 0) { $entries->whereEquals('section_id', (int) $filters['section_id']); } // Get records $rows = $entries->ordered('filter_order', 'filter_order_Dir')->paginated('limitstart', 'limit')->rows(); $forum = new Manager($filters['scope'], $filters['scope_id']); // Output the HTML $this->view->set('rows', $rows)->set('filters', $filters)->set('section', $section)->set('sections', $sections)->set('scopes', $forum->scopes())->display(); }
/** * Search threads and display a list of results * * @return void */ public function searchTask() { // Incoming $filters = array('scope' => $this->forum->get('scope'), 'scope_id' => $this->forum->get('scope_id'), 'state' => Category::STATE_PUBLISHED, 'access' => User::getAuthorisedViewLevels()); $section = Section::blank(); $section->set('scope', $this->forum->get('scope')); $section->set('title', Lang::txt('COM_FORUM_POSTS')); $section->set('alias', str_replace(' ', '-', $section->get('title'))); $section->set('alias', preg_replace("/[^a-zA-Z0-9\\-]/", '', strtolower($section->get('title')))); // Get all sections $sections = array(); foreach ($this->forum->sections($filters)->rows() as $section) { $sections[$section->get('id')] = $section; } $category = Category::blank(); $category->set('scope', $this->forum->get('scope')); $category->set('scope_id', $this->forum->get('scope_id')); $category->set('title', Lang::txt('COM_FORUM_SEARCH')); $category->set('alias', str_replace(' ', '-', $category->get('title'))); $category->set('alias', preg_replace("/[^a-zA-Z0-9\\-]/", '', strtolower($category->get('title')))); $categories = array(); foreach ($this->forum->categories($filters)->rows() as $category) { $categories[$category->get('id')] = $category; } $filters['search'] = Request::getVar('q', ''); if (!$filters['search']) { App::redirect(Route::url('index.php?option=' . $this->_option)); } // Get authorization $this->_authorize('category'); $this->_authorize('thread'); // Set the page title $this->buildTitle($section, $category); // Set the pathway $this->buildPathway($section, $category); $this->view->set('config', $this->config)->set('forum', $this->forum)->set('sections', $sections)->set('categories', $categories)->set('filters', $filters)->display(); }
/** * Get all available scopes * * @return array */ public function scopes() { $section = Section::blank(); $db = \App::get('db'); $db->setQuery("\n\t\t\tSELECT DISTINCT s.scope, s.scope_id\n\t\t\tFROM " . $section->getTableName() . " AS s\n\t\t\tORDER BY s.scope, s.scope_id\n\t\t"); $results = $db->loadObjectList(); if (!$results || !is_array($results)) { $results = array(); } $scope = $this->get('scope'); $scope_id = $this->get('scope_id'); foreach ($results as $i => $result) { $this->set('scope', $result->scope); $this->set('scope_id', $result->scope_id); $results[$i]->caption = $this->adapter()->name(); } $this->set('scope', $scope); $this->set('scope_id', $scope_id); return $results; }
/** * Search forum entries and display results * * @return string */ public function search() { // Incoming $filters = array('limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('q', ''), 'scope' => $this->forum->get('scope'), 'scope_id' => $this->forum->get('scope_id'), 'state' => 1, 'access' => array(1)); if (!$filters['search']) { return $this->sections(); } if (!User::isGuest()) { $filters['access'][] = 2; $filters['access'][] = 4; } if (in_array(User::get('id'), $this->members)) { $filters['access'][] = 5; } $section = Section::blank(); $section->set('scope', $this->forum->get('scope')); $section->set('title', Lang::txt('PLG_GROUPS_FORUM_POSTS')); $section->set('alias', str_replace(' ', '-', $section->get('title'))); $section->set('alias', preg_replace("/[^a-zA-Z0-9\\-]/", '', strtolower($section->get('title')))); // Get all sections $sections = array(); foreach ($this->forum->sections($filters)->rows() as $section) { $sections[$section->get('id')] = $section; } $category = Category::blank(); $category->set('scope', $this->forum->get('scope')); $category->set('scope_id', $this->forum->get('scope_id')); $category->set('title', Lang::txt('PLG_GROUPS_FORUM_SEARCH')); $category->set('alias', str_replace(' ', '-', $category->get('title'))); $category->set('alias', preg_replace("/[^a-zA-Z0-9\\-]/", '', strtolower($category->get('title')))); $categories = array(); foreach ($this->forum->categories($filters)->rows() as $category) { $categories[$category->get('id')] = $category; } $filters['search'] = Request::getVar('q', ''); //get authorization $this->_authorize('category'); $this->_authorize('thread'); return $this->view('search', 'categories')->set('option', $this->option)->set('group', $this->group)->set('config', $this->params)->set('forum', $this->forum)->set('sections', $sections)->set('categories', $categories)->set('filters', $filters)->setErrors($this->getErrors())->loadTemplate(); }