From 06403a8fa346be88fea15706ac1becea5f51d73b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 May 2016 16:31:11 +0100 Subject: [PATCH] [PASSED QA] Bug 16551: Display the name of lists to the search results at the OPAC This new enhancement will allow to add the name of lists containing a biblio to the search results at the OPAC. Test plan: 0/ Regenerate the css file to get the style change: % lessc --clean-css="--s0 --advanced --compatibility=ie7" koha-tmpl/opac-tmpl/bootstrap/less/opac.less > koha-tmpl/opac-tmpl/bootstrap/css/opac.css 1/ Create some lists and add items to them 2/ On the search results you should see the name of the lists which contains the record. Note that we could add a syspref to make this new behavior optional. Sponsored-by: University of the Arts London Signed-off-by: Owen Leonard Signed-off-by: Jonathan Field Signed-off-by: Katrin Fischer --- Koha/Virtualshelves.pm | 39 ++++++++++ .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 13 ++++ koha-tmpl/opac-tmpl/bootstrap/less/opac.less | 2 +- opac/opac-search.pl | 8 ++ t/db_dependent/Virtualshelves.t | 90 +++++++++++++++++++++- 5 files changed, 150 insertions(+), 2 deletions(-) diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 75ccfa8..a8d1b20 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -119,6 +119,45 @@ sub get_some_shelves { ); } +sub get_shelves_containing_record { + my ( $self, $params ) = @_; + my $borrowernumber = $params->{borrowernumber}; + my $biblionumber = $params->{biblionumber}; + + my @conditions = ( 'virtualshelfcontents.biblionumber' => $biblionumber ); + if ($borrowernumber) { + push @conditions, + { + -or => [ + { + category => 1, + -or => { + 'me.owner' => $borrowernumber, + -or => { + 'virtualshelfshares.borrowernumber' => $borrowernumber, + "me.allow_add" => 1, + }, + } + }, + { category => 2 }, + ] + }; + } else { + push @conditions, { category => 2 }; + } + + return Koha::Virtualshelves->search( + { + -and => \@conditions + }, + { + join => [ 'virtualshelfcontents', 'virtualshelfshares' ], + group_by => 'shelfnumber', + order_by => { -asc => 'shelfname' }, + } + ); +} + sub _type { return 'Virtualshelve'; } diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt index 41a046a..7301d70 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -459,6 +459,19 @@ [% END %] + [% IF Koha.Preference('virtualshelves') AND SEARCH_RESULT.shelves.count %] +
+ Lists: +
    + [% FOREACH shelf IN SEARCH_RESULT.shelves %] +
  • [% shelf.shelfname %]
  • + [%~ UNLESS loop.last %], [% ELSE %].[% END ~%] + [% END %] +
+ +
+ [% END %] + [% IF ( SEARCH_RESULT.searchhighlightblob ) %] Match: diff --git a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less b/koha-tmpl/opac-tmpl/bootstrap/less/opac.less index c8d9f9c..0bd32b4 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less +++ b/koha-tmpl/opac-tmpl/bootstrap/less/opac.less @@ -2214,7 +2214,7 @@ td img { line-height: 135%; } } -.tags { +.tags, .shelves { ul { display: inline; list-style: none; diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 37342f5..ccbc025 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -54,6 +54,7 @@ use C4::External::OverDrive; use Koha::LibraryCategories; use Koha::Ratings; +use Koha::Virtualshelves; use POSIX qw(ceil floor strftime); use URI::Escape; @@ -692,6 +693,13 @@ for (my $i=0;$i<@servers;$i++) { } } + $res->{shelves} = Koha::Virtualshelves->get_shelves_containing_record( + { + biblionumber => $res->{biblionumber}, + borrowernumber => $borrowernumber + } + ); + if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { my $ratings = Koha::Ratings->search({ biblionumber => $res->{biblionumber} }); $res->{ratings} = $ratings; diff --git a/t/db_dependent/Virtualshelves.t b/t/db_dependent/Virtualshelves.t index 58d3fec..c867056 100644 --- a/t/db_dependent/Virtualshelves.t +++ b/t/db_dependent/Virtualshelves.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; use DateTime::Duration; use C4::Context; @@ -404,6 +404,94 @@ subtest 'Get shelves' => sub { teardown(); }; +subtest 'Get shelves containing biblios' => sub { + + plan tests => 9; + my $patron1 = $builder->build( { source => 'Borrower', } ); + my $patron2 = $builder->build( { source => 'Borrower', } ); + my $biblio1 = $builder->build( { source => 'Biblio', } ); + my $biblio2 = $builder->build( { source => 'Biblio', } ); + my $biblio3 = $builder->build( { source => 'Biblio', } ); + my $biblio4 = $builder->build( { source => 'Biblio', } ); + + my $shelf1 = Koha::Virtualshelf->new( + { shelfname => "my first shelf", + owner => $patron1->{borrowernumber}, + category => 1, + } + )->store; + my $shelf2 = Koha::Virtualshelf->new( + { shelfname => "my x second shelf", # 'x' to make it sorted after 'third' + owner => $patron2->{borrowernumber}, + category => 1, + } + )->store; + my $shelf3 = Koha::Virtualshelf->new( + { shelfname => "my third shelf", + owner => $patron1->{borrowernumber}, + category => 2, + } + )->store; + + my $content1 = $shelf1->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} ); + my $content2 = $shelf1->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} ); + my $content3 = $shelf2->add_biblio( $biblio2->{biblionumber}, $patron2->{borrowernumber} ); + my $content4 = $shelf2->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} ); + my $content5 = $shelf2->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} ); + my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} ); + + my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record( + { + biblionumber => $biblio1->{biblionumber}, + } + ); + is ( $shelves_with_biblio1_for_any_patrons->count, 0, 'shelf1 is private and should not be displayed if patron is not logged in' ); + + my $shelves_with_biblio4_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record( + { + biblionumber => $biblio4->{biblionumber}, + } + ); + is ( $shelves_with_biblio4_for_any_patrons->count, 1, 'shelf3 is public and should be displayed for any patrons' ); + is ( $shelves_with_biblio4_for_any_patrons->next->shelfname, $shelf3->shelfname, 'The correct shelf (3) should be displayed' ); + + my $shelves_with_biblio1_for_other_patrons = Koha::Virtualshelves->get_shelves_containing_record( + { + biblionumber => $biblio1->{biblionumber}, + borrowernumber => $patron2->{borrowernumber}, + } + ); + is ( $shelves_with_biblio1_for_other_patrons->count, 0, 'shelf1 is private and should not be displayed for other patrons' ); + + my $shelves_with_biblio1_for_owner = Koha::Virtualshelves->get_shelves_containing_record( + { + biblionumber => $biblio1->{biblionumber}, + borrowernumber => $patron1->{borrowernumber}, + } + ); + is ( $shelves_with_biblio1_for_owner->count, 1, 'shelf1 is private and should be displayed for the owner' ); + + my $shelves_with_biblio2_for_patron1 = Koha::Virtualshelves->get_shelves_containing_record( + { + biblionumber => $biblio2->{biblionumber}, + borrowernumber => $patron1->{borrowernumber}, + } + ); + is ( $shelves_with_biblio2_for_patron1->count, 1, 'Only shelf1 should be displayed for patron 1 and biblio 1' ); + is ( $shelves_with_biblio2_for_patron1->next->shelfname, $shelf1->shelfname, 'The correct shelf (1) should be displayed for patron 1' ); + + my $shelves_with_biblio4_for_patron2 = Koha::Virtualshelves->get_shelves_containing_record( + { + biblionumber => $biblio4->{biblionumber}, + borrowernumber => $patron2->{borrowernumber}, + } + ); + is ( $shelves_with_biblio4_for_patron2->count, 2, 'Patron should shown private and public lists for a given biblio' ); + is ( $shelves_with_biblio4_for_patron2->next->shelfname, $shelf3->shelfname, 'The shelves should be sorted by shelfname' ); + + teardown(); +}; + sub teardown { $dbh->do(q|DELETE FROM virtualshelfshares|); $dbh->do(q|DELETE FROM virtualshelfcontents|); -- 2.7.4