Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
MonographONIX30XmlFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeExportFilter');
17 
19 
21  var $_doc;
22 
27  function MonographONIX30XmlFilter($filterGroup) {
28  $this->setDisplayName('ONIX 3.0 XML monograph export');
29  parent::NativeExportFilter($filterGroup);
30  }
31 
32 
33  //
34  // Implement template methods from PersistableFilter
35  //
39  function getClassName() {
40  return 'plugins.importexport.onix30.filter.MonographONIX30XmlFilter';
41  }
42 
43 
44  //
45  // Implement template methods from Filter
46  //
52  function &process(&$monograph) {
53 
54  // Note: There are ONIX fields that can only be assembled from a PublishedMonograph class.
55  // e.g. the Audience components. Since this filter can also be used for native import/import
56  // export, check to see if we have have a published monograph and use it, otherwise fall back
57  // with safe defaults.
58 
59  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
60  $publishedMonograph = $publishedMonographDao->getById($monograph->getId());
61  if ($publishedMonograph) {
62  $monograph = $publishedMonograph;
63  }
64 
65  // Create the XML document
66  $doc = new DOMDocument('1.0');
67  $this->_doc = $doc;
68 
69  $deployment = $this->getDeployment();
70 
71  // create top level ONIXMessage element
72  $rootNode = $doc->createElementNS($deployment->getNamespace(), 'ONIXMessage');
73  $rootNode->appendChild($this->createHeaderNode($doc, $monograph));
74 
75  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
76  $publicationFormats = $publicationFormatDao->getBySubmissionId($monograph->getId());
77 
78  // Append all publication formats as Product nodes.
79  while ($publicationFormat = $publicationFormats->next()) {
80  $rootNode->appendChild($this->createProductNode($doc, $monograph, $publicationFormat));
81  }
82  $doc->appendChild($rootNode);
83  $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
84  $rootNode->setAttribute('xsi:schemaLocation', $deployment->getNamespace() . ' ' . $deployment->getSchemaFilename());
85  $rootNode->setAttribute('release', '3.0');
86 
87  return $doc;
88  }
89 
90  //
91  // ONIX conversion functions
92  //
99  function createHeaderNode($doc, $submission) {
100  $deployment = $this->getDeployment();
101  $context = $deployment->getContext();
102 
103  $headNode = $doc->createElementNS($deployment->getNamespace(), 'Header');
104  $senderNode = $doc->createElementNS($deployment->getNamespace(), 'Sender');
105 
106  // Assemble SenderIdentifier element.
107  $senderIdentifierNode = $doc->createElementNS($deployment->getNamespace(), 'SenderIdentifier');
108  $senderIdentifierNode->appendChild($this->_buildTextNode($doc, 'SenderIDType', $context->getSetting('codeType')));
109  $senderIdentifierNode->appendChild($this->_buildTextNode($doc, 'IDValue', $context->getSetting('codeValue')));
110 
111  $senderNode->appendChild($senderIdentifierNode);
112 
113  // Assemble SenderName element.
114  $senderNode->appendChild($this->_buildTextNode($doc, 'SenderName', $context->getLocalizedName()));
115  $senderNode->appendChild($this->_buildTextNode($doc, 'ContactName', $context->getContactName()));
116  $senderNode->appendChild($this->_buildTextNode($doc, 'EmailAddress', $context->getContactEmail()));
117 
118  $headNode->appendChild($senderNode);
119 
120  // add SentDateTime element.
121  $headNode->appendChild($this->_buildTextNode($doc, 'SentDateTime', date('Ymd')));
122 
123  return $headNode;
124  }
125 
133  function createProductNode($doc, $submission, $publicationFormat) {
134 
135  $deployment = $this->getDeployment();
136  $context = $deployment->getContext();
137  $onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO');
138 
139  $productNode = $doc->createElementNS($deployment->getNamespace(), 'Product');
140 
141  $productNode->appendChild($this->_buildTextNode($doc, 'RecordReference', Request::url($context->getPath(), 'monograph', 'view', array($submission->getId()))));
142  $productNode->appendChild($this->_buildTextNode($doc, 'NotificationType', '03'));
143  $productNode->appendChild($this->_buildTextNode($doc, 'RecordSourceType', '04')); // Bibliographic agency
144 
145  $identificationCodes = $publicationFormat->getIdentificationCodes();
146 
147  while ($code = $identificationCodes->next()) {
148  $productIdentifierNode = $doc->createElementNS($deployment->getNamespace(), 'ProductIdentifier');
149  $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'ProductIDType', $code->getCode())); // GTIN-13 (ISBN-13 as GTIN)
150  $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'IDValue', $code->getValue()));
151  $productNode->appendChild($productIdentifierNode);
152 
153  unset($productIdentifierNode);
154  unset($code);
155  }
156 
157  // Deal with the possibility of a DOI pubId from the plugin.
158  $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true);
159  if (is_array($pubIdPlugins)) {
160  foreach ($pubIdPlugins as $plugin) {
161  if ($plugin->getEnabled() && $plugin->getPubIdType() == 'doi') {
162  $productIdentifierNode = $doc->createElementNS($deployment->getNamespace(), 'ProductIdentifier');
163  $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'ProductIDType', '06')); // DOI
164  $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'IDValue', $publicationFormat->getStoredPubId('doi'))); // GTIN-13 (ISBN-13 as GTIN)
165  $productNode->appendChild($productIdentifierNode);
166 
167  unset($productIdentifierNode);
168  }
169  unset($plugin);
170  }
171  }
172  unset($pubIdPlugins);
173 
174  /* --- Descriptive Detail --- */
175  $descDetailNode = $doc->createElementNS($deployment->getNamespace(), 'DescriptiveDetail');
176 
177  $descDetailNode->appendChild($this->_buildTextNode($doc, 'ProductComposition',
178  $publicationFormat->getProductCompositionCode() ? $publicationFormat->getProductCompositionCode() : '00')); // single item, trade only, etc. Default to single item if not specified.
179 
180  $descDetailNode->appendChild($this->_buildTextNode($doc, 'ProductForm', $publicationFormat->getEntryKey())); // paperback, hardcover, etc
181 
182  if ($publicationFormat->getProductFormDetailCode() != '') {
183  $descDetailNode->appendChild($this->_buildTextNode($doc, 'ProductFormDetail', $publicationFormat->getProductFormDetailCode())); // refinement of ProductForm
184  }
185 
186  /* --- Physical Book Measurements --- */
187  if ($publicationFormat->getPhysicalFormat()) {
188  // '01' => 'Height', '02' => 'Width', '03' => 'Thickness', '08' => 'Weight'
189  if ($publicationFormat->getHeight() != '') {
190  $measureNode = $this->_createMeasurementNode($doc, $deployment, '01', $publicationFormat->getHeight(), $publicationFormat->getHeightUnitCode());
191  $descDetailNode->appendChild($measureNode);
192  unset($measureNode);
193  }
194 
195  if ($publicationFormat->getWidth() != '') {
196  $measureNode = $this->_createMeasurementNode($doc, $deployment, '02', $publicationFormat->getWidth(), $publicationFormat->getWidthUnitCode());
197  $descDetailNode->appendChild($measureNode);
198  unset($measureNode);
199  }
200 
201  if ($publicationFormat->getThickness() != '') {
202  $measureNode = $this->_createMeasurementNode($doc, $deployment, '03', $publicationFormat->getThickness(), $publicationFormat->getThicknessUnitCode());
203  $descDetailNode->appendChild($measureNode);
204  unset($measureNode);
205  }
206 
207  if ($publicationFormat->getWeight() != '') {
208  $measureNode = $this->_createMeasurementNode($doc, $deployment, '08', $publicationFormat->getWeight(), $publicationFormat->getWeightUnitCode());
209  $descDetailNode->appendChild($measureNode);
210  unset($measureNode);
211  }
212  }
213 
214  if($publicationFormat->getCountryManufactureCode() != '') {
215  $descDetailNode->appendChild($this->_buildTextNode($doc, 'CountryOfManufacture', $publicationFormat->getCountryManufactureCode()));
216  }
217 
218  if (!$publicationFormat->getPhysicalFormat() && $publicationFormat->getTechnicalProtectionCode() != '') {
219  $descDetailNode->appendChild($this->_buildTextNode($doc, 'EpubTechnicalProtection', $publicationFormat->getTechnicalProtectionCode()));
220  }
221 
222  /* --- Collection information, first for series and then for product --- */
223 
224  $seriesCollectionNode = $doc->createElementNS($deployment->getNamespace(), 'Collection');
225  $seriesCollectionNode->appendChild($this->_buildTextNode($doc, 'CollectionType', '10')); // publisher series.
226  $descDetailNode->appendChild($seriesCollectionNode);
227 
228  $seriesTitleDetailNode = $doc->createElementNS($deployment->getNamespace(), 'TitleDetail');
229  $seriesTitleDetailNode->appendChild($this->_buildTextNode($doc, 'TitleType', '01'));
230  $seriesCollectionNode->appendChild($seriesTitleDetailNode);
231 
232  $titleElementNode = $doc->createElementNS($deployment->getNamespace(), 'TitleElement');
233  $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleElementLevel', '02')); // Collection level title
234  $seriesTitleDetailNode->appendChild($titleElementNode);
235 
236  /* --- Series information, if this monograph is part of one. --- */
237 
238  $seriesDao = DAORegistry::getDAO('SeriesDAO');
239  $series = $seriesDao->getById($submission->getSeriesId());
240  if ($series != null) {
241  $titleElementNode->appendChild($this->_buildTextNode($doc, 'PartNumber', $submission->getSeriesPosition()));
242 
243  if ($series->getLocalizedPrefix() == '' || $series->getLocalizedTitle() == '') {
244  $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim(join(' ', array($series->getLocalizedPrefix(), $series->getLocalizedTitle())))));
245  } else {
246  if ($series->getLocalizedPrefix() != '') {
247  $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $series->getLocalizedPrefix()));
248  }
249 
250  $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $series->getLocalizedTitle()));
251  }
252 
253  if ($series->getLocalizedSubtitle() != '') {
254  $titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $series->getLocalizedSubtitle()));
255  }
256  }
257 
258  /* --- and now product level info --- */
259 
260  $productTitleDetailNode = $doc->createElementNS($deployment->getNamespace(), 'TitleDetail');
261  $productTitleDetailNode->appendChild($this->_buildTextNode($doc, 'TitleType', '01'));
262  $descDetailNode->appendChild($productTitleDetailNode);
263 
264  $titleElementNode = $doc->createElementNS($deployment->getNamespace(), 'TitleElement');
265  $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleElementLevel', '01'));
266 
267  $productTitleDetailNode->appendChild($titleElementNode);
268 
269  if ($submission->getLocalizedPrefix() == '' || $submission->getLocalizedTitle() == '') {
270  $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim(join(' ', array($submission->getLocalizedPrefix(), $submission->getLocalizedTitle())))));
271  } else {
272  if ($submission->getLocalizedPrefix() != '') {
273  $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $submission->getLocalizedPrefix()));
274  }
275  $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $submission->getLocalizedTitle()));
276  }
277 
278  if ($submission->getLocalizedSubtitle() != '') {
279  $titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $submission->getLocalizedSubtitle()));
280  }
281 
282  /* --- Contributor information --- */
283 
284  $authors = $submission->getAuthors(); // sorts by sequence.
285  $sequence = 1;
286  foreach ($authors as $author) {
287  $contributorNode = $doc->createElementNS($deployment->getNamespace(), 'Contributor');
288  $contributorNode->appendChild($this->_buildTextNode($doc, 'SequenceNumber', $sequence));
289 
290  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
291  $userGroup = $userGroupDao->getById($author->getUserGroupId(), $submission->getContextId());
292 
293  $userGroupOnixMap = array('AU' => 'A01', 'VE' => 'B01', 'CA' => 'A01', 'Trans' => 'B06', 'PE' => 'B21'); // From List17, ContributorRole types.
294 
295  $role = array_key_exists($userGroup->getLocalizedAbbrev(), $userGroupOnixMap) ? $userGroupOnixMap[$userGroup->getLocalizedAbbrev()] : 'Z99'; // Z99 - unknown contributor type.
296 
297  $contributorNode->appendChild($this->_buildTextNode($doc, 'ContributorRole', $role));
298  $contributorNode->appendChild($this->_buildTextNode($doc, 'PersonName', $author->getFullName()));
299  $contributorNode->appendChild($this->_buildTextNode($doc, 'PersonNameInverted', $author->getFullName(true)));
300  $contributorNode->appendChild($this->_buildTextNode($doc, 'NamesBeforeKey', trim(join(' ', array($author->getFirstName(), $author->getMiddleName())))));
301  if ($author->getLastName() != '') {
302  $contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getLastName()));
303  } else {
304  $contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getFullName()));
305  }
306 
307  if ($author->getSuffix() != '') {
308  $contributorNode->appendChild($this->_buildTextNode($doc, 'SuffixToKey', $author->getSuffix()));
309  }
310 
311  if ($author->getLocalizedBiography() != '') {
312  $contributorNode->appendChild($this->_buildTextNode($doc, 'BiographicalNote', $author->getLocalizedBiography()));
313  }
314 
315  if ($author->getCountry() != '') {
316  $contributorPlaceNode = $doc->createElementNS($deployment->getNamespace(), 'ContributorPlace');
317  $contributorNode->appendChild($contributorPlaceNode);
318  $contributorPlaceNode->appendChild($this->_buildTextNode($doc, 'ContributorPlaceRelator', '04'));
319  $contributorPlaceNode->appendChild($this->_buildTextNode($doc, 'CountryCode', $author->getCountry()));
320  unset($contributorPlaceNode);
321  }
322 
323  $sequence++;
324  $descDetailNode->appendChild($contributorNode);
325 
326  unset($contributorNode);
327  unset($sequenceNode);
328  unset($userGroup);
329  unset($author);
330  }
331 
332  if (sizeof($authors) == 0) { // this will probably never happen, but include the possibility.
333  $descDetailNode->appendChild($this->_buildTextNode($doc, 'NoContributor', '')); // empty state of fact.
334  }
335 
336  /* --- Add Language elements --- */
337 
338  $submissionLanguageDao = DAORegistry::getDAO('SubmissionLanguageDAO');
339  $allLanguages = $submissionLanguageDao->getLanguages($submission->getId(), array_keys(AppLocale::getSupportedFormLocales()));
340  $uniqueLanguages = array();
341  foreach ($allLanguages as $locale => $languages) {
342  $uniqueLanguages = array_merge($uniqueLanguages, $languages);
343  }
344 
345  foreach ($uniqueLanguages as $language) {
346  $languageNode = $doc->createElementNS($deployment->getNamespace(), 'Language');
347  $descDetailNode->appendChild($languageNode);
348 
349  $languageNode->appendChild($this->_buildTextNode($doc, 'LanguageRole', '01'));
350  $onixLanguageCode = $onixCodelistItemDao->getCodeFromValue($language, 'List74');
351  $languageNode->appendChild($this->_buildTextNode($doc, 'LanguageCode', $onixLanguageCode));
352  unset($languageNode);
353  }
354 
355  /* --- add Extents for 00 (main content), 04 (back matter), 08 for digital works ---*/
356 
357  if ($publicationFormat->getFrontMatter() > 0) {
358  // 03 - Pages
359  $extentNode = $this->_createExtentNode($doc, $deployment, '00', $publicationFormat->getFrontMatter(), '03');
360  $descDetailNode->appendChild($extentNode);
361  unset($extentNode);
362  }
363 
364  if ($publicationFormat->getBackMatter() > 0) {
365  $extentNode = $this->_createExtentNode($doc, $deployment, '04', $publicationFormat->getBackMatter(), '03');
366  $descDetailNode->appendChild($extentNode);
367  unset($extentNode);
368  }
369 
370  if (!$publicationFormat->getPhysicalFormat()) { // EBooks and digital content have extent information about file sizes
371  $fileSize = $publicationFormat->getFileSize() ? $publicationFormat->getFileSize() : $publicationFormat->getCalculatedFileSize();
372  $extentNode = $this->_createExtentNode($doc, $deployment, '08', $fileSize, '05');
373  $descDetailNode->appendChild($extentNode);
374  unset($extentNode);
375  }
376 
377 
378  /* --- Add Subject elements --- */
379 
380  $subjectNode = $doc->createElementNS($deployment->getNamespace(), 'Subject');
381  $descDetailNode->appendChild($subjectNode);
382 
383  $mainSubjectNode = $doc->createElementNS($deployment->getNamespace(), 'MainSubject'); // Always empty as per 3.0 spec.
384  $subjectNode->appendChild($mainSubjectNode);
385  $subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeIdentifier', '12')); // 12 is BIC subject category code list.
386  $subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeVersion', '2')); // Version 2 of ^^
387 
388  $submissionSubjectDao =& DAORegistry::getDAO('SubmissionSubjectDAO');
389  $allSubjects =& $submissionSubjectDao->getSubjects($submission->getId(), array_keys(AppLocale::getSupportedFormLocales()));
390  $uniqueSubjects = array();
391  foreach ($allSubjects as $locale => $subjects) {
392  $uniqueSubjects = array_merge($uniqueSubjects, $subjects);
393  }
394 
395  if (sizeof($uniqueSubjects) > 0) {
396  $subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectCode', trim(join(' ', $uniqueSubjects))));
397  }
398 
399  /* --- Add Audience elements --- */
400 
401  if (is_a($submission, 'PublishedMonograph')) { // PublishedMonograph-specific fields.
402  if ($submission->getAudience()) {
403  $audienceNode = $doc->createElementNS($deployment->getNamespace(), 'Audience');
404  $descDetailNode->appendChild($audienceNode);
405  $audienceNode->appendChild($this->_buildTextNode($doc, 'AudienceCodeType', $submission->getAudience()));
406  $audienceNode->appendChild($this->_buildTextNode($doc, 'AudienceCodeValue', '01'));
407  }
408 
409  if ($submission->getAudienceRangeQualifier() != '') {
410  $audienceRangeNode = $doc->createElementNS($deployment->getNamespace(), 'AudienceRange');
411  $descDetailNode->appendChild($audienceRangeNode);
412  $audienceRangeNode->appendChild($this->_buildTextNode($doc, 'AudienceRangeQualifier', $submission->getAudienceRangeQualifier()));
413 
414  if ($submission->getAudienceRangeExact() != '') {
415  $audienceRangeNode->appendChild($this->_buildTextNode($doc, 'AudienceRangePrecision', '01')); // Exact, list31
416  $audienceRangeNode->appendChild($this->_buildTextNode($doc, 'AudienceRangeValue', $submission->getAudienceRangeExact()));
417  } else { // if not exact, then include the From -> To possibilities
418  if ($submission->getAudienceRangeFrom() != '') {
419  $audienceRangeNode->appendChild($this->_buildTextNode($doc, 'AudienceRangePrecision', '03')); // from
420  $audienceRangeNode->appendChild($this->_buildTextNode($doc, 'AudienceRangeValue', $submission->getAudienceRangeFrom()));
421  }
422  if ($submission->getAudienceRangeTo() != '') {
423  $audienceRangeNode->appendChild($this->_buildTextNode($doc, 'AudienceRangePrecision', '04')); // to
424  $audienceRangeNode->appendChild($this->_buildTextNode($doc, 'AudienceRangeValue', $submission->getAudienceRangeTo()));
425  }
426  }
427  }
428  }
429 
430  $productNode->appendChild($descDetailNode);
431 
432  // Back to assembling Product node.
433  /* --- Collateral Detail --- */
434 
435  $collateralDetailNode = $doc->createElementNS($deployment->getNamespace(), 'CollateralDetail');
436  $productNode->appendChild($collateralDetailNode);
437 
438  $abstract = strip_tags($submission->getLocalizedAbstract());
439 
440  $textContentNode = $doc->createElementNS($deployment->getNamespace(), 'TextContent');
441  $collateralDetailNode->appendChild($textContentNode);
442  $textContentNode->appendChild($this->_buildTextNode($doc, 'TextType', '02')); // short description
443  $textContentNode->appendChild($this->_buildTextNode($doc, 'ContentAudience', '00')); // Any audience
444  $textContentNode->appendChild($this->_buildTextNode($doc, 'Text', substr($abstract, 0, 250))); // Any audience
445 
446  $textContentNode = $doc->createElementNS($deployment->getNamespace(), 'TextContent');
447  $collateralDetailNode->appendChild($textContentNode);
448 
449  $textContentNode->appendChild($this->_buildTextNode($doc, 'TextType', '03')); // description
450  $textContentNode->appendChild($this->_buildTextNode($doc, 'ContentAudience', '00')); // Any audience
451  $textContentNode->appendChild($this->_buildTextNode($doc, 'Text', $abstract)); // Any audience
452 
453  /* --- Publishing Detail --- */
454 
455  $publishingDetailNode = $doc->createElementNS($deployment->getNamespace(), 'PublishingDetail');
456  $productNode->appendChild($publishingDetailNode);
457 
458  if ($publicationFormat->getImprint()) {
459  $imprintNode = $doc->createElementNS($deployment->getNamespace(), 'Imprint');
460  $publishingDetailNode->appendChild($imprintNode);
461  $imprintNode->appendChild($this->_buildTextNode($doc, 'ImprintName', $publicationFormat->getImprint()));
462  unset($imprintNode);
463  }
464 
465  $publisherNode = $doc->createElementNS($deployment->getNamespace(), 'Publisher');
466  $publishingDetailNode->appendChild($publisherNode);
467 
468  $publisherNode->appendChild($this->_buildTextNode($doc, 'PublishingRole', '01')); // Publisher
469  $publisherNode->appendChild($this->_buildTextNode($doc, 'PublisherName', $context->getSetting('publisher')));
470  if ($context->getSetting('location') != '') {
471  $publishingDetailNode->appendChild($this->_buildTextNode($doc, 'CityOfPublication', $context->getSetting('location')));
472  }
473 
474  $websiteNode = $doc->createElementNS($deployment->getNamespace(), 'Website');
475  $publisherNode->appendChild($websiteNode);
476 
477  $websiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '18')); // 18 -> Publisher's B2C website
478  $websiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', Request::url($context->getPath())));
479 
480  /* --- Publishing Dates --- */
481 
482  $publicationDates = $publicationFormat->getPublicationDates();
483  while ($date = $publicationDates->next()) {
484  $pubDateNode = $doc->createElementNS($deployment->getNamespace(), 'PublishingDate');
485  $publishingDetailNode->appendChild($pubDateNode);
486 
487  $pubDateNode->appendChild($this->_buildTextNode($doc, 'PublishingDateRole', $date->getRole()));
488 
489  $dateNode = $doc->createElementNS($deployment->getNamespace(), 'Date');
490  $dateNode->setAttribute('dateformat', $date->getDateFormat());
491  $pubDateNode->appendChild($dateNode);
492  $dateNode->appendChild($doc->createTextNode($date->getDate()));
493 
494  unset($pubDateNode);
495  unset($dateNode);
496  unset($date);
497  }
498 
499  /* -- Sales Rights -- */
500 
501  $allSalesRights = $publicationFormat->getSalesRights();
502  $salesRightsROW = null;
503  while ($salesRights = $allSalesRights->next()) {
504  if (!$salesRights->getROWSetting()) {
505 
506  $salesRightsNode = $doc->createElementNS($deployment->getNamespace(), 'SalesRights');
507  $publishingDetailNode->appendChild($salesRightsNode);
508  $salesRightsNode->appendChild($this->_buildTextNode($doc, 'SalesRightsType', $salesRights->getType()));
509 
510  // now do territories and countries.
511  $territoryNode = $doc->createElementNS($deployment->getNamespace(), 'Territory');
512  $salesRightsNode->appendChild($territoryNode);
513 
514  if (sizeof($salesRights->getRegionsIncluded()) > 0 && sizeof($salesRights->getCountriesExcluded()) > 0) {
515  $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsIncluded', trim(join(' ', $salesRights->getRegionsIncluded()))));
516  $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesExcluded', trim(join(' ', $salesRights->getCountriesExcluded()))));
517  } else if (sizeof($salesRights->getCountriesIncluded()) > 0) {
518  $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesIncluded', trim(join(' ', $salesRights->getCountriesIncluded()))));
519  }
520 
521  if (sizeof($salesRights->getRegionsExcluded()) > 0) {
522  $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsExcluded', trim(join(' ', $salesRights->getRegionsExcluded()))));
523  }
524 
525  unset($territoryNode);
526  unset($salesRightsNode);
527 
528  } else { // found the SalesRights object that is assigned 'rest of world'.
529  $salesRightsROW = $salesRights; // stash this for later since it always goes last.
530  }
531  unset($salesRights);
532  }
533  if ($salesRightsROW != null) {
534  $publishingDetailNode->appendChild($this->_buildTextNode($doc, 'ROWSalesRightsType', $salesRightsROW->getType()));
535  }
536 
537  /* --- Product Supply. We create one of these per defined Market. --- */
538 
539  $representativeDao = DAORegistry::getDAO('RepresentativeDAO');
540  $markets = $publicationFormat->getMarkets();
541 
542  while ($market = $markets->next()) {
543  $productSupplyNode = $doc->createElementNS($deployment->getNamespace(), 'ProductSupply');
544  $productNode->appendChild($productSupplyNode);
545 
546  $marketNode = $doc->createElementNS($deployment->getNamespace(), 'Market');
547  $productSupplyNode->appendChild($marketNode);
548 
549  $territoryNode = $doc->createElementNS($deployment->getNamespace(), 'Territory');
550  $marketNode->appendChild($territoryNode);
551 
552  if (sizeof($market->getCountriesIncluded()) > 0) {
553  $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesIncluded', trim(join(' ', $market->getCountriesIncluded()))));
554  }
555 
556  if (sizeof($market->getRegionsIncluded()) > 0) {
557  $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsIncluded', trim(join(' ', $market->getRegionsIncluded()))));
558  }
559 
560  if (sizeof($market->getCountriesExcluded()) > 0) {
561  $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesExcluded', trim(join(' ', $market->getCountriesExcluded()))));
562  }
563 
564  if (sizeof($market->getRegionsExcluded()) > 0) {
565  $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsExcluded', trim(join(' ', $market->getRegionsExcluded()))));
566  }
567 
568  unset($marketNode);
569  unset($territoryNode);
570 
571  /* --- Include a MarketPublishingDetail node --- */
572 
573  $marketPubDetailNode = $doc->createElementNS($deployment->getNamespace(), 'MarketPublishingDetail');
574  $productSupplyNode->appendChild($marketPubDetailNode);
575 
576  $agent = $representativeDao->getById($market->getAgentId());
577 
578  if (isset($agent)) {
579  $representativeNode = $doc->createElementNS($deployment->getNamespace(), 'PublisherRepresentative');
580  $marketPubDetailNode->appendChild($representativeNode);
581 
582  $representativeNode->appendChild($this->_buildTextNode($doc, 'AgentRole', $agent->getRole()));
583  $representativeNode->appendChild($this->_buildTextNode($doc, 'AgentName', $agent->getName()));
584 
585  if ($agent->getUrl() != '') {
586  $agentWebsiteNode = $doc->createElementNS($deployment->getNamespace(), 'Website');
587  $representativeNode->appendChild($agentWebsiteNode);
588 
589  $agentWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '18')); // 18 -> Public website
590  $agentWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $agent->getUrl()));
591  }
592  unset($representativeNode);
593  }
594 
595  $marketPubDetailNode->appendChild($this->_buildTextNode($doc, 'MarketPublishingStatus', '04')); // Active
596 
597  // MarketDate is a required field on the form. If that changes, this should be wrapped in a conditional.
598  $marketDateNode = $doc->createElementNS($deployment->getNamespace(), 'MarketDate');
599  $marketPubDetailNode->appendChild($marketDateNode);
600 
601  $marketDateNode->appendChild($this->_buildTextNode($doc, 'MarketDateRole', $market->getDateRole()));
602  $marketDateNode->appendChild($this->_buildTextNode($doc, 'DateFormat', $market->getDateFormat()));
603  $marketDateNode->appendChild($this->_buildTextNode($doc, 'Date', $market->getDate()));
604 
605  unset($marketDateNode);
606  unset($marketPubDetailNode);
607 
608  /* --- Supplier Detail Information --- */
609 
610  $supplier = $representativeDao->getById($market->getSupplierId());
611 
612  $supplyDetailNode = $doc->createElementNS($deployment->getNamespace(), 'SupplyDetail');
613  $productSupplyNode->appendChild($supplyDetailNode);
614 
615  if (isset($supplier)) {
616  $supplierNode = $doc->createElementNS($deployment->getNamespace(), 'Supplier');
617  $supplyDetailNode->appendChild($supplierNode);
618 
619  $supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierRole', $supplier->getRole()));
620  $supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierName', $supplier->getName()));
621  if ($supplier->getPhone()) {
622  $supplierNode->appendChild($this->_buildTextNode($doc, 'TelephoneNumber', $supplier->getPhone()));
623  }
624  if ($supplier->getFax()) {
625  $supplierNode->appendChild($this->_buildTextNode($doc, 'FaxNumber', $supplier->getFax()));
626  }
627  if ($supplier->getEmail()) {
628  $supplierNode->appendChild($this->_buildTextNode($doc, 'EmailAddress', $supplier->getEmail()));
629  }
630 
631  if ($supplier->getUrl() != '') {
632  $supplierWebsiteNode = $doc->createElementNS($deployment->getNamespace(), 'Website');
633  $supplierNode->appendChild($supplierWebsiteNode);
634 
635  $supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '18')); // 18 -> Public website
636  $supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $supplier->getUrl()));
637 
638  unset($supplierWebsiteNode);
639  }
640  unset($supplierNode);
641  unset($supplierWebsiteNode);
642 
643  } else { // No suppliers specified, use the Press settings instead.
644  $supplierNode = $doc->createElementNS($deployment->getNamespace(), 'Supplier');
645  $supplyDetailNode->appendChild($supplierNode);
646 
647  $supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierRole', '09')); // Publisher supplying to end customers
648  $supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierName', $context->getSetting('publisher')));
649 
650  if ($context->getSetting('contactEmail') != '') {
651  $supplierNode->appendChild($this->_buildTextNode($doc, 'EmailAddress', $context->getSetting('contactEmail')));
652  }
653 
654  $supplierWebsiteNode = $doc->createElementNS($deployment->getNamespace(), 'Website');
655  $supplierNode->appendChild($supplierWebsiteNode);
656 
657  $supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '18')); // 18 -> Public website
658  $supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', Request::url($context->getPath())));
659 
660  unset($supplierNode);
661  unset($supplierWebsiteNode);
662  }
663 
664  if ($publicationFormat->getReturnableIndicatorCode() != '') {
665  $returnsNode = $doc->createElementNS($deployment->getNamespace(), 'ReturnsConditions');
666  $supplyDetailNode->appendChild($returnsNode);
667 
668  $returnsNode->appendChild($this->_buildTextNode($doc, 'ReturnsCodeType', '02')); // we support the BISAC codes for these
669  $returnsNode->appendChild($this->_buildTextNode($doc, 'ReturnsCode', $publicationFormat->getReturnableIndicatorCode()));
670 
671  unset($returnsNode);
672  }
673 
674  $supplyDetailNode->appendChild($this->_buildTextNode($doc, 'ProductAvailability',
675  $publicationFormat->getProductAvailabilityCode() ? $publicationFormat->getProductAvailabilityCode() : '20')); // assume 'available' if not specified.
676 
677  $priceNode = $doc->createElementNS($deployment->getNamespace(), 'Price');
678  $supplyDetailNode->appendChild($priceNode);
679 
680  if ($market->getPriceTypeCode() != '') {
681  $priceNode->appendChild($this->_buildTextNode($doc, 'PriceType', $market->getPriceTypeCode()));
682  }
683 
684  if ($market->getDiscount() != '') {
685  $discountNode = $doc->createElementNS($deployment->getNamespace(), 'Discount');
686  $priceNode->appendChild($discountNode);
687  $discountNode->appendChild($this->_buildTextNode($doc, 'DiscountPercent', $market->getDiscount()));
688  unset($discountNode);
689  }
690 
691  $priceNode->appendChild($this->_buildTextNode($doc, 'PriceAmount', $market->getPrice()));
692 
693  if ($market->getTaxTypeCode() != '' || $market->getTaxRateCode() != '') {
694  $taxNode = $doc->createElementNS($deployment->getNamespace(), 'Tax');
695  $priceNode->appendChild($taxNode);
696 
697  if ($market->getTaxTypeCode()) {
698  $taxNode->appendChild($this->_buildTextNode($doc, 'TaxType', $market->getTaxTypeCode()));
699  }
700  if ($market->getTaxRateCode()) {
701  $taxNode->appendChild($this->_buildTextNode($doc, 'TaxRateCode', $market->getTaxRateCode()));
702  }
703  unset($taxNode);
704  }
705 
706  if ($market->getCurrencyCode() != '') {
707  $priceNode->appendChild($this->_buildTextNode($doc, 'CurrencyCode', $market->getCurrencyCode())); // CAD, GBP, USD, etc
708  }
709 
710  unset($priceNode);
711  unset($supplyDetailNode);
712  unset($market);
713  } // end of Market, closes ProductSupply.
714 
715  return $productNode;
716  }
717 
727  function _createMeasurementNode($doc, $deployment, $type, $measurement, $unitCode) {
728  $measureNode =& $doc->createElementNS($deployment->getNamespace(), 'Measure');
729 
730  $measureTypeNode = $doc->createElementNS($deployment->getNamespace(), 'MeasureType');
731  $measureTypeNode->appendChild($doc->createTextNode($type));
732 
733  $measurementNode = $doc->createElementNS($deployment->getNamespace(), 'Measurement');
734  $measurementNode->appendChild($doc->createTextNode($measurement));
735 
736  $measureUnitNode = $doc->createElementNS($deployment->getNamespace(), 'MeasureUnitCode');
737  $measureUnitNode->appendChild($doc->createTextNode($unitCode));
738 
739  $measureNode->appendChild($measureTypeNode);
740  $measureNode->appendChild($measurementNode);
741  $measureNode->appendChild($measureUnitNode);
742 
743  return $measureNode;
744  }
745 
755  function _createExtentNode($doc, $deployment, $type, $extentValue, $extentUnit) {
756  $extentNode =& $doc->createElementNS($deployment->getNamespace(), 'Extent');
757 
758  $typeNode = $doc->createElementNS($deployment->getNamespace(), 'ExtentType');
759  $typeNode->appendChild($doc->createTextNode($type));
760 
761  $valueNode = $doc->createElementNS($deployment->getNamespace(), 'ExtentValue');
762  $valueNode->appendChild($doc->createTextNode($extentValue));
763 
764  $unitNode = $doc->createElementNS($deployment->getNamespace(), 'ExtentUnit');
765  $unitNode->appendChild($doc->createTextNode($extentUnit));
766 
767  $extentNode->appendChild($typeNode);
768  $extentNode->appendChild($valueNode);
769  $extentNode->appendChild($unitNode);
770 
771  return $extentNode;
772  }
773 
781  function _buildTextNode($doc, $nodeName, $textContent) {
782  $deployment = $this->getDeployment();
783  $node = $doc->createElementNS($deployment->getNamespace(), $nodeName);
784  $node->appendChild($doc->createTextNode($textContent));
785  return $node;
786  }
787 }
788 
789 ?>
static & getDAO($name, $dbconn=null)
Base class that converts a monograph to an ONIX 3.0 document.
static & loadCategory($category, $enabledOnly=false, $mainContextId=null)
setDisplayName($displayName)
Definition: Filter.inc.php:140
createProductNode($doc, $submission, $publicationFormat)
_buildTextNode($doc, $nodeName, $textContent)
_createMeasurementNode($doc, $deployment, $type, $measurement, $unitCode)
Base class that converts a DataObject to a Native XML document.
static getSupportedFormLocales()
url($pressPath=null, $page=null, $op=null, $path=null, $params=null, $anchor=null, $escape=false)
Definition: Request.inc.php:88
_createExtentNode($doc, $deployment, $type, $extentValue, $extentUnit)