Open Preprint Systems  3.3.0
Dc11SchemaArticleAdapter.inc.php
1 <?php
2 
21 import('lib.pkp.classes.metadata.MetadataDataObjectAdapter');
22 
24  //
25  // Implement template methods from Filter
26  //
30  function getClassName() {
31  return 'plugins.metadata.dc11.filter.Dc11SchemaArticleAdapter';
32  }
33 
34 
35  //
36  // Implement template methods from MetadataDataObjectAdapter
37  //
43  function &injectMetadataIntoDataObject(&$metadataDescription, &$targetDataObject) {
44  // Not implemented
45  assert(false);
46  }
47 
53  function &extractMetadataFromDataObject(&$article) {
54  assert(is_a($article, 'Article'));
55 
56  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_SUBMISSION);
57 
58  // Retrieve data that belongs to the article.
59  // FIXME: Retrieve this data from the respective entity DAOs rather than
60  // from the OAIDAO once we've migrated all OAI providers to the
61  // meta-data framework. We're using the OAIDAO here because it
62  // contains cached entities and avoids extra database access if this
63  // adapter is called from an OAI context.
64  $oaiDao = DAORegistry::getDAO('OAIDAO'); /* @var $oaiDao OAIDAO */
65  $journal = $oaiDao->getJournal($article->getData('contextId'));
66  $section = $oaiDao->getSection($article->getSectionId());
67 
68  $dc11Description = $this->instantiateMetadataDescription();
69 
70  // Title
71  $this->_addLocalizedElements($dc11Description, 'dc:title', $article->getFullTitle(null));
72 
73  // Creator
74  $authors = $article->getAuthors();
75  foreach($authors as $author) {
76  $dc11Description->addStatement('dc:creator', $author->getFullName(false, true));
77  }
78 
79  // Subject
80  $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO');
81  $submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO');
82  $supportedLocales = array_keys(AppLocale::getSupportedFormLocales());
83  $subjects = array_merge_recursive(
84  (array) $submissionKeywordDao->getKeywords($article->getCurrentPublication()->getId(), $supportedLocales),
85  (array) $submissionSubjectDao->getSubjects($article->getCurrentPublication()->getId(), $supportedLocales)
86  );
87  $this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects);
88 
89  // Description
90  $this->_addLocalizedElements($dc11Description, 'dc:description', $article->getAbstract(null));
91 
92  // Publisher
93  $publisherInstitution = $journal->getData('publisherInstitution');
94  if (!empty($publisherInstitution)) {
95  $publishers = array($journal->getPrimaryLocale() => $publisherInstitution);
96  } else {
97  $publishers = $journal->getName(null); // Default
98  }
99  $this->_addLocalizedElements($dc11Description, 'dc:publisher', $publishers);
100 
101  // Contributor
102  $contributors = (array) $article->getSponsor(null);
103  foreach ($contributors as $locale => $contributor) {
104  $contributors[$locale] = array_map('trim', explode(';', $contributor));
105  }
106  $this->_addLocalizedElements($dc11Description, 'dc:contributor', $contributors);
107 
108 
109  // Date
110  if (is_a($article, 'Submission')) {
111  if ($article->getDatePublished()) $dc11Description->addStatement('dc:date', date('Y-m-d', strtotime($article->getDatePublished()))); }
112 
113  // Type
114  $driverType = 'info:eu-repo/semantics/preprint';
115  $dc11Description->addStatement('dc:type', $driverType, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
116  $this->_addLocalizedElements($dc11Description, 'dc:type', $types);
117  $driverVersion = 'info:eu-repo/semantics/publishedVersion';
118  $dc11Description->addStatement('dc:type', $driverVersion, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
119 
120  // Format
121  if (is_a($article, 'Submission')) {
122  $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $articleGalleyDao ArticleGalleyDAO */
123  $galleys = $articleGalleyDao->getByPublicationId($article->getCurrentPublication()->getId());
124  $formats = array();
125  while ($galley = $galleys->next()) {
126  $dc11Description->addStatement('dc:format', $galley->getFileType());
127  }
128  }
129 
130  // Identifier: URL
131  $request = Application::get()->getRequest();
132  if (is_a($article, 'Submission')) {
133  $dc11Description->addStatement('dc:identifier', $request->url($journal->getPath(), 'preprint', 'view', array($article->getBestId())));
134  }
135 
136  // Get galleys and supp files.
137  $galleys = array();
138  if (is_a($article, 'Submission')) {
139  $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $articleGalleyDao ArticleGalleyDAO */
140  $galleys = $articleGalleyDao->getByPublicationId($article->getCurrentPublication()->getId())->toArray();
141  }
142 
143  // Language
144  $locales = array();
145  if (is_a($article, 'Submission')) {
146  foreach ($galleys as $galley) {
147  $galleyLocale = $galley->getLocale();
148  if(!is_null($galleyLocale) && !in_array($galleyLocale, $locales)) {
149  $locales[] = $galleyLocale;
150  $dc11Description->addStatement('dc:language', AppLocale::getIso3FromLocale($galleyLocale));
151  }
152  }
153  }
154  $articleLanguage = $article->getLanguage();
155  if (empty($locales) && !empty($articleLanguage)) {
156  $dc11Description->addStatement('dc:language', strip_tags($articleLanguage));
157  }
158 
159  // Relation
160  // full text URLs
161  if ($includeUrls) foreach ($galleys as $galley) {
162  $relation = $request->url($journal->getPath(), 'article', 'view', array($article->getBestId(), $galley->getBestGalleyId()));
163  $dc11Description->addStatement('dc:relation', $relation);
164  }
165 
166  // Public identifiers
167  $pubIdPlugins = (array) PluginRegistry::loadCategory('pubIds', true, $journal->getId());
168  foreach ($pubIdPlugins as $pubIdPlugin) {
169  if ($pubArticleId = $article->getStoredPubId($pubIdPlugin->getPubIdType())) {
170  $dc11Description->addStatement('dc:identifier', $pubArticleId);
171  }
172  foreach ($galleys as $galley) {
173  if ($pubGalleyId = $galley->getStoredPubId($pubIdPlugin->getPubIdType())) {
174  $dc11Description->addStatement('dc:relation', $pubGalleyId);
175  }
176  }
177  }
178 
179  // Coverage
180  $this->_addLocalizedElements($dc11Description, 'dc:coverage', (array) $article->getCoverage(null));
181 
182  // Rights: Add both copyright statement and license
183  $copyrightHolder = $article->getLocalizedCopyrightHolder();
184  $copyrightYear = $article->getCopyrightYear();
185  if (!empty($copyrightHolder) && !empty($copyrightYear)) {
186  $dc11Description->addStatement('dc:rights', __('submission.copyrightStatement', array('copyrightHolder' => $copyrightHolder, 'copyrightYear' => $copyrightYear)));
187  }
188  if ($licenseUrl = $article->getLicenseURL()) $dc11Description->addStatement('dc:rights', $licenseUrl);
189 
190  HookRegistry::call('Dc11SchemaArticleAdapter::extractMetadataFromDataObject', array($this, $article, $journal, &$dc11Description));
191 
192  return $dc11Description;
193  }
194 
199  function getDataObjectMetadataFieldNames($translated = true) {
200  // All DC fields are mapped.
201  return array();
202  }
203 
204 
205  //
206  // Private helper methods
207  //
214  function _addLocalizedElements(&$description, $propertyName, $localizedValues) {
215  foreach(stripAssocArray((array) $localizedValues) as $locale => $values) {
216  if (is_scalar($values)) $values = array($values);
217  foreach($values as $value) {
218  if (!empty($value)) {
219  $description->addStatement($propertyName, $value, $locale);
220  }
221  }
222  }
223  }
224 }
Dc11SchemaArticleAdapter\getClassName
getClassName()
Definition: Dc11SchemaArticleAdapter.inc.php:30
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PKPLocale\getIso3FromLocale
static getIso3FromLocale($locale)
Definition: PKPLocale.inc.php:750
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
Dc11SchemaArticleAdapter\getDataObjectMetadataFieldNames
getDataObjectMetadataFieldNames($translated=true)
Definition: Dc11SchemaArticleAdapter.inc.php:199
Dc11SchemaArticleAdapter\injectMetadataIntoDataObject
& injectMetadataIntoDataObject(&$metadataDescription, &$targetDataObject)
Definition: Dc11SchemaArticleAdapter.inc.php:43
Dc11SchemaArticleAdapter
Abstract base class for meta-data adapters that injects/extracts Dublin Core schema compliant meta-da...
Definition: Dc11SchemaArticleAdapter.inc.php:23
Dc11SchemaArticleAdapter\_addLocalizedElements
_addLocalizedElements(&$description, $propertyName, $localizedValues)
Definition: Dc11SchemaArticleAdapter.inc.php:214
stripAssocArray
stripAssocArray($values)
Definition: functions.inc.php:263
Dc11SchemaArticleAdapter\extractMetadataFromDataObject
& extractMetadataFromDataObject(&$article)
Definition: Dc11SchemaArticleAdapter.inc.php:53
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
AppLocale\getSupportedFormLocales
static getSupportedFormLocales()
Definition: env1/MockAppLocale.inc.php:124