From 92caea4559a73153e1d882f214a28d7f919546e5 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Tue, 19 Oct 2021 22:51:21 +0000 Subject: [PATCH] Bug 29280: Add OpacStarRatings to opac-shelves.tt To test: -Apply patch and restart everything -Set the system preference 'OpacStarRatings' to 'results, detail, lists, and patron' -Build a public lists with some items that have ratings -View the list page and you should see the ratings appear -Make sure that the ratings and the number of votes are acurate -Ratings on the opac-shelves should look and function just like those on the OPAC results page -Turn the 'OpacStarRatings' system pref to 'only detials' and 'no', making sure they do not show in the lists display Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer --- .../prog/en/modules/admin/preferences/opac.pref | 2 +- .../opac-tmpl/bootstrap/en/modules/opac-shelves.tt | 26 ++++++++++++++++++++++ opac/opac-shelves.pl | 11 +++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index c3e793794c..d4d237d938 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -46,7 +46,7 @@ OPAC: - "Show star-ratings on" - pref: OpacStarRatings choices: - all: "results, details, and patron" + all: "results, details, lists, and patron" disable: "no" details: "only details" - "pages." 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 936a178442..e9d2f844a2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -477,6 +477,32 @@ [% itemsloo.XSLTBloc | $raw %] + [% IF ( OpacStarRatings == 'all' ) %] +
+ [% SET rating_avg = itemsloo.ratings.get_avg_rating() %] + [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] +
+
+ [% FOREACH i IN [ 1 2 3 4 5 ] %] + [% IF rating_avg_int == i %] + + [% ELSIF rating_avg_int > i %] + + [% ELSE %] + + [% END %] + [% END %] +
+
+ + [% IF itemsloo.ratings.count > 0 %] +   ([% itemsloo.ratings.count | html %] votes) + [% ELSE %] +
+ [% END %] +
+ [% END # / IF OpacStarRatings %] + [% IF ( TagsShowEnabled && itemsloo.TagLoop.size ) %]
Tags: diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 78ce49da0e..1ae3b3b340 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -43,6 +43,7 @@ use Koha::ItemTypes; use Koha::Patrons; use Koha::Virtualshelves; use Koha::RecordProcessor; +use Koha::Ratings; use constant ANYONE => 2; @@ -75,6 +76,10 @@ if( $op eq 'view' || $op eq 'list' ){ }); } +$template->param( + OpacStarRatings => C4::Context->preference("OpacStarRatings") +); + if (C4::Context->preference("BakerTaylorEnabled")) { $template->param( BakerTaylorImageURL => &image_url(), @@ -352,6 +357,12 @@ if ( $op eq 'view' ) { }); } + if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { + my $ratings = Koha::Ratings->search({ biblionumber => $this_item->{biblionumber} }); + $this_item->{ratings} = $ratings; + $this_item->{my_rating} = $loggedinuser ? $ratings->search({ borrowernumber => $loggedinuser })->next : undef; + } + my $items = $biblio->items->filter_by_visible_in_opac({ patron => $patron }); my $allow_onshelf_holds; while ( my $item = $items->next ) { -- 2.11.0