Open Monograph Press  3.3.0
Dc11SchemaPublicationFormatAdapter.inc.php
1 <?php
2 
20 import('lib.pkp.classes.metadata.MetadataDataObjectAdapter');
21 
27  function __construct(&$filterGroup) {
28  parent::__construct($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  //
51  function &injectMetadataIntoDataObject(&$dc11Description, &$publicationFormat) {
52  // Not implemented
53  assert(false);
54  }
55 
61  function extractMetadataFromDataObject(&$publicationFormat) {
62  assert(is_a($publicationFormat, 'PublicationFormat'));
63 
64  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
65 
66  // Retrieve data that belongs to the publication format.
67  // FIXME: Retrieve this data from the respective entity DAOs rather than
68  // from the OAIDAO once we've migrated all OAI providers to the
69  // meta-data framework. We're using the OAIDAO here because it
70  // contains cached entities and avoids extra database access if this
71  // adapter is called from an OAI context.
72  $oaiDao = DAORegistry::getDAO('OAIDAO'); /* @var $oaiDao OAIDAO */
73  $publication = Services::get('publication')->get($publicationFormat->getData('publicationId'));
74  $monograph = Services::get('submission')->get($publication->getData('submissionId'));
75  $press = $oaiDao->getPress($monograph->getPressId());
76  $series = $oaiDao->getSeries($monograph->getSeriesId()); /* @var $series Series */
77  $dc11Description = $this->instantiateMetadataDescription();
78 
79  // Title
80  $titles = array();
81  foreach ($monograph->getTitle(null) as $titleLocale => $title) {
82  $titles[$titleLocale] = $monograph->getFullTitle($titleLocale);
83  }
84  $this->_addLocalizedElements($dc11Description, 'dc:title', $titles);
85 
86  // Creator
87  $authors = $monograph->getAuthors();
88  foreach($authors as $author) {
89  $authorName = $author->getFullName(false, true);
90  $affiliation = $author->getLocalizedAffiliation();
91  if (!empty($affiliation)) {
92  $authorName .= '; ' . $affiliation;
93  }
94  $dc11Description->addStatement('dc:creator', $authorName);
95  unset($authorName);
96  }
97 
98  // Subject
99  $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /* @var $submissionKeywordDao SubmissionKeywordDAO */
100  $submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /* @var $submissionSubjectDao SubmissionSubjectDAO */
101  $supportedLocales = array_keys(AppLocale::getSupportedFormLocales());
102  $subjects = array_merge_recursive(
103  (array) $submissionKeywordDao->getKeywords($monograph->getId(), $supportedLocales),
104  (array) $submissionSubjectDao->getSubjects($monograph->getId(), $supportedLocales)
105  );
106  $this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects);
107 
108  // Description
109  $this->_addLocalizedElements($dc11Description, 'dc:description', $monograph->getAbstract(null));
110 
111  // Publisher
112  $publisherInstitution = $press->getSetting('publisherInstitution');
113  if (!empty($publisherInstitution)) {
114  $publishers = array($press->getPrimaryLocale() => $publisherInstitution);
115  } else {
116  $publishers = $press->getName(null); // Default
117  }
118  $this->_addLocalizedElements($dc11Description, 'dc:publisher', $publishers);
119 
120  // Contributor
121  $contributors = $monograph->getSponsor(null);
122  if (is_array($contributors)) {
123  foreach ($contributors as $locale => $contributor) {
124  $contributors[$locale] = array_map('trim', explode(';', $contributor));
125  }
126  $this->_addLocalizedElements($dc11Description, 'dc:contributor', $contributors);
127  }
128 
129  // Date
130  // FIXME: should we use the publication dates of the publication format? If yes,
131  // in which role preference order?
132  if (is_a($monograph, 'Submission')) {
133  if ($monograph->getDatePublished()) $dc11Description->addStatement('dc:date', date('Y-m-d', strtotime($monograph->getDatePublished())));
134  }
135 
136  // Type
137  $types = array_merge_recursive(
138  array(AppLocale::getLocale() => __('rt.metadata.pkp.dctype')),
139  (array) $monograph->getType(null)
140  );
141  $this->_addLocalizedElements($dc11Description, 'dc:type', $types);
142 
143  // Format
144  $onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /* @var $onixCodelistItemDao ONIXCodelistItemDAO */
145  $entryKeys = $onixCodelistItemDao->getCodes('List7'); // List7 is for object formats
146  if ($publicationFormat->getEntryKey()) {
147  $formatName = $entryKeys[$publicationFormat->getEntryKey()];
148  $dc11Description->addStatement('dc:format', $formatName);
149  }
150 
151  // Identifier: URL
152  if (is_a($monograph, 'Submission')) {
153  $request = Application::get()->getRequest();
154  $dc11Description->addStatement('dc:identifier', $request->url($press->getPath(), 'catalog', 'book', array($monograph->getId())));
155  }
156 
157  // Public idntifiers (e.g. DOI, URN)
158  $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true);
159  foreach ((array) $pubIdPlugins as $plugin) {
160  $pubId = $plugin->getPubId($publicationFormat);
161  if ($pubId) {
162  $dc11Description->addStatement('dc:identifier', $pubId);
163  }
164  }
165 
166  // Identifier: others
167  $identificationCodeFactory = $publicationFormat->getIdentificationCodes();
168  while ($identificationCode = $identificationCodeFactory->next()) {
169  $dc11Description->addStatement('dc:identifier', $identificationCode->getValue());
170  }
171 
172  // Source (press title and pages)
173  $sources = $press->getName(null);
174  $pages = $monograph->getPages();
175  if (!empty($pages)) $pages = '; ' . $pages;
176  foreach ($sources as $locale => $source) {
177  $sources[$locale] .= '; ';
178  $sources[$locale] .= $pages;
179  }
180  $this->_addLocalizedElements($dc11Description, 'dc:source', $sources);
181 
182  // Language
183 
184  // Relation
185 
186  // Coverage
187  $coverage = (array) $monograph->getCoverage(null);
188  $this->_addLocalizedElements($dc11Description, 'dc:coverage', $coverage);
189 
190  // Rights
191  $salesRightsFactory = $publicationFormat->getSalesRights();
192  while ($salesRight = $salesRightsFactory->next()) {
193  $dc11Description->addStatement('dc:rights', $salesRight->getNameForONIXCode());
194  }
195 
196  Hookregistry::call('Dc11SchemaPublicationFormatAdapter::extractMetadataFromDataObject', array(&$this, $monograph, $press, &$dc11Description));
197 
198  return $dc11Description;
199  }
200 
205  function getDataObjectMetadataFieldNames($translated = true) {
206  // All DC fields are mapped.
207  return array();
208  }
209 
210 
211  //
212  // Private helper methods
213  //
220  function _addLocalizedElements(&$description, $propertyName, $localizedValues) {
221  foreach(stripAssocArray((array) $localizedValues) as $locale => $values) {
222  if (is_scalar($values)) $values = array($values);
223  foreach($values as $value) {
224  $description->addStatement($propertyName, $value, $locale);
225  unset($value);
226  }
227  }
228  }
229 }
230 
Dc11SchemaPublicationFormatAdapter\getDataObjectMetadataFieldNames
getDataObjectMetadataFieldNames($translated=true)
Definition: Dc11SchemaPublicationFormatAdapter.inc.php:205
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
Dc11SchemaPublicationFormatAdapter\__construct
__construct(&$filterGroup)
Definition: Dc11SchemaPublicationFormatAdapter.inc.php:27
Dc11SchemaPublicationFormatAdapter\_addLocalizedElements
_addLocalizedElements(&$description, $propertyName, $localizedValues)
Definition: Dc11SchemaPublicationFormatAdapter.inc.php:220
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
Dc11SchemaPublicationFormatAdapter\getClassName
getClassName()
Definition: Dc11SchemaPublicationFormatAdapter.inc.php:38
Dc11SchemaPublicationFormatAdapter\extractMetadataFromDataObject
extractMetadataFromDataObject(&$publicationFormat)
Definition: Dc11SchemaPublicationFormatAdapter.inc.php:61
MetadataDataObjectAdapter
Class that injects/extracts a meta-data description into/from an application entity object (DataObjec...
Definition: MetadataDataObjectAdapter.inc.php:29
MetadataDataObjectAdapter\instantiateMetadataDescription
& instantiateMetadataDescription()
Definition: MetadataDataObjectAdapter.inc.php:324
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
Dc11SchemaPublicationFormatAdapter
Adapter that injects/extracts Dublin Core schema compliant meta-data into/from a PublicationFormat ob...
Definition: Dc11SchemaPublicationFormatAdapter.inc.php:22
stripAssocArray
stripAssocArray($values)
Definition: functions.inc.php:263
Dc11SchemaPublicationFormatAdapter\injectMetadataIntoDataObject
& injectMetadataIntoDataObject(&$dc11Description, &$publicationFormat)
Definition: Dc11SchemaPublicationFormatAdapter.inc.php:51
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40
AppLocale\getSupportedFormLocales
static getSupportedFormLocales()
Definition: env1/MockAppLocale.inc.php:124
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49