/** * Saves changes to the tag list on a resource * Redirects back to main resource listing * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $id = Request::getInt('id', 0); $entered = Request::getVar('tags', ''); $selected = Request::getVar('tgs', array(0)); // Process tags $tagging = new TagCloud($id); $tagArray = $tagging->parseTags($entered); $tagArray2 = $tagging->parseTags($entered, 1); $diffTags = array_diff($tagArray, $selected); foreach ($diffTags as $diffed) { array_push($selected, $tagArray2[$diffed]); } $tags = implode(',', $selected); $tagging->setTags($tags, User::get('id'), 1); // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=items', false), Lang::txt('COM_RESOURCES_TAGS_UPDATED', $id)); }
/** * Browse entries * * @return void */ public function browseTask() { // Set the default sort $default_sort = 'date'; if ($this->config->get('show_ranking')) { $default_sort = 'ranking'; } // Incoming $this->view->filters = array('type' => Request::getVar('type', ''), 'sortby' => Request::getCmd('sortby', $default_sort), 'limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'tag' => trim(Request::getVar('tag', '', 'request', 'none', 2)), 'tag_ignored' => array()); if (!in_array($this->view->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.', $this->view->filters['sortby'])); } if (isset($this->view->filters['tag']) && $this->view->filters['tag'] != '') { include_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'tags.php'; $tagging = new Tags(0); $tags = $tagging->parseTags($this->view->filters['tag']); if (count($tags) > 5) { $keep = array(); foreach ($tags as $i => $tag) { if ($i < 5) { $keep[] = $tag; } else { $this->view->filters['tag_ignored'][] = $tag; } } $this->view->filters['tag'] = implode(',', $keep); } } // Determine if user can edit $this->view->authorized = $this->_authorize(); // Get major types $t = new Type($this->database); $this->view->types = $t->getMajorTypes(); if (!is_numeric($this->view->filters['type'])) { // Normalize the title // This is so we can determine the type of resource to display from the URL // For example, /resources/learningmodules => Learning Modules for ($i = 0; $i < count($this->view->types); $i++) { $normalized = $this->view->types[$i]->alias ? $this->view->types[$i]->alias : $t->normalize($this->view->types[$i]->type); if (trim($this->view->filters['type']) == $normalized) { $this->view->filters['type'] = $this->view->types[$i]->id; break; } } } // Instantiate a resource object $rr = new Resource($this->database); // Execute count query $results = $rr->getCount($this->view->filters); $this->view->total = $results && is_array($results) ? count($results) : 0; // Run query with limit $this->view->results = $rr->getRecords($this->view->filters); // Get type if not given $this->_title = Lang::txt(strtoupper($this->_option)) . ': '; if ($this->view->filters['type'] != '') { $t->load($t->normalize($this->view->filters['type'])); $this->_title .= $t->type; $this->_task_title = $t->type; } else { $this->_title .= Lang::txt('COM_RESOURCES_ALL'); $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; $this->view->config = $this->config; foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->setName('browse')->setLayout('default')->display(); }
/** * Saves changes to the tag list on a resource * Redirects back to main resource listing * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $id = Request::getInt('id', 0); $entered = Request::getVar('tags', ''); $selected = Request::getVar('tgs', array(0)); // Process tags $tagging = new TagCloud($id); $tagArray = $tagging->parseTags($entered); $tagArray2 = $tagging->parseTags($entered, 1); $diffTags = array_diff($tagArray, $selected); foreach ($diffTags as $diffed) { array_push($selected, $tagArray2[$diffed]); } $tags = implode(',', $selected); $tagging->setTags($tags, User::get('id'), 1); Notify::success(Lang::txt('COM_RESOURCES_TAGS_UPDATED', $id)); // Redirect $this->cancelTask(); }