/**
  * Traitement des données
  *
  * @param string $datas les données suivant le template
  * @return array of File_MARC_Record
  */
 public function spell($datas)
 {
     $records = array();
     foreach ($datas as $data) {
         $record = new File_MARC_Record();
         foreach ($this->template as $fieldname => $fieldinfos) {
             if (isset($data[$fieldname])) {
                 $record->appendField($this->_field($fieldinfos, $data[$fieldname]));
             }
         }
         $records[] = $record;
     }
     return $records;
 }
Exemplo n.º 2
0
 /**
  * Get holdings structure for holdings
  *
  * @param    Integer $fieldName
  * @return    Array[]
  */
 protected function getStructuredHoldingsStructure($fieldName, $data = array())
 {
     //$data    = array();
     $fields = $this->holdings ? $this->holdings->getFields($fieldName) : false;
     $mapping = array('B' => 'network', 'F' => 'institution_chb');
     if (is_array($fields)) {
         foreach ($fields as $index => $field) {
             $item = $this->extractFieldData($field, $mapping);
             $networkCode = $item['network'];
             $institution = $item['institution_chb'];
             $groupCode = $this->getGroup($institution);
             // Prevent display of untranslated and ungrouped institutions
             $institutionLabel = $this->translator->translate($institution, 'institution');
             if ($groupCode == 'unknown' || $institutionLabel === $institution) {
                 if ($groupCode === 'unknown') {
                     $this->swissbibLogger->logUngroupedInstitution($institution);
                 }
                 continue;
             }
             // Make sure group is present
             if (!isset($data[$groupCode])) {
                 $data[$groupCode] = array('label' => $groupCode, 'networkCode' => $networkCode, 'institutions' => array());
             }
             // Make sure institution is present
             if (!isset($data[$groupCode]['institutions'][$institution])) {
                 $data[$groupCode]['institutions'][$institution] = array('label' => $institution, 'bibinfolink' => $this->getBibInfoLink($institution));
             }
         }
     }
     return $data;
 }
Exemplo n.º 3
0
 public function processExport($pa_data, $pa_options = array())
 {
     $pb_single_record = isset($pa_options['singleRecord']) && $pa_options['singleRecord'];
     //caDebug($pa_data,"Data to build MARC from");
     //caDebug($pa_options,"Export format options");
     $o_record = new File_MARC_Record();
     foreach ($pa_data as $va_item) {
         $vs_element = $va_item['element'];
         if (stripos($vs_element, "/") !== false) {
             // data field
             $va_split = explode("/", $vs_element);
             $vs_tag = $va_split[0];
             $vs_ind1 = substr($va_split[1], 0, 1);
             $vs_ind2 = substr($va_split[1], 1, 1);
             $va_subfields = array();
             // process sub-fields
             if (is_array($va_item['children'])) {
                 foreach ($va_item['children'] as $va_child) {
                     $va_subfields[] = new File_MARC_Subfield($va_child['element'], $va_child['text']);
                 }
             }
             $o_field = new File_MARC_Data_field($vs_tag, $va_subfields, $vs_ind1, $vs_ind2);
         } else {
             // simple control field
             $o_field = new File_MARC_Control_Field($vs_element, $va_item['text']);
         }
         $o_record->appendField($o_field);
     }
     if (isset($pa_options['settings']['MARC_outputFormat'])) {
         switch ($pa_options['settings']['MARC_outputFormat']) {
             case 'raw':
                 return $o_record->toRaw();
             case 'xml':
                 $vs_string = $o_record->toXML();
                 $vo_dom = new DOMDocument('1.0', 'utf-8');
                 $vo_dom->preserveWhiteSpace = false;
                 $vo_dom->loadXML($vs_string);
                 $vo_dom->formatOutput = true;
                 // when dealing with a record set export, we don't want <?xml tags in front so
                 // that we can simply dump each record in a file and have valid XML as result
                 return $pb_single_record ? $vo_dom->saveXML() : $vo_dom->saveXML($vo_dom->firstChild);
             case 'readable':
             default:
                 return $o_record->__toString();
         }
     } else {
         return $o_record->__toString();
     }
 }
Exemplo n.º 4
0
 function getNotes()
 {
     $additionalNotesFields = array('520' => 'Description', '500' => 'General Note', '504' => 'Bibliography', '511' => 'Participants/Performers', '518' => 'Date/Time and Place of Event', '310' => 'Current Publication Frequency', '321' => 'Former Publication Frequency', '351' => 'Organization & arrangement of materials', '362' => 'Dates of publication and/or sequential designation', '501' => '"With"', '502' => 'Dissertation', '506' => 'Restrictions on Access', '507' => 'Scale for Graphic Material', '508' => 'Creation/Production Credits', '510' => 'Citation/References', '513' => 'Type of Report an Period Covered', '515' => 'Numbering Peculiarities', '521' => 'Target Audience', '522' => 'Geographic Coverage', '525' => 'Supplement', '526' => 'Study Program Information', '530' => 'Additional Physical Form', '533' => 'Reproduction', '534' => 'Original Version', '536' => 'Funding Information', '538' => 'System Details', '545' => 'Biographical or Historical Data', '546' => 'Language', '547' => 'Former Title Complexity', '550' => 'Issuing Body', '555' => 'Cumulative Index/Finding Aids', '556' => 'Information About Documentation', '561' => 'Ownership and Custodial History', '563' => 'Binding Information', '580' => 'Linking Entry Complexity', '581' => 'Publications About Described Materials', '586' => 'Awards', '590' => 'Local note', '599' => 'Differentiable Local note');
     $notes = array();
     foreach ($additionalNotesFields as $tag => $label) {
         /** @var File_MARC_Data_Field[] $marcFields */
         $marcFields = $this->marcRecord->getFields($tag);
         foreach ($marcFields as $marcField) {
             $noteText = array();
             foreach ($marcField->getSubFields() as $subfield) {
                 /** @var File_MARC_Subfield $subfield */
                 $noteText[] = $subfield->getData();
             }
             $note = implode(',', $noteText);
             if (strlen($note) > 0) {
                 $notes[] = array('label' => $label, 'note' => $note);
             }
         }
     }
     return $notes;
 }
 /**
  * Return an array of all values extracted from the specified field/subfield
  * combination.  If multiple subfields are specified and $concat is true, they
  * will be concatenated together in the order listed -- each entry in the array
  * will correspond with a single MARC field.  If $concat is false, the return
  * array will contain separate entries for separate subfields.
  *
  * @param   string      $field          The MARC field number to read
  * @param   array       $subFields      The MARC subfield codes to read
  * @param   bool        $concatenate         Should we concatenate subfields?
  * @access  private
  * @return  array
  */
 private function getFieldArray($field, $subFields = null, $concatenate = true)
 {
     if (!$this->marcRecord) {
         return array();
     }
     // Default to subField a if nothing is specified.
     if (!is_array($subFields)) {
         $subFields = array('a');
     }
     // Initialize return array
     $matches = array();
     // Try to look up the specified field, return empty array if it doesn't exist.
     $fields = $this->marcRecord->getFields($field);
     if (!is_array($fields)) {
         return $matches;
     }
     // Extract all the requested subfields, if applicable.
     foreach ($fields as $currentField) {
         $next = $this->getSubfieldArray($currentField, $subFields, $concatenate);
         $matches = array_merge($matches, $next);
     }
     return $matches;
 }
Exemplo n.º 6
0
 /**
  * Decode a given raw MARC record
  *
  * Port of Andy Lesters MARC::File::USMARC->decode() Perl function into PHP.
  *
  * @param string $text Raw MARC record
  *
  * @return File_MARC_Record Decoded File_MARC_Record object
  */
 private function _decode($text)
 {
     $marc = new File_MARC_Record($this);
     $matches = array();
     if (!preg_match("/^(\\d{5})/", $text, $matches)) {
         $marc->addWarning(File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_NONNUMERIC_LENGTH], array("record_length" => substr($text, 0, 5))));
     }
     // Store record length
     $record_length = $matches[1];
     if ($record_length != strlen($text)) {
         $marc->addWarning(File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INCORRECT_LENGTH], array("record_length" => $record_length, "actual" => strlen($text))));
         // give up and set the record length to the actual byte length
         $record_length = strlen($text);
     }
     if (substr($text, -1, 1) != File_MARC::END_OF_RECORD) {
         throw new File_MARC_Exception(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_TERMINATOR], File_MARC_Exception::ERROR_INVALID_TERMINATOR);
     }
     // Store leader
     $marc->setLeader(substr($text, 0, File_MARC::LEADER_LEN));
     // bytes 12 - 16 of leader give offset to the body of the record
     $data_start = 0 + substr($text, 12, 5);
     // immediately after the leader comes the directory (no separator)
     $dir = substr($text, File_MARC::LEADER_LEN, $data_start - File_MARC::LEADER_LEN - 1);
     // -1 to allow for \x1e at end of directory
     // character after the directory must be \x1e
     if (substr($text, $data_start - 1, 1) != File_MARC::END_OF_FIELD) {
         $marc->addWarning(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_NO_DIRECTORY]);
     }
     // All directory entries 12 bytes long, so length % 12 must be 0
     if (strlen($dir) % File_MARC::DIRECTORY_ENTRY_LEN != 0) {
         $marc->addWarning(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_DIRECTORY_LENGTH]);
     }
     // go through all the fields
     $nfields = strlen($dir) / File_MARC::DIRECTORY_ENTRY_LEN;
     for ($n = 0; $n < $nfields; $n++) {
         // As pack returns to key 1, leave place 0 in list empty
         list(, $tag) = unpack("A3", substr($dir, $n * File_MARC::DIRECTORY_ENTRY_LEN, File_MARC::DIRECTORY_ENTRY_LEN));
         list(, $len) = unpack("A3/A4", substr($dir, $n * File_MARC::DIRECTORY_ENTRY_LEN, File_MARC::DIRECTORY_ENTRY_LEN));
         list(, $offset) = unpack("A3/A4/A5", substr($dir, $n * File_MARC::DIRECTORY_ENTRY_LEN, File_MARC::DIRECTORY_ENTRY_LEN));
         // Check directory validity
         if (!preg_match("/^[0-9A-Za-z]{3}\$/", $tag)) {
             $marc->addWarning(File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_DIRECTORY_TAG], array("tag" => $tag)));
         }
         if (!preg_match("/^\\d{4}\$/", $len)) {
             $marc->addWarning(File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_DIRECTORY_TAG_LENGTH], array("tag" => $tag, "len" => $len)));
         }
         if (!preg_match("/^\\d{5}\$/", $offset)) {
             $marc->addWarning(File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_DIRECTORY_OFFSET], array("tag" => $tag, "offset" => $offset)));
         }
         if ($offset + $len > $record_length) {
             $marc->addWarning(File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_DIRECTORY], array("tag" => $tag)));
         }
         $tag_data = substr($text, $data_start + $offset, $len);
         if (substr($tag_data, -1, 1) == File_MARC::END_OF_FIELD) {
             /* get rid of the end-of-tag character */
             $tag_data = substr($tag_data, 0, -1);
             $len--;
         } else {
             $marc->addWarning(File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_FIELD_EOF], array("tag" => $tag)));
         }
         if (preg_match("/^\\d+\$/", $tag) and $tag < 10) {
             $marc->appendField(new File_MARC_Control_Field($tag, $tag_data));
         } else {
             $subfields = explode(File_MARC::SUBFIELD_INDICATOR, $tag_data);
             $indicators = array_shift($subfields);
             if (strlen($indicators) != 2) {
                 $errorMessage = File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_INDICATORS], array("tag" => $tag, "indicators" => $indicators));
                 $marc->addWarning($errorMessage);
                 // Do the best with the indicators we've got
                 if (strlen($indicators) == 1) {
                     $ind1 = $indicators;
                     $ind2 = " ";
                 } else {
                     list($ind1, $ind2) = array(" ", " ");
                 }
             } else {
                 $ind1 = substr($indicators, 0, 1);
                 $ind2 = substr($indicators, 1, 1);
             }
             // Split the subfield data into subfield name and data pairs
             $subfield_data = array();
             foreach ($subfields as $subfield) {
                 if (strlen($subfield) > 0) {
                     $subfield_data[] = new File_MARC_Subfield(substr($subfield, 0, 1), substr($subfield, 1));
                 } else {
                     $errorMessage = File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_EMPTY_SUBFIELD], array("tag" => $tag));
                     $marc->addWarning($errorMessage);
                 }
             }
             if (!isset($subfield_data)) {
                 $errorMessage = File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_EMPTY_SUBFIELD], array("tag" => $tag));
                 $marc->addWarning($errorMessage);
             }
             // If the data is invalid, let's just ignore the one field
             try {
                 $new_field = new File_MARC_Data_Field($tag, $subfield_data, $ind1, $ind2);
                 $marc->appendField($new_field);
             } catch (Exception $e) {
                 $marc->addWarning($e->getMessage());
             }
         }
     }
     return $marc;
 }
Exemplo n.º 7
0
 /**
  * Extract an exact term from a MARC record.
  *
  * @param \File_MARC_Record $record MARC record
  *
  * @return string
  */
 protected function getExactTerm($record)
 {
     // Get exact terms:
     $actual = $record->getField('150');
     if (!$actual || !($main = $actual->getSubfield('a'))) {
         return false;
     }
     // Some versions of File_MARCXML seem to have trouble returning
     // strings properly (giving back XML objects instead); let's
     // cast to string to be sure we get what we expect!
     $main = (string) $main->getData();
     // Add subdivisions:
     $subdivisions = $actual->getSubfields('x');
     if ($subdivisions) {
         foreach ($subdivisions as $current) {
             $main .= ', ' . (string) $current->getData();
         }
     }
     return $main;
 }
Exemplo n.º 8
0
 /**
  * Get an XML RDF representation of the data in this record.
  *
  * @return mixed XML RDF data (empty if unsupported or error).
  */
 public function getRDFXML()
 {
     return XSLTProcessor::process('record-rdf-mods.xsl', trim($this->marcRecord->toXML()));
 }
Exemplo n.º 9
0
 /** Additional functions added by srickel1 to facitilate export of Authority records **/
 public function getAuthorityRecord($id)
 {
     // authority record query
     $sql = trim("\n\t\t\t\tSELECT\n\t\t\t\tauthority_view.id,\n\t\t\t\tauthority_view.record_creation_date_gmt,\n\t\t\t\tauthority_view.suppress_code,\n\t\t\t\tvarfield_view.marc_tag,\n\t\t\t\tvarfield_view.marc_ind1,\n\t\t\t\tvarfield_view.marc_ind2,\n\t\t\t\tTRIM(varfield_view.field_content),\n\t\t\t\tvarfield_view.varfield_type_code,\n\t\t\t\tcontrol_field.p40,\n\t\t\t\tcontrol_field.p41,\n\t\t\t\tcontrol_field.p42,\n\t\t\t\tleader_field.*\n\t\t\t\tFROM\n\t\t\t\tsierra_view.authority_view\n\t\t\t\tINNER JOIN\n\t\t\t\tsierra_view.varfield_view ON authority_view.id = varfield_view.record_id\n\t\t\t\tLEFT JOIN\n\t\t\t\tsierra_view.leader_field ON authority_view.id = leader_field.record_id\n\t\t\t\tLEFT JOIN\n\t\t\t\tsierra_view.control_field ON authority_view.id = control_field.record_id\n\t\t\t\tWHERE\n\t\t\t\tauthority_view.record_num = '{$id}' and control_field.control_num=8\n\t\t\t\tORDER BY\n\t\t\t\tmarc_tag\n\t\t\t\t");
     $results = $this->getResults($sql);
     if (count($results) == 0) {
         return null;
     }
     // let's parse a few things, shall we
     $result = $results[0];
     $internal_id = $result[0];
     // internal postgres id
     if ($result['suppress_code'] == 'n') {
         //suppressed item - let's delete it from the discovery tool data.
         $record = $this->createDeletedRecord($id);
         return $record;
     }
     //start the marc record
     $record = new File_MARC_Record();
     // leader
     // 0000's here get converted to correct lengths by File_MARC
     $leader = '00000';
     // 00-04 - Record length
     /* we have to determine what to do in the cases that we get no leader information back from the database */
     if ($this->getLeaderValue($result, 'record_status_code') == ' ') {
         $leader .= $this->getLeaderValue($result, 'p40');
     } else {
         $leader .= $this->getLeaderValue($result, 'record_status_code');
     }
     //we can get the following field from the bcode1 field
     if ($this->getLeaderValue($result, 'record_type_code') == ' ') {
         $leader .= $this->getLeaderValue($result, 'p41');
     } else {
         $leader .= $this->getLeaderValue($result, 'record_type_code');
     }
     // 06 - Type of record
     //we can get the following field from the ? field
     $leader .= $this->getLeaderValue($result, 'p42');
     $leader .= $this->getLeaderValue($result, 'control_type_code');
     // 08 - Type of control
     $leader .= $this->getLeaderValue($result, 'char_encoding_scheme_code');
     // 09 - Character coding scheme
     $leader .= '2';
     // 10 - Indicator count
     $leader .= '2';
     // 11 - Subfield code count
     $leader .= '00000';
     // 12-16 - Base address of data
     //found the next one in p43 of control_field
     $leader .= $this->getLeaderValue($result, 'encoding_level_code');
     // 17 - Encoding level
     $leader .= $this->getLeaderValue($result, 'descriptive_cat_form_code');
     // 18 - Descriptive cataloging form
     $leader .= $this->getLeaderValue($result, 'multipart_level_code');
     // 19 - Multipart resource record level
     $leader .= '4';
     // 20 - Length of the length-of-field portion
     $leader .= '5';
     // 21 - Length of the starting-character-position portion
     $leader .= '0';
     // 22 - Length of the implementation-defined portion
     $leader .= '0';
     // 23 - Undefined
     $record->setLeader($leader);
     // marc fields
     $record_id_field = new File_MARC_Data_Field('035');
     $record->appendField($record_id_field);
     $record_id_field->appendSubfield(new File_MARC_Subfield('a', $this->getFullRecordId($id, 'a')));
     foreach ($results as $result) {
         try {
             // skip missing tags and 'old' 9xx tags that mess with the above
             if ($result['marc_tag'] == null || $result['marc_tag'] == '907' || $result['marc_tag'] == '998') {
                 continue;
             }
             // control field
             if ((int) $result['marc_tag'] < 10) {
                 $control_field = new File_MARC_Control_Field($result['marc_tag'], $result['field_content']);
                 $record->appendField($control_field);
             } else {
                 $data_field = new File_MARC_Data_Field($result['marc_tag']);
                 $data_field->setIndicator(1, $result['marc_ind1']);
                 $data_field->setIndicator(2, $result['marc_ind2']);
                 $content = $result['field_content'];
                 $content_array = explode('|', $content);
                 foreach ($content_array as $subfield) {
                     $code = substr($subfield, 0, 1);
                     $data = substr($subfield, 1);
                     if ($code == '') {
                         continue;
                     }
                     $subfield = new File_MARC_Subfield($code, trim($data));
                     $data_field->appendSubfield($subfield);
                 }
                 $record->appendField($data_field);
             }
         } catch (File_MARC_Exception $e) {
             trigger_error($e->getMessage(), E_USER_WARNING);
         }
     }
     return $record;
 }
Exemplo n.º 10
0
 function buildMarc($bibData)
 {
     $mrc = new File_MARC_Record();
     $mrc->appendField(new File_MARC_Control_Field("001", $bibData["bibid"]));
     $ldr = '                       ';
     $ohOhEight = strftime("%Y%m%d", strtotime($bibData['create_dt'])) . '                           ';
     switch ($bibData["material_cd"]) {
         case 1:
             $ldr[6] = 'j';
             $ldr[7] = 'm';
             break;
         case 2:
             $ldr[6] = 'a';
             $ldr[7] = 'm';
             break;
         case 3:
             $ldr[6] = 'j';
             $ldr[7] = 'm';
             break;
         case 4:
             $ldr[6] = 'm';
             $ldr[7] = 'm';
             break;
         case 5:
             $ldr[6] = 'p';
             $ldr[7] = 'i';
             break;
         case 6:
             $ldr[6] = 'a';
             $ldr[7] = 's';
             break;
         case 7:
             $ldr[6] = 'e';
             $ldr[7] = 'm';
             break;
         case 8:
             $ldr[6] = 'g';
             $ldr[7] = 'm';
             break;
         default:
             $ldr[6] = 'a';
             $ldr[7] = 'm';
             break;
     }
     $subfields = array(new File_MARC_Subfield("a", $bibData["title"]));
     if ($bibData["title_remainder"]) {
         array_push($subfields, new File_MARC_Subfield("b", $bibData["title_remainder"]));
     }
     if ($bibData["responsibility_stmt"]) {
         array_push($subfields, new File_MARC_Subfield("c", $bibData["responsibility_stmt"]));
     }
     $title = new File_MARC_Data_Field("245", $subfields, "0", "0");
     $mrc->appendField($title);
     $author = new File_MARC_Data_Field("100", array(new File_MARC_Subfield("a", $bibData["author"])), "1", NULL);
     $mrc->appendField($author);
     $subjects = array($bibData["topic1"], $bibData["topic2"], $bibData["topic3"], $bibData["topic4"], $bibData["topic5"]);
     for ($i = 0; $i < count($subjects); $i++) {
         $sub = new File_MARC_Data_field("650", array(new File_MARC_Subfield("a", $subjects[$i])), NULL, "4");
         $mrc->appendField($sub);
     }
     $query = "SELECT * from biblio_field WHERE bibid = " . $bibData['bibid'] . " GROUP BY fieldid";
     $result = mysql_query($query);
     while ($row = mysql_fetch_assoc($result)) {
         if (!isset($fieldId)) {
             $fieldId = $row["fieldid"];
             if ($row["ind1_cd"] != "N") {
                 $ind1 = $row["ind1_cd"];
             } else {
                 $ind1 = NULL;
             }
             if ($row["ind2_cd"] != "N") {
                 $ind2 = $row["ind2_cd"];
             } else {
                 $ind2 = NULL;
             }
             $field = new File_MARC_Data_Field(str_pad($row["tag"], 3, "0", STR_PAD_LEFT), $ind1, $ind2);
         }
         if ($fieldId == $row["fieldid"]) {
             $field->appendSubfield(new File_MARC_Subfield($row["subfield_cd"], $row["field_data"]));
         } else {
             $mrc->appendField($field);
             $fieldId = $row["fieldid"];
             if ($row["ind1_cd"] != "N") {
                 $ind1 = $row["ind1_cd"];
             } else {
                 $ind1 = NULL;
             }
             if ($row["ind2_cd"] != "N") {
                 $ind2 = $row["ind2_cd"];
             } else {
                 $ind2 = NULL;
             }
             $field = new File_MARC_Data_Field(str_pad($row["tag"], 3, "0", STR_PAD_LEFT), $ind1, $ind2);
             $field->appendSubfield(new File_MARC_Subfield($row["subfield_cd"], $row["field_data"]));
         }
     }
     $mrc->setLeader($ldr);
     $mrc->appendField(new File_MARC_Control_Field("008", $ohOhEight));
     return $mrc;
 }
Exemplo n.º 11
0
 /**
  * Create a deleted record
  * 
  * This is essentially a placeholder record so we have something that represents a
  * record completely expunged from the system
  * 
  * @param int $id
  */
 public function createDeletedRecord($id)
 {
     $record = new File_MARC_Record();
     $control_field = new File_MARC_Control_Field('001', "deleted:{$id}");
     $record->appendField($control_field);
     // bib id field
     $bib_field = new File_MARC_Data_Field('907');
     $record->appendField($bib_field);
     $bib_field->appendSubfield(new File_MARC_Subfield('a', $this->getFullRecordId($id)));
     // mark as deleted
     $bib_field = new File_MARC_Data_Field('998');
     $record->appendField($bib_field);
     $bib_field->appendSubfield(new File_MARC_Subfield('f', 'd'));
     return $record;
 }
Exemplo n.º 12
0
 /**
  * @param File_MARC_Record $marcRecord
  * @return bool
  */
 function isRecordHoldable($marcRecord)
 {
     $pType = $this->getPType();
     /** @var File_MARC_Data_Field[] $items */
     $items = $marcRecord->getFields('989');
     $holdable = false;
     $itemNumber = 0;
     foreach ($items as $item) {
         $itemNumber++;
         $subfield_j = $item->getSubfield('j');
         if (is_object($subfield_j) && !$subfield_j->isEmpty()) {
             $iType = $subfield_j->getData();
         } else {
             $iType = '0';
         }
         $subfield_d = $item->getSubfield('d');
         if (is_object($subfield_d) && !$subfield_d->isEmpty()) {
             $locationCode = $subfield_d->getData();
         } else {
             $subfield_p = $item->getSubfield('p');
             if (is_object($subfield_p) && !$subfield_p->isEmpty()) {
                 $locationCode = $subfield_p->getData();
             } else {
                 $locationCode = '?????';
             }
         }
         //$logger->log("$itemNumber) iType = $iType, locationCode = $locationCode", PEAR_LOG_DEBUG);
         //Check the determiner table to see if this matches
         $holdable = $this->isItemHoldableToPatron($locationCode, $iType, $pType);
         if ($holdable) {
             break;
         }
     }
     return $holdable;
 }
Exemplo n.º 13
0
 /**
  * Decode a MARC holding record.
  *
  * @param File_MARC_Record $record Holding record to decode..
  *
  * @return array Has two elements: the first is the list of
  *               locations found in the record, the second are the
  *               decoded holdings per se.
  *
  * @todo Check if is OK to print multiple times textual holdings
  *       that had more than one $8.
  */
 protected function decodeMarcHoldingRecord($record)
 {
     $locations = [];
     $holdings = [];
     // First pass:
     //  - process locations
     //
     //  - collect textual holdings indexed by linking number to be
     //    able to easily check later what fields from enumeration
     //    and chronology they override.
     $textuals = [];
     foreach ($record->getFields('852|866', true) as $field) {
         switch ($field->getTag()) {
             case '852':
                 $locations[] = $this->processMarcHoldingLocation($field);
                 break;
             case '866':
                 $linking_fields = $field->getSubfields('8');
                 if ($linking_fields === false) {
                     // Skip textual holdings fields with no linking
                     continue 2;
                 }
                 foreach ($linking_fields as $linking_field) {
                     $linking = explode('.', $linking_field->getData());
                     // Only the linking part is used in textual
                     // holdings...
                     $linking = $linking[0];
                     // and it should be an int.
                     $textuals[(int) $linking] =& $field;
                 }
                 break;
         }
     }
     // Second pass: enumeration and chronology, biblio
     // Digits to use to build a combined index with linking number
     // and sequence number.
     // PS: Does this make this implementation year-3K safe?
     $link_digits = floor(strlen((string) PHP_INT_MAX) / 2);
     foreach (array_key_exists(0, $textuals) ? [] : $record->getFields('863') as $field) {
         $linking_field = $field->getSubfield('8');
         if ($linking_field === false) {
             // Skip record if there is no linking number
             continue;
         }
         $linking = explode('.', $linking_field->getData());
         if (1 < count($linking)) {
             $sequence = explode('\\', $linking[1]);
             // Lets ignore the link type, as we only care for \x
             $sequence = $sequence[0];
         } else {
             $sequence = 0;
         }
         $linking = $linking[0];
         if (array_key_exists((int) $linking, $textuals)) {
             // Skip coded holdings overridden by textual
             // holdings
             continue;
         }
         $decoded_holding = '';
         foreach ($field->getSubfields() as $subfield) {
             if (strpos('68x', $subfield->getCode()) !== false) {
                 continue;
             }
             $decoded_holding .= ' ' . $subfield->getData();
         }
         $ndx = (int) ($linking . sprintf("%0{$link_digits}u", $sequence));
         $holdings[$ndx] = trim($decoded_holding);
     }
     foreach ($textuals as $linking => $field) {
         $textual_holding = $field->getSubfield('a')->getData();
         foreach ($field->getSubfields('z') as $note) {
             $textual_holding .= ' ' . $note->getData();
         }
         $ndx = (int) ($linking . sprintf("%0{$link_digits}u", 0));
         $holdings[$ndx] = trim($textual_holding);
     }
     return [$locations, $holdings];
 }
Exemplo n.º 14
0
 /**
  * Decode a given MARCXML record
  *
  * @param string $text MARCXML record element
  *
  * @return File_MARC_Record Decoded File_MARC_Record object
  */
 private function _decode($text)
 {
     $marc = new File_MARC_Record($this);
     // Store leader
     $marc->setLeader($text->leader);
     // go through all the control fields
     foreach ($text->controlfield as $controlfield) {
         $controlfieldattributes = $controlfield->attributes();
         $marc->appendField(new File_MARC_Control_Field((string) $controlfieldattributes['tag'], $controlfield));
     }
     // go through all the data fields
     foreach ($text->datafield as $datafield) {
         $datafieldattributes = $datafield->attributes();
         $subfield_data = array();
         foreach ($datafield->subfield as $subfield) {
             $subfieldattributes = $subfield->attributes();
             $subfield_data[] = new File_MARC_Subfield((string) $subfieldattributes['code'], $subfield);
         }
         // If the data is invalid, let's just ignore the one field
         try {
             $new_field = new File_MARC_Data_Field((string) $datafieldattributes['tag'], $subfield_data, $datafieldattributes['ind1'], $datafieldattributes['ind2']);
             $marc->appendField($new_field);
         } catch (Exception $e) {
             $marc->addWarning($e->getMessage());
         }
     }
     return $marc;
 }
    if (array_key_exists($patronData['030_BARCODE'][0], $allPatrons)) {
        //already have this patron, must be a secondary address
        echo "Warning duplicate employee id exists {$patronData['030_BARCODE'][0]}\n";
    } else {
        $allPatrons[] = $patronData;
    }
}
//End reading raw data export
fclose($exportFhnd);
echo "Loaded " . count($allPatrons) . " from data extract, {$numInvalidBarcodes} Barcodes were removed because they were invalid.\n";
$patronsWritten = 0;
$finalFile = $libraryAddsFileName . ".mrc";
$finalFileHnd = fopen($finalFile, 'wb');
$numBlocked = 0;
foreach ($allPatrons as $patronData) {
    $record = new File_MARC_Record();
    $leader = $record->getLeader();
    $leader[5] = 'n';
    $leader[6] = 'a';
    $leader[7] = 'm';
    $record->setLeader($leader);
    //030 = barcode
    foreach ($patronData['030_BARCODE'] as $patronBarcode) {
        $record->appendField(new File_MARC_Data_Field('030', array(new File_MARC_Subfield('a', $patronBarcode))));
    }
    //080 = expiration date
    $record->appendField(new File_MARC_Data_Field('080', array(new File_MARC_Subfield('a', $patronData['080_EXP_DATE']))));
    //081 = age group
    $record->appendField(new File_MARC_Data_Field('081', array(new File_MARC_Subfield('a', $patronData['081_AGE_GRP']))));
    //082 = pcode2 REG LIB : should be 3 MNPS for all educators initially enrolled via MNPS data
    $record->appendField(new File_MARC_Data_Field('082', array(new File_MARC_Subfield('a', $patronData['082_REG_LIB']))));
    $patronData['600_PIN'] = date("md", strtotime($patronData['birth_date']));
    if (array_key_exists($patronData['030_BARCODE'][0], $allPatrons)) {
        //already have this patron, must be a secondary address
        echo "Warning duplicate student number exists {$patronData['030_BARCODE'][0]}\n";
    } else {
        $allPatrons[$patronData['030_BARCODE'][0]] = $patronData;
    }
}
//End reading raw data export
echo "Loaded " . count($allPatrons) . " from data extract, {$numInvalidBarcodes} Barcodes were removed because they were invalid.\n";
$patronsWritten = 0;
$finalFile = $libraryAddsFileName . ".mrc";
$finalFileHnd = fopen($finalFile, 'wb');
$numBlocked = 0;
foreach ($allPatrons as $patronData) {
    $record = new File_MARC_Record();
    $leader = $record->getLeader();
    $leader[5] = 'n';
    $leader[6] = 'a';
    $leader[7] = 'm';
    $record->setLeader($leader);
    //030 = barcode, repeatable
    foreach ($patronData['030_BARCODE'] as $pBarcode) {
        $record->appendField(new File_MARC_Data_Field('030', array(new File_MARC_Subfield('a', $pBarcode))));
    }
    //080 = expiration date
    $record->appendField(new File_MARC_Data_Field('080', array(new File_MARC_Subfield('a', $patronData['080_EXP_DATE']))));
    //081 = age group
    $record->appendField(new File_MARC_Data_Field('081', array(new File_MARC_Subfield('a', $patronData['081_AGE_GRP']))));
    //082 = pcode2 REG LIB : should be 3 MNPS for all patrons initially enrolled via MNPS data
    $record->appendField(new File_MARC_Data_Field('082', array(new File_MARC_Subfield('a', $patronData['082_REG_LIB']))));
Exemplo n.º 17
0
 /**
  * @param File_MARC_Record $marcRecord
  * @return bool
  */
 function isRecordHoldable($marcRecord)
 {
     global $configArray;
     $pType = $this->getPType();
     /** @var File_MARC_Data_Field[] $items */
     $marcItemField = isset($configArray['Reindex']['itemTag']) ? $configArray['Reindex']['itemTag'] : '989';
     $iTypeSubfield = isset($configArray['Reindex']['iTypeSubfield']) ? $configArray['Reindex']['iTypeSubfield'] : 'j';
     $locationSubfield = isset($configArray['Reindex']['locationSubfield']) ? $configArray['Reindex']['locationSubfield'] : 'j';
     $items = $marcRecord->getFields($marcItemField);
     $holdable = false;
     $itemNumber = 0;
     foreach ($items as $item) {
         $itemNumber++;
         $subfield_j = $item->getSubfield($iTypeSubfield);
         if (is_object($subfield_j) && !$subfield_j->isEmpty()) {
             $iType = $subfield_j->getData();
         } else {
             $iType = '0';
         }
         $subfield_d = $item->getSubfield($locationSubfield);
         if (is_object($subfield_d) && !$subfield_d->isEmpty()) {
             $locationCode = $subfield_d->getData();
         } else {
             $locationCode = '?????';
         }
         //$logger->log("$itemNumber) iType = $iType, locationCode = $locationCode", PEAR_LOG_DEBUG);
         //Check the determiner table to see if this matches
         $holdable = $this->isItemHoldableToPatron($locationCode, $iType, $pType);
         if ($holdable) {
             break;
         }
     }
     return $holdable;
 }
Exemplo n.º 18
0
 /**
  * Check all fields against the standard rules encoded in the class.
  *
  * @param File_MARC_Record $marc Record to check
  *
  * @return void
  */
 protected function standardFieldChecks($marc)
 {
     $fieldsSeen = array();
     foreach ($marc->getFields() as $current) {
         $tagNo = $current->getTag();
         // if 880 field, inherit rules from tagno in subfield _6
         if ($tagNo == 880) {
             if ($sub6 = $current->getSubfield(6)) {
                 $tagNo = substr($sub6->getData(), 0, 3);
                 $tagrules = isset($this->rules[$tagNo]) ? $this->rules[$tagNo] : null;
                 // 880 is repeatable, but its linked field may not be
                 if (isset($tagrules['repeatable']) && $tagrules['repeatable'] == 'NR' && isset($fieldsSeen['880.' . $tagNo])) {
                     $this->warn("{$tagNo}: Field is not repeatable.");
                 }
                 $fieldsSeen['880.' . $tagNo] = isset($fieldsSeen['880.' . $tagNo]) ? $fieldsSeen['880.' . $tagNo] + 1 : 1;
             } else {
                 $this->warn("880: No subfield 6.");
                 $tagRules = null;
             }
         } else {
             // Default case -- not an 880 field:
             $tagrules = isset($this->rules[$tagNo]) ? $this->rules[$tagNo] : null;
             if (isset($tagrules['repeatable']) && $tagrules['repeatable'] == 'NR' && isset($fieldsSeen[$tagNo])) {
                 $this->warn("{$tagNo}: Field is not repeatable.");
             }
             $fieldsSeen[$tagNo] = isset($fieldsSeen[$tagNo]) ? $fieldsSeen[$tagNo] + 1 : 1;
         }
         // Treat data fields differently from control fields:
         if (intval(ltrim($tagNo, '0')) >= 10) {
             if (!empty($tagrules)) {
                 $this->checkIndicators($tagNo, $current, $tagrules);
                 $this->checkSubfields($tagNo, $current, $tagrules);
             }
         } else {
             // Control field:
             if (strstr($current->toRaw(), chr(hexdec('1F')))) {
                 $this->warn("{$tagNo}: Subfields are not allowed in fields lower than 010");
             }
         }
         // Check to see if a checkxxx() function exists, and call it on the
         // field if it does
         $method = 'check' . $tagNo;
         if (method_exists($this, $method)) {
             $this->{$method}($current);
         }
     }
 }
Exemplo n.º 19
0
 /**
  *
  * Function to export biblio data to MARC records
  *
  **/
 public function marc_export($input_id = 0, $offset = 0, $total = 10000, $format = 'RAW')
 {
     global $dbs;
     $marc_records = '';
     $records = array();
     if ($total > 1000000) {
         $total = 10000;
     }
     if ($total < 1) {
         $total = 1000000;
     }
     if ($input_id == 'BATCH') {
         $records = $this->getRecords(null, $offset, $total);
     } else {
         $records = $this->getRecords(sprintf('biblio_id IN (%s)', $input_id), $offset, $total);
     }
     foreach ($records as $_recs) {
         $marc = new File_MARC_Record();
         if (isset($_recs['title']) && $_recs['title'] != "") {
             $main_title = preg_replace('@:.+$@i', '', $_recs['title']);
             $rest_title = preg_replace('@^.+:@i', '', $_recs['title']);
             if ($main_title != $rest_title) {
                 $tag['245'][] = new File_MARC_Subfield('a', preg_replace('/:.+$/i', '', $_recs['title']));
                 $tag['245'][] = new File_MARC_Subfield('b', ' : ' . preg_replace('/^.+:/i', '', $_recs['title']));
             } else {
                 $tag['245'][] = new File_MARC_Subfield('a', $_recs['title']);
             }
             if (isset($_recs['sor']) && $_recs['sor'] != "") {
                 $tag['245'][] = new File_MARC_Subfield('c', $_recs['sor']);
             }
             if (isset($_recs['gmd']) && $_recs['gmd'] != "") {
                 $tag['245'][] = new File_MARC_Subfield('h', $_recs['gmd']);
             }
             $marc->appendField(new File_MARC_Data_Field('245', $tag['245'], 0), null, null);
             // $tag['245'] = $sd.'a'.$_recs['title'].$sd.'h'.$_recs['gmd'];
         }
         if (isset($_recs['isbn_issn']) && $_recs['isbn_issn'] != "") {
             $marc->appendField(new File_MARC_Data_Field('020', array(new File_MARC_Subfield('a', $_recs['isbn_issn'])), null, null));
             // $tag['020'] = $sd.'a'.$_recs['isbn_issn'];
         }
         if (isset($_recs['edition']) && $_recs['edition'] != "") {
             $marc->appendField(new File_MARC_Data_Field('250', array(new File_MARC_Subfield('a', $_recs['edition'])), null, null));
             //$tag['250'] = $sd.'a'.$_recs['edition'];
         }
         // $tag[] = $_recs['author'];
         // get author name and roles first
         $_aut_q = $dbs->query('SELECT a.author_name,a.author_year,a.authority_type,i.level FROM biblio_author as i LEFT JOIN `mst_author` as a on a.author_id=i.author_id WHERE i.biblio_id=' . $_recs['biblio_id']);
         while ($_rs_aut = $_aut_q->fetch_assoc()) {
             if ($_rs_aut['level'] == 1) {
                 if ($_rs_aut['authority_type'] == 'p') {
                     $marc->appendField(new File_MARC_Data_Field('100', array(new File_MARC_Subfield('a', $_rs_aut['author_name'])), null, null));
                     //$tag['100'] = $sd.'a'.$_rs_aut['author_name'];
                 } elseif ($_rs_aut['authority_type'] == 'o') {
                     $marc->appendField(new File_MARC_Data_Field('110', array(new File_MARC_Subfield('a', $_rs_aut['author_name'])), null, null));
                     //$tag['110'] = $sd.'a'.$_rs_aut['author_name'];
                 } elseif ($_rs_aut['authority_type'] == 'c') {
                     $marc->appendField(new File_MARC_Data_Field('111', array(new File_MARC_Subfield('a', $_rs_aut['author_name'])), null, null));
                     //$tag['111'] = $sd.'a'.$_rs_aut['author_name'];
                 }
             } else {
                 if ($_rs_aut['authority_type'] == 'p') {
                     if (!isset($tag['700'])) {
                         $marc->appendField(new File_MARC_Data_Field('700', array(new File_MARC_Subfield('a', $_rs_aut['author_name'])), null, null));
                     } elseif ($_rs_aut['authority_type'] == 'o') {
                         $marc->appendField(new File_MARC_Data_Field('710', array(new File_MARC_Subfield('a', $_rs_aut['author_name'])), null, null));
                     } elseif ($_rs_aut['authority_type'] == 'c') {
                         $marc->appendField(new File_MARC_Data_Field('711', array(new File_MARC_Subfield('a', $_rs_aut['author_name'])), null, null));
                     }
                 }
             }
         }
         // $tag[] = $_recs['topic'];
         // get topic and its type first
         $_top_q = $dbs->query('SELECT t.topic,t.topic_type,i.level FROM biblio_topic as i LEFT JOIN `mst_topic` as t on t.topic_id=i.topic_id WHERE i.biblio_id=' . $_recs['biblio_id']);
         while ($_rs_top = $_top_q->fetch_assoc()) {
             if ($_rs_top['topic_type'] == 't') {
                 if (!isset($tag['650'])) {
                     $marc->appendField(new File_MARC_Data_Field('650', array(new File_MARC_Subfield('a', $_rs_top['topic'])), null, null));
                 }
             } elseif ($_rs_top['topic_type'] == 'n') {
                 if (!isset($tag['600'])) {
                     $marc->appendField(new File_MARC_Data_Field('600', array(new File_MARC_Subfield('a', $_rs_top['topic'])), null, null));
                 }
             } elseif ($_rs_top['topic_type'] == 'c') {
                 if (!isset($tag['610'])) {
                     $marc->appendField(new File_MARC_Data_Field('610', array(new File_MARC_Subfield('a', $_rs_top['topic'])), null, null));
                 }
             } elseif ($_rs_top['topic_type'] == 'g') {
                 if (!isset($tag['651'])) {
                     $marc->appendField(new File_MARC_Data_Field('651', array(new File_MARC_Subfield('a', $_rs_top['topic'])), null, null));
                 }
             } elseif ($_rs_top['topic_type'] == 'tm' || $_rs_top['topic_type'] == 'oc') {
                 if (!isset($tag['653'])) {
                     $marc->appendField(new File_MARC_Data_Field('653', array(new File_MARC_Subfield('a', $_rs_top['topic'])), null, null));
                 }
             } elseif ($_rs_top['topic_type'] == 'gr') {
                 if (!isset($tag['655'])) {
                     $marc->appendField(new File_MARC_Data_Field('655', array(new File_MARC_Subfield('a', $_rs_top['topic'])), null, null));
                 }
             }
         }
         $marc->appendField(new File_MARC_Data_Field('005', array(new File_MARC_Subfield('a', preg_replace("(-|:| )", "", $_recs['last_update']))), null, null));
         //$tag['005'] = $sd.'a'.preg_replace("(-|:| )", "", $_recs['last_update']);
         $marc->appendField(new File_MARC_Data_Field('260', array(new File_MARC_Subfield('a', $_recs['publish_place']), new File_MARC_Subfield('b', $_recs['publisher']), new File_MARC_Subfield('c', $_recs['publish_year'])), null, null));
         //$tag['260'] = $sd.'a'.$_recs['publish_place'].$sd.'b'.$_recs['publisher'].$sd.'c'.$_recs['publish_year'];
         $marc->appendField(new File_MARC_Data_Field('041', array(new File_MARC_Subfield('a', $_recs['language'])), null, null));
         //$tag['041'] = $sd.'a'.$_recs['language'];
         $marc->appendField(new File_MARC_Data_Field('084', array(new File_MARC_Subfield('a', $_recs['classification'])), null, null));
         //$tag['084'] = $sd.'a'.$_recs['classification'];
         //$tag['245'] = $_recs['spec_detail_info'];
         if (isset($_recs['collation']) && $_recs['collation'] != "") {
             $marc->appendField(new File_MARC_Data_Field('300', array(new File_MARC_Subfield('a', preg_replace('/;.*$/i', '', $_recs['collation'])), new File_MARC_Subfield('b', preg_replace('/(^.+;)|(:.*$)/i', '', $_recs['collation'])), new File_MARC_Subfield('c', preg_replace('/.+:$/i', '', $_recs['collation']))), null, null));
             //$tag['300'] = $sd.'a'.preg_replace("/;/", ";".$sd."c", preg_replace("/:/", ":".$sd."b", $_recs['collation']));
         }
         if (isset($_recs['notes']) && $_recs['notes'] != "") {
             $marc->appendField(new File_MARC_Data_Field('500', array(new File_MARC_Subfield('a', str_ireplace(array("\n", "\r"), '', $_recs['notes']))), null, null));
             //$tag['500'] = $sd.'a'.$_recs['notes'];
         }
         if (isset($_recs['series_title']) && $_recs['series_title'] != "") {
             $marc->appendField(new File_MARC_Data_Field('490', array(new File_MARC_Subfield('a', $_recs['series_title'])), null, null));
             //$tag['490'] = $sd.'a'.$_recs['series_title'];
         }
         if (isset($_recs['content_type']) && $_recs['content_type'] != "") {
             $marc->appendField(new File_MARC_Data_Field('336', array(new File_MARC_Subfield('a', $_recs['content_type'])), null, null));
             //$tag['336'] = $sd.'a'.$_recs['content_type'];
         }
         if (isset($_recs['media_type']) && $_recs['media_type'] != "") {
             $marc->appendField(new File_MARC_Data_Field('337', array(new File_MARC_Subfield('a', $_recs['media_type'])), null, null));
             //$tag['337'] = $sd.'a'.$_recs['media_type'];
         }
         if (isset($_recs['carrier_type']) && $_recs['carrier_type'] != "") {
             $marc->appendField(new File_MARC_Data_Field('338', array(new File_MARC_Subfield('a', $_recs['carrier_type'])), null, null));
             //$tag['338'] = $sd.'a'.$_recs['carrier_type'];
         }
         //print_r($tag);
         /*
         $fh = fopen($filename, 'w');
         fwrite($fh, $marc->toRaw());
         fclose($fh);
         */
         unset($tag);
         if ($format == 'XML') {
             $marc_records .= preg_replace('@<\\?xml.+?>@i', '', $marc->toXML('UTF-8', true, false));
         } else {
             if ($format == 'JSON') {
                 $marc_records .= $marc->toJSON() . ',';
             } else {
                 $marc_records .= $marc->toRaw();
             }
         }
     }
     if ($format == 'XML') {
         $output = '<?xml version="1.0" encoding="UTF-8"?>' . '<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">';
         $output .= $marc_records;
         $output .= '</marc:collection>';
         return $output;
     } else {
         if ($format == 'JSON') {
             $output = '[';
             $output .= substr_replace($marc_records, '', -1);
             $output .= ']';
             return $output;
         }
     }
     return $marc_records;
 }