|
| |
__construct () |
| |
| |
isTagValid ( $tag) |
| |
| |
assertTagValid ( $tag) |
| |
| |
isTagRepeatable ( $tag) |
| |
| |
tagOrder ( $a, $b) |
| |
| |
assertTagOrder ( $a, $b) |
| |
| |
loadFromBinaryString ( $string, $fuzzy=true) |
| |
| |
CheckField ( $field) |
| |
| |
loadFromMnemonicString ( $string) |
| |
| |
loadFromXMLString ( $string) |
| |
| |
asXMLString () |
| |
| |
loadFromString ( $string) |
| |
| |
ParseMnemonicLine ( $line) |
| |
| |
AppendField ( $field, $reorder=false) |
| |
| |
AsMnemonicString ( $leader_tag='LDR', $field_initiator='=', $tag_terminator=' ', $identifier_initiator='$', $field_terminator="\", $record_terminator="\", $space_replacer=' ') |
| |
| |
delFields ( $pattern) |
| |
| |
__construct () |
| |
| |
isTagValid ( $tag) |
| |
| |
assertTagValid ( $tag) |
| |
| |
isTagRepeatable ( $tag) |
| |
| |
assertTagRepeatable ( $tag) |
| |
| |
tagOrder ( $a, $b) |
| |
| |
assertTagOrder ( $a, $b) |
| |
| |
exception ( $string) |
| |
| |
loadFromBinaryStream ( $filehandle) |
| |
| |
setLeader ( $string) |
| |
| |
loadFromBinaryString ( $string, $fuzzy=true) |
| |
| |
DataNotInDirectory () |
| |
| |
loadFromString ( $string) |
| |
| |
ParseBinaryField ( $tag, $data, $directoryEntry) |
| |
| |
AppendFieldBinary ( $tag, $data, $directoryEntry=array(), $reorder=false) |
| |
| |
CheckField ( $field) |
| |
| |
AppendField ( $field, $reorder=false) |
| |
| |
removeField ( $field) |
| |
| |
delFields ( $tag) |
| |
| |
getFields ( $tag) |
| |
| |
getTagPattern ( $patt) |
| |
| |
AsBinaryString () |
| |
| |
AsMnemonicString ( $leader_tag="LDR", $field_initiator="=", $tag_terminator=" ", $identifier_initiator="\, $field_terminator="\\", $record_terminator="\\", $space_replacer=" ") |
| |
Definition at line 26 of file MARC21.php.
◆ __construct()
| MARC21Record::__construct |
( |
|
) |
|
Definition at line 28 of file MARC21.php.
29 parent::__construct();
33 $this->
set_default(
"lengthOfStartingCharacterPosition", 5 );
34 $this->
set_default(
"lengthOfImplementationDefined", 0 );
35 $this->mnemonicType =
"LC";
set_default( $name, $value)
◆ AppendField()
| MARC21Record::AppendField |
( |
|
$field, |
|
|
|
$reorder = false |
|
) |
|
|
Definition at line 255 of file MARC21.php.
256 if( is_string( $field ) ) {
259 if( is_a( $field,
"ISO2709Field" ) )
return parent::AppendField( $field, $reorder );
ParseMnemonicLine( $line)
◆ AsMnemonicString()
| MARC21Record::AsMnemonicString |
( |
|
$leader_tag = 'LDR', |
|
|
|
$field_initiator = '=', |
|
|
|
$tag_terminator = ' ', |
|
|
|
$identifier_initiator = '$', |
|
|
|
$field_terminator = "\r\n", |
|
|
|
$record_terminator = "\r\n", |
|
|
|
$space_replacer = ' ' |
|
) |
|
|
Definition at line 263 of file MARC21.php.
264 if( $this->mnemonicType ===
"TRME" )
return parent::AsMnemonicString(
"LDR",
"=",
" ",
"\$",
"\r\n",
"\r\n",
"\\" );
265 if( $this->mnemonicType ===
"LCMB" )
return parent::AsMnemonicString(
"000",
"=",
" ",
"\$",
"\r\n",
"\r\n",
"#" );
266 if( $this->mnemonicType ===
"VGER" )
return parent::AsMnemonicString(
"LEADER",
"=",
" ",
"|",
"\r\n",
"\r\n",
"#" );
267 #return parent::AsMnemonicString( "LDR", "=", " ", "\$", "\r\n", "\r\n", " " );
268 return parent::AsMnemonicString( $leader_tag, $field_initiator, $tag_terminator, $identifier_initiator, $field_terminator, $record_terminator, $space_replacer );
◆ assertTagOrder()
| MARC21Record::assertTagOrder |
( |
|
$a, |
|
|
|
$b |
|
) |
|
|
Definition at line 72 of file MARC21.php.
73 if( self::tagOrder( $a, $b ) > 0 ) {
74 $this->
exception(
"MARC21: 00* is ordered by ASCII, and the rest by century. Thus '$a' should not precede '$b'.");
77 return parent::assertTagOrder( $a, $b );
◆ assertTagValid()
| MARC21Record::assertTagValid |
( |
|
$tag |
) |
|
Definition at line 42 of file MARC21.php.
43 if( !self::isTagValid( $tag ) ) {
44 $this->
exception(
"MARC21: Tags must be numeric and must be 3 bytes long. Thus '$tag' is not allowed.");
47 return parent::assertTagValid( $tag );
◆ asXMLString()
| MARC21Record::asXMLString |
( |
|
) |
|
Definition at line 171 of file MARC21.php.
173 $str .=
'<leader>' . $this->leader .
'</leader>';
174 foreach( $this->fields as $field ) {
175 if ( isset($field->data ) ) {
176 $str .=
"<controlfield tag=\"{$field->tag}\">{$field->data}</controlfield>";
178 $str .=
"<datafield tag=\"{$field->tag}\">";
179 foreach( $field->subfields as $subfield ) {
180 $str .=
"<subfield code=\"{$subfield->identifier}\">{$subfield->data}</subfield>";
182 $str .=
'</datafield>';
◆ CheckField()
| MARC21Record::CheckField |
( |
|
$field |
) |
|
Definition at line 94 of file MARC21.php.
95 parent::CheckField( $field );
96 if( substr( $field->tag, 0, 2 ) ===
"00" ) {
100 if( !preg_match(
"/^[0-9a-z ]{2}$/", $field->indicators) )
101 $this->
exception(
"MARC21 8.3.5: indicators should be length 2, and each character should be lower case, numeric, or a space. " .
102 "So field '{$field->tag}' with indicators '{$field->indicators}' is not allowed." );
104 foreach( $field->subfields as $subfield ) {
105 if( !preg_match(
"/^[0-9a-z]$/", $subfield->identifier) )
106 $this->
exception(
"MARC21 8.3.5: subfield identifiers should be length 1, and each character should be lower case or numeric. " .
107 "So field '{$field->tag}' with subfield '{$subfield->identifier}' is not allowed." );
◆ delFields()
| MARC21Record::delFields |
( |
|
$pattern |
) |
|
Definition at line 271 of file MARC21.php.
272 foreach( $this->fields as $k => $v ) {
273 $vmne = $v->AsMnemonicString(
"=",
" ",
"\$",
"\r\n",
'\\' );
274 if( preg_match(
"@^" . $pattern .
"@", $vmne ) ) unset( $this->fields[$k] );
276 $this->fields = array_values( $this->fields );
◆ isTagRepeatable()
| MARC21Record::isTagRepeatable |
( |
|
$tag |
) |
|
Definition at line 50 of file MARC21.php.
51 return $tag !=
"001" and $tag !=
"005";
◆ isTagValid()
| MARC21Record::isTagValid |
( |
|
$tag |
) |
|
Definition at line 38 of file MARC21.php.
39 return is_string( $tag ) and ctype_digit( $tag ) and strlen( $tag ) == 3 and $tag !==
"000";
◆ loadFromBinaryString()
| MARC21Record::loadFromBinaryString |
( |
|
$string, |
|
|
|
$fuzzy = true |
|
) |
|
|
Definition at line 80 of file MARC21.php.
81 $ret = parent::loadFromBinaryString( $string );
82 if( $ret ===
false )
return $ret;
83 if( strlen($this->leader) != 24 )
return false;
84 if(!ctype_print($this->leader))
85 $this->
exception(
"MARC21: Leader can only contain 0x20 through 0x7E, not 0x" . bin2hex( $this->leader ) );
86 if($this->leader[23] !=
"0")
87 $this->
exception(
"MARC21: Last character of leader is supposed to be '0' not '{$this->leader[23]}'");
91 # 00*-00* are in numeric-alpha order in both directory and data (with no intervening in either directory or data)
◆ loadFromMnemonicString()
| MARC21Record::loadFromMnemonicString |
( |
|
$string |
) |
|
Definition at line 112 of file MARC21.php.
113 $this->leader = array();
114 $this->fields = array();
115 $this->exceptions = array();
116 $this->raw = $string;
117 foreach( explode(
"\r\n", $string ) as $line ) {
119 if( $field !==
false ) $this->
AppendField( $field );
ParseMnemonicLine( $line)
AppendField( $field, $reorder=false)
◆ loadFromString()
| MARC21Record::loadFromString |
( |
|
$string |
) |
|
Definition at line 189 of file MARC21.php.
190 if (preg_match(
"/^ *([^ ])/",$string,$m)) {
191 $starts_with = $m[1];
192 if ($starts_with ==
'<') {
195 if ($starts_with ==
'=') {
198 if (ctype_digit($starts_with)) {
loadFromMnemonicString( $string)
loadFromBinaryString( $string, $fuzzy=true)
loadFromXMLString( $string)
◆ loadFromXMLString()
| MARC21Record::loadFromXMLString |
( |
|
$string |
) |
|
Definition at line 123 of file MARC21.php.
124 $this->leader = array(); # XXX ??
125 $this->fields = array();
126 $this->exceptions = array();
127 $this->raw = $string;
129 $doc =
new DOMDocument();
130 $doc->loadXML($string);
131 $xpath =
new DOMXpath($doc);
133 $leaderfield = $xpath->query(
'//record/leader');
134 if ($leaderfield) { # <leader>00838mas a2200301 a 4500</leader>
135 $leader = $leaderfield[0]->nodeValue;
136 if( strlen($leader) != 24 )
return false;
140 # $field = new ISO2709Field( $tag, $data, $indicators, $subfields, $directoryEntry, $this );
142 $controlfield = $xpath->query(
'//record/controlfield');
143 if ($controlfield) { # <controlfield tag=
"001"> 92005291 </controlfield>
144 foreach ($controlfield as $cfd) {
145 $tag = $cfd->getAttribute(
'tag');
146 $data = $cfd->nodeValue;
152 $datafield = $xpath->query(
'//record/datafield');
153 if ($datafield) { # <datafield ind1=
" " ind2=
" " tag=
"035"><subfield code=
"9">AHE8121LM</subfield></datafield>
154 foreach ($datafield as $dfd) {
155 $tag = $dfd->getAttribute(
'tag');
156 $indicators = $dfd->getAttribute(
'ind1') . $dfd->getAttribute(
'ind2');
157 $subfields = array();
158 foreach ($dfd->childNodes as $subf) {
159 if ($subf->nodeType ==
'1') { # Element
160 $code = $subf->getAttribute(
'code');
161 $value = $subf->nodeValue;
165 $field =
new ISO2709Field( $tag, null, $indicators, $subfields);
AppendField( $field, $reorder=false)
◆ ParseMnemonicLine()
| MARC21Record::ParseMnemonicLine |
( |
|
$line |
) |
|
Definition at line 206 of file MARC21.php.
References ISO2709\SubfieldInitiator.
207 $equ = substr( $line, 0, 1 );
208 $tag = substr( $line, 1, 3 );
209 $spa = substr( $line, 4, 2 );
210 $dat = substr( $line, 6 );
211 if( $equ !==
"=" or $spa !==
" " ) {
212 $this->
exception(
"Mnemonic: unreadable line '$line'");
215 if( $tag ==
"LDR" or $tag ==
"000" ) {
216 $this->leader = $dat;
217 $this->indicatorLength = 2;
218 $this->identifierLength = 2;
219 $this->mnemonicType = ($tag ==
"LDR") ?
"TRME" :
"LCMB";
222 if( $this->mnemonicType ===
"TRME" ) {
224 $dat = str_replace(
'\\',
' ', $dat );
225 }
else if( $this->mnemonicType ===
"LCMB" ) {
227 $dat = str_replace(
'#',
' ', $dat );
239 if( substr($tag,0,2) ===
"00" ) {
240 $dat = str_replace(
'#',
' ', $dat );
241 $dat = str_replace(
'\\',
' ', $dat );
243 if( $dat[0] ==
'\\' ) $dat[0] =
' ';
244 if( $dat[1] ==
'\\' ) $dat[1] =
' ';
245 if( $dat[0] ==
'#' ) $dat[0] =
' ';
246 if( $dat[1] ==
'#' ) $dat[1] =
' ';
ParseBinaryField( $tag, $data, $directoryEntry)
◆ tagOrder()
| MARC21Record::tagOrder |
( |
|
$a, |
|
|
|
$b |
|
) |
|
|
Definition at line 55 of file MARC21.php.
56 if(!parent::isTagValid($a) || !parent::isTagValid($b))
return 0;
57 if( $a === $b )
return 0;
58 $a0 = substr( $a, 0, 2 );
59 $b0 = substr( $b, 0, 2 );
60 if( $a0 === $b0 and $a0 ===
"00" )
return strcmp( $a, $b );
61 if( $a0 ===
"00" ) {
return -1; }
62 if( $b0 ===
"00" ) {
return 1; }
63 $a0 = substr( $a, 0, 1 );
64 $b0 = substr( $b, 0, 1 );
65 if( $a0 ===
"0" and $b0 ===
"0" ) {
66 if( $a ===
"049" )
return 1;
67 if( $b ===
"049" )
return -1;
69 return strcmp( $a0, $b0 );
◆ $mnemonicType
| MARC21Record::$mnemonicType |
|
protected |
The documentation for this class was generated from the following file: