/** * Translate the PKP locale identifier into an * ISO639-2b compatible 3-letter string. * @param $locale string * @return string */ function get3LetterIsoFromLocale($locale) { assert(strlen($locale) == 5); $iso2Letter = substr($locale, 0, 2); return AppLocale::get3LetterFrom2LetterIsoLanguage($iso2Letter); }
/** * Try to translate an ISO language code to an OJS locale. * @param $language string 2- or 3-letter ISO language code * @return string|null An OJS locale or null if no matching * locale could be found. */ function translateLanguageToLocale($language) { $locale = null; if (strlen($language) == 2) { $language = AppLocale::get3LetterFrom2LetterIsoLanguage($language); } if (strlen($language) == 3) { $language = AppLocale::getLocaleFrom3LetterIso($language); } if (AppLocale::isLocaleValid($language)) { $locale = $language; } return $locale; }
/** * @see MetadataDataObjectAdapter::extractMetadataFromDataObject() * @param $submission Submission * @return MetadataDescription */ function extractMetadataFromDataObject(&$submission) { assert(is_a($submission, 'Submission')); $mods34Description = $this->instantiateMetadataDescription(); // Retrieve the primary locale. $catalogingLocale = AppLocale::getPrimaryLocale(); $catalogingLanguage = AppLocale::get3LetterIsoFromLocale($catalogingLocale); // Establish the association between the meta-data description // and the submission. $mods34Description->setAssocId($submission->getId()); // Title $localizedTitles = $submission->getTitle(null); // Localized $this->addLocalizedStatements($mods34Description, 'titleInfo/title', $localizedTitles); // Authors // FIXME: Move this to a dedicated adapter in the Author class. $authors = $submission->getAuthors(); foreach ($authors as $author) { /* @var $author Author */ // Create a new name description. $authorDescription = new MetadataDescription('lib.pkp.plugins.metadata.mods34.schema.Mods34NameSchema', ASSOC_TYPE_AUTHOR); // Type $authorType = 'personal'; $authorDescription->addStatement('[@type]', $authorType); // Family Name $authorDescription->addStatement('namePart[@type="family"]', $author->getLastName()); // Given Names $firstName = (string) $author->getFirstName(); $middleName = (string) $author->getMiddleName(); $givenNames = trim($firstName . ' ' . $middleName); if (!empty($givenNames)) { $authorDescription->addStatement('namePart[@type="given"]', $givenNames); } // Affiliation // NB: Our MODS mapping currently doesn't support translation for names. // This can be added when required by data consumers. We therefore only use // translations in the cataloging language. $affiliation = $author->getAffiliation($catalogingLocale); if ($affiliation) { $authorDescription->addStatement('affiliation', $affiliation); } // Terms of address (unmapped field) $termsOfAddress = $author->getData('nlm34:namePart[@type="termsOfAddress"]'); if ($termsOfAddress) { $authorDescription->addStatement('namePart[@type="termsOfAddress"]', $termsOfAddress); } // Date (unmapped field) $date = $author->getData('nlm34:namePart[@type="date"]'); if ($date) { $authorDescription->addStatement('namePart[@type="date"]', $date); } // Role $authorDescription->addStatement('role/roleTerm[@type="code" @authority="marcrelator"]', 'aut'); // Add the author to the MODS schema. $mods34Description->addStatement('name', $authorDescription); unset($authorDescription); } // Sponsor // NB: Our MODS mapping currently doesn't support translation for names. // This can be added when required by data consumers. We therefore only use // translations in the cataloging language. $supportingAgency = $submission->getSponsor($catalogingLocale); if ($supportingAgency) { $supportingAgencyDescription = new MetadataDescription('lib.pkp.plugins.metadata.mods34.schema.Mods34NameSchema', ASSOC_TYPE_AUTHOR); $sponsorNameType = 'corporate'; $supportingAgencyDescription->addStatement('[@type]', $sponsorNameType); $supportingAgencyDescription->addStatement('namePart', $supportingAgency); $sponsorRole = 'spn'; $supportingAgencyDescription->addStatement('role/roleTerm[@type="code" @authority="marcrelator"]', $sponsorRole); $mods34Description->addStatement('name', $supportingAgencyDescription); } // Type of resource $typeOfResource = 'text'; $mods34Description->addStatement('typeOfResource', $typeOfResource); // Creation & copyright date $submissionDate = $submission->getDateSubmitted(); if (strlen($submissionDate) >= 4) { $mods34Description->addStatement('originInfo/dateCreated[@encoding="w3cdtf"]', $submissionDate); $mods34Description->addStatement('originInfo/copyrightDate[@encoding="w3cdtf"]', substr($submissionDate, 0, 4)); } // Submission language $language = $submission->getLanguage(); if ($language) { $submissionLanguage = AppLocale::get3LetterFrom2LetterIsoLanguage($submission->getLanguage()); } else { $submissionLanguage = null; } if (!$submissionLanguage) { // Assume the cataloging language by default. $submissionLanguage = $catalogingLanguage; } $mods34Description->addStatement('language/languageTerm[@type="code" @authority="iso639-2b"]', $submissionLanguage); // Pages (extent) $mods34Description->addStatement('physicalDescription/extent', $submission->getPages()); // Abstract $localizedAbstracts =& $submission->getAbstract(null); // Localized $this->addLocalizedStatements($mods34Description, 'abstract', $localizedAbstracts); // Discipline $localizedDisciplines = $submission->getDiscipline(null); // Localized $this->addLocalizedStatements($mods34Description, 'subject/topic', $localizedDisciplines); // Subject $localizedSubjects = $submission->getSubject(null); // Localized $this->addLocalizedStatements($mods34Description, 'subject/topic', $localizedSubjects); // FIXME: Coverage not included // Record creation date $recordCreationDate = date('Y-m-d'); $mods34Description->addStatement('recordInfo/recordCreationDate[@encoding="w3cdtf"]', $recordCreationDate); // Record identifier $mods34Description->addStatement('recordInfo/recordIdentifier[@source="pkp"]', $submission->getId()); // Cataloging language $mods34Description->addStatement('recordInfo/languageOfCataloging/languageTerm[@authority="iso639-2b"]', $catalogingLanguage); // Handle unmapped fields. $this->extractUnmappedDataObjectMetadataFields($submission, $mods34Description); return $mods34Description; }
/** * Add the metadata XML of a single article to an * XML article list. * * @param $articleDoc DOMDocument * @param $article PublishedArticle * @param $journal Journal * @param $markToDelete boolean If true the returned XML * will only contain a deletion marker. */ function _addArticleXml(&$articleDoc, &$article, &$journal, $markToDelete = false) { assert(is_a($article, 'Article')); // Get the root node of the list. assert(is_a($articleDoc, 'DOMDocument')); $articleList =& $articleDoc->documentElement; // Create a new article node. $articleNode =& XMLCustomWriter::createElement($articleDoc, 'article'); // Add ID information. XMLCustomWriter::setAttribute($articleNode, 'id', $article->getId()); XMLCustomWriter::setAttribute($articleNode, 'sectionId', $article->getSectionId()); XMLCustomWriter::setAttribute($articleNode, 'journalId', $article->getJournalId()); XMLCustomWriter::setAttribute($articleNode, 'instId', $this->_instId); // Set the load action. $loadAction = $markToDelete ? 'delete' : 'replace'; XMLCustomWriter::setAttribute($articleNode, 'loadAction', $loadAction); XMLCustomWriter::appendChild($articleList, $articleNode); // The XML for an article marked to be deleted contains no metadata. if ($markToDelete) { return; } assert(is_a($article, 'PublishedArticle')); // Add authors. $authors = $article->getAuthors(); if (!empty($authors)) { $authorList =& XMLCustomWriter::createElement($articleDoc, 'authorList'); foreach ($authors as $author) { /* @var $author Author */ XMLCustomWriter::createChildWithText($articleDoc, $authorList, 'author', $author->getFullName(true)); } XMLCustomWriter::appendChild($articleNode, $authorList); } // We need the request to retrieve locales and build URLs. $request = PKPApplication::getRequest(); // Get all supported locales. $site = $request->getSite(); $supportedLocales = $site->getSupportedLocales() + array_keys($journal->getSupportedLocaleNames()); assert(!empty($supportedLocales)); // Add titles. $titleList =& XMLCustomWriter::createElement($articleDoc, 'titleList'); // Titles are used for sorting, we therefore need // them in all supported locales. assert(!empty($supportedLocales)); foreach ($supportedLocales as $locale) { $localizedTitle = $article->getLocalizedTitle($locale); if (!is_null($localizedTitle)) { // Add the localized title. $titleNode =& XMLCustomWriter::createChildWithText($articleDoc, $titleList, 'title', $localizedTitle); XMLCustomWriter::setAttribute($titleNode, 'locale', $locale); // If the title does not exist in the given locale // then use the localized title for sorting only. $title = $article->getTitle($locale); $sortOnly = empty($title) ? 'true' : 'false'; XMLCustomWriter::setAttribute($titleNode, 'sortOnly', $sortOnly); } } XMLCustomWriter::appendChild($articleNode, $titleList); // Add abstracts. $abstracts = $article->getAbstract(null); // return all locales if (!empty($abstracts)) { $abstractList =& XMLCustomWriter::createElement($articleDoc, 'abstractList'); foreach ($abstracts as $locale => $abstract) { $abstractNode =& XMLCustomWriter::createChildWithText($articleDoc, $abstractList, 'abstract', $abstract); XMLCustomWriter::setAttribute($abstractNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $abstractList); } // Add discipline. $disciplines = $article->getDiscipline(null); // return all locales if (!empty($disciplines)) { $disciplineList =& XMLCustomWriter::createElement($articleDoc, 'disciplineList'); foreach ($disciplines as $locale => $discipline) { $disciplineNode =& XMLCustomWriter::createChildWithText($articleDoc, $disciplineList, 'discipline', $discipline); XMLCustomWriter::setAttribute($disciplineNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $disciplineList); } // Add subjects and subject classes. $subjectClasses = $article->getSubjectClass(null); $subjects = $article->getSubject(null); if (!empty($subjectClasses) || !empty($subjects)) { $subjectList =& XMLCustomWriter::createElement($articleDoc, 'subjectList'); if (!is_array($subjectClasses)) { $subjectClasses = array(); } if (!is_array($subjects)) { $subjects = array(); } $locales = array_unique(array_merge(array_keys($subjectClasses), array_keys($subjects))); foreach ($locales as $locale) { $subject = ''; if (isset($subjectClasses[$locale])) { $subject .= $subjectClasses[$locale]; } if (isset($subjects[$locale])) { if (!empty($subject)) { $subject .= ' '; } $subject .= $subjects[$locale]; } $subjectNode =& XMLCustomWriter::createChildWithText($articleDoc, $subjectList, 'subject', $subject); XMLCustomWriter::setAttribute($subjectNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $subjectList); } // Add type. $types = $article->getType(null); // return all locales if (!empty($types)) { $typeList =& XMLCustomWriter::createElement($articleDoc, 'typeList'); foreach ($types as $locale => $type) { $typeNode =& XMLCustomWriter::createChildWithText($articleDoc, $typeList, 'type', $type); XMLCustomWriter::setAttribute($typeNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $typeList); } // Add coverage. $coverageGeo = $article->getCoverageGeo(null); $coverageChron = $article->getCoverageChron(null); $coverageSample = $article->getCoverageSample(null); if (!empty($coverageGeo) || !empty($coverageChron) || !empty($coverageSample)) { $coverageList =& XMLCustomWriter::createElement($articleDoc, 'coverageList'); if (!is_array($coverageGeo)) { $coverageGeo = array(); } if (!is_array($coverageChron)) { $coverageChron = array(); } if (!is_array($coverageSample)) { $coverageSample = array(); } $locales = array_unique(array_merge(array_keys($coverageGeo), array_keys($coverageChron), array_keys($coverageSample))); foreach ($locales as $locale) { $coverage = ''; if (isset($coverageGeo[$locale])) { $coverage .= $coverageGeo[$locale]; } if (isset($coverageChron[$locale])) { if (!empty($coverage)) { $coverage .= '; '; } $coverage .= $coverageChron[$locale]; } if (isset($coverageSample[$locale])) { if (!empty($coverage)) { $coverage .= '; '; } $coverage .= $coverageSample[$locale]; } $coverageNode =& XMLCustomWriter::createChildWithText($articleDoc, $coverageList, 'coverage', $coverage); XMLCustomWriter::setAttribute($coverageNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $coverageList); } // Add journal titles. $journalTitleList =& XMLCustomWriter::createElement($articleDoc, 'journalTitleList'); // Journal titles are used for sorting, we therefore need // them in all supported locales. foreach ($supportedLocales as $locale) { $localizedTitle = $journal->getName($locale); $sortOnly = false; if (is_null($localizedTitle)) { // If the title does not exist in the given locale // then use the localized title for sorting only. $journalTitle = $journal->getLocalizedName(); $sortOnly = true; } else { $journalTitle = $localizedTitle; } $journalTitleNode =& XMLCustomWriter::createChildWithText($articleDoc, $journalTitleList, 'journalTitle', $journalTitle); XMLCustomWriter::setAttribute($journalTitleNode, 'locale', $locale); $sortOnly = $sortOnly ? 'true' : 'false'; XMLCustomWriter::setAttribute($journalTitleNode, 'sortOnly', $sortOnly); } XMLCustomWriter::appendChild($articleNode, $journalTitleList); // Add publication dates. $publicationDate = $article->getDatePublished(); if (!empty($publicationDate)) { // Transform and store article publication date. $publicationDate = $this->_convertDate($publicationDate); $dateNode =& XMLCustomWriter::createChildWithText($articleDoc, $articleNode, 'publicationDate', $publicationDate); } $issueId = $article->getIssueId(); if (is_numeric($issueId)) { $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ $issue = $issueDao->getById($issueId); if (is_a($issue, 'Issue')) { $issuePublicationDate = $issue->getDatePublished(); if (!empty($issuePublicationDate)) { // Transform and store issue publication date. $issuePublicationDate = $this->_convertDate($issuePublicationDate); $dateNode =& XMLCustomWriter::createChildWithText($articleDoc, $articleNode, 'issuePublicationDate', $issuePublicationDate); } } } // We need the router to build file URLs. $router = $request->getRouter(); /* @var $router PageRouter */ // Add galley files $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); $galleys = $articleGalleyDao->getBySubmissionId($article->getId()); $galleyList = null; while ($galley = $galleys->next()) { /* @var $galley ArticleGalley */ $locale = $galley->getLocale(); $galleyUrl = $router->url($request, $journal->getPath(), 'article', 'download', array(intval($article->getId()), intval($galley->getId()))); if (!empty($locale) && !empty($galleyUrl)) { if (is_null($galleyList)) { $galleyList =& XMLCustomWriter::createElement($articleDoc, 'galleyList'); } $galleyNode =& XMLCustomWriter::createElement($articleDoc, 'galley'); XMLCustomWriter::setAttribute($galleyNode, 'locale', $locale); XMLCustomWriter::setAttribute($galleyNode, 'fileName', $galleyUrl); XMLCustomWriter::appendChild($galleyList, $galleyNode); } } // Wrap the galley XML as CDATA. if (!is_null($galleyList)) { if (is_callable(array($articleDoc, 'saveXml'))) { $galleyXml = $articleDoc->saveXml($galleyList); } else { $galleyXml = $galleyList->toXml(); } $galleyOuterNode =& XMLCustomWriter::createElement($articleDoc, 'galley-xml'); if (is_callable(array($articleDoc, 'createCDATASection'))) { $cdataNode = $articleDoc->createCDATASection($galleyXml); } else { $cdataNode = new XMLNode(); $cdataNode->setValue('<![CDATA[' . $galleyXml . ']]>'); } XMLCustomWriter::appendChild($galleyOuterNode, $cdataNode); XMLCustomWriter::appendChild($articleNode, $galleyOuterNode); } // Add supplementary files $fileDao = DAORegistry::getDAO('SuppFileDAO'); $suppFiles =& $fileDao->getSuppFilesByArticle($article->getId()); $suppFileList = null; foreach ($suppFiles as $suppFile) { /* @var $suppFile SuppFile */ // Try to map the supp-file language to a PKP locale. $locale = null; $language = $suppFile->getLanguage(); if (strlen($language) == 2) { $language = AppLocale::get3LetterFrom2LetterIsoLanguage($language); } if (strlen($language) == 3) { $locale = AppLocale::getLocaleFrom3LetterIso($language); } if (!AppLocale::isLocaleValid($locale)) { $locale = 'unknown'; } $suppFileUrl = $router->url($request, $journal->getPath(), 'article', 'downloadSuppFile', array(intval($article->getId()), intval($suppFile->getId()))); if (!empty($locale) && !empty($suppFileUrl)) { if (is_null($suppFileList)) { $suppFileList =& XMLCustomWriter::createElement($articleDoc, 'suppFileList'); } $suppFileNode =& XMLCustomWriter::createElement($articleDoc, 'suppFile'); XMLCustomWriter::setAttribute($suppFileNode, 'locale', $locale); XMLCustomWriter::setAttribute($suppFileNode, 'fileName', $suppFileUrl); XMLCustomWriter::appendChild($suppFileList, $suppFileNode); // Add supp file meta-data. $suppFileMetadata = array('title' => $suppFile->getTitle(null), 'creator' => $suppFile->getCreator(null), 'subject' => $suppFile->getSubject(null), 'typeOther' => $suppFile->getTypeOther(null), 'description' => $suppFile->getDescription(null), 'source' => $suppFile->getSource(null)); foreach ($suppFileMetadata as $field => $data) { if (!empty($data)) { $suppFileMDListNode =& XMLCustomWriter::createElement($articleDoc, $field . 'List'); foreach ($data as $locale => $value) { $suppFileMDNode =& XMLCustomWriter::createChildWithText($articleDoc, $suppFileMDListNode, $field, $value); XMLCustomWriter::setAttribute($suppFileMDNode, 'locale', $locale); unset($suppFileMDNode); } XMLCustomWriter::appendChild($suppFileNode, $suppFileMDListNode); unset($suppFileMDListNode); } } } } // Wrap the suppFile XML as CDATA. if (!is_null($suppFileList)) { if (is_callable(array($articleDoc, 'saveXml'))) { $suppFileXml = $articleDoc->saveXml($suppFileList); } else { $suppFileXml = $suppFileList->toXml(); } $suppFileOuterNode =& XMLCustomWriter::createElement($articleDoc, 'suppFile-xml'); if (is_callable(array($articleDoc, 'createCDATASection'))) { $cdataNode = $articleDoc->createCDATASection($suppFileXml); } else { $cdataNode = new XMLNode(); $cdataNode->setValue('<![CDATA[' . $suppFileXml . ']]>'); } XMLCustomWriter::appendChild($suppFileOuterNode, $cdataNode); XMLCustomWriter::appendChild($articleNode, $suppFileOuterNode); } }
/** * @covers PKPLocale */ public function testGet3LetterFrom2LetterIsoLanguage() { self::assertEquals('eng', AppLocale::get3LetterFrom2LetterIsoLanguage('en')); self::assertEquals('por', AppLocale::get3LetterFrom2LetterIsoLanguage('pt')); self::assertNull(AppLocale::get3LetterFrom2LetterIsoLanguage('xx')); }
/** * @see DOIExportDom::getPrimaryObjectLocale() * @param $suppFile SuppFile */ function getPrimaryObjectLocale(&$article, &$galley, &$suppFile) { $primaryObjectLocale = null; if (is_a($suppFile, 'SuppFile')) { // Try to map the supp-file language to a PKP locale. $suppFileLanguage = $suppFile->getLanguage(); if (strlen($suppFileLanguage) == 2) { $suppFileLanguage = AppLocale::get3LetterFrom2LetterIsoLanguage($suppFileLanguage); } if (strlen($suppFileLanguage) == 3) { $primaryObjectLocale = AppLocale::getLocaleFrom3LetterIso($suppFileLanguage); } } // If mapping didn't work or we do not have a supp file then // retrieve the locale from the other objects. if (!AppLocale::isLocaleValid($primaryObjectLocale)) { $primaryObjectLocale = parent::getPrimaryObjectLocale($article, $galley); } return $primaryObjectLocale; }
/** * @see MetadataDataObjectAdapter::extractMetadataFromDataObject() * @param $publicationFormat PublicationFormat * @return MetadataDescription */ function extractMetadataFromDataObject($publicationFormat) { assert(is_a($publicationFormat, 'PublicationFormat')); AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON); // Retrieve data that belongs to the publication format. $oaiDao = DAORegistry::getDAO('OAIDAO'); $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO'); $monographDao = DAORegistry::getDAO('MonographDAO'); $monograph = $publishedMonographDao->getById($publicationFormat->getMonographId()); $series = $oaiDao->getSeries($monograph->getSeriesId()); /* @var $series Series */ $press = $oaiDao->getPress($monograph->getPressId()); $chapterDao = DAORegistry::getDAO('ChapterDAO'); $chapters = $chapterDao->getChapters($monograph->getId()); $description = $this->instantiateMetadataDescription(); // Title $this->_addLocalizedElements($description, 'dc:title[@xsi:type="ddb:titleISO639-2"]', $monograph->getTitle(null)); // Creator $authors = $monograph->getAuthors(); foreach ($authors as $author) { $pc = new MetadataDescription('plugins.metadata.xmdp22.schema.Pc14NameSchema', ASSOC_TYPE_AUTHOR); $this->_checkForContentAndAddElement($pc, 'pc:person/pc:name[@type="nameUsedByThePerson"]/pc:foreName', $author->getFirstName()); $this->_checkForContentAndAddElement($pc, 'pc:person/pc:name[@type="nameUsedByThePerson"]/pc:surName', $author->getLastName()); $this->_checkForContentAndAddElement($description, 'dc:creator[@xsi:type="pc:MetaPers"]', $pc); } // Subject $subjects = array_merge_recursive((array) $monograph->getDiscipline(null), (array) $monograph->getSubject(null), (array) $monograph->getSubjectClass(null)); $this->_addLocalizedElements($description, 'dc:subject[@xsi:type="xMetaDiss:noScheme"]', $subjects); // Table of Contents // Abstract $this->_addLocalizedElements($description, 'dcterms:abstract[@xsi:type="ddb:contentISO639-2"]', $monograph->getAbstract(null)); // Publisher $publisherInstitution = $press->getSetting('publisherInstitution'); if (!empty($publisherInstitution)) { $publishers = array($press->getPrimaryLocale() => $publisherInstitution); } else { $publishers = $press->getName(null); // Default } // Corporate Core Institution Schema // Since composite elements cannot be localized, the content of this element is based on the primary press locale $cc = new MetadataDescription('plugins.metadata.xmdp22.schema.CC21InstitutionSchema', ASSOC_TYPE_PRESS); // Name $this->_checkForContentAndAddElement($cc, 'cc:universityOrInstitution/cc:name', $press->getName()[$press->getPrimaryLocale()]); // Address $metadataPlugins = PluginRegistry::loadCategory('metadata', true); $address = $press->getData("mailingAddress"); if (!$address) { $address = $metadataPlugins['Xmdp22MetadataPlugin']->getData("cc:address", $monograph->getPressId()); } $cc->addStatement('cc:address', $address); // Place $place = $address; $place = $metadataPlugins['Xmdp22MetadataPlugin']->getData("cc:place", $monograph->getPressId()); $cc->addStatement('cc:universityOrInstitution/cc:place', $place); $this->_checkForContentAndAddElement($description, 'dc:publisher[@xsi:type="cc:Publisher"]', $cc); // Contributor $contributors = $monograph->getSponsor(null); if (is_array($contributors)) { foreach ($contributors as $locale => $contributor) { $contributors[$locale] = array_map('trim', explode(';', $contributor)); } $this->_addLocalizedElements($description, 'dc:contributor', $contributors); } // Date submitted //$description->addStatement('dcterms:dateSubmitted', date('Y', strtotime($monograph->getDateSubmitted()))); // Issued $this->_checkForContentAndAddElement($description, 'dcterms:issued[@xsi:type="dcterms:W3CDTF"]', date('Y-m-d', strtotime($monograph->getDatePublished()))); // Type $types = array_merge_recursive(array_map('lcfirst', array(AppLocale::getLocale() => __('rt.metadata.pkp.dctype'))), array_map('lcfirst', (array) $monograph->getType(null))); $this->_addLocalizedElements($description, 'dc:type[@xsi:type="dini:PublType"]', $types); // Format $onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); $entryKeys = $onixCodelistItemDao->getCodes('List7'); // List7 is for object formats if ($publicationFormat->getEntryKey()) { $formatName = $entryKeys[$publicationFormat->getEntryKey()]; $this->_checkForContentAndAddElement($description, 'dc:format', $formatName); } // Identifier(s) // dc:identifier: xsi:type=urn:nbn|doi|hdl (1, mandatory) // ddb:identifier: ddb:type=URL|URN|DOI|handle|VG-Wort-Pixel|URL_Frontdoor|URL_Publikation|Erstkat-ID|ISSN|other (many, optional) $pubIdPlugins = PluginRegistry::loadCategory('pubIds'); if (isset($pubIdPlugins) && array_key_exists('DOIPubIdPlugin', $pubIdPlugins) && $pubIdPlugins['DOIPubIdPlugin']->getEnabled() == true) { $doi = $pubIdPlugins['DOIPubIdPlugin']->getPubId($publicationFormat); } if (isset($pubIdPlugins) && array_key_exists('URNDNBPubIdPlugin', $pubIdPlugins) && $pubIdPlugins['URNDNBPubIdPlugin']->getEnabled() == true) { $urn_dnb = $pubIdPlugins['URNDNBPubIdPlugin']->getPubId($monograph); $namespaces = explode(':', $urn_dnb); $numberOfNamespaces = min(sizeof($namespaces), 3); $scheme = implode(":", array_slice($namespaces, 0, $numberOfNamespaces)); } if (isset($urn_dnb)) { $description->addStatement('dc:identifier', $urn_dnb . ' [@xsi:type="' . $scheme . '"]'); if (isset($doi)) { $description->addStatement('ddb:identifier', $doi . ' [@ddb:type="DOI"]'); } } else { if (isset($doi)) { $description->addStatement('dc:identifier', $doi . ' [@xsi:type="doi"]'); } } $this->_checkForContentAndAddElement($description, 'ddb:identifier', Request::url($press->getPath(), 'catalog', 'book', array($monograph->getId())) . ' [@ddb:type="URL_Frontdoor"]'); // Source (press title and pages) $sources = $press->getName(null); $pages = $monograph->getPages(); if (!empty($pages)) { $pages = '; ' . $pages; } foreach ($sources as $locale => $source) { $sources[$locale] .= '; '; $sources[$locale] .= $pages; } $this->_addLocalizedElements($description, 'dc:source', $sources); // Language $language = $monograph->getLanguage(); if (!$language) { $language = AppLocale::get3LetterFrom2LetterIsoLanguage(substr($press->getPrimaryLocale(), 0, 2)); } else { $language = AppLocale::get3LetterFrom2LetterIsoLanguage($language); } $this->_checkForContentAndAddElement($description, 'dc:language[@xsi:type="dcterms:ISO639-2"]', $language); // Relation // Coverage $coverage = array_merge_recursive((array) $monograph->getCoverageGeo(null), (array) $monograph->getCoverageChron(null), (array) $monograph->getCoverageSample(null)); $this->_addLocalizedElements($description, 'dc:coverage[@xsi:type="ddb:encoding" @ddb:Scheme="None"]', $coverage); // Rights $salesRightsFactory = $publicationFormat->getSalesRights(); while ($salesRight = $salesRightsFactory->next()) { $this->_checkForContentAndAddElement($description, 'dc:rights', $salesRight->getNameForONIXCode()); } // File transfer // Per default, only the full manuscript or a file of a custom genre // (set via settings form) is transferred. If several files of the same // genre are found for one publication format, the first is selected as // the transfer file per default. // Alternative configurations (e.g. container formats) are thinkable, but not implemented. $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); $availableFiles = array_filter($submissionFileDao->getLatestRevisions($monograph->getId()), create_function('$a', 'return $a->getViewable() && $a->getDirectSalesPrice() !== null && $a->getAssocType() == ASSOC_TYPE_PUBLICATION_FORMAT;')); $genreDao = DAORegistry::getDAO('GenreDAO'); $genreId = $metadataPlugins['Xmdp22MetadataPlugin']->getData("genre:id", $monograph->getPressId()); if (!isset($genreId)) { // if genre is not set, try to make monograph default // -- this fails if the press uses custom components and the default components // have been deleted $genreId = $genreDao->getByKey('MANUSCRIPT', $press->getId())->getId(); if (isset($genreId)) { $metadataPlugins['Xmdp22MetadataPlugin']->updateSetting($monograph->getPressId(), "genre_id", $genreId); } } $transferableFiles = array(); foreach ($availableFiles as $availableFile) { if ($availableFile->getAssocId() == $publicationFormat->getId() && $availableFile->getGenreId() == $genreId) { // Collect all files that belong to this publication format and have the selected genre $transferableFiles[] = $availableFile; } } // first file that fits criteria is transfered per default // -- another solution would be to place all files in a container here if ($transferableFiles) { $transferFile = $transferableFiles[0]; $transferableFiles = array($transferFile); } // Number of files (will always be 1, unless a container solution is implemented) $this->_checkForContentAndAddElement($description, 'ddb:fileNumber', sizeof($transferableFiles)); // File Properties and Transfer link if (isset($transferFile)) { $description->addStatement('ddb:fileProperties', '[@ddb:fileName="' . $transferFile->getServerFileName() . '" @ddbfileSize="' . $transferFile->getFileSize() . '"]'); $description->addStatement('ddb:transfer[@ddb:type="dcterms:URI"]', Request::url($press->getPath(), 'catalog', 'download', array($monograph->getId(), $publicationFormat->getId(), $transferFile->getFileIdAndRevision()))); } // Contact ID $contactId = $metadataPlugins['Xmdp22MetadataPlugin']->getData("ddb:contactID", $monograph->getPressId()); $this->_checkForContentAndAddElement($description, 'ddb:contact', '[@ddb:contactID="' . $contactId . '"]'); // Rights $kind = $metadataPlugins['Xmdp22MetadataPlugin']->getData("ddb:kind", $monograph->getPressId()); $description->addStatement('ddb:rights', '[@ddb:kind="' . $kind . '"]'); Hookregistry::call('Xmdp22SchemaPublicationFormatAdapter::extractMetadataFromDataObject', array(&$this, $monograph, $press, &$description)); return $description; }