From 738713cf1e881a47b8bf4eb4f28ad4044dcc3c54 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 14 Apr 2020 16:31:28 +0000 Subject: [PATCH] Bug 25110: Allow patrons to add star ratings to titles on their summary/checkout page This patch adds the ability for logged-in patrons to add star ratings to titles in their list of current checkouts and on the reading history page. The reading history page previously only showed existing ratings. Now it will allow the entry of ratings as well. The JS and markup for the feature are in separate include files to facilitate re-use. To test, apply the patch and set the OpacStarRatings to all, "results, details, and user" pages. - Log in to the OPAC as a user with checkouts. - On the "your summary" page, test the features of setting star ratings: - Any title with existing ratings should show the rating and the average rating number. - Set a rating. Confirm that it shows a message with your rating. - Click the "cancel rating" link, and confirm that your rating is removed. - Set a rating and reload the page. Confirm that the rating was saved. - Test the "cancel rating" link on the title you set before you reloaded the page. The rating should be cancelled. - Test the same functionality on the "your reading history" page. - Test these pages with the OpacStarRatings preference set to "only details" or "no." The pages should function correctly. --- .../prog/en/modules/admin/preferences/opac.pref | 2 +- .../bootstrap/en/includes/user-star-ratings.inc | 41 ++++++++++++++++++++++ .../bootstrap/en/modules/opac-readingrecord.tt | 28 ++++++--------- .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 11 ++++++ opac/opac-user.pl | 7 ++++ 5 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc 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 c705a288c3..0bd9ecedcb 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 @@ -56,7 +56,7 @@ OPAC: - "Show star-ratings on" - pref: OpacStarRatings choices: - all: "results and details" + all: "results, details, and user" disable: "no" details: "only details" - "pages." diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc new file mode 100644 index 0000000000..c258c88380 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc @@ -0,0 +1,41 @@ +
+
+ + [% SET rating_avg = item.ratings.get_avg_rating() %] + [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] + + + + + + + + + + + + [% IF item.my_rating %] +
+ Your rating: [% item.my_rating.rating_value | html %]. + Cancel rating. +
+ [% ELSE %] + + + [% END %] + +
Average rating: [% rating_avg | html %] ([% item.ratings.count | html %] votes)
+
+
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt index 1f3dadcff5..3b95b586ed 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt @@ -145,24 +145,9 @@ [% END %]

[% issue.author | html %]

- [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' && issue.my_rating ) %] -
-
-
- [% FOREACH i IN [ 1 2 3 4 5 ] %] - [% IF issue.my_rating.rating_value == i %] - - [% ELSIF issue.my_rating.rating_value > i %] - - [% ELSE %] - - [% END %] - [% END %] -
-
- Rated on [% issue.my_rating.timestamp | $KohaDates %] -
- [% END # / IF OpacStarRatings %] + [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' ) %] + [% INCLUDE 'user-star-ratings.inc' item=issue %] + [% END %] @@ -235,5 +220,12 @@ } }); }); + var borrowernumber = "[% borrowernumber | html %]"; + var MSG_YOUR_RATING = _("Your rating: %s, "); + var MSG_AVERAGE_RATING = _("Average rating: %s (%s votes)"); + [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %] + [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %] + [% Asset.js("js/ratings.js") | $raw %] + [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index 256262818d..7d26a5a23b 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -294,6 +294,10 @@ [% INCLUDE 'biblio-title.inc' biblio=ISSUE %] [% IF ( ISSUE.enumchron ) %] [% ISSUE.enumchron | html %][% END %] + + [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %] + [% INCLUDE 'user-star-ratings.inc' item=ISSUE %] + [% END %] [% ISSUE.author | html %] @@ -963,7 +967,14 @@ } }); //]]> + var borrowernumber = "[% borrowernumber | html %]"; + var MSG_YOUR_RATING = _("Your rating: %s, "); + var MSG_AVERAGE_RATING = _("Average rating: %s (%s votes)"); + [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %] + [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %] + [% Asset.js("js/ratings.js") | $raw %] + [% END %] [% IF Koha.Preference('OverDriveCirculation') %] [% Asset.js("js/overdrive.js") | $raw %]