1 package C4::BookShelves;
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
26 use C4::Circulation::Circ2;
27 use vars qw($VERSION @ISA @EXPORT);
29 # set the version for version checking
34 C4::BookShelves - Functions for manipulating Koha virtual bookshelves
42 This module provides functions for manipulating virtual bookshelves,
43 including creating and deleting bookshelves, and adding and removing
44 items to and from bookshelves.
53 @EXPORT = qw(&GetShelfList &GetShelfContents &AddToShelf &RemoveFromShelf &AddShelf &RemoveShelf);
55 my $dbh = C4::Context->dbh;
59 $shelflist = &GetShelfList();
60 ($shelfnumber, $shelfhash) = each %{$shelflist};
62 Looks up the virtual bookshelves, and returns a summary. C<$shelflist>
63 is a reference-to-hash. The keys are the bookshelf numbers
64 (C<$shelfnumber>, above), and the values (C<$shelfhash>, above) are
65 themselves references-to-hash, with the following keys:
69 =item C<$shelfhash-E<gt>{shelfname}>
71 A string. The name of the shelf.
73 =item C<$shelfhash-E<gt>{count}>
75 The number of books on that bookshelf.
81 # FIXME - Wouldn't it be more intuitive to return a list, rather than
82 # a reference-to-hash? The shelf number can be just another key in the
85 # FIXME - These two database queries can be combined into one:
86 # SELECT bookshelf.shelfnumber, bookshelf.shelfname,
87 # count(shelfcontents.itemnumber)
89 # LEFT JOIN shelfcontents
90 # ON bookshelf.shelfnumber = shelfcontents.shelfnumber
91 # GROUP BY bookshelf.shelfnumber
92 my $sth=$dbh->prepare("select shelfnumber,shelfname from bookshelf");
95 while (my ($shelfnumber, $shelfname) = $sth->fetchrow) {
96 my $sti=$dbh->prepare("select count(*) from shelfcontents where shelfnumber=$shelfnumber");
97 # FIXME - Should there be an "order by" in here somewhere?
99 my ($count) = $sti->fetchrow;
100 $shelflist{$shelfnumber}->{'shelfname'}=$shelfname;
101 $shelflist{$shelfnumber}->{'count'}=$count;
106 =item GetShelfContents
108 $itemlist = &GetShelfContents($env, $shelfnumber);
110 Looks up information about the contents of virtual bookshelf number
113 Returns a reference-to-array, whose elements are references-to-hash,
114 as returned by C<&getiteminformation>.
116 I don't know what C<$env> is.
120 sub GetShelfContents {
121 my ($env, $shelfnumber) = @_;
123 my $sth=$dbh->prepare("select itemnumber from shelfcontents where shelfnumber=$shelfnumber order by itemnumber");
125 while (my ($itemnumber) = $sth->fetchrow) {
126 my ($item) = getiteminformation($env, $itemnumber, 0);
127 push (@itemlist, $item);
130 # FIXME - Wouldn't it be more intuitive to return a list,
131 # rather than a reference-to-list?
136 &AddToShelf($env, $itemnumber, $shelfnumber);
138 Adds item number C<$itemnumber> to virtual bookshelf number
139 C<$shelfnumber>, unless that item is already on that shelf.
146 my ($env, $itemnumber, $shelfnumber) = @_;
147 my $sth=$dbh->prepare("select * from shelfcontents where shelfnumber=$shelfnumber and itemnumber=$itemnumber");
152 $sth=$dbh->prepare("insert into shelfcontents (shelfnumber, itemnumber, flags) values ($shelfnumber, $itemnumber, 0)");
153 # FIXME - The default for 'flags' is NULL.
159 =item RemoveFromShelf
161 &RemoveFromShelf($env, $itemnumber, $shelfnumber);
163 Removes item number C<$itemnumber> from virtual bookshelf number
164 C<$shelfnumber>. If the item wasn't on that bookshelf to begin with,
171 sub RemoveFromShelf {
172 my ($env, $itemnumber, $shelfnumber) = @_;
173 my $sth=$dbh->prepare("delete from shelfcontents where shelfnumber=$shelfnumber and itemnumber=$itemnumber");
179 ($status, $msg) = &AddShelf($env, $shelfname);
181 Creates a new virtual bookshelf with name C<$shelfname>.
183 Returns a two-element array, where C<$status> is 0 if the operation
184 was successful, or non-zero otherwise. C<$msg> is "Done" in case of
185 success, or an error message giving the reason for failure.
191 # FIXME - Perhaps this could/should return the number of the new bookshelf
194 my ($env, $shelfname) = @_;
195 my $q_shelfname=$dbh->quote($shelfname);
196 my $sth=$dbh->prepare("select * from bookshelf where shelfname=$q_shelfname");
199 return(1, "Shelf \"$shelfname\" already exists");
201 $sth=$dbh->prepare("insert into bookshelf (shelfname) values ($q_shelfname)");
209 ($status, $msg) = &RemoveShelf($env, $shelfnumber);
211 Deletes virtual bookshelf number C<$shelfnumber>. The bookshelf must
214 Returns a two-element array, where C<$status> is 0 if the operation
215 was successful, or non-zero otherwise. C<$msg> is "Done" in case of
216 success, or an error message giving the reason for failure.
223 my ($env, $shelfnumber) = @_;
224 my $sth=$dbh->prepare("select count(*) from shelfcontents where shelfnumber=$shelfnumber");
226 my ($count)=$sth->fetchrow;
228 return (1, "Shelf has $count items on it. Please remove all items before deleting this shelf.");
230 $sth=$dbh->prepare("delete from bookshelf where shelfnumber=$shelfnumber");
236 END { } # module clean-up code here (global destructor)
242 # Revision 1.9 2002/10/13 08:29:18 arensb
243 # Deleted unused variables.
244 # Removed trailing whitespace.
246 # Revision 1.8 2002/10/10 04:32:44 arensb
247 # Simplified references.
249 # Revision 1.7 2002/10/05 09:50:10 arensb
250 # Merged with arensb-context branch: use C4::Context->dbh instead of
251 # &C4Connect, and generally prefer C4::Context over C4::Database.
253 # Revision 1.6.2.1 2002/10/04 02:24:43 arensb
254 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
257 # Revision 1.6 2002/09/23 13:50:30 arensb
258 # Fixed missing bit in POD.
260 # Revision 1.5 2002/09/22 17:29:17 arensb
262 # Added some FIXME comments.
263 # Removed useless trailing whitespace.
265 # Revision 1.4 2002/08/14 18:12:51 tonnesen
266 # Added copyright statement to all .pl and .pm files
268 # Revision 1.3 2002/07/02 17:48:06 tonnesen
269 # Merged in updates from rel-1-2
271 # Revision 1.2.2.1 2002/06/26 20:46:48 tonnesen
272 # Inserting some changes I made locally a while ago.
282 Koha Developement team <info@koha.org>
286 C4::Circulation::Circ2(3)