/** * Get citations on a resource * * @return boolean False if errors */ public function getCitations() { if (!$this->_id) { return 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 . 'author.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'secondary.php'; $cc = new \Components\Citations\Tables\Citation($this->_db); $this->citations = $cc->getCitations('resource', $this->_id); }
/** * Return data on a resource view (this will be some form of HTML) * * @param object $publication Current publication * @param string $option Name of the component * @param array $areas Active area(s) * @param string $rtrn Data to be returned * @param string $version Version name * @param boolean $extended Whether or not to show panel * @return array */ public function onPublication($publication, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true) { $arr = array('html' => '', 'metadata' => ''); // Check if our area is in the array of areas we want to return results for if (is_array($areas)) { if (!array_intersect($areas, $this->onPublicationAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationAreas($publication)))) { $rtrn = 'metadata'; } } if (!$publication->_category->_params->get('plg_citations')) { return $arr; } // Get a needed library 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 . 'author.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'secondary.php'; // Get citations for this publication $database = App::get('db'); $c = new \Components\Citations\Tables\Citation($database); $citations = $c->getCitations('publication', $publication->id); $arr['count'] = $citations ? count($citations) : 0; $arr['name'] = 'citations'; // Are we returning HTML? if ($rtrn == 'all' || $rtrn == 'html') { $config = Component::params($option); // Instantiate a view $view = $this->view('default', 'browse')->set('option', $option)->set('publication', $publication)->set('citations', $citations)->set('format', $config->get('citation_format', 'apa')); // Return the output $arr['html'] = $view->setErrors($this->getErrors())->loadTemplate(); } // Are we returning metadata? if ($rtrn == 'all' || $rtrn == 'metadata') { $view = $this->view('default', 'metadata')->set('url', Route::url('index.php?option=' . $option . '&' . ($publication->alias ? 'alias=' . $publication->alias : 'id=' . $publication->id) . '&active=citations&v=' . $publication->version_number))->set('citations', $citations); $arr['metadata'] = $view->loadTemplate(); } // Return results return $arr; }
/** * Get citations on a resource * Accepts a numeric array index * * @param integer $idx Index value * @return array */ public function citations($idx = null) { if (!$this->exists()) { return array(); } if (!isset($this->citations)) { $this->citations = array(); 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 . 'author.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'secondary.php'; $cc = new \Components\Citations\Tables\Citation($this->_db); if ($results = $cc->getCitations('resource', $this->resource->id)) { $this->citations = $results; } } if ($idx !== null && is_numeric($idx)) { if (isset($this->citations[$idx])) { return $this->citations[$idx]; } else { $this->setError(Lang::txt('Index not found: ') . __CLASS__ . '::' . __METHOD__ . '[' . $idx . ']'); return false; } } return $this->citations; }
/** * Get citations * * @return void */ public function getCitations() { if (!$this->exists()) { return false; } if (!isset($this->_citations)) { 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 . 'author.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'secondary.php'; $cc = new \Components\Citations\Tables\Citation($this->_db); $this->_citations = $cc->getCitations('publication', $this->get('id')); } return $this->_citations; }
/** * Check completion status * * @return object */ public function getStatus($pub = NULL, $manifest = NULL, $elementId = NULL) { $status = new \Components\Publications\Models\Status(); 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); } // Required? $required = $manifest->params->required; $status->status = $required && (!$pub->_citations || count($pub->_citations) == 0) ? 0 : 1; $status->status = !$required && (!$pub->_citations || count($pub->_citations) == 0) ? 2 : $status->status; return $status; }
/** * Return data on a resource view (this will be some form of HTML) * * @param object $resource Current resource * @param string $option Name of the component * @param array $areas Active area(s) * @param string $rtrn Data to be returned * @return array */ public function onResources($model, $option, $areas, $rtrn = 'all') { $arr = array('area' => $this->_name, 'html' => '', 'metadata' => ''); // Check if our area is in the array of areas we want to return results for if (is_array($areas)) { if (!array_intersect($areas, $this->onResourcesAreas($model)) && !array_intersect($areas, array_keys($this->onResourcesAreas($model)))) { $rtrn = 'metadata'; } } if (!$model->type->params->get('plg_citations')) { return $arr; } $database = App::get('db'); // Get a needed library 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 . 'author.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'secondary.php'; // Get reviews for this resource $c = new \Components\Citations\Tables\Citation($database); $citations = $c->getCitations('resource', $model->resource->id); // Are we returning HTML? if ($rtrn == 'all' || $rtrn == 'html') { // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Pass the view some info $view->option = $option; $view->resource = $model->resource; $view->citations = $citations; $view->citationFormat = $this->params->get('format', 'APA'); if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); } // Are we returning metadata? if ($rtrn == 'all' || $rtrn == 'metadata') { $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'metadata')); $view->url = Route::url('index.php?option=' . $option . '&' . ($model->resource->alias ? 'alias=' . $model->resource->alias : 'id=' . $model->resource->id) . '&active=citations'); $view->citations = $citations; $arr['metadata'] = $view->loadTemplate(); } // Return results return $arr; }