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