Ejemplo n.º 1
0
 /**
  * Add new citation
  *
  * @return  void
  */
 public function addItem($manifest, $blockId, $pub, $actor = 0, $elementId = 0, $cid = 0)
 {
     $cite = Request::getVar('cite', array(), 'post', 'none', 2);
     $new = $cite['id'] ? false : true;
     if (!$cite['type'] || !$cite['title']) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CITATIONS_ERROR_MISSING_REQUIRED'));
         return false;
     }
     $citation = new \Components\Citations\Tables\Citation($this->_parent->_db);
     if (!$citation->bind($cite)) {
         $this->setError($citation->getError());
         return false;
     }
     $citation->created = $new ? Date::toSql() : $citation->created;
     $citation->uid = $new ? $actor : $citation->uid;
     $citation->published = 1;
     if (!$citation->store(true)) {
         // This really shouldn't happen.
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CITATIONS_ERROR_SAVE'));
         return false;
     }
     // Create association
     if ($new == true && $citation->id) {
         $assoc = new \Components\Citations\Tables\Association($this->_parent->_db);
         $assoc->oid = $pub->id;
         $assoc->tbl = 'publication';
         $assoc->type = 'owner';
         $assoc->cid = $citation->id;
         // Store new content
         if (!$assoc->store()) {
             $this->setError($assoc->getError());
             return false;
         }
     }
     $this->set('_message', Lang::txt('PLG_PROJECTS_PUBLICATIONS_CITATIONS_SUCCESS_SAVE'));
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Attach a citation to a publication (in non-curated flow)
  *
  * @return     string
  */
 public function savecite()
 {
     // Incoming
     $cite = Request::getVar('cite', array(), 'post', 'none', 2);
     $pid = Request::getInt('pid', 0);
     $version = Request::getVar('version', 'dev');
     $new = $cite['id'] ? false : true;
     include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'citation.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'association.php';
     if (!$pid || !$cite['type'] || !$cite['title']) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CITATIONS_ERROR_MISSING_REQUIRED'));
     } else {
         $citation = new \Components\Citations\Tables\Citation($this->_database);
         if (!$citation->bind($cite)) {
             $this->setError($citation->getError());
         } else {
             $citation->created = $new == true ? Date::toSql() : $citation->created;
             $citation->uid = $new == true ? $this->_uid : $citation->uid;
             $citation->published = 1;
             if (!$citation->store(true)) {
                 // This really shouldn't happen.
                 $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CITATIONS_ERROR_SAVE'));
             }
         }
         // Create association
         if (!$this->getError() && $new == true && $citation->id) {
             $assoc = new \Components\Citations\Tables\Association($this->_database);
             $assoc->oid = $pid;
             $assoc->tbl = 'publication';
             $assoc->type = 'owner';
             $assoc->cid = $citation->id;
             // Store new content
             if (!$assoc->store()) {
                 $this->setError($assoc->getError());
             }
         }
         \Notify::message(Lang::txt('PLG_PROJECTS_LINKS_CITATION_SAVED'), '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';
     App::redirect(Route::url($route . '&pid=' . $pid . '&version=' . $version . '&section=citations'));
     return;
 }