@@ -, +, @@ --- C4/Utils/DataTables/VirtualShelves.pm | 3 +- C4/VirtualShelves.pm | 38 +--------------- .../en/modules/virtualshelves/addbybiblionumber.tt | 51 ++++++++++++---------- .../bootstrap/en/modules/opac-addbybiblionumber.tt | 19 +++++--- opac/opac-addbybiblionumber.pl | 47 ++++++++++++++------ opac/opac-shareshelf.pl | 1 + virtualshelves/addbybiblionumber.pl | 41 ++++++++++++++--- 7 files changed, 113 insertions(+), 87 deletions(-) --- a/C4/Utils/DataTables/VirtualShelves.pm +++ a/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, --- a/C4/VirtualShelves.pm +++ a/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. --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt +++ a/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 ) %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-addbybiblionumber.tt +++ a/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 --- a/opac/opac-addbybiblionumber.pl +++ a/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 { --- a/opac/opac-shareshelf.pl +++ a/opac/opac-shareshelf.pl @@ -35,6 +35,7 @@ use C4::Output; use C4::VirtualShelves; use Koha::Virtualshelves; +use Koha::Virtualshelfshares; #------------------------------------------------------------------------------- --- a/virtualshelves/addbybiblionumber.pl +++ a/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, ); } --