/** * Display publications user authors * * @apiMethod GET * @apiUri /publications/list * @apiParameter { * "name": "limit", * "description": "Number of result to return.", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "start", * "description": "Number of where to start returning results.", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "sort", * "description": "Field to sort results by.", * "type": "string", * "required": false, * "default": "title", * "allowedValues": "title, created, alias" * } * @apiParameter { * "name": "sort_Dir", * "description": "Direction to sort results by.", * "type": "string", * "required": false, * "default": "desc", * "allowedValues": "asc, desc" * } * @return void */ public function listTask() { $model = new Publication(); Lang::load('plg_projects_publications', PATH_CORE . DS . 'plugins' . DS . 'projects' . DS . 'publications'); // Set filters $filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('start', 0), 'sortby' => Request::getWord('sort', 'title'), 'sortdir' => strtoupper(Request::getWord('sort_Dir', 'ASC')), 'author' => User::get('id')); $response = new stdClass(); $response->publications = array(); $response->total = $model->entries('count', $filters); $database = \App::get('db'); $pa = new \Components\Publications\Tables\Author($database); if ($response->total) { $base = rtrim(Request::base(), '/'); foreach ($model->entries('list', $filters) as $i => $entry) { $obj = new stdClass(); $obj->id = $entry->get('id'); $obj->alias = $entry->get('alias'); $obj->title = $entry->get('title'); $obj->abstract = $entry->get('abstract'); $obj->creator = $entry->creator('name'); $obj->created = $entry->get('created'); $obj->published = $entry->published('date'); $obj->masterType = $entry->masterType()->type; $obj->category = $entry->category()->name; $obj->version = $entry->get('version_number'); $obj->versionLabel = $entry->get('version_label'); $obj->status = $entry->get('state'); $obj->statusName = $entry->getStatusName(); $obj->authors = $pa->getAuthors($entry->get('version_id')); $obj->thumbUrl = str_replace('/api', '', $base . '/' . ltrim(Route::url($entry->link('thumb')), '/')); $obj->uri = str_replace('/api', '', $base . '/' . ltrim(Route::url($entry->link('version')), '/')); $obj->manageUri = str_replace('/api', '', $base . '/' . ltrim(Route::url($entry->link('editversion')), '/')); $obj->project = $entry->project()->get('alias'); $response->publications[] = $obj; } } $this->send($response); }
/** * Browse publications * * @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('category' => Request::getVar('category', ''), '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', 'title', 'id', 'rating', 'ranking', 'popularity'))) { $this->view->filters['sortby'] = $default_sort; } // Get projects user has access to if (!User::isGuest()) { $obj = new \Components\Projects\Tables\Project($this->database); $this->view->filters['projects'] = $obj->getUserProjectIds(User::get('id')); } // Get major types $t = new Tables\Category($this->database); $this->view->categories = $t->getCategories(); if (is_numeric($this->view->filters['category'])) { $this->view->filters['category'] = (int) $this->view->filters['category']; } if (!is_int($this->view->filters['category'])) { foreach ($this->view->categories as $cat) { if (trim($this->view->filters['category']) == $cat->url_alias) { $this->view->filters['category'] = (int) $cat->id; break; } } if (!is_int($this->view->filters['category'])) { $this->view->filters['category'] = null; } } // Instantiate a publication object $model = new Models\Publication(); // Execute count query $this->view->total = $model->entries('count', $this->view->filters); // Run query with limit $this->view->results = $model->entries('list', $this->view->filters); // Initiate paging $this->view->pageNav = new \Hubzero\Pagination\Paginator($this->view->total, $this->view->filters['start'], $this->view->filters['limit']); // Get type if not given $this->_title = Lang::txt(strtoupper($this->_option)) . ': '; if ($this->view->filters['category'] != '') { $t->load($this->view->filters['category']); $this->_title .= $t->name; $this->_task_title = $t->name; } else { $this->_title .= Lang::txt('COM_PUBLICATIONS_ALL'); $this->_task_title = Lang::txt('COM_PUBLICATIONS_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(); }
/** * Produces archival package for publication * Redirects to edit task for the resource * * @return void */ public function archiveTask() { // Incoming $pid = Request::getInt('pid', 0); $vid = Request::getInt('vid', 0); $version = Request::getVar('version', 'default'); // Load publication $pub = new Models\Publication($pid, $version, $vid); if (!$pub->exists()) { throw new Exception(Lang::txt('COM_PUBLICATIONS_NOT_FOUND'), 404); } $url = Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=edit' . '&id[]=' . $pid . '&version=' . $version, false); // Get attachments $pub->attachments(); // Get authors $pub->authors(); // Set pub assoc and load curation $pub->setCuration(); // Produce archival package if (!$pub->_curationModel->package()) { // Checkin the resource $pub->publication->checkin(); // Redirect App::redirect($url, Lang::txt('COM_PUBLICATIONS_ERROR_ARCHIVAL'), 'error'); return; } // Checkin the resource $pub->publication->checkin(); // Redirect App::redirect($url, Lang::txt('COM_PUBLICATIONS_SUCCESS_ARCHIVAL')); }