Esempio n. 1
0
require 'File/MARC.php';
// File_MARC offers the ability to add subfields at any point within
// an existing set of subfields
// First, create some subfields
$subfields[] = new File_MARC_Subfield('a', 'nothing');
$subfields[] = new File_MARC_Subfield('z', 'everything');
// Then, create a field including those subfields
$field = new File_MARC_Data_Field('100', $subfields, '0');
// Create some new subfields
$subfield1 = new File_MARC_Subfield('g', 'a little');
$subfield2 = new File_MARC_Subfield('k', 'a bit more');
$subfield3 = new File_MARC_Subfield('t', 'a lot');
// Append a new subfield to the existing set of subfields
// Expected order: a-z-g
$field->appendSubfield($subfield1);
// Insert a new subfield after the first subfield with code 'z'
// Expected order: a-z-k-g
$sf = $field->getSubfields('z');
// getSubfields() always returns an array; we just want the first subfield
if (count($sf) > 0) {
    $field->insertSubfield($subfield2, $sf[0]);
}
// Insert a new subfield prior to the first subfield with code 'z'
// Expected order: a-t-z-k-g
$sf = $field->getSubfield('z');
// getSubfield() simply returns the first matching subfield
if ($sf) {
    $field->insertSubfield($subfield3, $sf, true);
}
// let's see the results
Esempio n. 2
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;
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
 /**
  * Fetch an individual record
  * 
  * @param string $id
  * @return File_MARC_Record|null
  */
 public function getBibRecord($id)
 {
     // bib record query
     $sql = trim("\r\n\t\t\tSELECT\r\n\t\t\t\tbib_view.id,\r\n\t\t\t\tbib_view.bcode1,\r\n\t\t\t\tbib_view.bcode2,\r\n\t\t\t\tbib_view.bcode3,\r\n\t\t\t\tbib_view.cataloging_date_gmt,\r\n\t\t\t\tvarfield_view.marc_tag,\r\n\t\t\t\tvarfield_view.marc_ind1,\r\n\t\t\t\tvarfield_view.marc_ind2,\r\n\t\t\t\tvarfield_view.field_content,\r\n\t\t\t\tvarfield_view.varfield_type_code,\r\n\t\t\t\tleader_field.*\r\n\t\t\tFROM\r\n\t\t\t\tsierra_view.bib_view\r\n\t\t\tINNER JOIN \r\n\t\t\t\tsierra_view.varfield_view ON bib_view.id = varfield_view.record_id\r\n\t\t\tLEFT JOIN\r\n\t\t\t\tsierra_view.leader_field ON bib_view.id = leader_field.record_id\r\n\t\t\tWHERE\r\n\t\t\t\tbib_view.record_num = '{$id}'\r\n\t\t\tORDER BY \r\n\t\t\t\tmarc_tag\r\n\t\t");
     $results = $this->getResults($sql);
     if (count($results) == 0) {
         return null;
     }
     $record = new File_MARC_Record();
     // let's parse a few things, shall we
     $result = $results[0];
     $internal_id = $result[0];
     // internal postgres id
     // leader
     // 0000's here get converted to correct lengths by File_MARC
     $leader = '00000';
     // 00-04 - Record length
     $leader .= $this->getLeaderValue($result, 'record_status_code');
     // 05 - Record status
     $leader .= $this->getLeaderValue($result, 'record_type_code');
     // 06 - Type of record
     $leader .= $this->getLeaderValue($result, 'bib_level_code');
     // 07 - Bibliographic level
     $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
     $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);
     // innovative bib record fields
     $bib_field = new File_MARC_Data_Field('907');
     $record->appendField($bib_field);
     $bib_field->appendSubfield(new File_MARC_Subfield('a', $this->getFullRecordId($id)));
     // cataloging info fields
     $bib_field = new File_MARC_Data_Field('998');
     $record->appendField($bib_field);
     $bib_field->appendSubfield(new File_MARC_Subfield('c', trim($result['cataloging_date_gmt'])));
     $bib_field->appendSubfield(new File_MARC_Subfield('d', trim($result['bcode1'])));
     $bib_field->appendSubfield(new File_MARC_Subfield('e', trim($result['bcode2'])));
     $bib_field->appendSubfield(new File_MARC_Subfield('f', trim($result['bcode3'])));
     // marc fields
     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);
         }
     }
     // location codes
     $sql = trim("\r\n\t\t\tSELECT location_code\r\n\t\t\tFROM\r\n\t\t\t\tsierra_view.bib_record_location\r\n\t\t\tWHERE\r\n\t\t\t\tbib_record_id = '{$internal_id}'\r\n\t\t");
     $results = $this->getResults($sql);
     if (count($results) > 0) {
         $location_record = new File_MARC_Data_Field('907');
         foreach ($results as $result) {
             $location_record->appendSubfield(new File_MARC_Subfield('b', trim((string) $result['location_code'])));
         }
         $record->appendField($location_record);
     }
     // item records
     $sql = trim("\r\n\t\t\tSELECT item_view.*\r\n\t\t\tFROM \r\n\t\t\t\tsierra_view.bib_view,\r\n\t\t\t\tsierra_view.item_view,\r\n\t\t\t\tsierra_view.bib_record_item_record_link\r\n\t\t\tWHERE \r\n\t\t\t\tbib_view.record_num = '{$id}' AND\r\n\t\t\t\tbib_view.id = bib_record_item_record_link.bib_record_id AND\r\n\t\t\t\titem_view.id = bib_record_item_record_link.item_record_id\t\t\t\t\r\n\t\t");
     $results = $this->getResults($sql);
     foreach ($results as $result) {
         $item_record = new File_MARC_Data_Field('945');
         $item_record->appendSubfield(new File_MARC_Subfield('l', trim($result['location_code'])));
         $record->appendField($item_record);
     }
     return $record;
 }