Open Journal 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, 'Submission'));
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  if (is_a($article, 'Submission')) { /* @var $article Submission */
68  $issue = $oaiDao->getIssue($article->getCurrentPublication()->getData('issueId'));
69  } else $issue = null;
70 
71  $dc11Description = $this->instantiateMetadataDescription();
72 
73  // Title
74  $this->_addLocalizedElements($dc11Description, 'dc:title', $article->getFullTitle(null));
75 
76  // Creator
77  $authors = $article->getAuthors();
78  foreach($authors as $author) {
79  $dc11Description->addStatement('dc:creator', $author->getFullName(false, true));
80  }
81 
82  // Subject
83  $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /* @var $submissionKeywordDao SubmissionKeywordDAO */
84  $submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /* @var $submissionSubjectDao SubmissionSubjectDAO */
85  $supportedLocales = array_keys(AppLocale::getSupportedFormLocales());
86  $subjects = array_merge_recursive(
87  (array) $submissionKeywordDao->getKeywords($article->getCurrentPublication()->getId(), $supportedLocales),
88  (array) $submissionSubjectDao->getSubjects($article->getCurrentPublication()->getId(), $supportedLocales)
89  );
90  $this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects);
91 
92  // Description
93  $this->_addLocalizedElements($dc11Description, 'dc:description', $article->getAbstract(null));
94 
95  // Publisher
96  $publisherInstitution = $journal->getData('publisherInstitution');
97  if (!empty($publisherInstitution)) {
98  $publishers = array($journal->getPrimaryLocale() => $publisherInstitution);
99  } else {
100  $publishers = $journal->getName(null); // Default
101  }
102  $this->_addLocalizedElements($dc11Description, 'dc:publisher', $publishers);
103 
104  // Contributor
105  $contributors = (array) $article->getSponsor(null);
106  foreach ($contributors as $locale => $contributor) {
107  $contributors[$locale] = array_map('trim', explode(';', $contributor));
108  }
109  $this->_addLocalizedElements($dc11Description, 'dc:contributor', $contributors);
110 
111 
112  // Date
113  if (is_a($article, 'Submission')) {
114  if ($article->getDatePublished()) $dc11Description->addStatement('dc:date', date('Y-m-d', strtotime($article->getDatePublished())));
115  elseif (isset($issue) && $issue->getDatePublished()) $dc11Description->addStatement('dc:date', date('Y-m-d', strtotime($issue->getDatePublished())));
116  }
117 
118  // Type
119  $driverType = 'info:eu-repo/semantics/article';
120  $dc11Description->addStatement('dc:type', $driverType, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
121  $types = $section->getIdentifyType(null);
122  $types = array_merge_recursive(
123  empty($types)?array(AppLocale::getLocale() => __('metadata.pkp.peerReviewed')):$types,
124  (array) $article->getType(null)
125  );
126  $this->_addLocalizedElements($dc11Description, 'dc:type', $types);
127  $driverVersion = 'info:eu-repo/semantics/publishedVersion';
128  $dc11Description->addStatement('dc:type', $driverVersion, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
129 
130 
131  // Format
132  if (is_a($article, 'Submission')) {
133  $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $articleGalleyDao ArticleGalleyDAO */
134  $galleys = $articleGalleyDao->getByPublicationId($article->getCurrentPublication()->getId());
135  $formats = array();
136  while ($galley = $galleys->next()) {
137  $dc11Description->addStatement('dc:format', $galley->getFileType());
138  }
139  }
140 
141  // Identifier: URL
142  import('classes.issue.IssueAction');
143  $issueAction = new IssueAction();
144  $request = Application::get()->getRequest();
145  $includeUrls = $journal->getSetting('publishingMode') != PUBLISHING_MODE_NONE || $issueAction->subscribedUser($request->getUser(), $journal, null, $article->getId());
146  if (is_a($article, 'Submission') && $includeUrls) {
147  $dc11Description->addStatement('dc:identifier', $request->url($journal->getPath(), 'article', 'view', array($article->getBestId())));
148  }
149 
150  // Source (journal title, issue id and pages)
151  $sources = $journal->getName(null);
152  $pages = $article->getPages();
153  if (!empty($pages)) $pages = '; ' . $pages;
154  foreach ($sources as $locale => $source) {
155  if (is_a($article, 'Submission')) {
156  $sources[$locale] .= '; ' . $issue->getIssueIdentification(array(), $locale);
157  }
158  $sources[$locale] .= $pages;
159  }
160  $this->_addLocalizedElements($dc11Description, 'dc:source', $sources);
161  if ($issn = $journal->getData('onlineIssn')) {
162  $dc11Description->addStatement('dc:source', $issn, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
163  }
164  if ($issn = $journal->getData('printIssn')) {
165  $dc11Description->addStatement('dc:source', $issn, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
166  }
167 
168  // Get galleys and supp files.
169  $galleys = array();
170  if (is_a($article, 'Submission')) {
171  $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $articleGalleyDao ArticleGalleyDAO */
172  $galleys = $articleGalleyDao->getByPublicationId($article->getCurrentPublication()->getId())->toArray();
173  }
174 
175  // Language
176  $locales = array();
177  if (is_a($article, 'Submission')) {
178  foreach ($galleys as $galley) {
179  $galleyLocale = $galley->getLocale();
180  if(!is_null($galleyLocale) && !in_array($galleyLocale, $locales)) {
181  $locales[] = $galleyLocale;
182  $dc11Description->addStatement('dc:language', AppLocale::getIso3FromLocale($galleyLocale));
183  }
184  }
185  }
186  $articleLanguage = $article->getLanguage();
187  if (empty($locales) && !empty($articleLanguage)) {
188  $dc11Description->addStatement('dc:language', strip_tags($articleLanguage));
189  }
190 
191  // Relation
192  // full text URLs
193  if ($includeUrls) foreach ($galleys as $galley) {
194  $relation = $request->url($journal->getPath(), 'article', 'view', array($article->getBestId(), $galley->getBestGalleyId()));
195  $dc11Description->addStatement('dc:relation', $relation);
196  }
197 
198  // Public identifiers
199  $pubIdPlugins = (array) PluginRegistry::loadCategory('pubIds', true, $journal->getId());
200  foreach ($pubIdPlugins as $pubIdPlugin) {
201  if ($issue && $pubIssueId = $issue->getStoredPubId($pubIdPlugin->getPubIdType())) {
202  $dc11Description->addStatement('dc:source', $pubIssueId, METADATA_DESCRIPTION_UNKNOWN_LOCALE);
203  }
204  if ($pubArticleId = $article->getStoredPubId($pubIdPlugin->getPubIdType())) {
205  $dc11Description->addStatement('dc:identifier', $pubArticleId);
206  }
207  foreach ($galleys as $galley) {
208  if ($pubGalleyId = $galley->getStoredPubId($pubIdPlugin->getPubIdType())) {
209  $dc11Description->addStatement('dc:relation', $pubGalleyId);
210  }
211  }
212  }
213 
214  // Coverage
215  $this->_addLocalizedElements($dc11Description, 'dc:coverage', (array) $article->getCoverage(null));
216 
217  // Rights: Add both copyright statement and license
218  $copyrightHolder = $article->getLocalizedCopyrightHolder();
219  $copyrightYear = $article->getCopyrightYear();
220  if (!empty($copyrightHolder) && !empty($copyrightYear)) {
221  $dc11Description->addStatement('dc:rights', __('submission.copyrightStatement', array('copyrightHolder' => $copyrightHolder, 'copyrightYear' => $copyrightYear)));
222  }
223  if ($licenseUrl = $article->getLicenseURL()) $dc11Description->addStatement('dc:rights', $licenseUrl);
224 
225  HookRegistry::call('Dc11SchemaArticleAdapter::extractMetadataFromDataObject', array($this, $article, $journal, $issue, &$dc11Description));
226 
227  return $dc11Description;
228  }
229 
234  function getDataObjectMetadataFieldNames($translated = true) {
235  // All DC fields are mapped.
236  return array();
237  }
238 
239 
240  //
241  // Private helper methods
242  //
249  function _addLocalizedElements(&$description, $propertyName, $localizedValues) {
250  foreach(stripAssocArray((array) $localizedValues) as $locale => $values) {
251  if (is_scalar($values)) $values = array($values);
252  foreach($values as $value) {
253  if (!empty($value)) {
254  $description->addStatement($propertyName, $value, $locale);
255  }
256  }
257  }
258  }
259 }
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
IssueAction
IssueAction class.
Definition: IssueAction.inc.php:17
Dc11SchemaArticleAdapter\getDataObjectMetadataFieldNames
getDataObjectMetadataFieldNames($translated=true)
Definition: Dc11SchemaArticleAdapter.inc.php:234
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:249
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\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40
AppLocale\getSupportedFormLocales
static getSupportedFormLocales()
Definition: env1/MockAppLocale.inc.php:124