Skip to content

Commit

Permalink
New feature from SAN Ouest Provence: ability to reserve a specific it…
Browse files Browse the repository at this point in the history
…em 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.
  • Loading branch information
plg committed May 17, 2006
1 parent a96d6fd commit 68924c5
Show file tree
Hide file tree
Showing 6 changed files with 1,139 additions and 76 deletions.
113 changes: 110 additions & 3 deletions C4/Biblio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ use C4::Context;
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);
Expand Down Expand Up @@ -82,6 +83,9 @@ $VERSION = do { my @v = '$Revision$' =~ /\d+/g;
&get_item_from_barcode
&MARCfind_MARCbibid_from_oldbiblionumber
get_itemnumbers_of
get_iteminfos_of
get_biblioiteminfos_of
);

=head1 NAME
Expand Down Expand Up @@ -2020,8 +2024,8 @@ create a biblioitem, the parameter is a hash
=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();
Expand Down Expand Up @@ -2504,6 +2508,7 @@ all copies are lost; otherwise, there is at least one copy available.
#'
sub bibitems {
my ($bibnum) = @_;

my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT biblioitems.*,
itemtypes.*,
Expand Down Expand Up @@ -3049,6 +3054,64 @@ sub DisplayISBN {
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)

Expand All @@ -3064,6 +3127,50 @@ Paul POULAIN paul.poulain@free.fr

# $Id$
# $Log$
# 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
Expand Down
59 changes: 55 additions & 4 deletions C4/Circulation/Circ2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,26 @@ Also deals with stocktaking.
=cut

@ISA = qw(Exporter);
@EXPORT = qw(&getpatroninformation
&currentissues &getissues &getiteminformation &renewstatus &renewbook
&canbookbeissued &issuebook &returnbook &find_reserves &transferbook &decode
&calc_charges &listitemsforinventory &itemseen &fixdate);
@EXPORT = 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

Expand Down Expand Up @@ -1916,6 +1932,41 @@ sub fixdate {

}

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__
Expand Down
137 changes: 137 additions & 0 deletions C4/Koha.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Koha.pm provides many functions for Koha scripts.
&getbranches &getbranch &getbranchdetail
&getprinters &getprinter
&getitemtypes &getitemtypeinfo
get_itemtypeinfos_of
&getframeworks &getframeworkinfo
&getauthtypes &getauthtype
&getallthemes &getalllanguages
Expand All @@ -62,6 +63,9 @@ Koha.pm provides many functions for Koha scripts.
getitemtypeimagesrcfromurl
&getcities
&getroadtypes
get_branchinfos_of
get_notforloan_label_of
get_infos_of
$DEBUG);

use vars qw();
Expand Down Expand Up @@ -304,6 +308,21 @@ sub getitemtypes {
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();
Expand Down Expand Up @@ -767,6 +786,124 @@ while (my $data=$sth->fetchrow_hashref){
}
}

=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__
Expand Down
Loading

0 comments on commit 68924c5

Please sign in to comment.