public function Field::__construct in Bibliography Module 7
Field init function.
Create a new Field object from passed arguments.
Parameters
array Array ( tagno, ind1, ind2, subfield_data ):
Return value
string Returns warnings if any issued during parse
File
- modules/
marcParse/ php-marc.php, line 832 - @package PHP-MARC
Class
- Field
- Field Class Create a MARC Field object.
Code
public function __construct() {
$args = func_get_args();
$tagno = array_shift($args);
$this->tagno = $tagno;
// Check if valid tag.
if (!preg_match("/^[0-9A-Za-z]{3}\$/", $tagno)) {
return $this
->_warn("Tag \"{$tagno}\" is not a valid tag.");
}
// Check if field is Control field.
$this->is_control = preg_match("/^\\d+\$/", $tagno) && $tagno < 10;
if ($this->is_control) {
$this->data = array_shift($args);
}
else {
foreach (array(
"ind1",
"ind2",
) as $indcode) {
$indicator = array_shift($args);
if (!preg_match("/^[0-9A-Za-z ]\$/", $indicator)) {
if ($indicator != "") {
$this
->_warn("Illegal indicator '{$indicator}' in field '{$tagno}' forced to blank");
}
$indicator = " ";
}
$this->{$indcode} = $indicator;
}
$subfields = array_shift($args);
if (count($subfields) < 1) {
return $this
->_warn("Field {$tagno} must have at least one subfield");
}
else {
$this
->add_subfields($subfields);
}
}
}