protected function setUp() { if (false === $this->record instanceof \File_MARC_Record) { // Retrieve a set of MARC records from a file $records = new \File_MARC('test/music.mrc'); // Iterate through the retrieved records $this->record = $records->next(); } }
public function loadXML($doc) { $id = null; $format = null; $score = null; $xml_data = ""; foreach ($doc->str as $str) { // marc record if ((string) $str["name"] == 'fullrecord') { $marc = trim((string) $str); // marc-xml if (substr($marc, 0, 5) == '<?xml') { $xml_data = $marc; } else { $marc = preg_replace('/#31;/', "", $marc); $marc = preg_replace('/#30;/', "", $marc); $marc_file = new \File_MARC($marc, \File_MARC::SOURCE_STRING); $marc_record = $marc_file->next(); $xml_data = $marc_record->toXML(); } } elseif ((string) $str["name"] == 'id') { $id = (string) $str; } } // format foreach ($doc->arr as $arr) { if ($arr["name"] == "format") { $format = (string) $arr->str; } } // score foreach ($doc->float as $float) { if ($float["name"] == "score") { $score = (string) $float; } } // load marc data $this->marc = new MarcRecord(); $this->marc->loadXML($xml_data); // save for later $this->document = Parser::convertToDOMDocument($doc); $this->serialized = $doc->asXml(); // process it $this->map(); $this->cleanup(); // add non-marc data $this->setRecordID($id); $this->setScore($score); $this->format()->setInternalFormat($format); $this->format()->setPublicFormat($format); // custom mappings if (class_exists('Local\\Model\\Solr\\Record')) { $local = new \Local\Model\Solr\Record(); $local->map($this, $this->marc); } }
/** * Constructor. We build the object using all the data retrieved * from the (Solr) index (which also happens to include the * 'fullrecord' field containing raw metadata). Since we have to * make a search call to find out which record driver to construct, * we will already have this data available, so we might as well * just pass it into the constructor. * * @param array $record All fields retrieved from the index. * * @access public */ public function __construct($record) { // Call the parent's constructor... parent::__construct($record); // Also process the MARC record: $marc = trim($record['fullrecord']); // check if we are dealing with MARCXML if (substr($marc, 0, 1) == '<') { $marc = new File_MARCXML($marc, File_MARCXML::SOURCE_STRING); } else { $marc = preg_replace('/#31;/', "", $marc); $marc = preg_replace('/#30;/', "", $marc); $marc = new File_MARC($marc, File_MARC::SOURCE_STRING); } $this->marcRecord = $marc->next(); if (!$this->marcRecord) { PEAR::raiseError(new PEAR_Error('Cannot Process MARC Record')); } }
/** * Return the MARC record in MARCXML format * * This method produces an XML representation of a MARC record that * attempts to adhere to the MARCXML standard documented at * http://www.loc.gov/standards/marcxml/ * * @param string $encoding output encoding for the MARCXML record * @param bool $indent pretty-print the MARCXML record * @param bool $single wrap the <record> element in a <collection> element * * @return string representation of MARC record in MARCXML format * * @todo Fix encoding input / output issues (PHP 6.0 required?) */ function toXML($encoding = "UTF-8", $indent = true, $single = true) { $this->marcxml->setIndent($indent); if ($single) { $this->marc->toXMLHeader(); } $this->marcxml->startElement("record"); // MARCXML schema has some strict requirements // We'll set reasonable defaults to avoid invalid MARCXML $xmlLeader = $this->getLeader(); // Record status if ($xmlLeader[5] == " ") { // Default to "n" (new record) $xmlLeader[5] = "n"; } // Type of record if ($xmlLeader[6] == " ") { // Default to "a" (language material) $xmlLeader[6] = "a"; } $this->marcxml->writeElement("leader", $xmlLeader); foreach ($this->fields as $field) { if (!$field->isEmpty()) { switch (get_class($field)) { case "File_MARC_Control_Field": $this->marcxml->startElement("controlfield"); $this->marcxml->writeAttribute("tag", $field->getTag()); $this->marcxml->text($field->getData()); $this->marcxml->endElement(); // end control field break; case "File_MARC_Data_Field": $this->marcxml->startElement("datafield"); $this->marcxml->writeAttribute("tag", $field->getTag()); $this->marcxml->writeAttribute("ind1", $field->getIndicator(1)); $this->marcxml->writeAttribute("ind2", $field->getIndicator(2)); foreach ($field->getSubfields() as $subfield) { $this->marcxml->startElement("subfield"); $this->marcxml->writeAttribute("code", $subfield->getCode()); $this->marcxml->text($subfield->getData()); $this->marcxml->endElement(); // end subfield } $this->marcxml->endElement(); // end data field break; } } } $this->marcxml->endElement(); // end record if ($single) { return $this->marc->toXMLFooter(); } }
/** * Set raw data to initialize the object. * * @param mixed $data Raw data representing the record; Record Model * objects are normally constructed by Record Driver objects using data * passed in from a Search Results object. In this case, $data is a Solr record * array containing MARC data in the 'fullrecord' field. * * @return void */ public function setRawData($data) { // Call the parent's set method... parent::setRawData($data); // Also process the MARC record: $marc = trim($data['fullrecord']); // check if we are dealing with MARCXML $xmlHead = '<?xml version'; if (strcasecmp(substr($marc, 0, strlen($xmlHead)), $xmlHead) === 0) { $marc = new \File_MARCXML($marc, \File_MARCXML::SOURCE_STRING); } else { $marc = preg_replace('/#31;/', "", $marc); $marc = preg_replace('/#30;/', "", $marc); $marc = new \File_MARC($marc, \File_MARC::SOURCE_STRING); } $this->marcRecord = $marc->next(); if (!$this->marcRecord) { throw new \File_MARC_Exception('Cannot Process MARC Record'); } }
/** * Process parameters and display the page. * * @return void * @access public */ public function launch() { global $interface; // Retrieve the record from the index if (!($record = $this->db->getRecord($_GET['id']))) { PEAR::raiseError(new PEAR_Error('Record Does Not Exist')); } // Send basic information to the template. $interface->setPageTitle(isset($record['heading']) ? $record['heading'] : 'Heading unavailable.'); $interface->assign('record', $record); // Load MARC data $marc = trim($record['fullrecord']); $marc = preg_replace('/#31;/', "", $marc); $marc = preg_replace('/#30;/', "", $marc); $marc = new File_MARC($marc, File_MARC::SOURCE_STRING); $marcRecord = $marc->next(); if (!$marcRecord) { PEAR::raiseError(new PEAR_Error('Cannot Process MARC Record')); } $xml = trim($marcRecord->toXML()); // Transform MARCXML $style = new DOMDocument(); $style->load('services/Record/xsl/record-marc.xsl'); $xsl = new XSLTProcessor(); $xsl->importStyleSheet($style); $doc = new DOMDocument(); if ($doc->loadXML($xml)) { $html = $xsl->transformToXML($doc); $interface->assign('details', $html); } // Assign the ID of the last search so the user can return to it. $interface->assign('lastsearch', isset($_SESSION['lastSearchURL']) ? $_SESSION['lastSearchURL'] : false); // Display Page $interface->setTemplate('record.tpl'); $interface->display('layout.tpl'); }
/** * Set raw data to initialize the object. * * @param mixed $data Raw data representing the record; Record Model * objects are normally constructed by Record Driver objects using data * passed in from a Search Results object. In this case, $data is a Solr record * array containing MARC data in the 'fullrecord' field. * * @return void */ public function setRawData($data) { // Call the parent's set method... parent::setRawData($data); // Also process the MARC record: $marc = trim($data['fullrecord']); // check if we are dealing with MARCXML if (substr($marc, 0, 1) == '<') { $marc = new \File_MARCXML($marc, \File_MARCXML::SOURCE_STRING); } else { // When indexing over HTTP, SolrMarc may use entities instead of certain // control characters; we should normalize these: $marc = str_replace(['#29;', '#30;', '#31;'], ["", "", ""], $marc); $marc = new \File_MARC($marc, \File_MARC::SOURCE_STRING); } $this->marcRecord = $marc->next(); if (!$this->marcRecord) { throw new \File_MARC_Exception('Cannot Process MARC Record'); } }
*/ if (!isset($argv[1])) { die('No delete file specified'); } require_once 'util.inc.php'; // set up util environment require_once 'File/MARC.php'; require_once 'sys/Solr.php'; // Read Config file $configArray = parse_ini_file('../web/conf/config.ini', true); // Setup Solr Connection $url = $configArray['Index']['url']; $solr = new Solr($url); if ($configArray['System']['debugSolr']) { $solr->debug = true; } // Parse delete.mrc file $collection = new File_MARC($argv[1]); // Iterate through the retrieved records $i = 0; while ($record = $collection->next()) { $idField = $record->getField('001'); $id = $idField->getData(); $solr->deleteRecord($id); $i++; } // Commit and Optimize if ($i) { $solr->commit(); $solr->optimize(); }
/** * Get textual holdings summary. * * @param string $marc Raw marc holdings records. * * @return array Array of holdings data similar to the one returned by * getHolding. * @access private */ private function _getMarcHoldings($marc) { $holdings = array(); $file = new File_MARC($marc, File_MARC::SOURCE_STRING); while ($marc = $file->next()) { list($locations, $record_holdings) = $this->decodeMarcHoldingRecord($marc); // Flatten locations with corresponding holdings as VuFind // expects it. foreach ($locations as $location) { $holdings[] = array_merge_recursive($location, array('summary' => $record_holdings)); } } return $holdings; }
// get system temporary directory location $temp_dir = sys_get_temp_dir(); $uploaded_file = $temp_dir . DS . $_FILES['importFile']['name']; // set max size $max_size = $sysconf['max_upload'] * 1024; $upload->setAllowableFormat(array('.mrc', '.xml', '.txt')); $upload->setMaxSize($max_size); $upload->setUploadDir($temp_dir); $upload_status = $upload->doUpload('importFile'); if ($upload_status != UPLOAD_SUCCESS) { utility::jsAlert(__('Upload failed! File type not allowed or the size is more than') . $sysconf['max_upload'] / 1024 . ' MB'); exit; } $updated_row = 0; $marc_string = file_get_contents($uploaded_file); $marc_data = new File_MARC($marc_string, File_MARC::SOURCE_STRING); // create dbop object $sql_op = new simbio_dbop($dbs); $gmd_cache = array(); $publ_cache = array(); $place_cache = array(); $lang_cache = array(); $sor_cache = array(); $author_cache = array(); $subject_cache = array(); $updated_row = ''; while ($record = $marc_data->next()) { $data = array(); $input_date = date('Y-m-d H:i:s'); $data['input_date'] = $input_date; $data['last_update'] = $input_date;
public function getHolding($id) { require_once 'File/MARC.php'; // There are two possible queries we can use to obtain status information. // The first (and most common) obtains information from a combination of // items and holdings records. The second (a rare case) obtains // information from the holdings record when no items are available. $items = "select ITEM_BARCODE.ITEM_BARCODE, ITEM.ITEM_ID, MFHD_DATA.RECORD_SEGMENT, MFHD_ITEM.ITEM_ENUM, ITEM.ON_RESERVE, ITEM.ITEM_SEQUENCE_NUMBER, ITEM_STATUS_DESC as status, LOCATION.LOCATION_DISPLAY_NAME as location, MFHD_MASTER.DISPLAY_CALL_NO as callnumber, CIRC_TRANSACTIONS.CURRENT_DUE_DATE as duedate " . "from {$this->dbName}.BIB_ITEM, {$this->dbName}.ITEM, {$this->dbName}.ITEM_STATUS_TYPE, {$this->dbName}.ITEM_STATUS, {$this->dbName}.LOCATION, {$this->dbName}.MFHD_ITEM, {$this->dbName}.MFHD_MASTER, {$this->dbName}.MFHD_DATA, {$this->dbName}.CIRC_TRANSACTIONS, {$this->dbName}.ITEM_BARCODE " . "where BIB_ITEM.BIB_ID = :id " . "and BIB_ITEM.ITEM_ID = ITEM.ITEM_ID " . "and ITEM.ITEM_ID = ITEM_STATUS.ITEM_ID " . "and ITEM_STATUS.ITEM_STATUS = ITEM_STATUS_TYPE.ITEM_STATUS_TYPE " . "and ITEM_BARCODE.ITEM_ID (+)= ITEM.ITEM_ID " . "and LOCATION.LOCATION_ID = ITEM.PERM_LOCATION " . "and CIRC_TRANSACTIONS.ITEM_ID (+)= ITEM.ITEM_ID " . "and MFHD_ITEM.ITEM_ID = ITEM.ITEM_ID " . "and MFHD_MASTER.MFHD_ID = MFHD_ITEM.MFHD_ID " . "and MFHD_DATA.MFHD_ID = MFHD_ITEM.MFHD_ID " . "and MFHD_MASTER.SUPPRESS_IN_OPAC='N' " . "order by ITEM.ITEM_SEQUENCE_NUMBER, MFHD_DATA.SEQNUM"; $noItems = "select null as ITEM_BARCODE, null as ITEM_ID, MFHD_DATA.RECORD_SEGMENT, null as ITEM_ENUM, 'N' as ON_RESERVE, 1 as ITEM_SEQUENCE_NUMBER, 'No information available' as status, LOCATION.LOCATION_DISPLAY_NAME as location, MFHD_MASTER.DISPLAY_CALL_NO as callnumber, null as duedate " . "from {$this->dbName}.BIB_MFHD, {$this->dbName}.LOCATION, {$this->dbName}.MFHD_MASTER, {$this->dbName}.MFHD_DATA " . "where BIB_MFHD.BIB_ID = :id " . "and LOCATION.LOCATION_ID = MFHD_MASTER.LOCATION_ID " . "and MFHD_MASTER.MFHD_ID = BIB_MFHD.MFHD_ID " . "and MFHD_DATA.MFHD_ID = BIB_MFHD.MFHD_ID " . "and MFHD_MASTER.SUPPRESS_IN_OPAC='N' " . "order by MFHD_DATA.SEQNUM"; $possibleQueries = array($items, $noItems); // Loop through the possible queries and try each in turn -- the first one // that yields results will cause us to break out of the loop. foreach ($possibleQueries as $sql) { // Execute SQL try { $holding = array(); $sqlStmt = $this->db->prepare($sql); $sqlStmt->execute(array(':id' => $id)); } catch (PDOException $e) { return new PEAR_Error($e->getMessage()); } // Build Holdings Array $i = 0; $data = array(); while ($row = $sqlStmt->fetch(PDO::FETCH_ASSOC)) { // Determine Copy Number $number = $row['ITEM_ENUM'] ? $row['ITEM_ENUM'] : $row['ITEM_SEQUENCE_NUMBER']; // Concat wrapped rows (MARC data more than 300 bytes gets split into multiple rows) if (isset($data[$row['ITEM_ID']]["{$number}"])) { // We don't want to concatenate the same MARC information to itself over and // over due to a record with multiple status codes -- we should only concat // wrapped rows for the FIRST status code we encounter! if ($data[$row['ITEM_ID']]["{$number}"]['STATUS_ARRAY'][0] == $row['STATUS']) { $data[$row['ITEM_ID']]["{$number}"]['RECORD_SEGMENT'] .= $row['RECORD_SEGMENT']; } // If we've encountered a new status code, we should track it: if (!in_array($row['STATUS'], $data[$row['ITEM_ID']]["{$number}"]['STATUS_ARRAY'])) { $data[$row['ITEM_ID']]["{$number}"]['STATUS_ARRAY'][] = $row['STATUS']; } } else { // This is the first time we've encountered this row number -- initialize // the row and start an array of statuses. $data[$row['ITEM_ID']]["{$number}"] = $row; $data[$row['ITEM_ID']]["{$number}"]['STATUS_ARRAY'] = array($row['STATUS']); } } // If we found data, we can leave the foreach loop -- we don't need to try // any more queries. if (count($data) > 0) { break; } } foreach ($data as $item) { foreach ($item as $number => $row) { // Get availability/status info based on the array of status codes: $availability = $this->determineAvailability($row['STATUS_ARRAY']); // If we found other statuses, we should override the display value // appropriately: if (count($availability['otherStatuses']) > 0) { $row['STATUS'] = $this->pickStatus($availability['otherStatuses']); } $holding[$i] = array('id' => $id, 'availability' => $availability['available'], 'status' => $row['STATUS'], 'location' => htmlentities($row['LOCATION']), 'reserve' => $row['ON_RESERVE'], 'callnumber' => $row['CALLNUMBER'], 'duedate' => $row['DUEDATE'], 'number' => $number, 'barcode' => $row['ITEM_BARCODE']); // Parse Holding Record if ($row['RECORD_SEGMENT']) { try { $marc = new File_MARC(str_replace(array("\n", "\r"), '', $row['RECORD_SEGMENT']), File_MARC::SOURCE_STRING); if ($record = $marc->next()) { // Get Notes if ($fields = $record->getFields('852')) { foreach ($fields as $field) { if ($subfields = $field->getSubfields('z')) { foreach ($subfields as $subfield) { // If this is the first time through, assume a single-line summary if (!isset($holding[$i]['notes'])) { $holding[$i]['notes'] = $subfield->getData(); // If we already have a summary line, convert it to an array and append more data } else { if (!is_array($holding[$i]['notes'])) { $holding[$i]['notes'] = array($holding[$i]['notes']); } $holding[$i]['notes'][] = $subfield->getData(); } } } } } // Get Summary (may be multiple lines) if ($fields = $record->getFields('866')) { foreach ($fields as $field) { if ($subfield = $field->getSubfield('a')) { // If this is the first time through, assume a single-line summary if (!isset($holding[$i]['summary'])) { $holding[$i]['summary'] = $subfield->getData(); // If we already have a summary line, convert it to an array and append more data } else { if (!is_array($holding[$i]['summary'])) { $holding[$i]['summary'] = array($holding[$i]['summary']); } $holding[$i]['summary'][] = $subfield->getData(); } } } } } } catch (Exception $e) { trigger_error('Poorly Formatted MFHD Record', E_USER_NOTICE); } } $i++; } } return $holding; }
/** * Protected support method for getHolding. * * @param array $recordSegment A Marc Record Segment obtained from an SQL query * * @return array Keyed data * @access protected */ protected function processRecordSegment($recordSegment) { $marcDetails = array(); try { $marc = new File_MARC(str_replace(array("\n", "\r"), '', $recordSegment), File_MARC::SOURCE_STRING); if ($record = $marc->next()) { // Get Notes $noteFields = array('506' => 'au', '845' => 'a', '852' => 'z'); foreach ($noteFields as $fieldCode => $subfieldCodes) { if ($fields = $record->getFields($fieldCode)) { foreach ($fields as $field) { if ($subfields = $field->getSubfields()) { $line = ''; foreach ($subfields as $code => $subfield) { if (!strstr($subfieldCodes, $code)) { continue; } if ($line) { $line .= ' '; } $line .= $subfield->getData(); } if ($line) { $marcDetails['notes'][] = $line; } } } } } // Get Summary (may be multiple lines) if ($fields = $record->getFields('863')) { foreach ($fields as $field) { if ($subfields = $field->getSubfields()) { $line = ''; foreach ($subfields as $code => $subfield) { if (!strstr('abiz', $code)) { continue; } if ($line) { $line .= ' '; } if ($code == 'i' || $code == 'z') { $line .= '(' . $subfield->getData() . ')'; } else { $line .= $subfield->getData(); } } if ($line) { $marcDetails['summary'][] = $line; } } } } if ($fields = $record->getFields('866')) { foreach ($fields as $field) { if ($subfields = $field->getSubfields()) { $line = ''; foreach ($subfields as $code => $subfield) { if (!strstr('az', $code)) { continue; } if ($line) { $line .= ' '; } $line .= $subfield->getData(); } if ($line) { $marcDetails['summary'][] = $line; } } } } // Get Supplementary material (may be multiple lines) if ($fields = $record->getFields('867')) { foreach ($fields as $field) { if ($subfields = $field->getSubfields()) { $line = ''; foreach ($subfields as $code => $subfield) { if (!strstr('az', $code)) { continue; } if ($line) { $line .= ' '; } if ($code == 'z') { $line .= '(' . $subfield->getData() . ')'; } else { $line .= $subfield->getData(); } } if ($line) { $marcDetails['supplements'][] = $line; } } } } // Get indexes (may be multiple lines) if ($fields = $record->getFields('868')) { foreach ($fields as $field) { if ($subfields = $field->getSubfields()) { $line = ''; foreach ($subfields as $code => $subfield) { if (!strstr('az', $code)) { continue; } if ($line) { $line .= ' '; } if ($code == 'z') { $line .= '(' . $subfield->getData() . ')'; } else { $line .= $subfield->getData(); } } if ($line) { $marcDetails['indexes'][] = $line; } } } } } } catch (Exception $e) { trigger_error('Poorly Formatted MFHD Record', E_USER_NOTICE); } return $marcDetails; }
/** * Return Solr results in an extended array * * @param array $result Optional results to process * * @return array Results */ protected function createResultArray($result = null) { global $configArray; // First, get the search results if none were provided if (is_null($result)) { // Let's do at most 100 at a time... if ($this->limit > 100) { $this->limit = 100; } // Get the results: $result = $this->processSearch(false, true); } if ($this->searchType == 'newitem') { $lookfor = translate('New Items'); } else { if ($this->searchType == 'reserves') { $lookfor = translate('Course Reserves'); } else { $lookfor = $this->displayQuery(); } } $resultHeader = array('searchTerms' => $lookfor, 'searchUrl' => $this->renderSearchUrl()); unset($result['responseHeader']); $result = array_merge($resultHeader, $result); // The marc_error nodes can cause problems, so let's get rid // of them at the same time. // We add the record image to the array: for MARC records we // use bookcover.php, for everything else thumbnail.php. // Finally we remove an extra slash in format values. for ($i = 0; $i < count($result['response']['docs']); $i++) { if (isset($result['response']['docs'][$i]['marc_error'])) { unset($result['response']['docs'][$i]['marc_error']); } if (isset($result['response']['docs'][$i]['thumbnail'])) { unset($result['response']['docs'][$i]['thumbnail']); } $id = isset($result['response']['docs'][$i]['id']) ? $result['response']['docs'][$i]['id'] : false; $type = isset($result['response']['docs'][$i]['recordtype']) ? $result['response']['docs'][$i]['recordtype'] : false; if ($type === 'marc') { if (isset($result['response']['docs'][$i]['fullrecord'])) { $marc = preg_replace('/#31;/', "", $result['response']['docs'][$i]['fullrecord']); $marc = preg_replace('/#30;/', "", $marc); $marc = new File_MARC($marc, File_MARC::SOURCE_STRING); $record = $marc->next(); $result['response']['docs'][$i]['fullrecord'] = $record->toXML(); } } $result['response']['docs'][$i]['record_link'] = $this->serverUrl . '/Record/' . urlencode($id); // Fetch image links and information $record = RecordDriverFactory::initRecordDriver($result['response']['docs'][$i]); for ($img = 0; $img < count($record->getAllImages()); $img++) { $result['response']['docs'][$i]['image_links'][] = $this->serverUrl . '/thumbnail.php?id=' . urlencode($id) . "&index={$img}&size=large"; } $thumbnail = $record->getThumbnail(); if ($thumbnail) { $result['response']['docs'][$i]['thumbnail_link'] = $thumbnail; } $result['response']['docs'][$i]['parsed_title'] = $record->getTitle(); $links = $record->getAllRecordLinks(); if ($links) { $result['response']['docs'][$i]['parsed_record_links'] = $links; } $urls = $record->getOnlineURLs(); if ($urls) { $result['response']['docs'][$i]['parsed_online_urls'] = $urls; } } return $result; }
public static function loadMarcRecordByHooplaId($id) { global $configArray; if (array_key_exists($id, MarcLoader::$loadedMarcRecords)) { return MarcLoader::$loadedMarcRecords[$id]; } $firstChars = substr($id, 0, 7); $individualName = $configArray['Hoopla']['individualMarcPath'] . "/{$firstChars}/{$id}.mrc"; $marcRecord = false; if (isset($configArray['Hoopla']['individualMarcPath'])) { if (file_exists($individualName)) { //Load file contents independently to avoid too many files open issue $rawMarc = file_get_contents($individualName); $marc = new File_MARC($rawMarc, File_MARC::SOURCE_STRING); if (!($marcRecord = $marc->next())) { PEAR_Singleton::raiseError(new PEAR_Error('Could not load marc record for hoopla record ' . $id)); } } } //Make sure not to use to much memory if (count(MarcLoader::$loadedMarcRecords) > 50) { array_shift(MarcLoader::$loadedMarcRecords); } MarcLoader::$loadedMarcRecords[$id] = $marcRecord; return $marcRecord; }
<?php require 'File/MARC.php'; // Read MARC records from a stream (a file, in this case) $marc_source = new File_MARC('example.mrc'); // Retrieve the first MARC record from the source $marc_record = $marc_source->next(); // Retrieve a personal name field from the record $names = $marc_record->getFields('100'); foreach ($names as $name_field) { // Now print the $a subfield switch ($name_field->getIndicator(1)) { case 0: print "Forename: "; break; case 1: print "Surname: "; break; case 2: print "Family name: "; break; } $name = $name_field->getSubfields('a'); if (count($name) == 1) { print $name[0]->getData() . "\n"; } else { print "Error -- \$a subfield appears more than once in this field!"; } } print "\nPrint all series statement fields (4xx):\n"; // Retrieve all series statement fields
yaz_ccl_conf($conn, $ccl_fields); // Define our query for a most excellent text $ccl_query = "ti='derby' and au='scott'"; // Parse the CCL query into yaz's native format $result = yaz_ccl_parse($conn, $ccl_query, $ccl_results); if (!$result) { echo "Error: " . $ccl_results['errorstring']; exit; } // Submit the query $rpn = $ccl_results['rpn']; yaz_search($conn, 'rpn', $rpn); yaz_wait(); // Any errors trying to retrieve this record? $error = yaz_error($conn); if ($error) { print "Error: {$error}\n"; exit; } // Retrieve the first MARC record as raw MARC $rec = yaz_record($conn, 1, "raw"); if (!$rec) { print "Error: Retrieved no results.\n"; exit; } // Parse the retrieved MARC record $marc_file = new File_MARC($rec, File_MARC::SOURCE_STRING); while ($marc_record = $marc_file->next()) { print $marc_record; print "\n"; }
/** * Start function * * Set all variables to defaults to create new File_MARC_Record object * * @param File_MARC $marc MARC record from File_MARC or File_MARCXML * * @return true */ function __construct($marc = null) { $this->fields = new File_MARC_List(); $this->setLeader(str_repeat(' ', 24)); if (!$marc) { $marc = new File_MARC(null, File_MARC::SOURCE_STRING); // oh the hack } $this->marc = $marc; $this->marcxml = $marc->getXMLWriter(); }
/** * Get access to the raw File_MARC object. * * @return \File_MARCBASE */ public function getMarcRecord() { if (null === $this->lazyMarcRecord) { $marc = trim($this->fields['fullrecord']); // check if we are dealing with MARCXML if (substr($marc, 0, 1) == '<') { $marc = new \File_MARCXML($marc, \File_MARCXML::SOURCE_STRING); } else { // When indexing over HTTP, SolrMarc may use entities instead of // certain control characters; we should normalize these: $marc = str_replace(['#29;', '#30;', '#31;'], ["", "", ""], $marc); $marc = new \File_MARC($marc, \File_MARC::SOURCE_STRING); } $this->lazyMarcRecord = $marc->next(); if (!$this->lazyMarcRecord) { throw new \File_MARC_Exception('Cannot Process MARC Record'); } } return $this->lazyMarcRecord; }
/** * Get Statuses from 999 Holdings Marc Tag for Vufind versions older than 1.4 * * Protected support method for parsing status info from the marc record * * @param array $ids The array of record ids to retrieve the item info for * @param array $marcMap The associative array of marc fields to map * * @return array An associative array of items with mapped marc fields * @access protected */ protected function get999HoldingsPre14($ids, $marcMap) { // Setup Search Engine Connection $db = ConnectionManager::connectToIndex(); $results = array(); foreach ($ids as $id) { // Retrieve the record from the index if (!($record = $db->getRecord($id))) { PEAR::raiseError(new PEAR_Error('Record Does Not Exist')); } // Also process the MARC record: $marc = trim($record['fullrecord']); // check if we are dealing with MARCXML $xmlHead = '<?xml version'; if (strcasecmp(substr($marc, 0, strlen($xmlHead)), $xmlHead) === 0) { $marc = new File_MARCXML($marc, File_MARCXML::SOURCE_STRING); } else { $marc = preg_replace('/#31;/', "", $marc); $marc = preg_replace('/#30;/', "", $marc); $marc = new File_MARC($marc, File_MARC::SOURCE_STRING); } $marcRecord = $marc->next(); if (!$marcRecord) { PEAR::raiseError(new PEAR_Error('Cannot Process MARC Record')); } $fields = $marcRecord->getFields($this->config['999Holdings']['entry_number']); if (!$fields) { continue; } foreach ($fields as $field) { $current = array(); $subfields = $field->getSubfields(); if ($subfields) { $current['id'] = $id; foreach ($subfields as $subfield) { if (!is_numeric($subfield->getCode())) { if (in_array('marc|' . $subfield->getCode(), $marcMap)) { $key = array_search('marc|' . $subfield->getCode(), $marcMap); $current[$key] = $subfield->getData(); } else { $current[$subfield->getCode()] = $subfield->getData(); } } } if (!empty($current)) { $results[] = $current; } } } } return $results; }