1 package C4::VirtualShelves;
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use constant SHELVES_MASTHEAD_MAX => 10; #number under Lists button in masthead
29 use constant SHELVES_COMBO_MAX => 10; #add to combo in search
30 use constant SHELVES_MGRPAGE_MAX => 20; #managing page
31 use constant SHELVES_POPUP_MAX => 40; #addbybiblio popup
33 use constant SHARE_INVITATION_EXPIRY_DAYS => 14; #two weeks to accept
35 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
38 # set the version for version checking
39 $VERSION = 3.07.00.049;
52 C4::VirtualShelves - Functions for manipulating Koha virtual shelves
56 use C4::VirtualShelves;
60 This module provides functions for manipulating virtual shelves,
61 including creating and deleting virtual shelves, and adding and removing
62 bibs to and from virtual shelves.
66 =head2 GetSomeShelfNames
68 Returns shelf names and numbers for Add to combo of search results and Lists button of OPAC header.
72 sub GetSomeShelfNames {
73 my ($owner, $purpose, $adding_allowed)= @_;
74 my ($bar, $pub, @params);
75 my $dbh = C4::Context->dbh;
77 my $bquery = 'SELECT vs.shelfnumber, vs.shelfname FROM virtualshelves vs ';
78 my $limit= ShelvesMax($purpose);
80 my $qry1= $bquery."WHERE vs.category=2 ";
81 $qry1.= "AND (allow_add=1 OR owner=?) " if $adding_allowed;
82 push @params, $owner||0 if $adding_allowed;
83 $qry1.= "ORDER BY vs.lastmodified DESC LIMIT $limit";
85 unless($adding_allowed && (!defined($owner) || $owner<=0)) {
86 #if adding items, user should be known
87 $pub= $dbh->selectall_arrayref($qry1,{Slice=>{}},@params);
91 my $qry2= $bquery. qq{
92 LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber AND sh.borrowernumber=?
93 WHERE vs.category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
94 @params=($owner,$owner,$owner);
95 $qry2.= "AND (allow_add=1 OR owner=?) " if $adding_allowed;
96 push @params, $owner if $adding_allowed;
97 $qry2.= "ORDER BY vs.lastmodified DESC ";
98 $qry2.= "LIMIT $limit";
99 $bar= $dbh->selectall_arrayref($qry2,{Slice=>{}},@params);
102 return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar);
107 $howmany= ShelvesMax($context);
109 Tells how much shelves are shown in which context.
110 POPUP refers to addbybiblionumber popup, MGRPAGE is managing page (in opac or
111 staff), COMBO refers to the Add to-combo of search results. MASTHEAD is the
112 main Koha toolbar with Lists button.
118 return SHELVES_POPUP_MAX if $which eq 'POPUP';
119 return SHELVES_MGRPAGE_MAX if $which eq 'MGRPAGE';
120 return SHELVES_COMBO_MAX if $which eq 'COMBO';
121 return SHELVES_MASTHEAD_MAX if $which eq 'MASTHEAD';
122 return SHELVES_MASTHEAD_MAX;
125 =head2 HandleDelBorrower
127 HandleDelBorrower($borrower);
129 When a member is deleted (DelMember in Members.pm), you should call me first.
130 This routine deletes/moves lists and entries for the deleted member/borrower.
131 Lists owned by the borrower are deleted, but entries from the borrower to
132 other lists are kept.
136 sub HandleDelBorrower {
139 my $dbh = C4::Context->dbh;
141 #Delete all lists and all shares of this borrower
142 #Consistent with the approach Koha uses on deleting individual lists
143 #Note that entries in virtualshelfcontents added by this borrower to
144 #lists of others will be handled by a table constraint: the borrower
145 #is set to NULL in those entries.
146 $query="DELETE FROM virtualshelves WHERE owner=?";
147 $dbh->do($query,undef,($borrower));
150 #We could handle the above deletes via a constraint too.
151 #But a new BZ report 11889 has been opened to discuss another approach.
152 #Instead of deleting we could also disown lists (based on a pref).
153 #In that way we could save shared and public lists.
154 #The current table constraints support that idea now.
155 #This pref should then govern the results of other routines/methods such as
156 #Koha::Virtualshelf->new->delete too.
160 my ($owner, $category) = @_;
162 # Find out how many shelves total meet the submitted criteria...
164 my $dbh = C4::Context->dbh;
165 my $query = "SELECT count(*) FROM virtualshelves vs ";
168 LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
169 AND sh.borrowernumber=?
170 WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
171 @params= ($owner, $owner, $owner);
174 $query.='WHERE category=2';
177 my $sth = $dbh->prepare($query);
178 $sth->execute(@params);
179 my ($total)= $sth->fetchrow;
189 Koha Development Team <http://koha-community.org/>
193 C4::Circulation::Circ2(3)