/** * Get FieldData * * @param \File_MARC_Data_Field $field Field * * @return array|Boolean */ protected function getFieldData($field) { // Make sure that there is a t field to be displayed: if ($title = $field->getSubfield('t')) { $title = $title->getData(); } else { return false; } // If set, display relationship information in i subfield if ($relation = $field->getSubfield('i')) { $relation = $relation->getData(); } else { $relation = $this->getRecordLinkNote($field); } $linkTypeSetting = isset($this->mainConfig->Record->marc_links_link_types) ? $this->mainConfig->Record->marc_links_link_types : 'id,oclc,dlc,isbn,issn,title'; $linkTypes = explode(',', $linkTypeSetting); $link = false; if (in_array('id', $linkTypes)) { // Search ID in field 9 $linkSubfield = $field->getSubfield('9'); if ($linkSubfield && ($bibLink = $this->getIdFromLinkingField($linkSubfield))) { $link = ['type' => 'bib', 'value' => $bibLink]; } } elseif (in_array('ctrlnum', $linkTypes)) { // Extract ctrlnum from field w, ignore the prefix $linkFields = $linkFields = $field->getSubfields('w'); foreach ($linkFields as $current) { if (preg_match('/\\(([^)]+)\\)(.+)/', $current->getData(), $matches)) { $link = ['type' => 'ctrlnum', 'value' => $matches[1] . $matches[2]]; } } } // Found link based on special conditions, stop here if ($link) { return ['title' => $relation, 'value' => $title, 'link' => $link]; } // Fallback to base method if no custom field found return parent::getFieldData($field); }
/** * Returns the array element for the 'getAllRecordLinks' method * * @param File_MARC_Data_Field $field Field to examine * * @return array|bool Array on success, boolean false if no * valid link could be found in the data. */ protected function getFieldData($field) { // Make sure that there is a t field to be displayed: if ($title = $field->getSubfield('t')) { $title = $title->getData(); } else { return false; } $linkTypeSetting = isset($this->mainConfig->Record->marc_links_link_types) ? $this->mainConfig->Record->marc_links_link_types : 'id,oclc,dlc,isbn,issn,title'; $linkTypes = explode(',', $linkTypeSetting); $linkFields = $field->getSubfields('w'); // Run through the link types specified in the config. // For each type, check field for reference // If reference found, exit loop and go straight to end // If no reference found, check the next link type instead foreach ($linkTypes as $linkType) { switch (trim($linkType)) { case 'oclc': foreach ($linkFields as $current) { if ($oclc = $this->getIdFromLinkingField($current, 'OCoLC')) { $link = ['type' => 'oclc', 'value' => $oclc]; } } break; case 'dlc': foreach ($linkFields as $current) { if ($dlc = $this->getIdFromLinkingField($current, 'DLC', true)) { $link = ['type' => 'dlc', 'value' => $dlc]; } } break; case 'id': foreach ($linkFields as $current) { if ($bibLink = $this->getIdFromLinkingField($current)) { $link = ['type' => 'bib', 'value' => $bibLink]; } } break; case 'isbn': if ($isbn = $field->getSubfield('z')) { $link = ['type' => 'isn', 'value' => trim($isbn->getData()), 'exclude' => $this->getUniqueId()]; } break; case 'issn': if ($issn = $field->getSubfield('x')) { $link = ['type' => 'isn', 'value' => trim($issn->getData()), 'exclude' => $this->getUniqueId()]; } break; case 'title': $link = ['type' => 'title', 'value' => $title]; break; } // Exit loop if we have a link if (isset($link)) { break; } } // Make sure we have something to display: return !isset($link) ? false : ['title' => $this->getRecordLinkNote($field), 'value' => $title, 'link' => $link]; }
// File_MARC offers the ability to add subfields at any point within // an existing set of subfields // First, create some subfields $subfields[] = new File_MARC_Subfield('a', 'nothing'); $subfields[] = new File_MARC_Subfield('z', 'everything'); // Then, create a field including those subfields $field = new File_MARC_Data_Field('100', $subfields, '0'); // Create some new subfields $subfield1 = new File_MARC_Subfield('g', 'a little'); $subfield2 = new File_MARC_Subfield('k', 'a bit more'); $subfield3 = new File_MARC_Subfield('t', 'a lot'); // Append a new subfield to the existing set of subfields // Expected order: a-z-g $field->appendSubfield($subfield1); // Insert a new subfield after the first subfield with code 'z' // Expected order: a-z-k-g $sf = $field->getSubfields('z'); // getSubfields() always returns an array; we just want the first subfield if (count($sf) > 0) { $field->insertSubfield($subfield2, $sf[0]); } // Insert a new subfield prior to the first subfield with code 'z' // Expected order: a-t-z-k-g $sf = $field->getSubfield('z'); // getSubfield() simply returns the first matching subfield if ($sf) { $field->insertSubfield($subfield3, $sf, true); } // let's see the results print $field; print "\n";
/** * @param File_MARC_Data_Field $marcField * @param File_MARC_Subfield $subField * @return string */ public function getSubfieldData($marcField, $subField) { if ($marcField) { return $marcField->getSubfield($subField) ? $marcField->getSubfield($subField)->getData() : ''; } else { return ''; } }
/** * Returns the array element for the 'getAllRecordLinks' method * * @param File_MARC_Data_Field $field Field to examine * @param string $value Field name for use in label * * @access protected * @return array|bool Array on success, boolean false if no * valid link could be found in the data. */ protected function getFieldData($field, $value) { global $configArray; $labelPrfx = 'note_'; $baseURI = $configArray['Site']['url']; $relInfo = $field->getSubfield('i') ? $field->getSubfield('i')->getData() : ''; $title = $field->getSubfield('t') ? $field->getSubfield('t')->getData() : ''; $diff = $field->getSubfield('c') ? $field->getSubfield('c')->getData() : ''; $issn = $field->getSubfield('x') ? $field->getSubfield('x')->getData() : ''; $isbn = $field->getSubfield('z') ? $field->getSubfield('z')->getData() : ''; if ($diff) { $title .= " {$diff}"; } $fallbackTitle = ''; if (empty($title)) { if (!empty($relInfo)) { $fallbackTitle = $relInfo . ' '; } if (!empty($issn)) { $fallbackTitle .= $issn; } else { $fallbackTitle .= $isbn; } } // There are two possible ways we may want to link to a record with subfield w // -- either we will have a raw bibliographic record in subfield w, or else we // will have an OCLC number prefixed by (OCoLC). If we have both, we want to // favor the bib number over the OCLC number. If we have an unrecognized // parenthetical prefix to the number, we should simply ignore it. $bib = $oclc = ''; $linkFields = $field->getSubfields('w'); foreach ($linkFields as $current) { $text = $current->getData(); // Extract parenthetical prefixes: if (preg_match('/\\(([^)]+)\\)(.+)/', $text, $matches)) { // Is it an OCLC number? if ($matches[1] == 'OCoLC') { $oclc = $baseURI . '/Search/Results?lookfor=' . urlencode($matches[2]) . '&type=oclc_num&jumpto=1'; } } else { // No parenthetical prefix found -- assume raw bib number: $bib = $baseURI . '/Record/' . $text; } } // Check which link type we found in the code above... and use title search // if we found nothing! if (!empty($bib)) { $link = $bib; } else { if (!empty($oclc)) { $link = $oclc; } else { if (!empty($issn)) { $link = $baseURI . '/Search/Results?lookfor=' . urlencode($issn) . '&type=ISN'; } else { if (!empty($isbn)) { $link = $baseURI . '/Search/Results?lookfor=' . urlencode($isbn) . '&type=ISN'; } else { $link = $baseURI . '/Search/Results?lookfor=' . urlencode('"' . $title . '"') . '&type=Title'; } } } } return array('title' => $labelPrfx . $value, 'value' => empty($title) ? $fallbackTitle : $title, 'issn' => $issn, 'link' => $link); }
/** * MatchesConditions * * @param array $conditions Conditions * @param \File_MARC_Data_Field $marcRecord MarcRecord * * @return bool */ protected function matchesConditions(array $conditions, \File_MARC_Data_Field $marcRecord) { if (empty($conditions)) { return true; } $matchesOr = false; $orConditionsCount = count($conditions); $i = 0; while (!$matchesOr && $i < $orConditionsCount) { $j = 0; $matchesAnd = true; $andConditions = explode('&&', $conditions[$i]); $andConditionsCount = count($andConditions); while ($matchesAnd && $j < $andConditionsCount) { list($subfieldKey, $subfieldValue) = explode('|', $andConditions[$j]); $subfield = $marcRecord->getSubfield(trim($subfieldKey)); $matchesAnd = $subfield && preg_match('/' . trim($subfieldValue) . '/', $subfield->getData()); $j++; } $matchesOr = $matchesOr || $matchesAnd; $i++; } return $matchesOr; }
/** * Returns the array element for the 'getAllRecordLinks' method * * @param File_MARC_Data_Field $field Field to examine * @param string $value Field name for use in label * * @return array|bool Array on success, boolean false if no * valid link could be found in the data. */ protected function getFieldData($field, $value) { $labelPrfx = 'note_'; // There are two possible ways we may want to link to a record -- either // we will have a raw bibliographic record in subfield w, or else we will // have an OCLC number prefixed by (OCoLC). If we have both, we want to // favor the bib number over the OCLC number. If we have an unrecognized // parenthetical prefix to the number, we should simply ignore it. $bib = $oclc = ''; $linkFields = $field->getSubfields('w'); foreach ($linkFields as $current) { $text = $current->getData(); // Extract parenthetical prefixes: if (preg_match('/\\(([^)]+)\\)(.+)/', $text, $matches)) { // Is it an OCLC number? if ($matches[1] == 'OCoLC') { $oclc = $matches[2]; } } else { // No parenthetical prefix found -- assume raw bib number: $bib = $text; } } // Check which link type we found in the code above... and fail if we // found nothing! if (!empty($bib)) { $link = array('type' => 'bib', 'value' => $bib); } else { if (!empty($oclc)) { $link = array('type' => 'oclc', 'value' => $oclc); } else { return false; } } return array('title' => $labelPrfx . $value, 'value' => $field->getSubfield('t')->getData(), 'link' => $link); }