function createArticleNode($doc, $pubObject)
{
$deployment = $this->getDeployment();
$context = $deployment->getContext();
$cache = $deployment->getCache();
$plugin = $deployment->getPlugin();
$request = Application::getRequest();
$router = $request->getRouter();
assert(is_a($pubObject, 'PublishedArticle') && $this->isWork($context, $plugin) || is_a($pubObject, 'ArticleGalley') && !$this->isWork($context, $plugin));
if (is_a($pubObject, 'PublishedArticle')) {
$galley = null;
$article = $pubObject;
if (!$cache->isCached('articles', $article->getId())) {
$cache->add($article, null);
}
$articleNodeName = 'DOISerialArticleWork';
$workOrProduct = 'Work';
$epubFormat = O4DOI_EPUB_FORMAT_HTML;
} else {
$galley = $pubObject;
$galleyFile = $galley->getFile();
if ($cache->isCached('articles', $galley->getSubmissionId())) {
$article = $cache->get('articles', $galley->getSubmissionId());
} else {
$publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
/* @var $publishedArticleDao PublishedArticleDAO */
$article = $publishedArticleDao->getPublishedArticleByArticleId($galley->getSubmissionId());
if ($article) {
$cache->add($article, null);
}
}
$articleNodeName = 'DOISerialArticleVersion';
$workOrProduct = 'Product';
$epubFormat = null;
if ($galley->isPdfGalley()) {
$epubFormat = O4DOI_EPUB_FORMAT_PDF;
} else {
if ($galley->getRemoteURL() || $galleyFile->getFileType() == 'text/html') {
$epubFormat = O4DOI_EPUB_FORMAT_HTML;
}
}
}
$articleNode = $doc->createElementNS($deployment->getNamespace(), $articleNodeName);
// Notification type (mandatory)
$doi = $pubObject->getStoredPubId('doi');
$registeredDoi = $pubObject->getData('medra::registeredDoi');
assert(empty($registeredDoi) || $registeredDoi == $doi);
$notificationType = empty($registeredDoi) ? O4DOI_NOTIFICATION_TYPE_NEW : O4DOI_NOTIFICATION_TYPE_UPDATE;
$articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'NotificationType', $notificationType));
// DOI (mandatory)
$articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'DOI', htmlspecialchars($doi, ENT_COMPAT, 'UTF-8')));
// DOI URL (mandatory)
$urlPath = $article->getBestArticleId();
if ($galley) {
$urlPath = array($article->getBestArticleId(), $galley->getBestGalleyId());
}
$url = $router->url($request, $context->getPath(), 'article', 'view', $urlPath, null, null, true);
if ($plugin->isTestMode($context)) {
// Change server domain for testing.
$url = PKPString::regexp_replace('#://[^\\s]+/index.php#', '://example.com/index.php', $url);
}
$articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'DOIWebsiteLink', $url));
// DOI strucural type
$articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'DOIStructuralType', $this->getDOIStructuralType()));
// Registrant (mandatory)
$articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'RegistrantName', htmlspecialchars($plugin->getSetting($context->getId(), 'registrantName'), ENT_COMPAT, 'UTF-8')));
// Registration authority (mandatory)
$articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'RegistrationAuthority', 'mEDRA'));
// WorkIdentifier - proprietary ID
$pubObjectProprietaryId = $context->getId() . '-' . $article->getIssueId() . '-' . $article->getId();
if ($galley) {
$pubObjectProprietaryId .= '-g' . $galley->getId();
}
$articleNode->appendChild($this->createIdentifierNode($doc, $workOrProduct, O4DOI_ID_TYPE_PROPRIETARY, $pubObjectProprietaryId));
// Issue/journal locale precedence.
$journalLocalePrecedence = $this->getObjectLocalePrecedence($context, null, null);
// Serial Publication (mandatory)
$articleNode->appendChild($this->createSerialPublicationNode($doc, $journalLocalePrecedence, $epubFormat));
// Journal Issue (mandatory)
$issueId = $article->getIssueId();
if ($cache->isCached('issues', $issueId)) {
$issue = $cache->get('issues', $issueId);
} else {
$issueDao = DAORegistry::getDAO('IssueDAO');
/* @var $issueDao IssueDAO */
$issue = $issueDao->getById($issueId, $context->getId());
if ($issue) {
$cache->add($issue, null);
}
}
$articleNode->appendChild($this->createJournalIssueNode($doc, $issue, $journalLocalePrecedence));
// Object locale precedence.
$objectLocalePrecedence = $this->getObjectLocalePrecedence($context, $article, $galley);
// Content Item (mandatory for articles)
$articleNode->appendChild($this->createContentItemNode($doc, $issue, $article, $galley, $objectLocalePrecedence));
return $articleNode;
}