コード例 #1
0
 /**
  * Get component parts in a sorted array
  *
  * @param string $sourceId     Source ID
  * @param string $hostRecordId Host record ID (doesn't include source id)
  *
  * @return array Array of component parts
  */
 protected function getComponentPartsSorted($sourceId, $hostRecordId)
 {
     $componentsIter = $this->db->record->find(['source_id' => $sourceId, 'host_record_id' => $hostRecordId])->timeout($this->cursorTimeout);
     $components = [];
     foreach ($componentsIter as $component) {
         $components[MetadataUtils::createIdSortKey($component['_id'])] = $component;
     }
     ksort($components);
     return array_values($components);
 }
コード例 #2
0
 /**
  * Merge component parts to this record
  *
  * @param MongoCollection $componentParts Component parts to be merged
  *
  * @return int Count of records merged
  */
 public function mergeComponentParts($componentParts)
 {
     $count = 0;
     $parts = [];
     foreach ($componentParts as $componentPart) {
         $data = MetadataUtils::getRecordData($componentPart, true);
         $marc = new MARCRecord($data, '', $this->source, $this->idPrefix);
         $title = $marc->getFieldSubfields('245', ['a' => 1, 'b' => 1, 'n' => 1, 'p' => 1]);
         $uniTitle = $marc->getFieldSubfields('240', ['a' => 1, 'n' => 1, 'p' => 1]);
         if (!$uniTitle) {
             $uniTitle = $marc->getFieldSubfields('130', ['a' => 1, 'n' => 1, 'p' => 1]);
         }
         $additionalTitles = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '740', ['a' => 1]]]);
         $authors = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '100', ['a' => 1, 'e' => 1]], [MarcRecord::GET_NORMAL, '110', ['a' => 1, 'e' => 1]]]);
         $additionalAuthors = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '700', ['a' => 1, 'e' => 1]], [MarcRecord::GET_NORMAL, '710', ['a' => 1, 'e' => 1]]]);
         $duration = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '306', ['a' => 1]]]);
         $languages = [substr($marc->getField('008'), 35, 3)];
         $languages = array_unique(array_merge($languages, $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '041', ['a' => 1]], [MarcRecord::GET_NORMAL, '041', ['d' => 1]]], false, true, true)));
         $originalLanguages = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '041', ['h' => 1]]], false, true, true);
         $subtitleLanguages = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '041', ['j' => 1]]], false, true, true);
         $id = $componentPart['_id'];
         $newField = ['i1' => ' ', 'i2' => ' ', 's' => [['a' => $id]]];
         if ($title) {
             $newField['s'][] = ['b' => $title];
         }
         if ($authors) {
             $newField['s'][] = ['c' => array_shift($authors)];
             foreach ($authors as $author) {
                 $newField['s'][] = ['d' => $author];
             }
         }
         foreach ($additionalAuthors as $addAuthor) {
             $newField['s'][] = ['d' => $addAuthor];
         }
         if ($uniTitle) {
             $newField['s'][] = ['e' => $uniTitle];
         }
         if ($duration) {
             $newField['s'][] = ['f' => reset($duration)];
         }
         foreach ($additionalTitles as $addTitle) {
             $newField['s'][] = ['g' => $addTitle];
         }
         foreach ($languages as $language) {
             if (preg_match('/^\\w{3}$/', $language) && $language != 'zxx' && $language != 'und') {
                 $newField['s'][] = ['h' => $language];
             }
         }
         foreach ($originalLanguages as $language) {
             if (preg_match('/^\\w{3}$/', $language) && $language != 'zxx' && $language != 'und') {
                 $newField['s'][] = ['i' => $language];
             }
         }
         foreach ($subtitleLanguages as $language) {
             if (preg_match('/^\\w{3}$/', $language) && $language != 'zxx' && $language != 'und') {
                 $newField['s'][] = ['j' => $language];
             }
         }
         $key = MetadataUtils::createIdSortKey($id);
         $parts["{$key} {$count}"] = $newField;
         ++$count;
     }
     ksort($parts);
     $this->fields['979'] = array_values($parts);
     return $count;
 }