From 54fc66fe968eaade7f923e228fe6f44afc3df284 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 16 Jul 2015 12:29:48 +0100 Subject: [PATCH] Bug 14544: Get rid of GetAllShelves Signed-off-by: Koha Alex Arnaud Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- C4/Utils/DataTables/VirtualShelves.pm | 3 +- C4/VirtualShelves.pm | 38 +------------- .../virtualshelves/addbybiblionumber.tt | 52 +++++++++++-------- .../en/modules/opac-addbybiblionumber.tt | 20 ++++--- opac/opac-addbybiblionumber.pl | 47 ++++++++++++----- opac/opac-shareshelf.pl | 1 + virtualshelves/addbybiblionumber.pl | 41 ++++++++++++--- 7 files changed, 115 insertions(+), 87 deletions(-) diff --git a/C4/Utils/DataTables/VirtualShelves.pm b/C4/Utils/DataTables/VirtualShelves.pm index a305617ecf..e331447a1a 100644 --- a/C4/Utils/DataTables/VirtualShelves.pm +++ b/C4/Utils/DataTables/VirtualShelves.pm @@ -28,8 +28,7 @@ sub search { my $dbh = C4::Context->dbh; # FIXME refactore the following queries - # We should call C4::VirtualShelves::GetShelves and C4::VirtualShelves::GetAllShelves - # But the code is too dirty to refactor... + # We should call Koha::Virtualshelves my $select = q| SELECT vs.shelfnumber, vs.shelfname, vs.owner, vs.category AS type, vs.created_on, vs.lastmodified as modification_time, diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 68e9a4795d..5668a784e2 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -47,7 +47,7 @@ BEGIN { &GetBibliosShelves ); @EXPORT_OK = qw( - &GetAllShelves &ShelvesMax + &ShelvesMax ); } @@ -136,42 +136,6 @@ sub GetShelves { return \%shelflist; } -=head2 GetAllShelves - - $shelflist = GetAllShelves($category, $owner) - -This function returns a reference to an array of hashrefs containing all shelves -sorted by the shelf name. - -This function is intended to return a dataset reflecting all the shelves for -the submitted parameters. - -=cut - -sub GetAllShelves { - my ($category,$owner,$adding_allowed) = @_; - my @params; - my $dbh = C4::Context->dbh; - my $query = 'SELECT vs.* FROM virtualshelves vs '; - if($category==1) { - $query.= qq{ - LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber - AND sh.borrowernumber=? - WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; - @params = ($owner, $owner, $owner); - } - else { - $query.='WHERE category=2 '; - @params = (); - } - $query.='AND (allow_add=1 OR owner=?) ' if $adding_allowed; - push @params, $owner if $adding_allowed; - $query.= 'ORDER BY shelfname ASC'; - my $sth = $dbh->prepare( $query ); - $sth->execute(@params); - return $sth->fetchall_arrayref({}); -} - =head2 GetSomeShelfNames Returns shelf names and numbers for Add to combo of search results and Lists button of OPAC header. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt index 8dae4bff24..63974a98bc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt @@ -38,28 +38,35 @@ [% UNLESS ( newshelf ) %]
- Select an existing list -
    -
  1. - - -
  2. -
+ Select an existing list +
    +
  1. + + +
  2. +
[% FOREACH biblio IN biblios %][% END %] [% UNLESS ( biblionumbers ) %] @@ -100,6 +107,7 @@
+ Cancel
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-addbybiblionumber.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-addbybiblionumber.tt index 859a091d6a..164c750fd0 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-addbybiblionumber.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-addbybiblionumber.tt @@ -23,19 +23,24 @@ [% END %] - [% IF ( existingshelves ) %] + [% IF private_shelves.count or public_shelves.count or private_shelves_shared_with_me %]
Select a list @@ -85,6 +90,7 @@ [% END %]
+ Cancel
diff --git a/opac/opac-addbybiblionumber.pl b/opac/opac-addbybiblionumber.pl index 38f95bd013..4c730d1c37 100755 --- a/opac/opac-addbybiblionumber.pl +++ b/opac/opac-addbybiblionumber.pl @@ -24,7 +24,7 @@ use warnings; use CGI qw ( -utf8 ); use C4::Biblio; -use C4::VirtualShelves qw/:DEFAULT GetAllShelves/; +use C4::VirtualShelves qw/:DEFAULT/; use C4::Output; use C4::Auth; @@ -132,20 +132,41 @@ sub HandleSelectedShelf { sub HandleSelect { return unless $authorized= $loggedinuser>0; - my $privateshelves = GetAllShelves(1,$loggedinuser,1); - if(@{$privateshelves}){ - $template->param ( - privatevirtualshelves => $privateshelves, - existingshelves => 1 + my $private_shelves = Koha::Virtualshelves->search( + { + category => 1, + owner => $loggedinuser, + }, + { order_by => 'shelfname' } ); - } - my $publicshelves = GetAllShelves(2,$loggedinuser,1); - if(@{$publicshelves}){ - $template->param ( - publicvirtualshelves => $publicshelves, - existingshelves => 1 + my $shelves_shared_with_me = Koha::Virtualshelves->search( + { + category => 1, + 'virtualshelfshares.borrowernumber' => $loggedinuser, + -or => { + allow_add => 1, + owner => $loggedinuser, + } + }, + { + join => 'virtualshelfshares', + } + ); + my $public_shelves= Koha::Virtualshelves->search( + { + category => 2, + -or => { + allow_add => 1, + owner => $loggedinuser, + } + }, + { order_by => 'shelfname' } + ); + $template->param ( + private_shelves => $private_shelves, + private_shelves_shared_with_me => $shelves_shared_with_me, + public_shelves => $public_shelves, ); - } } sub LoadBib { diff --git a/opac/opac-shareshelf.pl b/opac/opac-shareshelf.pl index 99133cd3bf..a75875c8a7 100755 --- a/opac/opac-shareshelf.pl +++ b/opac/opac-shareshelf.pl @@ -35,6 +35,7 @@ use C4::Output; use C4::VirtualShelves; use Koha::Virtualshelves; +use Koha::Virtualshelfshares; #------------------------------------------------------------------------------- diff --git a/virtualshelves/addbybiblionumber.pl b/virtualshelves/addbybiblionumber.pl index 2a58ef9172..c769c3a682 100755 --- a/virtualshelves/addbybiblionumber.pl +++ b/virtualshelves/addbybiblionumber.pl @@ -64,7 +64,7 @@ use warnings; use CGI qw ( -utf8 ); use C4::Biblio; use C4::Output; -use C4::VirtualShelves qw/:DEFAULT GetAllShelves/; +use C4::VirtualShelves qw/:DEFAULT/; use C4::Auth; use Koha::Virtualshelves; @@ -182,11 +182,40 @@ sub HandleSelectedShelf { } sub HandleSelect { - my $privateshelves = GetAllShelves(1,$loggedinuser,1); - my $publicshelves = GetAllShelves(2,$loggedinuser,1); - $template->param( - privatevirtualshelves => $privateshelves, - publicvirtualshelves => $publicshelves, + my $private_shelves = Koha::Virtualshelves->search( + { + category => 1, + owner => $loggedinuser, + }, + { order_by => 'shelfname' } + ); + my $shelves_shared_with_me = Koha::Virtualshelves->search( + { + category => 1, + 'virtualshelfshares.borrowernumber' => $loggedinuser, + -or => { + allow_add => 1, + owner => $loggedinuser, + } + }, + { + join => 'virtualshelfshares', + } + ); + my $public_shelves= Koha::Virtualshelves->search( + { + category => 2, + -or => { + allow_add => 1, + owner => $loggedinuser, + } + }, + { order_by => 'shelfname' } + ); + $template->param ( + private_shelves => $private_shelves, + private_shelves_shared_with_me => $shelves_shared_with_me, + public_shelves => $public_shelves, ); } -- 2.39.5