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(); } }
/** * 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())); }
/** * * 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; }