2016-04-28 13:32:17 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: jaco
|
|
|
|
* Date: 28/04/16
|
|
|
|
* Time: 12.34
|
|
|
|
*/
|
|
|
|
$doc = <<<DOC
|
|
|
|
Rebal.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
rebal.php [<input> <output>]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h --help Show this screen.
|
|
|
|
--version Show version.
|
|
|
|
|
|
|
|
DOC;
|
|
|
|
|
|
|
|
require('src/docopt.php');
|
|
|
|
require 'File/MARC.php';
|
|
|
|
$args = Docopt::handle($doc, array('version'=>'RebAl-CLI 0.1'));
|
|
|
|
//foreach ($args as $k=>$v)
|
|
|
|
// print $k.': '.$v.PHP_EOL;
|
|
|
|
$in = $args['<input>'];
|
|
|
|
$out = $args['<output>'];
|
2016-09-27 17:14:48 +02:00
|
|
|
$count = 0;
|
2016-04-28 13:32:17 +02:00
|
|
|
// Retrieve a set of MARC records from a file
|
|
|
|
$entries = new File_MARC($in);
|
|
|
|
// Prepare to write the new MARC file
|
|
|
|
$marc21_file = fopen($out, "wb");
|
|
|
|
|
|
|
|
// Iterate through the retrieved records
|
|
|
|
while ($record = $entries->next()) {
|
|
|
|
// Get the UNIMARC author field and iterate through subfields
|
|
|
|
// normalising the output if the Name is found without comma
|
|
|
|
$lead_authors = $record->getFields('700');
|
2016-09-27 17:14:48 +02:00
|
|
|
$sec_authors = $record->getFields('702');
|
2016-04-28 13:32:17 +02:00
|
|
|
foreach ($lead_authors as $auth) {
|
|
|
|
$a = $auth->getSubfield('a');
|
|
|
|
$b = $auth->getSubfield('b');
|
|
|
|
if ($b && strpos($b, ',')) {
|
|
|
|
//print $b;
|
|
|
|
//print "\n";
|
|
|
|
$count++;
|
|
|
|
} else if ($b) {
|
|
|
|
$bdata = $b->getData();
|
|
|
|
$b->setData(', ' . $bdata);
|
|
|
|
//print $b;
|
|
|
|
//print "\n";
|
|
|
|
}
|
2016-09-27 17:14:48 +02:00
|
|
|
if ($a) {
|
|
|
|
$adata= $a->getData();
|
|
|
|
$a->setData(ucwords(strtolower($adata)));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
foreach ($sec_authors as $auth) {
|
|
|
|
$a = $auth->getSubfield('a');
|
|
|
|
$b = $auth->getSubfield('b');
|
|
|
|
if ($b && strpos($b, ',')) {
|
|
|
|
//print $b;
|
|
|
|
//print "\n";
|
|
|
|
$count++;
|
|
|
|
} else if ($b) {
|
|
|
|
$bdata = $b->getData();
|
|
|
|
$b->setData(', ' . $bdata);
|
|
|
|
//print $b;
|
|
|
|
//print "\n";
|
|
|
|
}
|
|
|
|
if ($a) {
|
|
|
|
$adata= $a->getData();
|
|
|
|
$a->setData(ucwords(strtolower($adata)));
|
|
|
|
};
|
2016-04-28 13:32:17 +02:00
|
|
|
}
|
|
|
|
fwrite($marc21_file, $record->toRaw());
|
|
|
|
//print "\n";
|
|
|
|
}
|
|
|
|
print $count;
|
|
|
|
fclose($marc21_file);
|
|
|
|
?>
|