/** * 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; }
/** * Build a database query * * @param array $filters Options for building the query * @return string SQL */ private function _buildPluginQuery($filters = array()) { $database = App::get('db'); include_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'category.php'; $rt = new \Components\Publications\Tables\Category($database); if (isset($filters['select']) && $filters['select'] == 'count') { if (isset($filters['tags'])) { $query = "SELECT count(f.id) FROM (SELECT r.id, COUNT(DISTINCT t.tagid) AS uniques "; } else { $query = "SELECT count(DISTINCT r.id) "; } } else { $query = "SELECT DISTINCT r.id, V.title, V.version_number as alias,\n\t\t\t\t\tV.abstract as itext, V.id as ftext, V.state AS state, V.created, V.created_by,\n\t\t\t\t\tV.modified, V.published_up as publish_up, V.published_down as publish_down,\n\t\t\t\t\tCONCAT('index.php?option=com_publications&id=', r.id) AS href, 'publications' AS section "; if (isset($filters['tags'])) { $query .= ", COUNT(DISTINCT t.tagid) AS uniques "; } $query .= ", V.params, r.rating AS rcount, r.category AS data1, rt.name AS data2, r.ranking data3 "; } $query .= "FROM #__publication_versions as V, #__publications AS r "; $query .= "LEFT JOIN " . $rt->getTableName() . " AS rt ON r.category=rt.id"; if (isset($filters['tag'])) { $query .= ", #__tags_object AS t, #__tags AS tg "; } if (isset($filters['tags'])) { $query .= ", #__tags_object AS t "; } $query .= "WHERE V.publication_id=r.id AND V.state=1 AND V.main = 1 "; if (isset($filters['tag'])) { $query .= "AND t.objectid=r.id AND t.tbl='publications' AND t.tagid=tg.id AND (tg.tag='" . $filters['tag'] . "' OR tg.alias='" . $filters['tag'] . "') "; } if (isset($filters['tags'])) { $ids = implode(',', $filters['tags']); $query .= "AND t.objectid=r.id AND t.tbl='publications' AND t.tagid IN (" . $ids . ") "; } if (isset($filters['category']) && $filters['category'] != '') { $query .= "AND r.category=" . $filters['category'] . " "; } if (isset($filters['tags'])) { $query .= " GROUP BY r.id HAVING uniques=" . count($filters['tags']) . " "; } if (isset($filters['select']) && $filters['select'] != 'count') { if (isset($filters['sortby'])) { if (isset($filters['groupby'])) { $query .= "GROUP BY r.id "; } $query .= "ORDER BY "; switch ($filters['sortby']) { case 'title': $query .= 'title ASC, publish_up DESC'; break; case 'rating': $query .= "rating DESC, times_rated DESC"; break; case 'ranking': $query .= "ranking DESC"; break; case 'relevance': $query .= "relevance DESC"; break; case 'users': case 'usage': $query .= "users DESC"; break; case 'jobs': $query .= "jobs DESC"; break; case 'date': default: $query .= 'publish_up DESC'; break; } } if (isset($filters['limit']) && $filters['limit'] != 'all') { $query .= " LIMIT " . $filters['limitstart'] . "," . $filters['limit']; } } if (isset($filters['select']) && $filters['select'] == 'count') { if (isset($filters['tags'])) { $query .= ") AS f"; } } return $query; }
/** * Change status * Redirects to list * * @return void */ public function changestatusTask($dir = 0) { // Check for request forgeries Request::checkToken(); // Incoming $ids = Request::getVar('id', array(0), '', 'array'); // Initialize $row = new \Components\Publications\Tables\Category($this->database); foreach ($ids as $id) { if (intval($id)) { // Load row $row->load($id); $row->state = $row->state == 1 ? 0 : 1; // Save if (!$row->store()) { $this->addComponentMessage($row->getError(), 'error'); App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); return; } } } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_PUBLICATIONS_CATEGORY_ITEM_STATUS_CHNAGED')); }
/** * 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(); }
/** * Provision a new publication draft * * @return object */ public function createDraft() { // Incoming $base = Request::getVar('base', 'files'); // Check permission if ($this->model->exists() && !$this->model->access('content')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } // Load publication & version classes $objP = new \Components\Publications\Tables\Publication($this->_database); $objC = new \Components\Publications\Tables\Category($this->_database); $mt = new \Components\Publications\Tables\MasterType($this->_database); // Determine publication master type $choices = $mt->getTypes('alias', 1); if (count($choices) == 1) { $base = $choices[0]; } // Default to file type $mastertype = in_array($base, $choices) ? $base : 'files'; // Need to provision a project if (!$this->model->exists()) { $alias = 'pub-' . strtolower(\Components\Projects\Helpers\Html::generateCode(10, 10, 0, 1, 1)); $this->model->set('provisioned', 1); $this->model->set('alias', $alias); $this->model->set('title', $alias); $this->model->set('type', 2); // publication $this->model->set('state', 1); $this->model->set('setup_stage', 3); $this->model->set('created', Date::toSql()); $this->model->set('created_by_user', $this->_uid); $this->model->set('owned_by_user', $this->_uid); $this->model->set('params', $this->model->type()->params); // Save changes if (!$this->model->store()) { throw new Exception($this->model->getError()); return false; } } // Get type params $mType = $mt->getType($mastertype); // Make sure we got type info if (!$mType) { throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_LOAD_TYPE')); return false; } // Get curation model for the type $curationModel = new \Components\Publications\Models\Curation($mType->curation); // Get default category from manifest $cat = isset($curationModel->_manifest->params->default_category) ? $curationModel->_manifest->params->default_category : 1; if (!$objC->load($cat)) { $cat = 1; } // Get default title from manifest $title = isset($curationModel->_manifest->params->default_title) ? $curationModel->_manifest->params->default_title : Lang::txt('Untitled Draft'); // Make a new publication entry $objP->master_type = $mType->id; $objP->category = $cat; $objP->project_id = $this->model->get('id'); $objP->created_by = $this->_uid; $objP->created = Date::toSql(); $objP->access = 0; if (!$objP->store()) { throw new Exception($objP->getError()); return false; } if (!$objP->id) { $objP->checkin(); } $this->_pid = $objP->id; // Initizalize Git repo and transfer files from member dir if ($this->model->isProvisioned()) { if (!$this->_prepDir()) { // Roll back $this->model->delete(); $objP->delete(); throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_FAILED_INI_GIT_REPO')); return false; } else { // Add creator as project owner $objO = $this->model->table('Owner'); if (!$objO->saveOwners($this->model->get('id'), $this->_uid, $this->_uid, 0, 1, 1, 1)) { throw new Exception(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError()); return false; } } } // Make a new dev version entry $row = new \Components\Publications\Tables\Version($this->_database); $row->publication_id = $this->_pid; $row->title = $row->getDefaultTitle($this->model->get('id'), $title); $row->state = 3; // dev $row->main = 1; $row->created_by = $this->_uid; $row->created = Date::toSql(); $row->version_number = 1; $row->license_type = 0; $row->access = 0; $row->secret = strtolower(\Components\Projects\Helpers\Html::generateCode(10, 10, 0, 1, 1)); if (!$row->store()) { // Roll back $objP->delete(); throw new Exception($row->getError(), 500); return false; } if (!$row->id) { $row->checkin(); } // Models\Publication $pub = new \Components\Publications\Models\Publication($this->_pid, 'dev'); // Record action, notify team $this->onAfterCreate($pub); // Return publication object return $pub; }
/** * 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(); }