From 56d4ac55a7b2f313c42743fb6ecc27ecb877f84f Mon Sep 17 00:00:00 2001 From: tipaul Date: Thu, 6 Jun 2002 16:23:36 +0000 Subject: [PATCH] today stuff around marc. Will change soon as we will use MARC::record (see marcpm.sourceforge.net) --- C4/Catalogue.pm | 70 +++++++++++++++++++++++++++++++++--------- C4/test.pl | 54 ++++++++++---------------------- marc/perlmarcstructure | 13 ++++---- 3 files changed, 78 insertions(+), 59 deletions(-) diff --git a/C4/Catalogue.pm b/C4/Catalogue.pm index fce576179d..8834fb841c 100644 --- a/C4/Catalogue.pm +++ b/C4/Catalogue.pm @@ -21,7 +21,7 @@ $VERSION = 0.01; @ISA = qw(Exporter); @EXPORT = qw(&newBiblio &newBiblioItem &newItem &updateBiblio &updateBiblioItem &updateItem &changeSubfield &addSubfield &findSubfield - &addMarcBiblio + &addMarcBiblio &nextsubfieldid &getorders &bookseller &breakdown &basket &newbasket &bookfunds &ordersearch &newbiblio &newbiblioitem &newsubject &newsubtitle &neworder @@ -225,9 +225,10 @@ sub addMarcBiblio { # pass the marcperlstructure to this function, and it will create the records in the marc tables my ($marcstructure) = @_; my $dbh=C4Connect; - my $tags; - my $i; - my $j; + my $tag; + my $tagorder; + my $subfield; + my $subfieldorder; # adding main table, and retrieving bibid $dbh->do("lock tables marc_biblio WRITE"); my $sth=$dbh->prepare("insert into marc_biblio (datecreated,origincode) values (now(),?)"); @@ -239,22 +240,61 @@ sub addMarcBiblio { $sth->finish; $dbh->do("unlock tables"); # now, add subfields... - foreach $tags ($marcstructure->{tags}) { - foreach $i (keys %{$tags}) { - foreach $j (keys %{$tags->{$i}->{subfields}}) { - &addSubfield($marcstructure->{bibid}, - $tags->{$i}->{tag}, - $tags->{$i}->{tagorder}, - $tags->{$i}->{subfields}->{$j}->{mark}, - $tags->{$i}->{subfields}->{$j}->{subfieldorder}, - $tags->{$i}->{subfields}->{$j}->{value} - ); - print $tags->{$i}->{tag}."//".$tags->{$i}->{subfields}->{$j}->{value}."\n"; + foreach $tag (keys %{$marcstructure->{tags}}) { + foreach $tagorder (keys %{$marcstructure->{tags}->{$tag}}) { + foreach $subfield (keys %{$marcstructure->{tags}->{$tag}->{$tagorder}->{subfields}}) { + foreach $subfieldorder (keys %{$marcstructure->{tags}->{$tag}->{$tagorder}->{subfields}->{$subfield}}) { + &addSubfield($marcstructure->{bibid}, + $tag, + $tagorder, + $subfield, + $subfieldorder, + $marcstructure->{tags}->{$tag}->{$tagorder}->{subfields}->{$subfield}->{$subfieldorder} + ); +# print "$tag / $tagorder / $subfield / $subfieldorder / ".$marcstructure->{tags}->{$tag}->{$tagorder}->{subfields}->{$subfield}->{$subfieldorder}."\n"; + } } } } } +sub buildPerlmarcstructure { +# this function builds perlmarcstructure from the old koha-DB fields + my ($biblionumber,$author,$title,$unititle,$notes,$abstract, + $serial,$seriestitle,$copyrightdate,$biblioitemnumber,$volume,$number, + $classification,$itemtype,$isbn,$issn, + $dewey,$subclass,$publicationyear,$publishercode, + $volumedate,$illus,$pages,$notes, + $size,$place,$lccn) = @_; + + my $tagfield; + my $tagsubfield; + my $perlmarcstructure={}; + my $i=0; + my $dbh=&C4Connect; + my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"); + $sth->execute("biblionumber"); + if (($tagfield,$tagsubfield)=$sth->fetchrow) { + $i=nextsubfieldid($perlmarcstructure->{tags}->{$tagfield}->{1}->{subfields}->{$tagsubfield}); + $perlmarcstructure->{tags}->{$i}->{tag}=$tagfield; + $perlmarcstructure->{tags}->{$i}->{tagorder}=1; + $perlmarcstructure->{tags}->{$i}->{indicator}='##'; + } +} + +sub nextsubfieldid { + my $subfieldhash=shift; + my $maxsubfieldnumber=0; + my $subfield; + my $number; + foreach $subfield (keys %$subfieldhash) { + foreach $number (keys %{$subfieldhash->{$subfield}}) { + ($number>$maxsubfieldnumber) && ($maxsubfieldnumber=$number); + } + } + return $maxsubfieldnumber+1; +} + sub updateBiblio { # Update the biblio with biblionumber $biblio->{'biblionumber'} # I guess this routine should search through all marc records for a record that diff --git a/C4/test.pl b/C4/test.pl index 5d0a0a8d66..2d5fb74536 100755 --- a/C4/test.pl +++ b/C4/test.pl @@ -7,10 +7,10 @@ use C4::Catalogue; my $dbh=&C4Connect; $dbh->do("delete from marc_subfield_table"); $dbh->do("delete from marc_blob_subfield"); -&addSubfield(1,'001','a','1 - This is a value',1); -&addSubfield(1,'001','b','2 - This is another value',1); -&addSubfield(1,'001','c',"3 - This is a value very very long. I try to make it longer than 255 char. I need to add something else. will it be long enough now... I'm not sure. That's why i continue to add a few word to this very important sentence. Now I hope it will be enough... Oh, not it need some more characters. So i add stupid strings : xxxxxxxxxxxxxxx dddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeee rrrrrrrrrrrrrrrrrrr ffffffffffffffffff",1); -&addSubfield(1,'001','d',"4 - This is another value very very long. I try to make it longer than 255 char. I need to add something else. will it be long enough now... I'm not sure. That's why i continue to add a few word to this very important sentence. Now I hope it will be enough... Oh, not it need some more characters. So i add stupid strings : xxxxxxxxxxxxxxx dddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeee rrrrrrrrrrrrrrrrrrr ffffffffffffffffff",1); +&addSubfield(1,'001','a',1,'1 - This is a value'); +&addSubfield(1,'001','b',1,'2 - This is another value'); +&addSubfield(1,'001','c',1,"3 - This is a value very very long. I try to make it longer than 255 char. I need to add something else. will it be long enough now... I'm not sure. That's why i continue to add a few word to this very important sentence. Now I hope it will be enough... Oh, not it need some more characters. So i add stupid strings : xxxxxxxxxxxxxxx dddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeee rrrrrrrrrrrrrrrrrrr ffffffffffffffffff"); +&addSubfield(1,'001','d',1,"4 - This is another value very very long. I try to make it longer than 255 char. I need to add something else. will it be long enough now... I'm not sure. That's why i continue to add a few word to this very important sentence. Now I hope it will be enough... Oh, not it need some more characters. So i add stupid strings : xxxxxxxxxxxxxxx dddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeee rrrrrrrrrrrrrrrrrrr ffffffffffffffffff"); print "change 1\n"; &changeSubfield(1,"1new - this is a changed value"); print "change 2\n"; @@ -21,39 +21,19 @@ print "change 4\n"; &changeSubfield(4,"4new - stay with blob subfield...uuuuuuuuuuuuuuuuuuuuuuuu yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy tttttttttttttttttttttttttttttttt rrrrrrrrrrrrrrrrrrrrrr eeeeeeeeeeeeeeeeeeeeeeeee zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq ssssssssssssssssssssssssss ddddddddddddddddddddddddddddddd fffffffffffffffffffffffff ggggggggggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhh jjjjjjjjjjjjjjjjjjjjjkkkkkkkkkkkkkkkkkkkkkkkk"); my $x= &findSubfield(1,'001','a','',1); print "subfieldid : $x\n"; -my $marcstru={}; -$marcstru->{bibid}=58973; -$marcstru->{tags}->{1}->{tag}='110'; -$marcstru->{tags}->{1}->{tagorder}=1; -$marcstru->{tags}->{1}->{subfields}->{1}->{mark}='a'; -$marcstru->{tags}->{1}->{subfields}->{1}->{subfieldorder}=1; -$marcstru->{tags}->{1}->{subfields}->{1}->{value}='this is a test'; -$marcstru->{tags}->{1}->{subfields}->{2}->{mark}='b'; -$marcstru->{tags}->{1}->{subfields}->{2}->{subfieldorder}=1; -$marcstru->{tags}->{1}->{subfields}->{2}->{value}='this is another test'; +my $record={}; +#$marcstru->{bibid}=58973; # calculated auto_increment in addMarcBiblio +$record->{bibid}=58973; +$record->{tags}->{110}->{1}->{indicator}='##'; +$record->{tags}->{110}->{1}->{subfields}->{a}->{1}='first text'; +$record->{tags}->{110}->{1}->{subfields}->{a}->{2}='second text'; +$record->{tags}->{110}->{1}->{subfields}->{b}->{3}='third text'; -$marcstru->{tags}->{2}->{tag}='220'; -$marcstru->{tags}->{2}->{tagorder}=1; -$marcstru->{tags}->{2}->{subfields}->{1}->{mark}='a'; -$marcstru->{tags}->{2}->{subfields}->{1}->{subfieldorder}=1; -$marcstru->{tags}->{2}->{subfields}->{1}->{value}='this is a test for 220'; -$marcstru->{tags}->{2}->{subfields}->{2}->{mark}='b'; -$marcstru->{tags}->{2}->{subfields}->{2}->{subfieldorder}=1; -$marcstru->{tags}->{2}->{subfields}->{2}->{value}='this is another test for 220'; -$marcstru->{tags}->{2}->{subfields}->{3}->{mark}='b'; -$marcstru->{tags}->{2}->{subfields}->{3}->{subfieldorder}=2; -$marcstru->{tags}->{2}->{subfields}->{3}->{value}='this is a third test for 220'; +$record->{tags}->{120}->{1}->{indicator}='##'; +$record->{tags}->{120}->{1}->{subfields}->{a}->{1}='last text ??'; -$marcstru->{tags}->{3}->{tag}='330'; -$marcstru->{tags}->{3}->{tagorder}=1; -$marcstru->{tags}->{3}->{subfields}->{1}->{mark}='a'; -$marcstru->{tags}->{3}->{subfields}->{1}->{subfieldorder}=1; -$marcstru->{tags}->{3}->{subfields}->{1}->{value}='this is a test for 330'; -$marcstru->{tags}->{3}->{subfields}->{2}->{mark}='b'; -$marcstru->{tags}->{3}->{subfields}->{2}->{subfieldorder}=1; -$marcstru->{tags}->{3}->{subfields}->{2}->{value}='this is another test for 330'; -$marcstru->{tags}->{3}->{subfields}->{3}->{mark}='b'; -$marcstru->{tags}->{3}->{subfields}->{3}->{subfieldorder}=2; -$marcstru->{tags}->{3}->{subfields}->{3}->{value}='this is a third test for 330'; +$record->{tags}->{120}->{2}->{indicator}='01'; +$record->{tags}->{120}->{2}->{subfields}->{n}->{1}='no, another text'; +print "NEXT IS : ".nextsubfieldid($record->{tags}->{110}->{1}->{subfields})."\n"; -&addMarcBiblio($marcstru); +&addMarcBiblio($record); diff --git a/marc/perlmarcstructure b/marc/perlmarcstructure index 3142c54bf6..c9ef0778cb 100644 --- a/marc/perlmarcstructure +++ b/marc/perlmarcstructure @@ -29,18 +29,17 @@ bibid=58973, 120 01 $nno, another text in perlmarcstructure, it can be writen : -$record->{bibid}=58973 +$record->{bibid}=58973; $record->{tags}->{110}->{1}->{indicator}='##'; -$record->{tags}->{110}->{1}->->{a}->{1}='first text'; -$record->{tags}->{110}->{1}->{a}->{2}='second text'; -$record->{tags}->{110}->{1}->{b}->{1}='third text'; +$record->{tags}->{110}->{1}->{subfields}->{a}->{1}='first text'; +$record->{tags}->{110}->{1}->{subfields}->{a}->{2}='second text'; +$record->{tags}->{110}->{1}->{subfields}->{b}->{1}='third text'; $record->{tags}->{120}->{1}->{indicator}='##'; -$record->{tags}->{120}->{1}->{a}->{1}='last text ??'; +$record->{tags}->{120}->{1}->{subfields}->{a}->{1}='last text ??'; $record->{tags}->{120}->{2}->{indicator}='01'; -$record->{tags}->{120}->{2}->{n}->{1}='no, another text'; - +$record->{tags}->{120}->{2}->{subfields}->{n}->{1}='no, another text'; This takes care of possible repeating tags and subfields as well as ordering of tags and subfields, but it makes it difficult to look up specific tags and -- 2.39.5