Bug 11969: Show patrons star rating on their reading history
authorOwen Leonard <oleonard@myacpl.org>
Tue, 26 Mar 2019 13:51:47 +0000 (13:51 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 17 Apr 2019 12:25:25 +0000 (12:25 +0000)
This patch adds display of a user's ratings to their reading history in
the OPAC.

Also changed: Removed obsolete "border" attribute from the template, and
removed obsolete JavaScript include from opac-results.tt

To test, apply the patch and rebuild the OPAC CSS. OpacStarRatings
should be set to all (results and details).

 - Log in to the OPAC as a user with a reading history and titles in
   that history which have ratings.
 - Under the "your reading history" tab, your ratings should show under
   rated titles with the date of the rating.
 - Test also with OpacStarRatings set to a value other than "all."

Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz>
Star ratings are displayed in Reading History with OpacStarRatings
enabled, and are not displayed when OpacStarRatings is disabled, as
expected.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt
opac/opac-readingrecord.pl

index d03d518..5a880b2 100644 (file)
                                                     [% END %]
                                                     [% IF  OPACAmazonCoverImages %]
                                                         [% IF  issue.normalized_isbn %]
-                                                            <a href="http://www.amazon.com/gp/reader/[% issue.normalized_isbn | uri %][% AmazonAssocTag | uri %]#reader-link"><img border="0" src="https://images-na.ssl-images-amazon.com/images/P/[% issue.normalized_isbn | html %].01.THUMBZZZ.jpg" alt="" class="item-thumbnail" /></a>
+                                                            <a href="http://www.amazon.com/gp/reader/[% issue.normalized_isbn | uri %][% AmazonAssocTag | uri %]#reader-link"><img src="https://images-na.ssl-images-amazon.com/images/P/[% issue.normalized_isbn | html %].01.THUMBZZZ.jpg" alt="" class="item-thumbnail" /></a>
                                                         [% ELSE %]
                                                              <span class="no-image">No cover image available</span>
                                                         [% END %]
                                                 [% ELSE %]
                                                      <a class="title" href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% issue.biblionumber |url %]">[% issue.title | html %] [% IF issue.subtitle %][% FOREACH subtitl IN issue.subtitle %][% subtitl.subfield | html %][% END %][% END %]</a>
                                                 [% END %]
-                                                <span class="item-details">[% issue.author | html %]</span>
+                                                <p class="results-summary item-details">[% issue.author | html %]</p>
+
+                                                    [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' && issue.my_rating ) %]
+                                                        <div class="results_summary ratings">
+                                                            <div class="br-wrapper br-theme-fontawesome-stars">
+                                                                <div class="br-widget br-readonly">
+                                                                    [% FOREACH i IN [ 1 2 3 4 5  ] %]
+                                                                        [% IF issue.my_rating.rating_value == i %]
+                                                                            <a href="#" class="br-selected br-current"></a>
+                                                                        [% ELSIF issue.my_rating.rating_value > i %]
+                                                                            <a href="#" class="br-selected"></a>
+                                                                        [% ELSE %]
+                                                                            <a href="#"></a>
+                                                                        [% END %]
+                                                                    [% END %]
+                                                                </div>
+                                                            </div>
+                                                            Rated on [% issue.my_rating.timestamp | $KohaDates %]
+                                                        </div> <!-- / .results_summary -->
+                                                    [% END # / IF OpacStarRatings %]
+
                                                 </td>
                                                 <td>
                                                 [% UNLESS ( noItemTypeImages ) %]
 [% BLOCK jsinclude %]
 [% INCLUDE 'datatables.inc' %]
 <script>
-//<![CDATA[
     $(document).ready(function(){
         [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
             $('#sortsubmit').hide();
             }
         });
     });
-//]]>
 </script>
 [% END %]
index 2e233f1..6f53cab 100644 (file)
 [% IF ( LibraryThingForLibrariesID ) %]
     <script src="https://ltfl.librarything.com/forlibraries/widget.js?id=[% LibraryThingForLibrariesID | html %]&amp;systype=koha"></script>
 [% END %]
-[% IF ( OpacStarRatings == 'all' || Koha.Preference('Babeltheque') ) %][% Asset.js("lib/jquery/plugins/jquery.rating.js") | $raw %][% END %]
 [% IF ( OverDriveEnabled ) %][% Asset.js("js/overdrive.js") | $raw %][% END %]
 [% IF ( RecordedBooksEnabled ) %][% Asset.js("js/recordedbooks.js") | $raw %][% END %]
 [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
index 49348ad..c01409a 100755 (executable)
@@ -33,6 +33,7 @@ use C4::Charset qw(StripNonXmlChars);
 use Koha::Patrons;
 
 use Koha::ItemTypes;
+use Koha::Ratings;
 
 my $query = new CGI;
 
@@ -121,6 +122,12 @@ foreach my $issue ( @{$issues} ) {
           : $my_summary_html =~ s/{BIBLIONUMBER}//g;
         $issue->{MySummaryHTML} = $my_summary_html;
     }
+    # Star ratings
+    if ( C4::Context->preference('OpacStarRatings') eq 'all' ) {
+        my $ratings = Koha::Ratings->search({ biblionumber => $issue->{biblionumber} });
+        $issue->{ratings} = $ratings;
+        $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
+    }
 }
 
 if (C4::Context->preference('BakerTaylorEnabled')) {
@@ -140,7 +147,7 @@ BEGIN {
        }
 }
 
-for(qw(AmazonCoverImages GoogleJackets)) {     # BakerTaylorEnabled handled above
+for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above
        C4::Context->preference($_) or next;
        $template->param($_=>1);
        $template->param(JacketImages=>1);