/** * 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; }
/** * 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; }
public function processExport($pa_data, $pa_options = array()) { $pb_single_record = isset($pa_options['singleRecord']) && $pa_options['singleRecord']; $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(); } }
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; }
/** 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; }
/** * 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; }
//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'])))); //083 = zip/PCODE3? $record->appendField(new File_MARC_Data_Field('083', array(new File_MARC_Subfield('a', $patronData['083_ZIP'])))); //084 = patron type : should be 33 for all Elementary Students $record->appendField(new File_MARC_Data_Field('084', array(new File_MARC_Subfield('a', $patronData['084_PTYPE'])))); //085 = hold pickup library = school $record->appendField(new File_MARC_Data_Field('085', array(new File_MARC_Subfield('a', $patronData['085_HOLD_LIBR'])))); //086 = mblock $record->appendField(new File_MARC_Data_Field('086', array(new File_MARC_Subfield('a', $patronData['086_MBLOCK']))));
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'])))); //084 = patron type : should be 30 for all MNPS educators $record->appendField(new File_MARC_Data_Field('084', array(new File_MARC_Subfield('a', $patronData['084_PTYPE'])))); //085 = hold pickup library = school // in 2014-2015, initially set to "ps " because we do not trust MNPS data to correctly locate educators. When an educator activates her account, she selects her pickup location // in 2015-2016, we are going to trust the patrons to correct their pickup location if necessary $record->appendField(new File_MARC_Data_Field('085', array(new File_MARC_Subfield('a', $patronData['085_HOLD_LIBR'])))); //086 = mblock $record->appendField(new File_MARC_Data_Field('086', array(new File_MARC_Subfield('a', $patronData['086_MBLOCK']))));
/** * 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; }
/** * * 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; }