/** * @param \File_MARC_Data_Field $field * * @return DataField */ private function convertDataField(\File_MARC_Data_Field $field) { $tag = $field->getTag(); $ind1 = $field->getIndicator(1); $ind2 = $field->getIndicator(2); $dataField = new DataField($tag, [$ind1, $ind2]); foreach ($field->getSubfields() as $subField) { $dataField->addSubField($this->convertSubfield($subField)); } return $dataField; }
/** * 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]; }
/** * Convert sub fields to array map * * @param \File_MARC_Data_Field $field Field * @param Array $fieldMap FieldMap * @param Boolean $includeIndicators Add the two indicators to the * field list * * @return Array */ protected function getMappedFieldData($field, array $fieldMap, $includeIndicators = true) { $subFieldValues = []; if ($includeIndicators) { $subFieldValues['@ind1'] = $field->getIndicator(1); $subFieldValues['@ind2'] = $field->getIndicator(2); } foreach ($fieldMap as $code => $name) { if (substr($code, 0, 1) === '_') { // Underscore means repeatable $code = substr($code, 1); // Remove underscore /** * Subfields * * @var \File_MARC_Subfield[] $subFields */ $subFields = $field->getSubfields((string) $code); if (sizeof($subFields)) { //$subFieldValues[$name] = array(); $i = 1; foreach ($subFields as $subField) { $subFieldValues[$i . $name] = $subField->getData(); $i++; } } } else { // Normal single field $subField = $field->getSubfield((string) $code); if ($subField) { $subFieldValues[$name] = $subField->getData(); } } } return $subFieldValues; }
/** * Extract field data * * @param \File_MARC_Data_Field $field * @param Array $fieldMapping Field code=>name mapping * @return Array */ protected function extractFieldData(\File_MARC_Data_Field $field, array $fieldMapping) { $subFields = $field->getSubfields(); $rawData = array(); $data = array(); // Fetch data foreach ($subFields as $code => $subdata) { if ($this->useConcatenation($code, $rawData)) { $rawData[$code] .= $this->concatenationMapping[$code] . $subdata->getData(); } else { $rawData[$code] = $subdata->getData(); } } foreach ($fieldMapping as $code => $name) { $data[$name] = isset($rawData[$code]) ? $rawData[$code] : ''; } return $data; }
/** * * * @param \File_MARC_Data_Field $field * @param String $fieldIndex */ protected function getFieldData($field, $fieldIndex) { // 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); $link = false; if (in_array('id', $linkTypes)) { // Search ID in field 9 $linkSubfield = $field->getSubfield('9'); if ($linkSubfield && ($bibLink = $this->getIdFromLinkingField($linkSubfield))) { $link = array('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 = array('type' => 'ctrlnum', 'value' => $matches[1] . $matches[2]); } } } // Found link based on special conditions, stop here if ($link) { return array('title' => $this->getRecordLinkNote($field), 'value' => $title, 'link' => $link); } // Fallback to base method if no custom field found return parent::getFieldData($field, $fieldIndex); }
// 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";
/** * 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); }
/** * 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); }