From 6b62fb397028fb7afae4ba15c7d374fb35e9205c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 17 Aug 2015 20:45:34 +0100 Subject: [PATCH] Bug 14544: Get rid of GetSomeShelfNames Signed-off-by: Alex Arnaud Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- C4/Auth.pm | 44 +++++++++----- C4/VirtualShelves.pm | 39 ------------ Koha/Virtualshelves.pm | 39 ++++++++++++ catalogue/search.pl | 29 ++++++--- installer/data/mysql/kohastructure.sql | 6 +- .../prog/en/modules/catalogue/results.tt | 41 +++++++++---- .../prog/en/modules/virtualshelves/shelves.tt | 26 ++++---- .../bootstrap/en/includes/masthead.inc | 56 ++++++++++------- .../bootstrap/en/modules/opac-results.tt | 60 ++++++++++--------- members/deletemem.pl | 3 +- misc/cronjobs/delete_patrons.pl | 3 +- opac/opac-search.pl | 27 ++++++--- opac/opac-shelves.pl | 6 -- tools/cleanborrowers.pl | 3 +- virtualshelves/shelves.pl | 25 +++++--- 15 files changed, 245 insertions(+), 162 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index b8ee9a56c1..8c6d747da4 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -226,13 +226,21 @@ sub get_template_and_user { $template->param( sessionID => $sessionID ); if ( $in->{'type'} eq 'opac' ) { - require C4::VirtualShelves; - my ( $total, $pubshelves, $barshelves ) = C4::VirtualShelves::GetSomeShelfNames( $borrowernumber, 'MASTHEAD' ); + require Koha::Virtualshelves; + my $some_private_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $borrowernumber, + category => 1, + } + ); + my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( + { + category => 2, + } + ); $template->param( - pubshelves => $total->{pubtotal}, - pubshelvesloop => $pubshelves, - barshelves => $total->{bartotal}, - barshelvesloop => $barshelves, + some_private_shelves => $some_private_shelves, + some_public_shelves => $some_public_shelves, ); } @@ -363,11 +371,14 @@ sub get_template_and_user { $template->param( sessionID => $sessionID ); if ( $in->{'type'} eq 'opac' ){ - require C4::VirtualShelves; - my ( $total, $pubshelves ) = C4::VirtualShelves::GetSomeShelfNames( undef, 'MASTHEAD' ); + require Koha::Virtualshelves; + my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( + { + category => 2, + } + ); $template->param( - pubshelves => $total->{pubtotal}, - pubshelvesloop => $pubshelves, + some_public_shelves => $some_public_shelves, ); } } @@ -739,7 +750,7 @@ sub checkauth { # state variables my $loggedin = 0; my %info; - my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); + my ( $userid, $cookie, $sessionID, $flags ); my $logout = $query->param('logout.x'); my $anon_search_history; @@ -1232,11 +1243,14 @@ sub checkauth { $template->param( loginprompt => 1 ) unless $info{'nopermission'}; if ( $type eq 'opac' ) { - require C4::VirtualShelves; - my ( $total, $pubshelves ) = C4::VirtualShelves::GetSomeShelfNames( undef, 'MASTHEAD' ); + require Koha::Virtualshelves; + my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( + { + category => 2, + } + ); $template->param( - pubshelves => $total->{pubtotal}, - pubshelvesloop => $pubshelves, + some_public_shelves => $some_public_shelves, ); } diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index e85f920485..29126cc0be 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -63,45 +63,6 @@ bibs to and from virtual shelves. =head1 FUNCTIONS -=head2 GetSomeShelfNames - -Returns shelf names and numbers for Add to combo of search results and Lists button of OPAC header. - -=cut - -sub GetSomeShelfNames { - my ($owner, $purpose, $adding_allowed)= @_; - my ($bar, $pub, @params); - my $dbh = C4::Context->dbh; - - my $bquery = 'SELECT vs.shelfnumber, vs.shelfname FROM virtualshelves vs '; - my $limit= ShelvesMax($purpose); - - my $qry1= $bquery."WHERE vs.category=2 "; - $qry1.= "AND (allow_add=1 OR owner=?) " if $adding_allowed; - push @params, $owner||0 if $adding_allowed; - $qry1.= "ORDER BY vs.lastmodified DESC LIMIT $limit"; - - unless($adding_allowed && (!defined($owner) || $owner<=0)) { - #if adding items, user should be known - $pub= $dbh->selectall_arrayref($qry1,{Slice=>{}},@params); - } - - if($owner) { - my $qry2= $bquery. qq{ - LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber AND sh.borrowernumber=? - WHERE vs.category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; - @params=($owner,$owner,$owner); - $qry2.= "AND (allow_add=1 OR owner=?) " if $adding_allowed; - push @params, $owner if $adding_allowed; - $qry2.= "ORDER BY vs.lastmodified DESC "; - $qry2.= "LIMIT $limit"; - $bar= $dbh->selectall_arrayref($qry2,{Slice=>{}},@params); - } - - return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar); -} - =head2 ShelvesMax $howmany= ShelvesMax($context); diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 65b068059b..34b1003200 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -80,6 +80,45 @@ sub get_public_shelves { ); } +sub get_some_shelves { + my ( $self, $params ) = @_; + my $borrowernumber = $params->{borrowernumber} || 0; + my $category = $params->{category} || 1; + my $add_allowed = $params->{add_allowed}; + + my @conditions; + if ( $add_allowed ) { + push @conditions, { + -or => + { + "me.allow_add" => 1, + "me.owner" => $borrowernumber, + } + }; + } + if ( $category == 1 ) { + push @conditions, { + -or => + { + "virtualshelfshares.borrowernumber" => $borrowernumber, + "me.owner" => $borrowernumber, + } + }; + } + + $self->search( + { + category => $category, + ( @conditions ? ( -and => \@conditions ) : () ), + }, + { + join => [ 'virtualshelfshares' ], + group_by => 'shelfnumber', + order_by => 'lastmodified desc', + } + ); +} + sub type { return 'Virtualshelve'; } diff --git a/catalogue/search.pl b/catalogue/search.pl index c3ec804b46..facb7f6763 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -153,6 +153,8 @@ use POSIX qw(ceil floor); use C4::Branch; # GetBranches use C4::Search::History; +use Koha::Virtualshelves; + use URI::Escape; my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold"); @@ -746,14 +748,25 @@ if ($query_desc || $limit_desc) { # VI. BUILD THE TEMPLATE -# Build drop-down list for 'Add To:' menu... -my ($totalref, $pubshelves, $barshelves)= - C4::VirtualShelves::GetSomeShelfNames($borrowernumber,'COMBO',1); +my $some_private_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $borrowernumber, + add_allowed => 1, + category => 1, + } +); +my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $borrowernumber, + add_allowed => 1, + category => 2, + } +); + + $template->param( - addbarshelves => $totalref->{bartotal}, - addbarshelvesloop => $barshelves, - addpubshelves => $totalref->{pubtotal}, - addpubshelvesloop => $pubshelves, - ); + add_to_some_private_shelves => $some_private_shelves, + add_to_some_public_shelves => $some_public_shelves, +); output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index d72999e02e..27b7864212 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2304,7 +2304,7 @@ CREATE TABLE `virtualshelves` ( -- information about lists (or virtual shelves) `allow_delete_own` tinyint(1) default 1, -- permission for deleting entries frm list that you added yourself `allow_delete_other` tinyint(1) default 0, -- permission for deleting entries from list that another person added PRIMARY KEY (`shelfnumber`), - CONSTRAINT `virtualshelves_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in VirtualShelves.pm + CONSTRAINT `virtualshelves_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in Members.pm ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- @@ -2322,7 +2322,7 @@ CREATE TABLE `virtualshelfcontents` ( -- information about the titles in a list KEY `biblionumber` (`biblionumber`), CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `shelfcontents_ibfk_3` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in VirtualShelves.pm + CONSTRAINT `shelfcontents_ibfk_3` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in Members.pm ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- @@ -2337,7 +2337,7 @@ CREATE TABLE `virtualshelfshares` ( -- shared private lists `invitekey` varchar(10), -- temporary string used in accepting the invitation to access thist list; not-empty means that the invitation has not been accepted yet `sharedate` datetime, -- date of invitation or acceptance of invitation CONSTRAINT `virtualshelfshares_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `virtualshelfshares_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in VirtualShelves.pm + CONSTRAINT `virtualshelfshares_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in Members.pm ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index 1f7925300b..db1480f12a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -91,17 +91,38 @@ $('#sort_by').change(function() { }); var param1 = "