Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
Dc11SchemaPublicationFormatAdapter.inc.php
1 <?php
2 
20 import('lib.pkp.classes.metadata.MetadataDataObjectAdapter');
21 
22 class Dc11SchemaPublicationFormatAdapter extends MetadataDataObjectAdapter {
27  function Dc11SchemaPublicationFormatAdapter(&$filterGroup) {
28  parent::MetadataDataObjectAdapter($filterGroup);
29  }
30 
31 
32  //
33  // Implement template methods from Filter
34  //
38  function getClassName() {
39  return 'plugins.metadata.dc11.filter.Dc11SchemaPublicationFormatAdapter';
40  }
41 
42 
43  //
44  // Implement template methods from MetadataDataObjectAdapter
45  //
52  function &injectMetadataIntoDataObject(&$dc11Description, &$publicationFormat, $authorClassName) {
53  // Not implemented
54  assert(false);
55  }
56 
62  function extractMetadataFromDataObject($publicationFormat) {
63  assert(is_a($publicationFormat, 'PublicationFormat'));
64 
65  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
66 
67  // Retrieve data that belongs to the publication format.
68  // FIXME: Retrieve this data from the respective entity DAOs rather than
69  // from the OAIDAO once we've migrated all OAI providers to the
70  // meta-data framework. We're using the OAIDAO here because it
71  // contains cached entities and avoids extra database access if this
72  // adapter is called from an OAI context.
73  $oaiDao = DAORegistry::getDAO('OAIDAO'); /* @var $oaiDao OAIDAO */
74  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
75  $monograph = $publishedMonographDao->getById($publicationFormat->getMonographId());
76  $press = $oaiDao->getPress($monograph->getPressId());
77  $series = $oaiDao->getSeries($monograph->getSeriesId()); /* @var $series Series */
78  $dc11Description = $this->instantiateMetadataDescription();
79 
80  // Title
81  $this->_addLocalizedElements($dc11Description, 'dc:title', $monograph->getTitle(null));
82 
83  // Creator
84  $authors = $monograph->getAuthors();
85  foreach($authors as $author) {
86  $authorName = $author->getFullName(true);
87  $affiliation = $author->getLocalizedAffiliation();
88  if (!empty($affiliation)) {
89  $authorName .= '; ' . $affiliation;
90  }
91  $dc11Description->addStatement('dc:creator', $authorName);
92  unset($authorName);
93  }
94 
95  // Subject
96  $subjects = array_merge_recursive(
97  (array) $monograph->getDiscipline(null),
98  (array) $monograph->getSubject(null),
99  (array) $monograph->getSubjectClass(null));
100  $this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects);
101 
102  // Description
103  $this->_addLocalizedElements($dc11Description, 'dc:description', $monograph->getAbstract(null));
104 
105  // Publisher
106  $publisherInstitution = $press->getSetting('publisherInstitution');
107  if (!empty($publisherInstitution)) {
108  $publishers = array($press->getPrimaryLocale() => $publisherInstitution);
109  } else {
110  $publishers = $press->getName(null); // Default
111  }
112  $this->_addLocalizedElements($dc11Description, 'dc:publisher', $publishers);
113 
114  // Contributor
115  $contributors = $monograph->getSponsor(null);
116  if (is_array($contributors)) {
117  foreach ($contributors as $locale => $contributor) {
118  $contributors[$locale] = array_map('trim', explode(';', $contributor));
119  }
120  $this->_addLocalizedElements($dc11Description, 'dc:contributor', $contributors);
121  }
122 
123  // Date
124  // FIXME: should we use the publication dates of the publication format? If yes,
125  // in which role preference order?
126  if (is_a($monograph, 'PublishedMonograph')) {
127  if ($monograph->getDatePublished()) $dc11Description->addStatement('dc:date', date('Y-m-d', strtotime($monograph->getDatePublished())));
128  }
129 
130  // Type
131  $types = array_merge_recursive(
132  array(AppLocale::getLocale() => __('rt.metadata.pkp.peerReviewed')),
133  (array) $monograph->getType(null)
134  );
135  $this->_addLocalizedElements($dc11Description, 'dc:type', $types);
136 
137  // Format
138  $onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO');
139  $entryKeys = $onixCodelistItemDao->getCodes('List7'); // List7 is for object formats
140  if ($publicationFormat->getEntryKey()) {
141  $formatName = $entryKeys[$publicationFormat->getEntryKey()];
142  $dc11Description->addStatement('dc:format', $formatName);
143  }
144 
145  // Identifier: URL
146  if (is_a($monograph, 'PublishedMonograph')) {
147  $dc11Description->addStatement('dc:identifier', Request::url($press->getPath(), 'catalog', 'book', array($monograph->getId())));
148  }
149 
150  // Identifier: others
151  $identificationCodeFactory = $publicationFormat->getIdentificationCodes();
152  while ($identificationCode = $identificationCodeFactory->next()) {
153  $dc11Description->addStatement('dc:identifier', $identificationCode->getNameForONIXCode());
154  }
155 
156  // Source (press title and pages)
157  $sources = $press->getName(null);
158  $pages = $monograph->getPages();
159  if (!empty($pages)) $pages = '; ' . $pages;
160  foreach ($sources as $locale => $source) {
161  $sources[$locale] .= '; ';
162  $sources[$locale] .= $pages;
163  }
164  $this->_addLocalizedElements($dc11Description, 'dc:source', $sources);
165 
166  // Language
167 
168  // Relation
169 
170  // Coverage
171  $coverage = array_merge_recursive(
172  (array) $monograph->getCoverageGeo(null),
173  (array) $monograph->getCoverageChron(null),
174  (array) $monograph->getCoverageSample(null));
175  $this->_addLocalizedElements($dc11Description, 'dc:coverage', $coverage);
176 
177  // Rights
178  $salesRightsFactory = $publicationFormat->getSalesRights();
179  while ($salesRight = $salesRightsFactory->next()) {
180  $dc11Description->addStatement('dc:rights', $salesRight->getNameForONIXCode());
181  }
182 
183  Hookregistry::call('Dc11SchemaPublicationFormatAdapter::extractMetadataFromDataObject', array(&$this, $monograph, $press, &$dc11Description));
184 
185  return $dc11Description;
186  }
187 
192  function getDataObjectMetadataFieldNames($translated = true) {
193  // All DC fields are mapped.
194  return array();
195  }
196 
197 
198  //
199  // Private helper methods
200  //
207  function _addLocalizedElements(&$description, $propertyName, $localizedValues) {
208  foreach(stripAssocArray((array) $localizedValues) as $locale => $values) {
209  if (is_scalar($values)) $values = array($values);
210  foreach($values as $value) {
211  $description->addStatement($propertyName, $value, $locale);
212  unset($value);
213  }
214  }
215  }
216 }
217 ?>
static & getDAO($name, $dbconn=null)
static requireComponents()
& injectMetadataIntoDataObject(&$dc11Description, &$publicationFormat, $authorClassName)
static getLocale()
Adapter that injects/extracts Dublin Core schema compliant meta-data into/from a PublicationFormat ob...
url($pressPath=null, $page=null, $op=null, $path=null, $params=null, $anchor=null, $escape=false)
Definition: Request.inc.php:88
_addLocalizedElements(&$description, $propertyName, $localizedValues)