koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha C4/Circulation/Circ2.pm C4/Reserves2.pm C4...


From: Pierrick LE GALL
Subject: [Koha-cvs] koha C4/Circulation/Circ2.pm C4/Reserves2.pm C4...
Date: Wed, 17 May 2006 16:06:24 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         
Changes by:     Pierrick LE GALL <address@hidden>       06/05/17 16:06:24

Modified files:
        C4/Circulation : Circ2.pm 
        C4             : Reserves2.pm Koha.pm Biblio.pm 
Added files:
        reserve        : request.pl 
        koha-tmpl/intranet-tmpl/prog/en/reserve: request.tmpl 

Log message:
        New feature from SAN Ouest Provence: ability to reserve a specific item 
in
        the intranet. The development was made on branch 2.2 by Arnaud Laurin 
from
        Ouest Provence and integrated on HEAD by Pierrick Le Gall from INEO 
media
        system.
        
        New page reserve/request.pl taking a biblionumber as entry point.
        
        New functions:
        
        - C4::Biblio::get_iteminfos_of retrieves item informations for a list of
        itemnumbers
        
        - C4::Biblio::get_biblioiteminfos_of retrieves biblioitem informations 
for a
        list of biblioitemnumbers
        
        - C4::Biblio::get_itemnumbers_of retrieve the list of itemnumbers 
related to
        each biblionumber given in argument.
        
        - C4::Circulation::Circ2::get_return_date_of retrieves return date for a
        list of itemnumbers.
        
        - C4::Koha::get_itemtypeinfos_of retrieves the informations related to a
        list of itemtypes.
        
        - C4::Koha::get_branchinfos_of retrieves the informations related to a 
list
        of branchcodes.
        
        - C4::Koha::get_notforloan_label_of retrives the list of status/label 
for
        the authorised_values related to notforloan.
        
        - C4::Koha::get_infos_of is the generic function used by all 
get_*infos_of.
        
        - C4::Reserves2::GetNumberReservesFromBorrower
        
        - C4::Reserves2::GetFirstReserveDateFromItem
        
        Modified functions:
        
        - C4::Reserves2::FindReserves was simplified to be more readable.
        
        The reservation page is reserve/request.pl and is linked from nowhere as
        long as zebra is not stable yet on HEAD.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/koha/reserve/request.pl?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha/koha-tmpl/intranet-tmpl/prog/en/reserve/request.tmpl?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha/C4/Circulation/Circ2.pm.diff?tr1=1.101&tr2=1.102&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/koha/koha/C4/Reserves2.pm.diff?tr1=1.41&tr2=1.42&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/koha/koha/C4/Koha.pm.diff?tr1=1.31&tr2=1.32&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/koha/koha/C4/Biblio.pm.diff?tr1=1.170&tr2=1.171&r1=text&r2=text

Patches:
Index: koha/C4/Biblio.pm
diff -u koha/C4/Biblio.pm:1.170 koha/C4/Biblio.pm:1.171
--- koha/C4/Biblio.pm:1.170     Sat Apr 15 02:47:47 2006
+++ koha/C4/Biblio.pm   Wed May 17 16:06:24 2006
@@ -23,16 +23,17 @@
 use C4::Database;
 use C4::Date;
 use C4::Search;
+use C4::Koha;
 use MARC::Record;
 use MARC::File::USMARC;
 use MARC::File::XML;
-use Smart::Comments;
+# use Smart::Comments;
 
 use ZOOM;
 use vars qw($VERSION @ISA @EXPORT);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.170 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.171 $' =~ /\d+/g;
                 shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 @ISA = qw(Exporter);
@@ -82,6 +83,9 @@
   &get_item_from_barcode
   &MARCfind_MARCbibid_from_oldbiblionumber
 
+  get_itemnumbers_of
+  get_iteminfos_of
+  get_biblioiteminfos_of
 );
 
 =head1 NAME
@@ -2020,8 +2024,8 @@
 =cut
 
 sub newbiblioitem {
-    my ($dbh, $biblioitem) = @_;
-    #my $dbh        = C4::Context->dbh;
+    my ($biblioitem) = @_;
+    my $dbh        = C4::Context->dbh;
        # add biblio information to the hash
     my $MARCbiblio = MARCkoha2marcBiblio( $dbh, $biblioitem );
        $biblioitem->{marc} = $MARCbiblio->as_usmarc();
@@ -2504,6 +2508,7 @@
 #'
 sub bibitems {
     my ($bibnum) = @_;
+
     my $dbh   = C4::Context->dbh;
     my $sth   = $dbh->prepare("SELECT biblioitems.*,
                         itemtypes.*,
@@ -3049,6 +3054,64 @@
        return "$seg1-$seg2-$seg3-$seg4";
 }
 
+=head2 get_itemnumbers_of
+
+  my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
+
+Given a list of biblionumbers, return the list of corresponding itemnumbers
+for each biblionumber.
+
+Return a reference on a hash where keys are biblionumbers and values are
+references on array of itemnumbers.
+
+=cut
+sub get_itemnumbers_of {
+    my @biblionumbers = @_;
+
+    my $dbh = C4::Context->dbh;
+
+    my $query = '
+SELECT itemnumber,
+       biblionumber
+  FROM items
+  WHERE biblionumber IN (?'.(',?' x scalar @biblionumbers - 1).')
+';
+    my $sth = $dbh->prepare($query);
+    $sth->execute(@biblionumbers);
+
+    my %itemnumbers_of;
+
+    while (my ($itemnumber, $biblionumber) = $sth->fetchrow_array) {
+        push @{$itemnumbers_of{$biblionumber}}, $itemnumber;
+    }
+
+    return \%itemnumbers_of;
+}
+
+sub get_iteminfos_of {
+    my @itemnumbers = @_;
+
+    my $query = '
+SELECT *
+  FROM items
+  WHERE itemnumber IN ('.join(',', @itemnumbers).')
+';
+    return get_infos_of($query, 'itemnumber');
+}
+
+sub get_biblioiteminfos_of {
+    my @biblioitemnumbers = @_;
+
+    my $query = '
+SELECT biblioitemnumber,
+       publicationyear,
+       itemtype
+  FROM biblioitems
+  WHERE biblioitemnumber IN ('.join(',', @biblioitemnumbers).')
+';
+
+    return get_infos_of($query, 'biblioitemnumber');
+}
 
 END { }    # module clean-up code here (global destructor)
 
@@ -3062,8 +3125,52 @@
 
 =cut
 
-# $Id: Biblio.pm,v 1.170 2006/04/15 02:47:47 tgarip1957 Exp $
+# $Id: Biblio.pm,v 1.171 2006/05/17 16:06:24 plg Exp $
 # $Log: Biblio.pm,v $
+# Revision 1.171  2006/05/17 16:06:24  plg
+# New feature from SAN Ouest Provence: ability to reserve a specific item in
+# the intranet. The development was made on branch 2.2 by Arnaud Laurin from
+# Ouest Provence and integrated on HEAD by Pierrick Le Gall from INEO media
+# system.
+#
+# New page reserve/request.pl taking a biblionumber as entry point.
+#
+# New functions:
+#
+# - C4::Biblio::get_iteminfos_of retrieves item informations for a list of
+#   itemnumbers
+#
+# - C4::Biblio::get_biblioiteminfos_of retrieves biblioitem informations for a
+#   list of biblioitemnumbers
+#
+# - C4::Biblio::get_itemnumbers_of retrieve the list of itemnumbers related to
+#   each biblionumber given in argument.
+#
+# - C4::Circulation::Circ2::get_return_date_of retrieves return date for a
+#   list of itemnumbers.
+#
+# - C4::Koha::get_itemtypeinfos_of retrieves the informations related to a
+#   list of itemtypes.
+#
+# - C4::Koha::get_branchinfos_of retrieves the informations related to a list
+#   of branchcodes.
+#
+# - C4::Koha::get_notforloan_label_of retrives the list of status/label for
+#   the authorised_values related to notforloan.
+#
+# - C4::Koha::get_infos_of is the generic function used by all get_*infos_of.
+#
+# - C4::Reserves2::GetNumberReservesFromBorrower
+#
+# - C4::Reserves2::GetFirstReserveDateFromItem
+#
+# Modified functions:
+#
+# - C4::Reserves2::FindReserves was simplified to be more readable.
+#
+# The reservation page is reserve/request.pl and is linked from nowhere as
+# long as zebra is not stable yet on HEAD.
+#
 # Revision 1.170  2006/04/15 02:47:47  tgarip1957
 # Change the MARC Leader to UTF-8 incase user did not set it. Important for 
Zebra.
 # The new M::F::XML is sensitive to leader settings
Index: koha/C4/Circulation/Circ2.pm
diff -u koha/C4/Circulation/Circ2.pm:1.101 koha/C4/Circulation/Circ2.pm:1.102
--- koha/C4/Circulation/Circ2.pm:1.101  Mon Apr 10 20:42:18 2006
+++ koha/C4/Circulation/Circ2.pm        Wed May 17 16:06:23 2006
@@ -3,7 +3,7 @@
 
 package C4::Circulation::Circ2;
 
-# $Id: Circ2.pm,v 1.101 2006/04/10 20:42:18 tgarip1957 Exp $
+# $Id: Circ2.pm,v 1.102 2006/05/17 16:06:23 plg Exp $
 
 #package to deal with Returns
 #written 3/11/99 by address@hidden
@@ -64,10 +64,26 @@
 =cut
 
 @ISA = qw(Exporter);
address@hidden = qw(&getpatroninformation
-       &currentissues &getissues &getiteminformation &renewstatus &renewbook
-       &canbookbeissued &issuebook &returnbook &find_reserves &transferbook 
&decode
-       &calc_charges &listitemsforinventory &itemseen &fixdate);
address@hidden = qw(
+                &getpatroninformation
+                &currentissues
+                &getissues
+                &getiteminformation
+                &renewstatus
+                &renewbook
+                &canbookbeissued
+                &issuebook
+                &returnbook
+                &find_reserves
+                &transferbook
+                &decode
+                &calc_charges
+                &listitemsforinventory
+                &itemseen
+                &fixdate
+                get_return_date_of
+                get_transfert_infos
+        );
 
 # &getbranches &getprinters &getbranch &getprinter => moved to C4::Koha.pm
 
@@ -1916,6 +1932,41 @@
        
 }
 
+sub get_return_date_of {
+    my (@itemnumbers) = @_;
+
+    my $query = '
+SELECT date_due,
+       itemnumber
+  FROM issues
+  WHERE itemnumber IN ('.join(',', @itemnumbers).')
+';
+    return get_infos_of($query, 'itemnumber', 'date_due');
+}
+
+sub get_transfert_infos {
+    my ($itemnumber) = @_;
+
+    my $dbh = C4::Context->dbh;
+
+    my $query = '
+SELECT datesent,
+       frombranch,
+       tobranch
+  FROM branchtransfers
+  WHERE itemnumber = ?
+    AND datearrived IS NULL
+';
+    my $sth = $dbh->prepare($query);
+    $sth->execute($itemnumber);
+
+    my @row = $sth->fetchrow_array();
+
+    $sth->finish;
+
+    return @row;
+}
+
 1;
 __END__
 
Index: koha/C4/Koha.pm
diff -u koha/C4/Koha.pm:1.31 koha/C4/Koha.pm:1.32
--- koha/C4/Koha.pm:1.31        Fri Apr 14 09:32:57 2006
+++ koha/C4/Koha.pm     Wed May 17 16:06:24 2006
@@ -52,6 +52,7 @@
                        &getbranches &getbranch &getbranchdetail
                        &getprinters &getprinter
                        &getitemtypes &getitemtypeinfo
+                        get_itemtypeinfos_of
                        &getframeworks &getframeworkinfo
                        &getauthtypes &getauthtype
                        &getallthemes &getalllanguages
@@ -62,6 +63,9 @@
                         getitemtypeimagesrcfromurl
                        &getcities
                        &getroadtypes
+                        get_branchinfos_of
+                        get_notforloan_label_of
+                        get_infos_of
                        $DEBUG);
 
 use vars qw();
@@ -304,6 +308,21 @@
        return (\%itemtypes);
 }
 
+# FIXME this function is better and should replace getitemtypes everywhere
+sub get_itemtypeinfos_of {
+    my @itemtypes = @_;
+
+    my $query = '
+SELECT itemtype,
+       description,
+       notforloan
+  FROM itemtypes
+  WHERE itemtype IN ('.join(',', map({"'".$_."'"} @itemtypes)).')
+';
+
+    return get_infos_of($query, 'itemtype');
+}
+
 =head2 getauthtypes
 
   $authtypes = &getauthtypes();
@@ -767,6 +786,124 @@
        }
 }
 
+=head2 get_branchinfos_of
+
+  my $branchinfos_of = get_branchinfos_of(@branchcodes);
+
+Associates a list of branchcodes to the information of the branch, taken in
+branches table.
+
+Returns a href where keys are branchcodes and values are href where keys are
+branch information key.
+
+  print 'branchname is ', $branchinfos_of->{$code}->{branchname};
+
+=cut
+sub get_branchinfos_of {
+    my @branchcodes = @_;
+
+    my $query = '
+SELECT branchcode,
+       branchname
+  FROM branches
+  WHERE branchcode IN ('.join(',', map({"'".$_."'"} @branchcodes)).')
+';
+    return get_infos_of($query, 'branchcode');
+}
+
+=head2 get_notforloan_label_of
+
+  my $notforloan_label_of = get_notforloan_label_of();
+
+Each authorised value of notforloan (information available in items and
+itemtypes) is link to a single label.
+
+Returns a href where keys are authorised values and values are corresponding
+labels.
+
+  foreach my $authorised_value (keys %{$notforloan_label_of}) {
+    printf(
+        "authorised_value: %s => %s\n",
+        $authorised_value,
+        $notforloan_label_of->{$authorised_value}
+    );
+  }
+
+=cut
+sub get_notforloan_label_of {
+    my $dbh = C4::Context->dbh;
+
+    my $query = '
+SELECT authorised_value
+  FROM marc_subfield_structure
+  WHERE kohafield = \'items.notforloan\'
+  LIMIT 0, 1
+';
+    my $sth = $dbh->prepare($query);
+    $sth->execute();
+    my ($statuscode) = $sth->fetchrow_array();
+
+    $query = '
+SELECT lib,
+       authorised_value
+  FROM authorised_values
+  WHERE category = ?
+';
+    $sth = $dbh->prepare($query);
+    $sth->execute($statuscode);
+    my %notforloan_label_of;
+    while (my $row = $sth->fetchrow_hashref) {
+        $notforloan_label_of{ $row->{authorised_value} } = $row->{lib};
+    }
+    $sth->finish;
+
+    return \%notforloan_label_of;
+}
+
+=head2 get_infos_of
+
+Return a href where a key is associated to a href. You give a query, the
+name of the key among the fields returned by the query. If you also give as
+third argument the name of the value, the function returns a href of scalar.
+
+  my $query = '
+SELECT itemnumber,
+       notforloan,
+       barcode
+  FROM items
+';
+
+  # generic href of any information on the item, href of href.
+  my $iteminfos_of = get_infos_of($query, 'itemnumber');
+  print $iteminfos_of->{$itemnumber}{barcode};
+
+  # specific information, href of scalar
+  my $barcode_of_item = get_infos_of($query, 'itemnumber', 'barcode');
+  print $barcode_of_item->{$itemnumber};
+
+=cut
+sub get_infos_of {
+    my ($query, $key_name, $value_name) = @_;
+
+    my $dbh = C4::Context->dbh;
+
+    my $sth = $dbh->prepare($query);
+    $sth->execute();
+
+    my %infos_of;
+    while (my $row = $sth->fetchrow_hashref) {
+        if (defined $value_name) {
+            $infos_of{ $row->{$key_name} } = $row->{$value_name};
+        }
+        else {
+            $infos_of{ $row->{$key_name} } = $row;
+        }
+    }
+    $sth->finish;
+
+    return \%infos_of;
+}
+
 1;
 __END__
 
Index: koha/C4/Reserves2.pm
diff -u koha/C4/Reserves2.pm:1.41 koha/C4/Reserves2.pm:1.42
--- koha/C4/Reserves2.pm:1.41   Wed Oct 26 09:12:33 2005
+++ koha/C4/Reserves2.pm        Wed May 17 16:06:24 2006
@@ -3,7 +3,7 @@
 
 package C4::Reserves2;
 
-# $Id: Reserves2.pm,v 1.41 2005/10/26 09:12:33 tipaul Exp $
+# $Id: Reserves2.pm,v 1.42 2006/05/17 16:06:24 plg Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -66,6 +66,8 @@
     &UpdateReserve
     &getreservetitle
     &Findgroupreserve
+    GetFirstReserveDateFromItem
+    GetNumberReservesFromBorrower
 );
 
 # make all your functions, whether exported or not;
@@ -93,79 +95,123 @@
 
 C<$count> is the number of elements in C<$results>.
 
-C<$results> is a reference-to-array; each element is a
-reference-to-hash, whose keys are (I think) all of the fields of the
-reserves, borrowers, and biblio tables of the Koha database.
+C<$results> is a reference to an array of references of hashes. Each hash
+has for keys a list of column from reserves table (see details in function).
 
 =cut
 #'
 sub FindReserves {
-       my ($bib,$bor)address@hidden;
-       my $dbh = C4::Context->dbh;
-       # Find the desired items in the reserves
-       my $query="SELECT *,reserves.branchcode,biblio.title AS btitle, 
reserves.timestamp as rtimestamp FROM reserves,borrowers,biblio ";
-       # FIXME - These three bits of SQL seem to contain a fair amount of
-       # redundancy. Wouldn't it be better to have a @clauses array, add
-       # one or two clauses as necessary, then join(" AND ", @clauses) ?
-       # FIXME: not keen on quote() and interpolation either, but it looks safe
-       if ($bib ne ''){
-               $bib = $dbh->quote($bib);
-               if ($bor ne ''){
-                       # Both $bib and $bor specified
-                       # Find a particular book for a particular patron
-                       $bor = $dbh->quote($bor);
-                       $query .=  " where reserves.biblionumber   = $bib
-                                               and borrowers.borrowernumber = 
$bor
-                                               and reserves.borrowernumber = 
borrowers.borrowernumber
-                                               and biblio.biblionumber     = 
$bib
-                                               and cancellationdate is NULL
-                                               and (found <> 'F' or found is 
NULL)";
-               } else {
-                       # $bib specified, but not $bor
-                       # Find a particular book for all patrons
-                       $query .= " where reserves.borrowernumber = 
borrowers.borrowernumber
-                                       and biblio.biblionumber     = $bib
-                                       and reserves.biblionumber   = $bib
-                                       and cancellationdate is NULL
-                                       and (found <> 'F' or found is NULL)";
-               }
-       } else {
-               # FIXME - Check that $bor was given
-               # No $bib given.
-               # Find all books for the given patron.
-               $query .= " where borrowers.borrowernumber = $bor
-                                       and reserves.borrowernumber  = 
borrowers.borrowernumber
-                                       and reserves.biblionumber    = 
biblio.biblionumber
-                                       and cancellationdate is NULL and
-                                       (found <> 'F' or found is NULL)";
-       }
-       $query.=" order by priority";
-       my $sth=$dbh->prepare($query);
-       $sth->execute;
-       my @results;
-       while (my $data=$sth->fetchrow_hashref){
-               # FIXME - What is this if-statement doing? How do constraints 
work?
-               if ($data->{'constrainttype'} eq 'o') {
-                       my $csth=$dbh->prepare("SELECT biblioitemnumber FROM 
reserveconstraints
-                                                       WHERE biblionumber   = ?
-                                                       AND borrowernumber = ?
-                                                       AND reservedate    = 
?");
-                       $csth->execute($data->{'biblionumber'}, 
$data->{'borrowernumber'}, $data->{'reservedate'});
-                       my ($bibitemno) = $csth->fetchrow_array;
-                       $csth->finish;
-                       # Look up the book we just found.
-                       my $bdata = bibitemdata($bibitemno);
-                       # Add the results of this latest search to the current
-                       # results.
-                       # FIXME - An 'each' would probably be more efficient.
-                       foreach my $key (keys %$bdata) {
-                               $data->{$key} = $bdata->{$key};
-                       }
-               }
-               push @results, $data;
-       }
-       $sth->finish;
-       return($#results+1,address@hidden);
+    my ($bib, $bor) = @_;
+    my $dbh = C4::Context->dbh;
+    my @bind;
+
+    # Find the desired items in the reserves
+    my $query = '
+SELECT branchcode,
+       timestamp AS rtimestamp,
+       priority,
+       biblionumber,
+       borrowernumber,
+       reservedate,
+       constrainttype,
+       found
+  FROM reserves
+  WHERE cancellationdate IS NULL
+    AND        (found <> \'F\' OR found IS NULL)
+';
+
+    if ($bib ne '') {
+        $query.= '
+    AND biblionumber = ?
+';
+        push @bind, $bib;
+    }
+
+    if ($bor ne '') {
+        $query.= '
+    AND borrowernumber = ?
+';
+        push @bind, $bor;
+    }
+
+    $query.= '
+  ORDER BY priority
+';
+    my $sth=$dbh->prepare($query);
+    $sth->execute(@bind);
+    my @results;
+    while (my $data = $sth->fetchrow_hashref){
+        # FIXME - What is this if-statement doing? How do constraints work?
+        if ($data->{constrainttype} eq 'o') {
+            $query = '
+SELECT biblioitemnumber
+  FROM reserveconstraints
+  WHERE biblionumber   = ?
+    AND borrowernumber = ?
+    AND reservedate    = ?
+';
+            my $csth=$dbh->prepare($query);
+            $csth->execute(
+                $data->{biblionumber},
+                $data->{borrowernumber},
+                $data->{reservedate},
+            );
+            my ($bibitemno) = $csth->fetchrow_array;
+            $csth->finish;
+            # Look up the book we just found.
+            my $bdata = bibitemdata($bibitemno);
+            # Add the results of this latest search to the current
+            # results.
+            # FIXME - An 'each' would probably be more efficient.
+            foreach my $key (keys %$bdata) {
+                $data->{$key} = $bdata->{$key};
+            }
+        }
+        push @results, $data;
+    }
+    $sth->finish;
+
+    return($#results+1,address@hidden);
+}
+
+sub GetNumberReservesFromBorrower {
+    my ($borrowernumber) = @_;
+
+    my $dbh = C4::Context->dbh;
+
+    my $query = '
+SELECT COUNT(*) AS counter
+  FROM reserves
+  WHERE borrowernumber = ?
+    AND cancellationdate IS NULL
+    AND (found != \'F\' OR found IS NULL)
+';
+    my $sth = $dbh->prepare($query);
+    $sth->execute($borrowernumber);
+    my $row = $sth->fetchrow_hashref;
+    $sth->finish;
+
+    return $row->{counter};
+}
+
+sub GetFirstReserveDateFromItem {
+    my ($itemnumber) = @_;
+
+    my $dbh = C4::Context->dbh;
+
+    my $query = '
+SELECT reservedate
+  FROM reserves
+  WHERE itemnumber = ?
+    AND cancellationdate IS NULL
+    AND (found != \'F\' OR found IS NULL)
+';
+    my $sth = $dbh->prepare($query);
+    $sth->execute($itemnumber);
+    my $row = $sth->fetchrow_hashref;
+    $sth->finish;
+
+    return $row->{reservedate};
 }
 
 =item CheckReserves




reply via email to

[Prev in Thread] Current Thread [Next in Thread]