/** * Method to get the field options for category * Use the extension attribute in a form to specify the.specific extension for * which categories should be displayed. * Use the show_root attribute to specify whether to show the global category root in the list. * * @return array The field option objects. */ protected function getOptions() { $options = array(); $options[] = Html::select('option', '0', Lang::txt('All')); include_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'category.php'; $db = App::get('db'); $sr = new \Components\Publications\Tables\Category($db); $types = $sr->getCategories(); foreach ($types as $anode) { $options[] = Html::select('option', $anode->id, stripslashes($anode->name)); } return $options; }
/** * List types * * @return void */ public function displayTask() { // Incoming $this->view->filters = array('limit' => Request::getState($this->_option . '.categories.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.categories.limitstart', 'limitstart', 0, 'int'), 'search' => Request::getState($this->_option . '.categories.search', 'search', ''), 'sort' => Request::getState($this->_option . '.categories.sort', 'filter_order', 'id'), 'sort_Dir' => Request::getState($this->_option . '.categories.sortdir', 'filter_order_Dir', 'ASC')); $this->view->filters['state'] = 'all'; // Instantiate an object $rt = new \Components\Publications\Tables\Category($this->database); // Get a record count $this->view->total = $rt->getCount($this->view->filters); // Get records $this->view->rows = $rt->getCategories($this->view->filters); // Set any errors if ($this->getError()) { $this->view->setError($this->getError()); } // Output the HTML $this->view->display(); }
/** * Retrieve records for items tagged with specific tags * * @param array $tags Tags to match records against * @param mixed $limit SQL record limit * @param integer $limitstart SQL record limit start * @param string $sort The field to sort records by * @param mixed $areas An array or string of areas that should retrieve records * @return mixed Returns integer when counting records, array when retrieving records */ public function onTagView($tags, $limit = 0, $limitstart = 0, $sort = '', $areas = null) { $response = array('name' => $this->_name, 'title' => Lang::txt('PLG_TAGS_PUBLICATIONS'), 'total' => 0, 'results' => null, 'sql' => '', 'children' => array()); $database = App::get('db'); $rt = new \Components\Publications\Tables\Category($database); foreach ($rt->getCategories() as $category) { $response['children'][$category->url_alias] = array('name' => $category->url_alias, 'title' => $category->name, 'total' => 0, 'results' => null, 'sql' => '', 'id' => $category->id); } if (empty($tags)) { return $response; } $ids = array(); foreach ($tags as $tag) { $ids[] = $tag->get('id'); } // Instantiate some needed objects $rr = new \Components\Publications\Tables\Publication($database); // Build query $filters = array(); $filters['tags'] = $ids; $filters['now'] = Date::toSql(); $filters['sortby'] = $sort ? $sort : 'ranking'; $filters['authorized'] = false; $filters['usergroups'] = \Hubzero\User\Helper::getGroups(User::get('id'), 'all'); $filters['select'] = 'count'; foreach ($response['children'] as $k => $t) { $filters['category'] = $t['id']; // Execute a count query for each area/category $database->setQuery($this->_buildPluginQuery($filters)); $response['children'][$k]['total'] = $database->loadResult(); $response['total'] += $response['children'][$k]['total']; } if ($areas && ($areas == $response['name'] || isset($response['children'][$areas]))) { $filters['select'] = 'records'; $filters['limit'] = $limit; $filters['limitstart'] = $limitstart; $filters['sortby'] = $sort ? $sort : 'date'; // Check the area of return. If we are returning results for a specific area/category // we'll need to modify the query a bit if (isset($response['children'][$areas])) { $filters['category'] = $response['children'][$areas]['id']; $database->setQuery($this->_buildPluginQuery($filters)); $response['children'][$areas]['results'] = $database->loadObjectList(); } else { unset($filters['category']); $database->setQuery($this->_buildPluginQuery($filters)); $response['results'] = $database->loadObjectList(); } } else { $filters['select'] = 'records'; $filters['limit'] = 'all'; $filters['limitstart'] = $limitstart; $filters['sortby'] = $sort ? $sort : 'date'; // Check the area of return. If we are returning results for a specific area/category // we'll need to modify the query a bit if (isset($response['children'][$areas])) { $filters['category'] = $response['children'][$areas]['id']; $response['children'][$key]['sql'] = $this->_buildPluginQuery($filters); } else { unset($filters['category']); $response['sql'] = $this->_buildPluginQuery($filters); } } return $response; }
/** * Edit a type * * @return void */ public function editTask($row = null) { $this->view->setLayout('curation'); if ($row) { $this->view->row = $row; } else { // Incoming (expecting an array) $id = Request::getVar('id', array(0)); if (is_array($id)) { $id = $id[0]; } else { $id = 0; } // Load the object $this->view->row = new \Components\Publications\Tables\MasterType($this->database); $this->view->row->load($id); $this->view->curation = new \Components\Publications\Models\Curation($this->view->row->curation); // Get blocks model $blocksModel = new \Components\Publications\Models\Blocks($this->database); // Get available blocks $this->view->blocks = $blocksModel->getBlocks('*', " WHERE status=1", " ORDER BY ordering, id"); } // Set any errors if ($this->getError()) { $this->view->setError($this->getError()); } $this->view->config = $this->config; // Get all active categories $objC = new \Components\Publications\Tables\Category($this->database); $this->view->cats = $objC->getCategories(); // Push some styles to the template Document::addStyleSheet('components' . DS . $this->_option . DS . 'assets' . DS . 'css' . DS . 'publications.css'); Document::addScript('components' . DS . $this->_option . DS . 'assets' . DS . 'js' . DS . 'curation.js'); // Output the HTML $this->view->display(); }
/** * Sets the fields in this class with database data. * * @return boolean True if succss and False otherwise */ private function populateRDFData() { // Grabs database object $database = \App::get('db'); $resource = new \Components\Publications\Tables\Version($database); $resource = $resource->getLastPubRelease($this->id); if (!$resource) { // Return if ID does not exist throw new Exception(Lang::txt('COM_PUBLICATIONS_FILE_NOT_FOUND'), 404); return false; } $this->setPaths(); // Gets the author name $this->author_id = $resource->created_by; $this->created_by = User::getInstance($this->author_id)->name; // Set created date $this->date_created = $this->formatDate($resource->created); // Set description $this->intro = $resource->description; // Set title $this->title = $resource->title; // Set last modified date $this->date_modified = $this->formatDate($resource->modified); // Set published date $this->date_published = $this->formatDate($resource->published_up); // Set version ID $this->version_id = $resource->id; // Load the $types variable. In the form of array([type_id] => [type_name]). $resource = new \Components\Publications\Tables\Publication($database); $pub = $resource->getPublication($this->id); $type_id = $pub->category; $typesData = new \Components\Publications\Tables\Category($database); $allTypes = $typesData->getCategories(array('state' => 'all')); $this->types = array(); foreach ($allTypes as $type) { $types[$type->id] = $type->name; } // Get the type name of this resource $this->type = $types[$type_id]; // Get attachments $pubAttach = new \Components\Publications\Tables\Attachment($database); $attachments = $pubAttach->getAttachments($this->version_id); foreach ($attachments as $child) { $this->aggregates[$child->id]['parent_id'] = $this->id; $this->aggregates[$child->id]['title'] = basename($child->path); $this->aggregates[$child->id]['created'] = $this->formatDate($child->created); $this->aggregates[$child->id]['standalone'] = 0; $this->aggregates[$child->id]['path'] = $child->path; $this->aggregates[$child->id]['url'] = $this->componentURL . $this->id . '/serve?a=' . $child->id; } return true; }
/** * Parse the segments of a URL. * * @param array &$segments The segments of the URL to parse. * @return array The URL attributes to be used by the application. */ public function parse(&$segments) { $vars = array(); // Valid tasks not requiring id $tasks = array('browse', 'start', 'submit', 'edit', 'publication'); if (empty($segments[0])) { return $vars; } if (!empty($segments[0]) && $segments[0] == 'curation') { $vars['controller'] = 'curation'; if (!empty($segments[1]) && is_numeric($segments[1])) { $vars['id'] = $segments[1]; if (!empty($segments[2])) { $vars['task'] = $segments[2]; } else { $vars['task'] = 'view'; } } return $vars; } if (is_numeric($segments[0])) { $vars['task'] = 'view'; $vars['id'] = $segments[0]; if (!empty($segments[1])) { if (is_numeric($segments[1]) || $segments[1] == 'dev' || $segments[1] == 'default') { $vars['v'] = $segments[1]; } } } elseif (isset($segments[1]) && $segments[1] == 'submit') { // Links within projects publications plugin $vars['task'] = 'submit'; $vars['active'] = $segments[0]; if (!empty($segments[2]) && is_numeric($segments[2])) { $vars['pid'] = $segments[2]; } return $vars; } elseif (in_array($segments[0], $tasks)) { $vars['task'] = $segments[0]; if (!empty($segments[1])) { if (is_numeric($segments[1])) { $vars['pid'] = $segments[1]; } } } else { include_once dirname(__DIR__) . DS . 'tables' . DS . 'category.php'; $database = \App::get('db'); $t = new \Components\Publications\Tables\Category($database); $cats = $t->getCategories(); foreach ($cats as $cat) { if (trim($segments[0]) == $cat->url_alias) { $vars['category'] = $segments[0]; $vars['task'] = 'browse'; } } if (!isset($vars['category'])) { $vars['alias'] = $segments[0]; $vars['task'] = 'view'; } } if (!empty($segments[1])) { switch ($segments[1]) { case 'edit': $vars['task'] = 'edit'; if (is_numeric($segments[0])) { $vars['pid'] = $segments[0]; $vars['id'] = ''; } break; case 'download': case 'wiki': case 'play': case 'serve': case 'video': $vars['task'] = $segments[1]; if (!empty($segments[2])) { $vars['v'] = $segments[2]; } if (!empty($segments[3])) { $vars['a'] = $segments[3]; } break; case 'citation': $vars['task'] = 'citation'; break; case 'feed.rss': $vars['task'] = 'feed'; break; case 'feed': $vars['task'] = 'feed'; break; case 'license': $vars['task'] = 'license'; break; case 'main': $vars['task'] = 'main'; break; default: if ($segments[0] == 'browse') { $vars['category'] = $segments[1]; } else { $vars['active'] = $segments[1]; if ($vars['active'] == 'share' && !empty($segments[2])) { $vars['v'] = $segments[2]; } } break; } } // are we serving up a file $uri = Request::getVar('REQUEST_URI', '', 'server'); if (strstr($uri, 'Image:') || strstr($uri, 'File:')) { $vars['task'] = 'download'; $vars['controller'] = 'media'; } return $vars; }
/** * Edit a type * * @param object $row * @return void */ public function editTask($row = null) { Request::setVar('hidemainmenu', 1); $database = App::get('db'); if (!is_object($row)) { // Incoming (expecting an array) $id = Request::getVar('id', array(0)); $id = is_array($id) ? $id[0] : $id; // Load the object $row = new \Components\Publications\Tables\MasterType($database); $row->load($id); } $this->view->row = $row; $this->view->curation = new \Components\Publications\Models\Curation($this->view->row->curation); // Get blocks model $blocksModel = new \Components\Publications\Models\Blocks($database); // Get available blocks $this->view->blocks = $blocksModel->getBlocks('*', " WHERE status=1", " ORDER BY ordering, id"); // Set any errors if ($this->getError()) { $this->view->setError($this->getError()); } $this->view->config = $this->config; // Get all active categories $objC = new \Components\Publications\Tables\Category($database); $this->view->cats = $objC->getCategories(); // Output the HTML $this->view->setLayout('curation')->display(); }