Ejemplo n.º 1
0
 /**
  * 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 Locale::get3LetterFrom2LetterIsoLanguage($iso2Letter);
 }
 /**
  * @see MetadataDataObjectAdapter::extractMetadataFromDataObject()
  * @param $submission Submission
  * @param $authorMarcrelatorRole string the marcrelator role to be used
  *  for submission authors.
  * @return MetadataDescription
  */
 function &extractMetadataFromDataObject(&$submission, $authorMarcrelatorRole = 'aut')
 {
     assert(is_a($submission, 'Submission'));
     $mods34Description =& $this->instantiateMetadataDescription();
     // Retrieve the primary locale.
     $catalogingLocale = Locale::getPrimaryLocale();
     $catalogingLanguage = Locale::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"]', $authorMarcrelatorRole);
         // 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
     $submissionLanguage = Locale::get3LetterFrom2LetterIsoLanguage($submission->getLanguage());
     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 class
     $localizedSubjectClasses = $submission->getSubjectClass(null);
     // Localized
     $this->addLocalizedStatements($mods34Description, 'subject/topic', $localizedSubjectClasses);
     // Subject
     $localizedSubjects = $submission->getSubject(null);
     // Localized
     $this->addLocalizedStatements($mods34Description, 'subject/topic', $localizedSubjects);
     // Geographical coverage
     $localizedCoverageGeo = $submission->getCoverageGeo(null);
     // Localized
     $this->addLocalizedStatements($mods34Description, 'subject/geographic', $localizedCoverageGeo);
     // Chronological coverage
     $localizedCoverageChron = $submission->getCoverageChron(null);
     // Localized
     $this->addLocalizedStatements($mods34Description, 'subject/temporal', $localizedCoverageChron);
     // 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;
 }
Ejemplo n.º 3
0
 /**
  * @covers PKPLocale
  */
 public function testGet3LetterFrom2LetterIsoLanguage()
 {
     self::assertEquals('eng', Locale::get3LetterFrom2LetterIsoLanguage('en'));
     self::assertEquals('por', Locale::get3LetterFrom2LetterIsoLanguage('pt'));
     self::assertNull(Locale::get3LetterFrom2LetterIsoLanguage('xx'));
 }