function createContentItemNode($doc, $issue, $article, $galley, $objectLocalePrecedence)
{
$deployment = $this->getDeployment();
$context = $deployment->getContext();
$plugin = $deployment->getPlugin();
$contentItemNode = $doc->createElementNS($deployment->getNamespace(), 'ContentItem');
// Sequence number
$seq = $article->getSequence();
assert(!empty($seq));
$contentItemNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'SequenceNumber', $seq));
// Number of pages
$pages = $article->getPages();
if (is_numeric($pages)) {
$pages = (int) $pages;
} else {
// If the field is not numeric then try to parse it (eg. "pp. 3-8").
if (preg_match("/([0-9]+)\\s*-\\s*([0-9]+)/i", $pages, $matches)) {
if (is_numeric($matches[1]) && is_numeric($matches[2])) {
$firstPage = (int) $matches[1];
$lastPage = (int) $matches[2];
$pages = $lastPage - $firstPage + 1;
}
}
}
if (is_integer($pages)) {
$textItemNode = $doc->createElementNS($deployment->getNamespace(), 'TextItem');
$textItemNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'NumberOfPages', $pages));
$contentItemNode->appendChild($textItemNode);
}
// Extent (for article-as-manifestation only)
if ($galley && !$galley->getRemoteURL()) {
$galleyFile = $galley->getFile();
$contentItemNode->appendChild($this->createExtentNode($doc, $galleyFile));
}
// Article Title (mandatory)
$titles = $this->getTranslationsByPrecedence($article->getTitle(null), $objectLocalePrecedence);
assert(!empty($titles));
foreach ($titles as $locale => $title) {
$contentItemNode->appendChild($this->createTitleNode($doc, $locale, $title, O4DOI_TITLE_TYPE_FULL));
}
// Contributors
$authors = $article->getAuthors();
assert(!empty($authors));
foreach ($authors as $author) {
$contentItemNode->appendChild($this->createContributorNode($doc, $author, $objectLocalePrecedence));
}
// Language
$languageCode = AppLocale::get3LetterIsoFromLocale($objectLocalePrecedence[0]);
assert(!empty($languageCode));
$languageNode = $doc->createElementNS($deployment->getNamespace(), 'Language');
$languageNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'LanguageRole', O4DOI_LANGUAGE_ROLE_LANGUAGE_OF_TEXT));
$languageNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'LanguageCode', $languageCode));
$contentItemNode->appendChild($languageNode);
// Article keywords
// SubjectClass will be left out here, because we don't know the scheme/classification name
$submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO');
$allKeywords = $submissionKeywordDao->getKeywords($article->getId(), $context->getSupportedSubmissionLocales());
$keywords = $this->getPrimaryTranslation($allKeywords, $objectLocalePrecedence);
if (!empty($keywords)) {
$keywordsString = implode(';', $keywords);
$contentItemNode->appendChild($this->createSubjectNode($doc, O4DOI_SUBJECT_SCHEME_PUBLISHER, $keywordsString));
}
// Object Description 'OtherText'
$descriptions = $this->getTranslationsByPrecedence($article->getAbstract(null), $objectLocalePrecedence);
foreach ($descriptions as $locale => $description) {
$contentItemNode->appendChild($this->createOtherTextNode($doc, $locale, $description));
}
// Article Publication Date
$datePublished = $article->getDatePublished();
if (!empty($datePublished)) {
$contentItemNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'PublicationDate', date('Ymd', strtotime($datePublished))));
}
// Relations
// Issue
if ($plugin->getSetting($context->getId(), 'exportIssuesAs') == O4DOI_ISSUE_AS_WORK) {
// related work:
// - is part of issue-as-work
$issueWorkOrProduct = 'Work';
} else {
// related product:
// - is part of issue-as-manifestation
$issueWorkOrProduct = 'Product';
}
$issueProprietaryId = $context->getId() . '-' . $issue->getId();
$relatedIssueIds = array(O4DOI_ID_TYPE_PROPRIETARY => $issueProprietaryId);
$issueDoi = $issue->getStoredPubId('doi');
if (!empty($issueDoi)) {
$relatedIssueIds[O4DOI_ID_TYPE_DOI] = $issueDoi;
}
$relatedIssueNode = $this->createRelatedNode($doc, $issueWorkOrProduct, O4DOI_RELATION_IS_PART_OF, $relatedIssueIds);
// Galleys
$galleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
/* @var $galleyDao ArticleGalleyDAO */
$galleysByArticle = $galleyDao->getBySubmissionId($article->getId())->toArray();
if (!$galley) {
// if exporting object is an article
$contentItemNode->appendChild($relatedIssueNode);
// related products:
// - is manifested in articles-as-manifestation
foreach ($galleysByArticle as $relatedGalley) {
$galleyProprietaryId = $context->getId() . '-' . $issue->getId() . '-' . $article->getId() . '-g' . $relatedGalley->getId();
$relatedGalleyIds = array(O4DOI_ID_TYPE_PROPRIETARY => $galleyProprietaryId);
$galleyDoi = $relatedGalley->getStoredPubId('doi');
if (!empty($galleyDoi)) {
$relatedGalleyIds[O4DOI_ID_TYPE_DOI] = $galleyDoi;
}
$contentItemNode->appendChild($this->createRelatedNode($doc, 'Product', O4DOI_RELATION_IS_MANIFESTED_IN, $relatedGalleyIds));
unset($relatedGalley, $relatedGalleyIds, $galleyProprietaryId, $galleyDoi);
}
} else {
// Include issue-as-work before article-as-work.
if ($issueWorkOrProduct == 'Work') {
$contentItemNode->appendChild($relatedIssueNode);
}
// related work:
// - is a manifestation of article-as-work
$articleProprietaryId = $context->getId() . '-' . $article->getIssueId() . '-' . $article->getId();
$relatedArticleIds = array(O4DOI_ID_TYPE_PROPRIETARY => $articleProprietaryId);
$doi = $article->getStoredPubId('doi');
if (!empty($doi)) {
$relatedArticleIds[O4DOI_ID_TYPE_DOI] = $doi;
}
$contentItemNode->appendChild($this->createRelatedNode($doc, 'Work', O4DOI_RELATION_IS_A_MANIFESTATION_OF, $relatedArticleIds));
unset($relatedArticleIds);
// Include issue-as-manifestation after article-as-work.
if ($issueWorkOrProduct == 'Product') {
$contentItemNode->appendChild($relatedIssueNode);
}
// related products:
foreach ($galleysByArticle as $relatedGalley) {
$galleyProprietaryId = $context->getId() . '-' . $issue->getId() . '-' . $article->getId() . '-g' . $relatedGalley->getId();
$relatedGalleyIds = array(O4DOI_ID_TYPE_PROPRIETARY => $galleyProprietaryId);
$galleyDoi = $relatedGalley->getStoredPubId('doi');
if (!empty($galleyDoi)) {
$relatedGalleyIds[O4DOI_ID_TYPE_DOI] = $galleyDoi;
}
// - is a different form of all other articles-as-manifestation
// with the same article id and language but different form
if ($galley->getLocale() == $relatedGalley->getLocale() && $galley->getLabel() != $relatedGalley->getLabel()) {
$contentItemNode->appendChild($this->createRelatedNode($doc, 'Product', O4DOI_RELATION_IS_A_DIFFERENT_FORM_OF, $relatedGalleyIds));
}
// - is a different language version of all other articles-as-manifestation
// with the same article id and form/label but different language
if ($galley->getLabel() == $relatedGalley->getLabel() && $galley->getLocale() != $relatedGalley->getLocale()) {
$contentItemNode->appendChild($this->createRelatedNode($doc, 'Product', O4DOI_RELATION_IS_A_LANGUAGE_VERSION_OF, $relatedGalleyIds));
}
unset($relatedGalley, $relatedGalleyIds, $galleyProprietaryId, $galleyDoi);
}
}
return $contentItemNode;
}