/** * Browse resources by tags * * @return void */ public function browsetagsTask() { // Check if we're using this view type if ($this->config->get('browsetags') == 'off') { return $this->browseTask(); } // Incoming $this->view->tag = preg_replace("/[^a-zA-Z0-9]/", '', strtolower(Request::getVar('tag', ''))); $this->view->tag2 = preg_replace("/[^a-zA-Z0-9]/", '', strtolower(Request::getVar('with', ''))); $this->view->type = strtolower(Request::getVar('type', 'tools')); // default tag in tag browser is config var $this->view->supportedtag = $this->config->get('supportedtag'); $this->view->supportedtag_default = $this->config->get('browsetags_defaulttag', ''); if (!$this->view->tag && $this->view->supportedtag_default != '' && $this->view->type == 'tools') { $this->view->tag = $this->view->supportedtag_default; } // Get major types $t = new Type($this->database); $this->view->types = $t->getMajorTypes(); // Normalize the title // This is so we can determine the type of resource to display from the URL // For example, /resources/learningmodules => Learning Modules $activetype = 0; $activetitle = ''; for ($i = 0; $i < count($this->view->types); $i++) { if (trim($this->view->type) == $this->view->types[$i]->alias) { $activetype = $this->view->types[$i]->id; $activetitle = $this->view->types[$i]->type; } } asort($this->view->types); // Ensure we have a type to display if (!$activetype) { $this->_redirect = Route::url('index.php?option=' . $this->_option); return; } // Instantiate a resource object $rr = new Resource($this->database); // Determine if user can edit $this->view->authorized = $this->_authorize(); // Set the default sort $default_sort = 'rating'; if ($this->config->get('show_ranking')) { $default_sort = 'ranking'; } // Set some filters $this->view->filters = array('tag' => $this->view->tag2 ? $this->view->tag2 : '', 'type' => $activetype, 'sortby' => $default_sort, 'limit' => 10, 'start' => 0); // Run query with limit $this->view->results = $rr->getRecords($this->view->filters); $this->type = $this->view->type; if ($activetitle) { $this->_task_title = $activetitle; } else { $this->_task_title = Lang::txt('COM_RESOURCES_ALL'); } // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Output HTML $this->view->title = $this->_title; foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->config = $this->config; $this->view->setName('browse')->setLayout('tags')->display(); }
/** * Get a list of resources * * @apiMethod GET * @apiUri /resources/list * @apiParameter { * "name": "limit", * "description": "Number of result to return.", * "type": "integer", * "required": false, * "default": 25 * } * @apiParameter { * "name": "start", * "description": "Number of where to start returning results.", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "type", * "description": "Type of resource to filter results.", * "type": "string", * "required": false, * "default": "" * } * @apiParameter { * "name": "sortby", * "description": "Value to sort results by.", * "type": "string", * "required": false, * "default": "date", * "allowedValues": "date, title, random" * } * @apiParameter { * "name": "search", * "description": "A word or phrase to search for.", * "type": "string", * "required": false, * "default": "" * } * @return void */ public function listTask() { // Incoming $filters = array('type' => Request::getVar('type', ''), 'sortby' => Request::getCmd('sortby', 'date'), 'limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', '')); if (!in_array($filters['sortby'], array('date', 'date_published', 'date_created', 'date_modified', 'title', 'rating', 'ranking', 'random'))) { App::abort(404, Lang::txt('Invalid sort value of "%s" used.', $filters['sortby'])); } require_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php'; require_once Component::path('com_resources') . DS . 'tables' . DS . 'type.php'; $database = App::get('db'); // Instantiate a resource object $rr = new Resource($database); // encode results and return response $response = new stdClass(); $response->records = array(); $response->total = $rr->getCount($filters); if ($response->total) { // Get major types $t = new Type($database); $types = array(); foreach ($t->getMajorTypes() as $type) { unset($type->params); unset($type->customFields); $types[$type->id] = $type; } $response->records = $rr->getRecords($filters); $base = rtrim(Request::base(), '/'); foreach ($response->records as $i => $entry) { $entry->url = str_replace('/api', '', $base . '/' . ltrim(Route::url('index.php?option=com_resources&' . ($entry->alias ? 'alias=' . $entry->alias : 'id=' . $entry->id)), '/')); if (isset($types[$entry->type])) { $entry->type = $types[$entry->type]; } $response->records[$i] = $entry; } } $response->success = true; $this->send($response); }