/** * Determine if user is part of publication project and is allowed to edit citation * * @param array $assocs * @return void */ public function isPubAuthor($assocs) { if (!$assocs) { return false; } if (!is_file(PATH_ROOT . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'publication.php')) { return false; } require_once PATH_ROOT . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'publication.php'; require_once PATH_ROOT . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'owner.php'; // Get connections to publications foreach ($assocs as $entry) { if ($entry->tbl == 'publication') { $pubID = $entry->oid; $objP = new \Components\Publications\Tables\Publication($this->database); if ($objP->load($pubID)) { $objO = new \ProjectOwner($this->database); if ($objO->isOwner(User::get('id'), $objP->project_id)) { return true; } } } } return false; }
/** * Delete a citation from a publication * * @return string */ public function deleteCitation() { // Incoming $cid = Request::getInt('cid', 0); $version = Request::getVar('version', 'dev'); $pid = Request::getInt('pid', 0); if (!$cid || !$pid) { $this->setError(Lang::txt('PLG_PROJECTS_LINKS_ERROR_CITATION_DELETE')); } // Make sure this publication belongs to this project $objP = new \Components\Publications\Tables\Publication($this->_database); if (!$objP->load($pid) || $objP->project_id != $this->model->get('id')) { $this->setError(Lang::txt('PLG_PROJECTS_LINKS_ERROR_CITATION_DELETE')); } // Remove citation if (!$this->getError()) { // Unattach citation if ($this->unattachCitation($pid, $cid)) { \Notify::message(Lang::txt('PLG_PROJECTS_LINKS_CITATION_DELETED'), 'success', 'projects'); } } // Pass success or error message if ($this->getError()) { \Notify::message($this->getError(), 'error', 'projects'); } // Build pub url $route = $this->model->isProvisioned() ? 'index.php?option=com_publications&task=submit' : 'index.php?option=com_projects&alias=' . $this->model->get('alias') . '&active=publications'; $url = Route::url($route . '&pid=' . $pid . '&version=' . $version . '§ion=citations'); App::redirect($url); return; }
/** * Save block content * * @return string HTML */ public function save($manifest = NULL, $blockId = 0, $pub = NULL, $actor = 0, $elementId = 0) { // Set block manifest if ($this->_manifest === NULL) { $this->_manifest = $manifest ? $manifest : self::getManifest(); } // Make sure changes are allowed if ($this->_parent->checkFreeze($this->_manifest->params, $pub)) { return false; } // Load publication version $objP = new \Components\Publications\Tables\Publication($this->_parent->_db); if (!$objP->load($pub->id)) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NOT_FOUND')); return false; } if (!isset($pub->_citations)) { // Get citations for this publication $c = new \Components\Citations\Tables\Citation($this->_parent->_db); $pub->_citations = $c->getCitations('publication', $pub->id); } // Incoming $url = Request::getVar('citation-doi', ''); if (!$url) { return true; } $parts = explode("doi:", $url); $doi = count($parts) > 1 ? $parts[1] : $url; $citationFormat = $pub->config('citation_format', 'apa'); // Plugin params $plugin_params = array($pub->id, $doi, $citationFormat, $actor, true); // Attach citation $output = Event::trigger('projects.attachCitation', $plugin_params); if (isset($output[0])) { if ($output[0]['success']) { $this->set('_message', Lang::txt('PLG_PROJECTS_PUBLICATIONS_CITATION_SAVED')); // Reflect the update in curation record $this->_parent->set('_update', 1); } else { $this->setError($output[0]['error']); return false; } } else { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CITATION_ERROR_SAVING')); return false; } return true; }
/** * Save block content * * @return string HTML */ public function save($manifest = NULL, $blockId = 0, $pub = NULL, $actor = 0, $elementId = 0) { // Set block manifest if ($this->_manifest === NULL) { $this->_manifest = $manifest ? $manifest : self::getManifest(); } // Make sure changes are allowed if ($this->_parent->checkFreeze($this->_manifest->params, $pub)) { return false; } // Load publication version $objP = new \Components\Publications\Tables\Publication($this->_parent->_db); if (!$objP->load($pub->id)) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NOT_FOUND')); return false; } $tagsHelper = new \Components\Publications\Helpers\Tags($this->_parent->_db); $tags = trim(Request::getVar('tags', '', 'post')); $tagsHelper->tag_object($actor, $pub->id, $tags, 1); // Reflect the update in curation record $this->_parent->set('_update', 1); // Save category $cat = Request::getInt('pubtype', 0); if ($cat && $pub->_category->id != $cat) { $objP->category = $cat; $objP->store(); } return true; }