diff --git a/plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php b/plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php index 54e889da576..194b8b6df5a 100644 --- a/plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php +++ b/plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php @@ -247,24 +247,23 @@ function createProductNode($doc, $submission, $publicationFormat) { /* --- Collection information, first for series and then for product --- */ - $seriesCollectionNode = $doc->createElementNS($deployment->getNamespace(), 'Collection'); - $seriesCollectionNode->appendChild($this->_buildTextNode($doc, 'CollectionType', '10')); // publisher series. - $descDetailNode->appendChild($seriesCollectionNode); - - $seriesTitleDetailNode = $doc->createElementNS($deployment->getNamespace(), 'TitleDetail'); - $seriesTitleDetailNode->appendChild($this->_buildTextNode($doc, 'TitleType', '01')); - $seriesCollectionNode->appendChild($seriesTitleDetailNode); - - $titleElementNode = $doc->createElementNS($deployment->getNamespace(), 'TitleElement'); - $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleElementLevel', '02')); // Collection level title - $seriesTitleDetailNode->appendChild($titleElementNode); - /* --- Series information, if this monograph is part of one. --- */ $seriesDao = DAORegistry::getDAO('SeriesDAO'); /* @var $seriesDao SeriesDAO */ $series = $seriesDao->getById($submission->getCurrentPublication()->getData('seriesId')); if ($series != null) { + $seriesCollectionNode = $doc->createElementNS($deployment->getNamespace(), 'Collection'); + $seriesCollectionNode->appendChild($this->_buildTextNode($doc, 'CollectionType', '10')); // publisher series. + + $seriesTitleDetailNode = $doc->createElementNS($deployment->getNamespace(), 'TitleDetail'); + $seriesTitleDetailNode->appendChild($this->_buildTextNode($doc, 'TitleType', '01')); + $seriesCollectionNode->appendChild($seriesTitleDetailNode); + + $titleElementNode = $doc->createElementNS($deployment->getNamespace(), 'TitleElement'); + $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleElementLevel', '02')); // Collection level title + $seriesTitleDetailNode->appendChild($titleElementNode); + if ($submission->getCurrentPublication()->getData('seriesPosition')) { $titleElementNode->appendChild($this->_buildTextNode($doc, 'PartNumber', $submission->getCurrentPublication()->getData('seriesPosition'))); } @@ -274,15 +273,20 @@ function createProductNode($doc, $submission, $publicationFormat) { } else { if ($series->getLocalizedPrefix() != '') { $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $series->getLocalizedPrefix())); + } else { + $titleElementNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'NoPrefix')); } - $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $series->getLocalizedTitle(false))); } if ($series->getLocalizedSubtitle() != '') { $titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $series->getLocalizedSubtitle())); } + } else { + $seriesCollectionNode = $doc->createElementNS($deployment->getNamespace(), 'NoCollection'); } + $descDetailNode->appendChild($seriesCollectionNode); + /* --- and now product level info --- */ @@ -301,7 +305,10 @@ function createProductNode($doc, $submission, $publicationFormat) { } else { if ($publication->getLocalizedData('prefix')) { $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $publication->getLocalizedData('prefix'))); + } else { + $titleElementNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'NoPrefix')); } + $titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $publication->getLocalizedTitle())); } @@ -405,17 +412,18 @@ function createProductNode($doc, $submission, $publicationFormat) { /* --- Add Subject elements --- */ - $subjectNode = $doc->createElementNS($deployment->getNamespace(), 'Subject'); - $mainSubjectNode = $doc->createElementNS($deployment->getNamespace(), 'MainSubject'); // Always empty as per 3.0 spec. - $subjectNode->appendChild($mainSubjectNode); - $subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeIdentifier', '12')); // 12 is BIC subject category code list. - $subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeVersion', '2')); // Version 2 of ^^ - if ($publication->getData('subjects')) { + $subjectNode = $doc->createElementNS($deployment->getNamespace(), 'Subject'); + $mainSubjectNode = $doc->createElementNS($deployment->getNamespace(), 'MainSubject'); // Always empty as per 3.0 spec. + + $subjectNode->appendChild($mainSubjectNode); + $subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeIdentifier', '12')); // 12 is BIC subject category code list. + $subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeVersion', '2')); // Version 2 of ^^ + $allSubjects = ($publication->getData('subjects')[$publication->getData('locale')]); $subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectCode', trim(join(', ', $allSubjects)))); + $descDetailNode->appendChild($subjectNode); } - $descDetailNode->appendChild($subjectNode); if ($publication->getData('keywords')) { $allKeywords = ($publication->getData('keywords')[$publication->getData('locale')]); @@ -553,33 +561,41 @@ function createProductNode($doc, $submission, $publicationFormat) { $allSalesRights = $publicationFormat->getSalesRights(); $salesRightsROW = null; while ($salesRights = $allSalesRights->next()) { - if (!$salesRights->getROWSetting()) { - $salesRightsNode = $doc->createElementNS($deployment->getNamespace(), 'SalesRights'); - $publishingDetailNode->appendChild($salesRightsNode); - $salesRightsNode->appendChild($this->_buildTextNode($doc, 'SalesRightsType', $salesRights->getType())); + $salesRightsNode = $doc->createElementNS($deployment->getNamespace(), 'SalesRights'); + $publishingDetailNode->appendChild($salesRightsNode); + $salesRightsNode->appendChild($this->_buildTextNode($doc, 'SalesRightsType', $salesRights->getType())); - // now do territories and countries. - $territoryNode = $doc->createElementNS($deployment->getNamespace(), 'Territory'); - $salesRightsNode->appendChild($territoryNode); - - if (sizeof($salesRights->getRegionsIncluded()) > 0 && sizeof($salesRights->getCountriesExcluded()) > 0) { - $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsIncluded', trim(join(' ', $salesRights->getRegionsIncluded())))); - $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesExcluded', trim(join(' ', $salesRights->getCountriesExcluded())))); - } else if (sizeof($salesRights->getCountriesIncluded()) > 0) { - $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesIncluded', trim(join(' ', $salesRights->getCountriesIncluded())))); - } - - if (sizeof($salesRights->getRegionsExcluded()) > 0) { + // now do territories and countries. + $territoryNode = $doc->createElementNS($deployment->getNamespace(), 'Territory'); + $salesRightsNode->appendChild($territoryNode); + + $salesCountriesIncluded = sizeof($salesRights->getCountriesIncluded()) > 0; + $salesRegionsIncluded = sizeof($salesRights->getRegionsIncluded()) > 0; + $salesCountriesExcluded = sizeof($salesRights->getCountriesExcluded()) > 0; + $salesRegionsExcluded = sizeof($salesRights->getRegionsExcluded()) > 0; + + if ($salesRights->getROWSetting()) { + $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsIncluded', 'WORLD')); + $salesRightsROW = $salesRights; + } else if ($salesCountriesIncluded) { + $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesIncluded', trim(join(' ', $salesRights->getCountriesIncluded())))); + if (!in_array('WORLD', $salesRights->getRegionsIncluded())) { + if ($salesRegionsIncluded) $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsIncluded', trim(join(' ', $salesRights->getRegionsIncluded())))); + if ($salesRegionsExcluded) $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsExcluded', trim(join(' ', $salesRights->getRegionsExcluded())))); + } else if ($salesRegionsExcluded) { $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsExcluded', trim(join(' ', $salesRights->getRegionsExcluded())))); } - - unset($territoryNode); - unset($salesRightsNode); - - } else { // found the SalesRights object that is assigned 'rest of world'. - $salesRightsROW = $salesRights; // stash this for later since it always goes last. + } else if ($salesRegionsIncluded) { + $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsIncluded', trim(join(' ', $salesRights->getRegionsIncluded())))); + if (in_array('WORLD', $salesRights->getRegionsIncluded())) { + if ($salesCountriesExcluded) $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesExcluded', trim(join(' ', $salesRights->getCountriesExcluded())))); + if ($salesRegionsExcluded) $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsExcluded', trim(join(' ', $salesRights->getRegionsExcluded())))); + } } + + unset($territoryNode); + unset($salesRightsNode); unset($salesRights); } if ($salesRightsROW != null) { @@ -601,20 +617,25 @@ function createProductNode($doc, $submission, $publicationFormat) { $territoryNode = $doc->createElementNS($deployment->getNamespace(), 'Territory'); $marketNode->appendChild($territoryNode); - if (sizeof($market->getCountriesIncluded()) > 0) { - $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesIncluded', trim(join(' ', $market->getCountriesIncluded())))); - } + $marketCountriesIncluded = sizeof($market->getCountriesIncluded()) > 0; + $marketRegionsIncluded = sizeof($market->getRegionsIncluded()) > 0; + $marketCountriesExcluded = sizeof($market->getCountriesExcluded()) > 0; + $marketRegionsExcluded = sizeof($market->getRegionsExcluded()) > 0; - if (sizeof($market->getRegionsIncluded()) > 0) { + if ($marketCountriesIncluded) { + $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesIncluded', trim(join(' ', $market->getCountriesIncluded())))); + if (!in_array('WORLD', $market->getRegionsIncluded())) { + if ($marketRegionsIncluded) $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsIncluded', trim(join(' ', $market->getRegionsIncluded())))); + if ($marketRegionsExcluded) $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsExcluded', trim(join(' ', $market->getRegionsExcluded())))); + } else if ($marketRegionsExcluded) { + $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsExcluded', trim(join(' ', $market->getRegionsExcluded())))); + } + } else if ($marketRegionsIncluded) { $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsIncluded', trim(join(' ', $market->getRegionsIncluded())))); - } - - if (sizeof($market->getCountriesExcluded()) > 0) { - $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesExcluded', trim(join(' ', $market->getCountriesExcluded())))); - } - - if (sizeof($market->getRegionsExcluded()) > 0) { - $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsExcluded', trim(join(' ', $market->getRegionsExcluded())))); + if (in_array('WORLD', $market->getRegionsIncluded())) { + if ($marketCountriesExcluded) $territoryNode->appendChild($this->_buildTextNode($doc, 'CountriesExcluded', trim(join(' ', $market->getCountriesExcluded())))); + if ($marketRegionsExcluded) $territoryNode->appendChild($this->_buildTextNode($doc, 'RegionsExcluded', trim(join(' ', $market->getRegionsExcluded())))); + } } unset($marketNode); @@ -732,8 +753,12 @@ function createProductNode($doc, $submission, $publicationFormat) { $priceNode = $doc->createElementNS($deployment->getNamespace(), 'Price'); $supplyDetailNode->appendChild($priceNode); + $excludeTaxNode = false; + if ($market->getPriceTypeCode() != '') { $priceNode->appendChild($this->_buildTextNode($doc, 'PriceType', $market->getPriceTypeCode())); + $priceTypeTaxEx = ['02', '04', '07', '09', '12', '14', '17', '22', '24', '27', '34', '42']; // Price type codes that include tax + if (in_array($market->getPriceTypeCode(), $priceTypeTaxEx)) $excludeTaxNode = true; } if ($market->getDiscount() != '') { @@ -745,7 +770,7 @@ function createProductNode($doc, $submission, $publicationFormat) { $priceNode->appendChild($this->_buildTextNode($doc, 'PriceAmount', $market->getPrice())); - if ($market->getTaxTypeCode() != '' || $market->getTaxRateCode() != '') { + if (!$excludeTaxNode && ($market->getTaxTypeCode() != '' || $market->getTaxRateCode() != '')) { $taxNode = $doc->createElementNS($deployment->getNamespace(), 'Tax'); $priceNode->appendChild($taxNode); @@ -754,7 +779,12 @@ function createProductNode($doc, $submission, $publicationFormat) { } if ($market->getTaxRateCode()) { $taxNode->appendChild($this->_buildTextNode($doc, 'TaxRateCode', $market->getTaxRateCode())); + if ($market->getTaxRateCode() == 'Z') { + $taxNode->appendChild($this->_buildTextNode($doc, 'TaxRatePercent', '0')); // Zero-rated tax rate type + } } + + $taxNode->appendChild($this->_buildTextNode($doc, 'TaxableAmount', $market->getPrice())); // Taxable amount defaults to full price unset($taxNode); }