Пример #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;
 }
Пример #2
0
 /**
  * Attach citation
  *
  * @return   boolean
  */
 public function attachCitation($pid = 0, $doi = NULL, $format = 'apa', $actor = 0, $returnStatus = false)
 {
     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';
     include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'type.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'helpers' . DS . 'format.php';
     $out = array('error' => NULL, 'success' => NULL);
     if (!$doi || !$pid) {
         $this->setError(Lang::txt('PLG_PROJECTS_LINKS_NO_DOI'));
         if ($returnStatus) {
             $out['error'] = $this->getError();
             return $out;
         }
         return false;
     }
     $database = App::get('db');
     $c = new \Components\Citations\Tables\Citation($database);
     if ($c->loadPubCitation($doi, $pid)) {
         $this->setError(Lang::txt('PLG_PROJECTS_LINKS_CITATION_ALREADY_ATTACHED'));
         if ($returnStatus) {
             $out['error'] = $this->getError();
             return $out;
         }
         return false;
     } else {
         // Get DOI preview
         $output = self::parseUrl($doi, true, true, $format);
         $output = json_decode($output);
         if (isset($output->error) && $output->error) {
             $this->setError($output->error);
             if ($returnStatus) {
                 $out['error'] = $this->getError();
                 return $out;
             }
             return false;
         } elseif (isset($output->preview) && $output->preview) {
             // Load citation record with the same DOI if present
             if (!$c->loadByDoi($doi)) {
                 $c->created = Date::toSql();
                 $c->title = $doi;
                 $c->uid = $actor;
                 $c->affiliated = 1;
             }
             $c->formatted = $output->preview;
             $c->format = $format;
             $c->doi = $doi;
             // Try getting more metadata
             $url = '';
             $data = self::getDoiMetadata($doi, false, $url);
             // Save available data
             if ($data) {
                 foreach ($c as $key => $value) {
                     $column = strtolower($key);
                     if (isset($data->{$column})) {
                         $c->{$column} = $data->{$column};
                     }
                 }
                 // Some extra mapping hacks
                 $c->pages = $data->page;
                 // Get type ID
                 $ct = new \Components\Citations\Tables\Type($database);
                 $types = $ct->getType();
                 $dType = isset($data->type) ? $data->type : 'article';
                 // Hub types don't match library types
                 // Trying to match the best we can
                 $validTypes = array();
                 foreach ($types as $type) {
                     if ($type['type'] == $dType) {
                         $c->type = $type['id'];
                     } elseif ($type['type'] == 'article') {
                         $validTypes['journal-article'] = $type['id'];
                     } elseif ($type['type'] == 'chapter') {
                         $validTypes['book-chapter'] = $type['id'];
                     } elseif ($type['type'] == 'inproceedings') {
                         $validTypes['proceedings'] = $type['id'];
                     }
                 }
                 if (isset($validTypes[$dType])) {
                     $c->type = $validTypes[$dType];
                 } elseif (!intval($c->type)) {
                     // Default to article
                     $c->type = $validTypes['journal-article'];
                 }
             }
             if (!$c->store()) {
                 $this->setError(Lang::txt('PLG_PROJECTS_LINKS_CITATION_ERROR_SAVE'));
                 if ($returnStatus) {
                     $out['error'] = $this->getError();
                     return $out;
                 }
                 return false;
             }
             // Create association
             if ($c->id) {
                 $assoc = new \Components\Citations\Tables\Association($database);
                 $assoc->oid = $pid;
                 $assoc->tbl = 'publication';
                 $assoc->type = 'owner';
                 $assoc->cid = $c->id;
                 // Store new content
                 if (!$assoc->store()) {
                     $this->setError($assoc->getError());
                     if ($returnStatus) {
                         $out['error'] = $this->getError();
                         return $out;
                     }
                     return false;
                 }
             }
         } else {
             $this->setError(Lang::txt('PLG_PROJECTS_LINKS_CITATION_COULD_NOT_LOAD'));
             if ($returnStatus) {
                 $out['error'] = $this->getError();
                 return $out;
             }
             return false;
         }
     }
     if ($returnStatus) {
         $out['success'] = true;
         return $out;
     }
     return true;
 }