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 <oleonard@myacpl.org>

Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com>

Signed-off-by: Katrin Fischer  <katrin.fischer@bsz-bw.de>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-05-17 16:31:11 +01:00 committed by Kyle M Hall
parent f89400a8ff
commit c39eaca298
5 changed files with 150 additions and 2 deletions

View File

@ -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';
}

View File

@ -459,6 +459,19 @@
</div>
[% END %]
[% IF Koha.Preference('virtualshelves') AND SEARCH_RESULT.shelves.count %]
<div class="results_summary shelves">
<span class="label">Lists:</span>
<ul>
[% FOREACH shelf IN SEARCH_RESULT.shelves %]
<li><a href="/cgi-bin/koha/opac-shelves.pl?op=view&amp;shelfnumber=[% shelf.shelfnumber %]">[% shelf.shelfname %]</a></li>
[%~ UNLESS loop.last %], [% ELSE %].[% END ~%]
[% END %]
</ul>
</span>
</div>
[% END %]
[% IF ( SEARCH_RESULT.searchhighlightblob ) %]
<span class="results_summary">
<span class="label">Match:</span>

View File

@ -2214,7 +2214,7 @@ td img {
line-height: 135%;
}
}
.tags {
.tags, .shelves {
ul {
display: inline;
list-style: none;

View File

@ -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;

View File

@ -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|);