1 package C4::BookShelves; #assumes C4/BookShelves
6 #requires DBI.pm to be installed
9 # Copyright 2000-2002 Katipo Communications
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA 02111-1307 USA
30 use C4::Circulation::Circ2;
31 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
33 # set the version for version checking
38 C4::BookShelves - Functions for manipulating Koha virtual bookshelves
46 This module provides functions for manipulating virtual bookshelves,
47 including creating and deleting bookshelves, and adding and removing
48 items to and from bookshelves.
57 @EXPORT = qw(&GetShelfList &GetShelfContents &AddToShelf &RemoveFromShelf &AddShelf &RemoveShelf);
58 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
60 # your exported package globals go here,
61 # as well as any optionally exported functions
63 @EXPORT_OK = qw($Var1 %Hashit); # FIXME - Never used
66 # non-exported package globals go here
67 use vars qw(@more $stuff); # FIXME - Never used
69 # initalize package globals, first exported ones
74 # then the others (which are still accessible as $Some::Module::stuff)
79 # all file-scoped lexicals must be created before
80 # the functions below that use them.
82 # file-private lexicals go here
87 # here's a file-private function as a closure,
88 # callable as &$priv_func; it cannot be prototyped.
94 # make all your functions, whether exported or not;
100 $shelflist = &GetShelfList();
101 ($shelfnumber, $shelfhash) = each %{$shelflist};
103 Looks up the virtual bookshelves, and returns a summary. C<$shelflist>
104 is a reference-to-hash. The keys are the bookshelf numbers
105 (C<$shelfnumber>, above), and the values (C<$shelfhash>, above) are
106 themselves references-to-hash, with the following keys:
110 =item C<$shelfhash-E<gt>{shelfname}>
112 A string. The name of the shelf.
114 =item C<$shelfhash-E<gt>{count}>
116 The number of books on that bookshelf.
122 # FIXME - Wouldn't it be more intuitive to return a list, rather than
123 # a reference-to-hash? The shelf number can be just another key in the
126 # FIXME - These two database queries can be combined into one:
127 # SELECT bookshelf.shelfnumber, bookshelf.shelfname,
128 # count(shelfcontents.itemnumber)
130 # LEFT JOIN shelfcontents
131 # ON bookshelf.shelfnumber = shelfcontents.shelfnumber
132 # GROUP BY bookshelf.shelfnumber
133 my $sth=$dbh->prepare("select shelfnumber,shelfname from bookshelf");
136 while (my ($shelfnumber, $shelfname) = $sth->fetchrow) {
137 my $sti=$dbh->prepare("select count(*) from shelfcontents where shelfnumber=$shelfnumber");
138 # FIXME - Should there be an "order by" in here somewhere?
140 my ($count) = $sti->fetchrow;
141 $shelflist{$shelfnumber}->{'shelfname'}=$shelfname;
142 $shelflist{$shelfnumber}->{'count'}=$count;
147 =item GetShelfContents
149 $itemlist = &GetShelfContents($env, $shelfnumber);
151 Looks up information about the contents of virtual bookshelf number
154 Returns a reference-to-array, whose elements are references-to-hash,
155 as returned by C<&getiteminformation>.
157 I don't know what C<$env> is.
161 sub GetShelfContents {
162 my ($env, $shelfnumber) = @_;
164 my $sth=$dbh->prepare("select itemnumber from shelfcontents where shelfnumber=$shelfnumber order by itemnumber");
166 while (my ($itemnumber) = $sth->fetchrow) {
167 my ($item) = getiteminformation($env, $itemnumber, 0);
168 push (@itemlist, $item);
171 # FIXME - Wouldn't it be more intuitive to return a list,
172 # rather than a reference-to-list?
177 &AddToShelf($env, $itemnumber, $shelfnumber);
179 Adds item number C<$itemnumber> to virtual bookshelf number
180 C<$shelfnumber>, unless that item is already on that shelf.
187 my ($env, $itemnumber, $shelfnumber) = @_;
188 my $sth=$dbh->prepare("select * from shelfcontents where shelfnumber=$shelfnumber and itemnumber=$itemnumber");
193 $sth=$dbh->prepare("insert into shelfcontents (shelfnumber, itemnumber, flags) values ($shelfnumber, $itemnumber, 0)");
194 # FIXME - The default for 'flags' is NULL.
200 =item RemoveFromShelf
202 &RemoveFromShelf($env, $itemnumber, $shelfnumber);
204 Removes item number C<$itemnumber> from virtual bookshelf number
205 C<$shelfnumber>. If the item wasn't on that bookshelf to begin with,
212 sub RemoveFromShelf {
213 my ($env, $itemnumber, $shelfnumber) = @_;
214 my $sth=$dbh->prepare("delete from shelfcontents where shelfnumber=$shelfnumber and itemnumber=$itemnumber");
220 ($status, $msg) = &AddShelf($env, $shelfname);
222 Creates a new virtual bookshelf with name C<$shelfname>.
224 Returns a two-element array, where C<$status> is 0 if the operation
225 was successful, or non-zero otherwise. C<$msg> is "Done" in case of
226 success, or an error message giving the reason for failure.
232 # FIXME - Perhaps this could/should return the number of the new bookshelf
235 my ($env, $shelfname) = @_;
236 my $q_shelfname=$dbh->quote($shelfname);
237 my $sth=$dbh->prepare("select * from bookshelf where shelfname=$q_shelfname");
240 return(1, "Shelf \"$shelfname\" already exists");
242 $sth=$dbh->prepare("insert into bookshelf (shelfname) values ($q_shelfname)");
250 ($status, $msg) = &RemoveShelf($env, $shelfnumber);
252 Deletes virtual bookshelf number C<$shelfnumber>. The bookshelf must
255 Returns a two-element array, where C<$status> is 0 if the operation
256 was successful, or non-zero otherwise. C<$msg> is "Done" in case of
257 success, or an error message giving the reason for failure.
264 my ($env, $shelfnumber) = @_;
265 my $sth=$dbh->prepare("select count(*) from shelfcontents where shelfnumber=$shelfnumber");
267 my ($count)=$sth->fetchrow;
269 return (1, "Shelf has $count items on it. Please remove all items before deleting this shelf.");
271 $sth=$dbh->prepare("delete from bookshelf where shelfnumber=$shelfnumber");
277 END { } # module clean-up code here (global destructor)
283 # Revision 1.6 2002/09/23 13:50:30 arensb
284 # Fixed missing bit in POD.
286 # Revision 1.5 2002/09/22 17:29:17 arensb
288 # Added some FIXME comments.
289 # Removed useless trailing whitespace.
291 # Revision 1.4 2002/08/14 18:12:51 tonnesen
292 # Added copyright statement to all .pl and .pm files
294 # Revision 1.3 2002/07/02 17:48:06 tonnesen
295 # Merged in updates from rel-1-2
297 # Revision 1.2.2.1 2002/06/26 20:46:48 tonnesen
298 # Inserting some changes I made locally a while ago.
308 Koha Developement team <info@koha.org>
314 L<C4::Circulation::Circ2(3)>