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
00033
00037 function getClassName() {
00038 return 'plugins.metadata.dc11.filter.Dc11SchemaPublicationFormatAdapter';
00039 }
00040
00041
00042
00043
00044
00051 function &injectMetadataIntoDataObject(&$dc11Description, &$publicationFormat, $authorClassName) {
00052
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
00067
00068
00069
00070
00071
00072 $oaiDao =& DAORegistry::getDAO('OAIDAO');
00073 $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00074 $monograph =& $publishedMonographDao->getById($publicationFormat->getMonographId());
00075 $press =& $oaiDao->getPress($monograph->getPressId());
00076 $series =& $oaiDao->getSeries($monograph->getSeriesId());
00077 $dc11Description =& $this->instantiateMetadataDescription();
00078
00079
00080 $this->_addLocalizedElements($dc11Description, 'dc:title', $monograph->getTitle(null));
00081
00082
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
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
00102 $this->_addLocalizedElements($dc11Description, 'dc:description', $monograph->getAbstract(null));
00103
00104
00105 $publisherInstitution = $press->getSetting('publisherInstitution');
00106 if (!empty($publisherInstitution)) {
00107 $publishers = array($press->getPrimaryLocale() => $publisherInstitution);
00108 } else {
00109 $publishers = $press->getName(null);
00110 }
00111 $this->_addLocalizedElements($dc11Description, 'dc:publisher', $publishers);
00112
00113
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
00123
00124
00125 if (is_a($monograph, 'PublishedMonograph')) {
00126 if ($monograph->getDatePublished()) $dc11Description->addStatement('dc:date', date('Y-m-d', strtotime($monograph->getDatePublished())));
00127 }
00128
00129
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
00137 $onixCodelistItemDao =& DAORegistry::getDAO('ONIXCodelistItemDAO');
00138 $entryKeys = $onixCodelistItemDao->getCodes('List7');
00139 if ($publicationFormat->getEntryKey()) {
00140 $formatName = $entryKeys[$publicationFormat->getEntryKey()];
00141 $dc11Description->addStatement('dc:format', $formatName);
00142 }
00143
00144
00145 if (is_a($monograph, 'PublishedMonograph')) {
00146 $dc11Description->addStatement('dc:identifier', Request::url($press->getPath(), 'catalog', 'book', array($monograph->getId())));
00147 }
00148
00149
00150 $identificationCodeFactory = $publicationFormat->getIdentificationCodes();
00151 while ($identificationCode = $identificationCodeFactory->next()) {
00152 $dc11Description->addStatement('dc:identifier', $identificationCode->getNameForONIXCode());
00153 }
00154
00155
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
00166
00167
00168
00169
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
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
00193 return array();
00194 }
00195
00196
00197
00198
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 ?>