예제 #1
0
 /**
  * Dedup: Return record title
  *
  * @param bool $forFiling Whether the title is to be used in filing
  *                        (e.g. sorting, non-filing characters should be removed)
  *
  * @return string
  */
 public function getTitle($forFiling = false)
 {
     $punctuation = ['b' => ' : ', 'n' => '. ', 'p' => '. ', 'c' => ' '];
     $acceptSubfields = ['b', 'n', 'p'];
     if ($forFiling) {
         $acceptSubfields[] = 'c';
     }
     foreach (['245', '240'] as $fieldCode) {
         $field = $this->getField($fieldCode);
         if ($field) {
             $title = $this->getSubfield($field, 'a');
             if ($forFiling) {
                 $nonfiling = $this->getIndicator($field, 2);
                 if ($nonfiling > 0) {
                     $title = substr($title, $nonfiling);
                 }
             }
             foreach ($field['s'] as $subfield) {
                 if (!in_array(key($subfield), $acceptSubfields)) {
                     continue;
                 }
                 if (!MetadataUtils::hasTrailingPunctuation($title)) {
                     $title .= $punctuation[key($subfield)];
                 } else {
                     $title .= ' ';
                 }
                 $title .= current($subfield);
             }
             $title = MetadataUtils::stripTrailingPunctuation($title);
             if ($forFiling) {
                 $title = MetadataUtils::stripLeadingPunctuation($title);
                 $title = mb_strtolower($title, 'UTF-8');
             }
             if (!empty($title)) {
                 return $title;
             }
         }
     }
     return '';
 }