From c695a00d77eaca708ed0d57980c17f49d034b7bb Mon Sep 17 00:00:00 2001 From: amillar Date: Wed, 26 Jun 2002 07:24:12 +0000 Subject: [PATCH] New subs to streamline biblio additions: addcompletebiblioitem and getoraddbiblio --- C4/Biblio.pm | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index d476f2af50..78f954236e 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1,9 +1,18 @@ package C4::Biblio; #assumes C4/Biblio.pm +# $Id$ + +#----------------- +# General requirements use strict; + require Exporter; + +# Other Koha modules use C4::Database; +#----------------- + use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); # set the version for version checking @@ -19,6 +28,8 @@ $VERSION = 0.01; &findall &needsmod &updatecost &getbiblioitem &getitemsbybiblioitem &isbnsearch &keywordsearch &websitesearch &addwebsite &updatewebsite &deletewebsite + &newcompletebiblioitem + &getoraddbiblio ); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], @@ -37,7 +48,6 @@ my $Var1 = ''; my %Hashit = (); - # then the others (which are still accessible as $Some::Module::stuff) my $stuff = ''; my @more = (); @@ -843,4 +853,128 @@ sub deletewebsite { } # sub deletewebsite + + +#------------------------------------------------ + +# Add a biblioitem and related data to Koha database +sub newcompletebiblioitem { + use strict; + + my ( + $dbh, # DBI handle + $biblio, # hash ref to biblio record + $biblioitem, # hash ref to biblioitem record + $subjects, # list ref of subjects + $addlauthors, # list ref of additional authors + )=@_ ; + + my ( $biblionumber, $biblioitemnumber, $error); # return values + + my $debug=0; + my $sth; + my $subjectheading; + my $additionalauthor; + + #-------- + requireDBI($dbh,"newcompletebiblioitem"); + + print "
Trying to add biblio item Title=$biblio->{title} " .
+		"ISBN=$biblioitem->{isbn} 
\n" if $debug; + + # Make sure master biblio entry exists + ($biblionumber,$error)=getoraddbiblio($dbh, $biblio); + + if ( ! $error ) { + + $biblioitem->{biblionumber}=$biblionumber; + + # Add biblioitem + $biblioitemnumber=newbiblioitem($biblioitem); + + # Add subjects + $sth=$dbh->prepare("insert into bibliosubject + (biblionumber,subject) + values (?, ? )" ); + foreach $subjectheading (@{$subjects} ) { + $sth->execute($biblionumber, $subjectheading) + or $error.=$sth->errstr ; + + } # foreach subject + + # Add additional authors + $sth=$dbh->prepare("insert into additionalauthors + (biblionumber,author) + values (?, ? )"); + foreach $additionalauthor (@{$addlauthors} ) { + $sth->execute($biblionumber, $additionalauthor) + or $error.=$sth->errstr ; + } # foreach author + + } else { + # couldn't get biblio + $biblionumber=''; + $biblioitemnumber=''; + + } # if no biblio error + + return ( $biblionumber, $biblioitemnumber, $error); + +} # sub newcompletebiblioitem + +#--------------------------------------- +# Find a biblio entry, or create a new one if it doesn't exist. +# If a "subtitle" entry is in hash, add it to subtitle table +sub getoraddbiblio { + # input params + my ( + $dbh, # db handle + $biblio, # hash ref to fields + )=@_; + + # return + my $biblionumber; + + my $debug=0; + my $sth; + my $error; + + #----- + requireDBI($dbh,"getoraddbiblio"); + + print "
Looking for biblio 
\n" if $debug; + $sth=$dbh->prepare("select biblionumber + from biblio + where title=? and author=? + and copyrightdate=? and seriestitle=?"); + $sth->execute( + $biblio->{title}, $biblio->{author}, + $biblio->{copyright}, $biblio->{seriestitle} ); + if ($sth->rows) { + ($biblionumber) = $sth->fetchrow; + print "
Biblio exists with number $biblionumber
\n" if $debug; + } else { + # Doesn't exist. Add new one. + print "
Adding biblio
\n" if $debug; + ($biblionumber,$error)=&newbiblio($biblio); + if ( $biblionumber ) { + print "
Added with biblio number=$biblionumber
\n" if $debug; + if ( $biblio->{subtitle} ) { + &newsubtitle($biblionumber,$biblio->{subtitle} ); + } # if subtitle + } else { + print "
Couldn't add biblio: $error
\n" if $debug; + } # if added + } + + return $biblionumber,$error; + +} # sub getoraddbiblio + END { } # module clean-up code here (global destructor) + +#--------------------------------------- +# $Log$ +# Revision 1.1.2.3 2002/06/26 07:24:12 amillar +# New subs to streamline biblio additions: addcompletebiblioitem and getoraddbiblio +# -- 2.39.5