Esempio n. 1
0
 /**
  * @see MetadataDataObjectAdapter::extractMetadataFromDataObject()
  * @param $article Article
  * @return MetadataDescription
  */
 function &extractMetadataFromDataObject(&$article)
 {
     assert(is_a($article, 'Article'));
     AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
     // Retrieve data that belongs to the article.
     // FIXME: Retrieve this data from the respective entity DAOs rather than
     // from the OAIDAO once we've migrated all OAI providers to the
     // meta-data framework. We're using the OAIDAO here because it
     // contains cached entities and avoids extra database access if this
     // adapter is called from an OAI context.
     $oaiDao = DAORegistry::getDAO('OAIDAO');
     /* @var $oaiDao OAIDAO */
     $journal = $oaiDao->getJournal($article->getJournalId());
     $section = $oaiDao->getSection($article->getSectionId());
     if (is_a($article, 'PublishedArticle')) {
         /* @var $article PublishedArticle */
         $issue = $oaiDao->getIssue($article->getIssueId());
     }
     $dc11Description = $this->instantiateMetadataDescription();
     // Title
     $this->_addLocalizedElements($dc11Description, 'dc:title', $article->getTitle(null));
     // Creator
     $authors = $article->getAuthors();
     foreach ($authors as $author) {
         $authorName = $author->getFullName(true);
         $affiliation = $author->getLocalizedAffiliation();
         if (!empty($affiliation)) {
             $authorName .= '; ' . $affiliation;
         }
         $dc11Description->addStatement('dc:creator', $authorName);
         unset($authorName);
     }
     // Subject
     $subjects = array_merge_recursive((array) $article->getDiscipline(null), (array) $article->getSubject(null), (array) $article->getSubjectClass(null));
     $this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects);
     // Description
     $this->_addLocalizedElements($dc11Description, 'dc:description', $article->getAbstract(null));
     // Publisher
     $publisherInstitution = $journal->getSetting('publisherInstitution');
     if (!empty($publisherInstitution)) {
         $publishers = array($journal->getPrimaryLocale() => $publisherInstitution);
     } else {
         $publishers = $journal->getName(null);
         // Default
     }
     $this->_addLocalizedElements($dc11Description, 'dc:publisher', $publishers);
     // Contributor
     $contributors = (array) $article->getSponsor(null);
     foreach ($contributors as $locale => $contributor) {
         $contributors[$locale] = array_map('trim', explode(';', $contributor));
     }
     $this->_addLocalizedElements($dc11Description, 'dc:contributor', $contributors);
     // Date
     if (is_a($article, 'PublishedArticle')) {
         if ($article->getDatePublished()) {
             $dc11Description->addStatement('dc:date', date('Y-m-d', strtotime($article->getDatePublished())));
         } elseif ($issue->getDatePublished()) {
             $dc11Description->addStatement('dc:date', date('Y-m-d', strtotime($issue->getDatePublished())));
         }
     }
     // Type
     $driverType = 'info:eu-repo/semantics/article';
     $dc11Description->addStatement('dc:type', $driverType, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
     $types = $section->getIdentifyType(null);
     $types = array_merge_recursive(empty($types) ? array(AppLocale::getLocale() => __('rt.metadata.pkp.peerReviewed')) : $types, (array) $article->getType(null));
     $this->_addLocalizedElements($dc11Description, 'dc:type', $types);
     $driverVersion = 'info:eu-repo/semantics/publishedVersion';
     $dc11Description->addStatement('dc:type', $driverVersion, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
     // Format
     if (is_a($article, 'PublishedArticle')) {
         $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
         /* @var $articleGalleyDao ArticleGalleyDAO */
         $galleys = $articleGalleyDao->getBySubmissionId($article->getId());
         $formats = array();
         while ($galley = $galleys->next()) {
             $dc11Description->addStatement('dc:format', $galley->getFileType());
         }
     }
     // Identifier: URL
     if (is_a($article, 'PublishedArticle')) {
         $dc11Description->addStatement('dc:identifier', Request::url($journal->getPath(), 'article', 'view', array($article->getBestArticleId())));
     }
     // Source (journal title, issue id and pages)
     $sources = $journal->getName(null);
     $pages = $article->getPages();
     if (!empty($pages)) {
         $pages = '; ' . $pages;
     }
     foreach ($sources as $locale => $source) {
         if (is_a($article, 'PublishedArticle')) {
             $sources[$locale] .= '; ' . $issue->getIssueIdentification();
         }
         $sources[$locale] .= $pages;
     }
     $this->_addLocalizedElements($dc11Description, 'dc:source', $sources);
     if ($issn = $journal->getSetting('onlineIssn')) {
         $dc11Description->addStatement('dc:source', $issn, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
     }
     if ($issn = $journal->getSetting('printIssn')) {
         $dc11Description->addStatement('dc:source', $issn, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
     }
     // Get galleys and supp files.
     $galleys = array();
     $suppFiles = array();
     if (is_a($article, 'PublishedArticle')) {
         $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
         /* @var $articleGalleyDao ArticleGalleyDAO */
         $galleys = $articleGalleyDao->getBySubmissionId($article->getId())->toArray();
         $suppFiles = $article->getSuppFiles();
     }
     // Language
     $locales = array();
     if (is_a($article, 'PublishedArticle')) {
         foreach ($galleys as $galley) {
             $galleyLocale = $galley->getLocale();
             if (!is_null($galleyLocale) && !in_array($galleyLocale, $locales)) {
                 $locales[] = $galleyLocale;
                 $dc11Description->addStatement('dc:language', AppLocale::getIso3FromLocale($galleyLocale));
             }
         }
     }
     $articleLanguage = $article->getLanguage();
     if (empty($locales) && !empty($articleLanguage)) {
         $dc11Description->addStatement('dc:language', strip_tags($articleLanguage));
     }
     // Relation
     // full text URLs
     foreach ($galleys as $galley) {
         $relation = Request::url($journal->getPath(), 'article', 'view', array($article->getBestArticleId($journal), $galley->getBestGalleyId($journal)));
         $dc11Description->addStatement('dc:relation', $relation);
         unset($relation);
     }
     // supp file URLs
     foreach ($suppFiles as $suppFile) {
         $relation = Request::url($journal->getPath(), 'article', 'downloadSuppFile', array($article->getBestArticleId($journal), $suppFile->getBestSuppFileId($journal)));
         $dc11Description->addStatement('dc:relation', $relation);
         unset($relation);
     }
     // Public identifiers
     $pubIdPlugins = (array) PluginRegistry::loadCategory('pubIds', true, $journal->getId());
     foreach ($pubIdPlugins as $pubIdPlugin) {
         if ($pubIssueId = $pubIdPlugin->getPubId($issue)) {
             $dc11Description->addStatement('dc:source', $pubIssueId, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
             unset($pubIssueId);
         }
         if ($pubArticleId = $pubIdPlugin->getPubId($article)) {
             $dc11Description->addStatement('dc:identifier', $pubArticleId);
             unset($pubArticleId);
         }
         foreach ($galleys as $galley) {
             if ($pubGalleyId = $pubIdPlugin->getPubId($galley)) {
                 $dc11Description->addStatement('dc:relation', $pubGalleyId);
                 unset($pubGalleyId);
             }
         }
         foreach ($suppFiles as $suppFile) {
             if ($pubSuppFileId = $pubIdPlugin->getPubId($suppFile)) {
                 $dc11Description->addStatement('dc:relation', $pubSuppFileId);
                 unset($pubSuppFileId);
             }
         }
     }
     // Coverage
     $coverage = array_merge_recursive((array) $article->getCoverageGeo(null), (array) $article->getCoverageChron(null), (array) $article->getCoverageSample(null));
     $this->_addLocalizedElements($dc11Description, 'dc:coverage', $coverage);
     // Rights
     $this->_addLocalizedElements($dc11Description, 'dc:rights', $journal->getSetting('copyrightNotice'));
     Hookregistry::call('Dc11SchemaArticleAdapter::extractMetadataFromDataObject', array($this, $article, $journal, $issue, &$dc11Description));
     return $dc11Description;
 }
 /**
  * @see OAIMetadataFormat#toXML
  */
 function toXml(&$record, $format = null)
 {
     $response = null;
     if (!HookRegistry::call('OAIMetadataFormat_DC::toXml', array(&$this, $record, &$response))) {
         $article =& $record->getData('article');
         $journal =& $record->getData('journal');
         $section =& $record->getData('section');
         $issue =& $record->getData('issue');
         $galleys =& $record->getData('galleys');
         AppLocale::requireComponents(array(LOCALE_COMPONENT_APPLICATION_COMMON));
         // Sources contains journal title, issue ID, and pages
         $sources = $this->stripAssocArray((array) $journal->getTitle(null));
         $pages = $article->getPages();
         if (!empty($pages)) {
             $pages = '; ' . $pages;
         }
         foreach ($sources as $key => $source) {
             $sources[$key] .= '; ' . $issue->getIssueIdentification() . $pages;
         }
         // Format creators
         $creators = array();
         $authors = $article->getAuthors();
         for ($i = 0, $num = count($authors); $i < $num; $i++) {
             $authorName = $authors[$i]->getFullName(true);
             $affiliation = $authors[$i]->getLocalizedAffiliation();
             if (!empty($affiliation)) {
                 $authorName .= '; ' . $affiliation;
             }
             $creators[] = $authorName;
         }
         // Publisher
         $publishers = $this->stripAssocArray((array) $journal->getTitle(null));
         // Default
         $publisherInstitution = $journal->getSetting('publisherInstitution');
         if (!empty($publisherInstitution)) {
             $publishers = array($journal->getPrimaryLocale() => $publisherInstitution);
         }
         // Contributor
         $contributors = $this->stripAssocArray((array) $article->getSponsor(null));
         foreach ($contributors as $key => $contributor) {
             $contributors[$key] = array_map('trim', explode(';', $contributor));
         }
         // Types
         $driverType = 'info:eu-repo/semantics/article';
         $driverVersion = 'info:eu-repo/semantics/publishedVersion';
         $types = $this->stripAssocArray((array) $section->getIdentifyType(null));
         $types = array_merge_recursive(empty($types) ? array(AppLocale::getLocale() => __('rt.metadata.pkp.peerReviewed')) : $types, $this->stripAssocArray((array) $article->getType(null)));
         // Formats
         $formats = array();
         foreach ($galleys as $galley) {
             $formats[] = $galley->getFileType();
         }
         // Languages
         $languages = array();
         foreach ($galleys as $galley) {
             $galleyLocale = $galley->getLocale();
             $iso3 = AppLocale::getIso3FromLocale($galleyLocale);
             if (!in_array($iso3, $languages)) {
                 $languages[] = $iso3;
             }
         }
         // Relation
         $relation = array();
         // full texts URLs
         foreach ($galleys as $galley) {
             $relation[] = Request::url($journal->getPath(), 'article', 'view', array($article->getBestArticleId($journal), $galley->getBestGalleyId($journal)));
         }
         // supp files URLs
         foreach ($article->getSuppFiles() as $suppFile) {
             $relation[] = Request::url($journal->getPath(), 'article', 'downloadSuppFile', array($article->getBestArticleId($journal), $suppFile->getBestSuppFileId($journal)));
         }
         $response = "<oai_dc:dc\n" . "\txmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\"\n" . "\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" . "\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" . "\txsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/\n" . "\thttp://www.openarchives.org/OAI/2.0/oai_dc.xsd\">\n" . $this->formatElement('title', $this->stripAssocArray((array) $article->getTitle(null)), true) . $this->formatElement('creator', $creators) . $this->formatElement('subject', array_merge_recursive($this->stripAssocArray((array) $article->getDiscipline(null)), $this->stripAssocArray((array) $article->getSubject(null)), $this->stripAssocArray((array) $article->getSubjectClass(null))), true) . $this->formatElement('description', $this->stripAssocArray((array) $article->getAbstract(null)), true) . $this->formatElement('publisher', $publishers, true) . $this->formatElement('contributor', $contributors, true) . $this->formatElement('date', date('Y-m-d', strtotime($issue->getDatePublished()))) . $this->formatElement('type', $driverType) . $this->formatElement('type', $types, true) . $this->formatElement('type', $driverVersion) . $this->formatElement('format', $formats) . $this->formatElement('identifier', Request::url($journal->getPath(), 'article', 'view', array($article->getBestArticleId()))) . (($doi = $article->getDOI()) ? $this->formatElement('identifier', $doi, false) : '') . $this->formatElement('source', $sources, true) . $this->formatElement('language', $languages) . $this->formatElement('relation', $relation) . $this->formatElement('coverage', array_merge_recursive($this->stripAssocArray((array) $article->getCoverageGeo(null)), $this->stripAssocArray((array) $article->getCoverageChron(null)), $this->stripAssocArray((array) $article->getCoverageSample(null))), true) . $this->formatElement('rights', $this->stripAssocArray((array) $journal->getSetting('copyrightNotice'))) . "</oai_dc:dc>\n";
     }
     return $response;
 }