From c13e20c44e8a461df918335e9f1991927e2ec9f1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 16 Jul 2015 17:42:03 +0100 Subject: [PATCH] Bug 14544: Get rid of GetShelves This does not work for now, see later. --- C4/VirtualShelves.pm | 70 +--------------------- C4/VirtualShelves/Page.pm | 17 +++++- Koha/Virtualshelves.pm | 43 +++++++++++++ .../opac-tmpl/bootstrap/en/modules/opac-shelves.tt | 6 +- 4 files changed, 62 insertions(+), 74 deletions(-) diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 8f23f85..ebfb016 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -40,7 +40,7 @@ BEGIN { require Exporter; @ISA = qw(Exporter); @EXPORT = qw( - &GetShelves &GetShelfContents + &GetShelfContents &ShelfPossibleAction ); @EXPORT_OK = qw( @@ -65,74 +65,6 @@ bibs to and from virtual shelves. =head1 FUNCTIONS -=head2 GetShelves - - $shelflist = &GetShelves($category, $row_count, $offset, $owner); - ($shelfnumber, $shelfhash) = each %{$shelflist}; - -Returns the number of shelves specified by C<$row_count> and C<$offset> as well as the total -number of shelves that meet the C<$owner> and C<$category> criteria. C<$category>, -C<$row_count>, and C<$offset> are required. C<$owner> must be supplied when C<$category> == 1. -When C<$category> is 2, supply undef as argument for C<$owner>. - -This function is used by shelfpage in VirtualShelves/Page.pm when listing all shelves for lists management in opac or staff client. Order is by shelfname. - -C<$shelflist>is a reference-to-hash. The keys are the virtualshelves numbers (C<$shelfnumber>, above), -and the values (C<$shelfhash>, above) are themselves references-to-hash, with the following keys: - -=over - -=item C<$shelfhash-E{shelfname}> - -A string. The name of the shelf. - -=back - -=cut - -sub GetShelves { - my ($category, $row_count, $offset, $owner) = @_; - $offset ||= 0; - my @params = ( $offset, $row_count ); - my $dbh = C4::Context->dbh; - my $query = qq{ - SELECT vs.shelfnumber, vs.shelfname,vs.owner, - bo.surname,bo.firstname,vs.category,vs.sortfield, - count(vc.biblionumber) as count - FROM virtualshelves vs - LEFT JOIN borrowers bo ON vs.owner=bo.borrowernumber - LEFT JOIN virtualshelfcontents vc USING (shelfnumber) }; - 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=?) }; - unshift @params, ($owner) x 3; - } - else { - $query.= 'WHERE category=2 '; - } - $query.= qq{ - GROUP BY vs.shelfnumber - ORDER BY vs.shelfname - LIMIT ?, ?}; - - my $sth2 = $dbh->prepare($query); - $sth2->execute(@params); - my %shelflist; - while( my ($shelfnumber, $shelfname, $owner, $surname, $firstname, $category, $sortfield, $count)= $sth2->fetchrow) { - $shelflist{$shelfnumber}->{'shelfname'} = $shelfname; - $shelflist{$shelfnumber}->{'count'} = $count; - $shelflist{$shelfnumber}->{'single'} = $count==1; - $shelflist{$shelfnumber}->{'sortfield'} = $sortfield; - $shelflist{$shelfnumber}->{'category'} = $category; - $shelflist{$shelfnumber}->{'owner'} = $owner; - $shelflist{$shelfnumber}->{'surname'} = $surname; - $shelflist{$shelfnumber}->{'firstname'} = $firstname; - } - return \%shelflist; -} - =head2 GetSomeShelfNames Returns shelf names and numbers for Add to combo of search results and Lists button of OPAC header. diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index 69a85c1..47efb14 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -89,7 +89,13 @@ sub shelfpage { # getting the Shelves list my $category = ( ( $displaymode eq 'privateshelves' ) ? 1 : 2 ); - my $shelflist = GetShelves( $category, $shelveslimit, $shelvesoffset, $loggedinuser ); + + my $shelflist; + if ( $category == 2 ) { + $shelflist = Koha::Virtualshelves->get_public_shelves({ limit => $shelveslimit, offset => $shelvesoffset }); + } else { + $shelflist = Koha::Virtualshelves->get_private_shelves({ limit => $shelveslimit, offset => $shelvesoffset, borrowernumber => $loggedinuser }); + } my $totshelves = C4::VirtualShelves::GetShelfCount( $loggedinuser, $category ); my $op = $query->param('op'); @@ -438,7 +444,14 @@ sub shelfpage { my $numberCanManage = 0; # rebuild shelflist in case a shelf has been added - $shelflist = GetShelves( $category, $shelveslimit, $shelvesoffset, $loggedinuser ) unless $delflag; + unless ( $delflag ) { + if ( $category == 2 ) { + $shelflist = Koha::Virtualshelves->get_public_shelves({ limit => $shelveslimit, offset => $shelvesoffset }); + } else { + $shelflist = Koha::Virtualshelves->get_private_shelves({ limit => $shelveslimit, offset => $shelvesoffset, borrowernumber => $loggedinuser }); + } + } + $totshelves = C4::VirtualShelves::GetShelfCount( $loggedinuser, $category ) unless $delflag; foreach my $element ( sort { lc( $shelflist->{$a}->{'shelfname'} ) cmp lc( $shelflist->{$b}->{'shelfname'} ) } keys %$shelflist ) { my %line; diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 5627afa..98f9d40 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -39,6 +39,49 @@ Koha::Virtualshelf - Koha Virtualshelf Object class =cut +sub get_private_shelves { + my ( $self, $params ) = @_; + my $limit = $params->{limit}; + my $offset = $params->{offset} || 0; + my $borrowernumber = $params->{borrowernumber}; + + $self->search( + { + 'virtualshelfshares.borrowernumber' => $borrowernumber, + category => 1, + -or => { + 'virtualshelfshares.owner' => $borrowernumber, + 'virtualshelves.borrowernumber' => $borrowernumber, + } + }, + { + join => ['borrowers', 'virtualshelfcontents', 'virtualshelfshares' ], + group_by => 'shelfnumber', + order_by => 'shelfname', + limit => "$limit,$offset", + } + ); +} + + +sub get_public_shelves { + my ( $self, $params ) = @_; + my $limit = $params->{limit}; + my $offset = $params->{offset} || 0; + + $self->search( + { + category => 1, + }, + { + join => [ 'virtualshelfcontents' ], + group_by => 'shelfnumber', + order_by => 'shelfname', + limit => "$limit,$offset", + } + ); +} + sub type { return 'Virtualshelve'; } diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index 08ff95d..d7363f3 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -115,7 +115,7 @@ [% IF ( paramsloo.need_confirm ) %]
The list [% paramsloo.need_confirm %] is not empty. -
It has [% paramsloo.count %] [% IF ( paramsloo.single ) %]entry[% ELSE %]entries[% END %]. +
It has [% paramsloo.count %] [% IF paramsloo.count == 1 %]entry[% ELSE %]entries[% END %].
Use the "Confirm" button below to confirm deletion.
[% END %] @@ -642,7 +642,7 @@ [% FOREACH shelveslooppri IN shelveslooppriv %] [% shelveslooppri.shelfname |html %] - [% IF ( shelveslooppri.count ) %][% shelveslooppri.count %] [% IF ( shelveslooppri.single ) %]item[% ELSE %]items[% END %][% ELSE %]Empty[% END %] + [% IF ( shelveslooppri.count ) %][% shelveslooppri.count %] [% IF shelveslooppri.count == 1 %]item[% ELSE %]items[% END %][% ELSE %]Empty[% END %] [% IF ( shelveslooppri.viewcategory1 ) %][% IF !shelveslooppri.shares %]Private[% ELSE %]Shared[% END %][% END %] @@ -716,7 +716,7 @@ [% FOREACH shelvesloo IN shelvesloop %] [% shelvesloo.shelfname |html %] - [% shelvesloo.count %] [% IF ( shelvesloo.single ) %]item[% ELSE %]item(s)[% END %] + [% shelvesloo.count %] [% IF shelvesloo.count == 1 %]item[% ELSE %]item(s)[% END %] [% IF ( shelvesloo.viewcategory2 ) %]Public[% END %] -- 2.1.0