• Main Page
  • Modules
  • Classes
  • Files
  • File List

plugins/metadata/dc11/filter/Dc11SchemaPublicationFormatAdapter.inc.php

00001 <?php
00002 
00019 import('lib.pkp.classes.metadata.MetadataDataObjectAdapter');
00020 
00021 class Dc11SchemaPublicationFormatAdapter extends MetadataDataObjectAdapter {
00026    function Dc11SchemaPublicationFormatAdapter(&$filterGroup) {
00027       parent::MetadataDataObjectAdapter($filterGroup);
00028    }
00029 
00030 
00031    //
00032    // Implement template methods from Filter
00033    //
00037    function getClassName() {
00038       return 'plugins.metadata.dc11.filter.Dc11SchemaPublicationFormatAdapter';
00039    }
00040 
00041 
00042    //
00043    // Implement template methods from MetadataDataObjectAdapter
00044    //
00051    function &injectMetadataIntoDataObject(&$dc11Description, &$publicationFormat, $authorClassName) {
00052       // Not implemented
00053       assert(false);
00054    }
00055 
00061    function &extractMetadataFromDataObject(&$publicationFormat) {
00062       assert(is_a($publicationFormat, 'PublicationFormat'));
00063 
00064       AppLocale::requireComponents(LOCALE_COMPONENT_APPLICATION_COMMON);
00065 
00066       // Retrieve data that belongs to the publication format.
00067       // FIXME: Retrieve this data from the respective entity DAOs rather than
00068       // from the OAIDAO once we've migrated all OAI providers to the
00069       // meta-data framework. We're using the OAIDAO here because it
00070       // contains cached entities and avoids extra database access if this
00071       // adapter is called from an OAI context.
00072       $oaiDao =& DAORegistry::getDAO('OAIDAO'); /* @var $oaiDao OAIDAO */
00073       $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00074       $monograph =& $publishedMonographDao->getById($publicationFormat->getMonographId());
00075       $press =& $oaiDao->getPress($monograph->getPressId());
00076       $series =& $oaiDao->getSeries($monograph->getSeriesId()); /* @var $series Series */
00077       $dc11Description =& $this->instantiateMetadataDescription();
00078 
00079       // Title
00080       $this->_addLocalizedElements($dc11Description, 'dc:title', $monograph->getTitle(null));
00081 
00082       // Creator
00083       $authors = $monograph->getAuthors();
00084       foreach($authors as $author) {
00085          $authorName = $author->getFullName(true);
00086          $affiliation = $author->getLocalizedAffiliation();
00087          if (!empty($affiliation)) {
00088             $authorName .= '; ' . $affiliation;
00089          }
00090          $dc11Description->addStatement('dc:creator', $authorName);
00091          unset($authorName);
00092       }
00093 
00094       // Subject
00095       $subjects = array_merge_recursive(
00096             (array) $monograph->getDiscipline(null),
00097             (array) $monograph->getSubject(null),
00098             (array) $monograph->getSubjectClass(null));
00099       $this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects);
00100 
00101       // Description
00102       $this->_addLocalizedElements($dc11Description, 'dc:description', $monograph->getAbstract(null));
00103 
00104       // Publisher
00105       $publisherInstitution = $press->getSetting('publisherInstitution');
00106       if (!empty($publisherInstitution)) {
00107          $publishers = array($press->getPrimaryLocale() => $publisherInstitution);
00108       } else {
00109          $publishers = $press->getName(null); // Default
00110       }
00111       $this->_addLocalizedElements($dc11Description, 'dc:publisher', $publishers);
00112 
00113       // Contributor
00114       $contributors = $monograph->getSponsor(null);
00115       if (is_array($contributors)) {
00116          foreach ($contributors as $locale => $contributor) {
00117             $contributors[$locale] = array_map('trim', explode(';', $contributor));
00118          }
00119          $this->_addLocalizedElements($dc11Description, 'dc:contributor', $contributors);
00120       }
00121 
00122       // Date
00123       // FIXME: should we use the publication dates of the publication format? If yes,
00124       // in which role preference order?
00125       if (is_a($monograph, 'PublishedMonograph')) {
00126          if ($monograph->getDatePublished()) $dc11Description->addStatement('dc:date', date('Y-m-d', strtotime($monograph->getDatePublished())));
00127       }
00128 
00129       // Type
00130       $types = array_merge_recursive(
00131          array(AppLocale::getLocale() => __('rt.metadata.pkp.peerReviewed')),
00132          (array) $monograph->getType(null)
00133       );
00134       $this->_addLocalizedElements($dc11Description, 'dc:type', $types);
00135 
00136       // Format
00137       $onixCodelistItemDao =& DAORegistry::getDAO('ONIXCodelistItemDAO');
00138       $entryKeys = $onixCodelistItemDao->getCodes('List7'); // List7 is for object formats
00139       if ($publicationFormat->getEntryKey()) {
00140          $formatName = $entryKeys[$publicationFormat->getEntryKey()];
00141          $dc11Description->addStatement('dc:format', $formatName);
00142       }
00143 
00144       // Identifier: URL
00145       if (is_a($monograph, 'PublishedMonograph')) {
00146          $dc11Description->addStatement('dc:identifier', Request::url($press->getPath(), 'catalog', 'book', array($monograph->getId())));
00147       }
00148 
00149       // Identifier: others
00150       $identificationCodeFactory = $publicationFormat->getIdentificationCodes();
00151       while ($identificationCode = $identificationCodeFactory->next()) {
00152          $dc11Description->addStatement('dc:identifier', $identificationCode->getNameForONIXCode());
00153       }
00154 
00155       // Source (press title and pages)
00156       $sources = $press->getName(null);
00157       $pages = $monograph->getPages();
00158       if (!empty($pages)) $pages = '; ' . $pages;
00159       foreach ($sources as $locale => $source) {
00160          $sources[$locale] .= '; ';
00161          $sources[$locale] .=  $pages;
00162       }
00163       $this->_addLocalizedElements($dc11Description, 'dc:source', $sources);
00164 
00165       // Language
00166 
00167       // Relation
00168 
00169       // Coverage
00170       $coverage = array_merge_recursive(
00171             (array) $monograph->getCoverageGeo(null),
00172             (array) $monograph->getCoverageChron(null),
00173             (array) $monograph->getCoverageSample(null));
00174       $this->_addLocalizedElements($dc11Description, 'dc:coverage', $coverage);
00175 
00176       // Rights
00177       $salesRightsFactory = $publicationFormat->getSalesRights();
00178       while ($salesRight = $salesRightsFactory->next()) {
00179          $dc11Description->addStatement('dc:rights', $salesRight->getNameForONIXCode());
00180       }
00181 
00182       Hookregistry::call('Dc11SchemaPublicationFormatAdapter::extractMetadataFromDataObject', array(&$this, $monograph, $press, &$dc11Description));
00183 
00184       return $dc11Description;
00185    }
00186 
00191    function getDataObjectMetadataFieldNames($translated = true) {
00192       // All DC fields are mapped.
00193       return array();
00194    }
00195 
00196 
00197    //
00198    // Private helper methods
00199    //
00206    function _addLocalizedElements(&$description, $propertyName, $localizedValues) {
00207       foreach(stripAssocArray((array) $localizedValues) as $locale => $values) {
00208          if (is_scalar($values)) $values = array($values);
00209          foreach($values as $value) {
00210             $description->addStatement($propertyName, $value, $locale);
00211             unset($value);
00212          }
00213       }
00214    }
00215 }
00216 ?>

Generated on Mon Sep 17 2012 13:58:56 for Open Monograph Press by  doxygen 1.7.1