From 8bd112377af76e01af7aad6bee1e8ea49816467f 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 --- 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 ++++++---- .../opac-tmpl/bootstrap/en/includes/masthead.inc | 56 +++++++++++--------- .../opac-tmpl/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 ef0c585..b32e397 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -203,13 +203,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, ); } @@ -340,11 +348,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, ); } } @@ -714,7 +725,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; @@ -1207,11 +1218,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 e85f920..29126cc 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 2cbd41c..c3159ce 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 1abacb6..031c934 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -154,6 +154,8 @@ use String::Random; use C4::Branch; # GetBranches use C4::Search::History; +use Koha::Virtualshelves; + use URI::Escape; my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold"); @@ -747,14 +749,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 13b6a6a..3a497ae 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2320,7 +2320,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; -- @@ -2338,7 +2338,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; -- @@ -2353,7 +2353,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 4b1c94b..091c633 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 = "