Bugzilla – Attachment 54337 Details for
Bug 17089
Move the star ratings related code to Koha::Ratings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17089: Koha::Ratings - Remove GetRating
Bug-17089-KohaRatings---Remove-GetRating.patch (text/plain), 12.56 KB, created by
Marcel de Rooy
on 2016-08-12 08:19:00 UTC
(
hide
)
Description:
Bug 17089: Koha::Ratings - Remove GetRating
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2016-08-12 08:19:00 UTC
Size:
12.56 KB
patch
obsolete
>From 328e611e1b02da8b8eace4e195353b8c83636b43 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 9 Aug 2016 15:01:21 +0100 >Subject: [PATCH] Bug 17089: Koha::Ratings - Remove GetRating >Content-Type: text/plain; charset=utf-8 > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Ratings.pm | 19 +++++++++++++++++++ > .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 19 ++++++++++--------- > .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 13 ++++++------- > opac/opac-detail.pl | 11 +++++------ > opac/opac-ratings-ajax.pl | 18 ++++++++++-------- > opac/opac-ratings.pl | 1 - > opac/opac-search.pl | 10 ++++------ > 7 files changed, 54 insertions(+), 37 deletions(-) > >diff --git a/Koha/Ratings.pm b/Koha/Ratings.pm >index 27ee47e..d449a85 100644 >--- a/Koha/Ratings.pm >+++ b/Koha/Ratings.pm >@@ -35,6 +35,25 @@ Koha::Ratings - Koha Rating Object set class > > =cut > >+=head3 get_avg_rating >+ >+=cut >+ >+sub get_avg_rating { >+ my ( $self ) = @_; >+ >+ my $sum = $self->_resultset->get_column('rating_value')->sum(); >+ my $total = $self->count(); >+ >+ my $avg = 0; >+ if ( $sum and $total ) { >+ eval { $avg = $sum / $total }; >+ } >+ $avg = sprintf( "%.1f", $avg ); >+ >+ return $avg; >+} >+ > =head3 type > > =cut >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >index 3440af7..979a808 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >@@ -1,3 +1,4 @@ >+[% USE Math %] > [% USE Koha %] > [% USE KohaDates %] > [% USE Branches %] >@@ -468,10 +469,12 @@ > <form method="post" action="/cgi-bin/koha/opac-ratings.pl"> > <div class="results_summary ratings"> > >+ [% SET rating_avg = ratings.get_avg_rating() %] >+ [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] > [% FOREACH i IN [ 1 2 3 4 5 ] %] >- [% IF rating_avg == i && borrowernumber %] >+ [% IF rating_avg_int == i && borrowernumber %] > <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" checked="checked" /> >- [% ELSIF rating_avg == i %] >+ [% ELSIF rating_avg_int == i %] > <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" checked="checked" disabled="disabled" /> > [% ELSIF borrowernumber %] > <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" /> >@@ -483,19 +486,17 @@ > <!-- define some hidden vars for ratings --> > > <input type="hidden" name='biblionumber' value="[% biblionumber %]" /> >- <input type="hidden" name='rating_value' id='rating_value' value="[% rating_value %]" /> >- <input type="hidden" name='rating_total' id='rating_total' value="[% rating_total %]" /> >- <input type="hidden" name='rating_avg_int' id='rating_avg_int' value="[% rating_avg_int %]" /> >+ <input type="hidden" name='rating_value' id='rating_value' value="[% my_rating.rating_value %]" /> > > [% UNLESS ( rating_readonly ) %] <input name="rate_button" type="submit" value="Rate me" />[% END %] > >- [% IF ( rating_value ) %] >- <span id="rating_value_text">your rating: [% rating_value %], </span> >+ [% IF my_rating %] >+ <span id="rating_value_text">your rating: [% my_rating.rating_value %], </span> > [% ELSE %] > <span id="rating_value_text"></span> > [% END %] > >- <span id="rating_text">average rating: [% rating_avg_int %] ([% rating_total %] votes)</span> >+ <span id="rating_text">average rating: [% rating_avg %] ([% ratings.count %] votes)</span> > </div> > </form> > [% END # / IF OpacStarRatings != 'disable' %] >@@ -1597,7 +1598,7 @@ > $("#rating_value_text").text(''); > } > >- $("#rating_text").text(_("average rating: ") + data.rating_avg_int + " (" + data.rating_total + ' ' + _("votes") + ")"); >+ $("#rating_text").text(_("average rating: ") + data.rating_avg + " (" + data.rating_total + ' ' + _("votes") + ")"); > > } > }, "json"); >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 7021638..41a046a 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >@@ -468,19 +468,18 @@ > > [% IF ( OpacStarRatings == 'all' ) %] > <div class="results_summary ratings"> >+ [% SET rating_avg = SEARCH_RESULT.ratings.get_avg_rating() %] >+ [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] > [% FOREACH i IN [ 1 2 3 4 5 ] %] >- [% IF ( SEARCH_RESULT.rating_avg == i ) %] >+ [% IF rating_avg_int == i %] > <input class="star" type="radio" name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" checked="checked" disabled="disabled" /> >- [% ELSE %] >+ [% ELSE %] > <input class="star" type="radio" name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" disabled="disabled" /> > [% END %] > [% END %] > >- <input type="hidden" name="biblionumber" value="[% SEARCH_RESULT.biblionumber %]" /> >- <input type="hidden" name="loggedinuser" value="[% loggedinuser %]" /> >- >- [% IF SEARCH_RESULT.rating_total && SEARCH_RESULT.rating_total > 0 %] >- <span id="rating_total_[% SEARCH_RESULT.biblionumber %]"> ([% SEARCH_RESULT.rating_total %] votes)</span> >+ [% IF SEARCH_RESULT.ratings.count > 0 %] >+ <span id="rating_total_[% SEARCH_RESULT.biblionumber %]"> ([% SEARCH_RESULT.ratings.count %] votes)</span> > [% ELSE %] > <br /> > [% END %] >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 98afe3e..b307d05 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -37,7 +37,6 @@ use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn); > use C4::External::Amazon; > use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes ); > use C4::Review; >-use C4::Ratings; > use C4::Members; > use C4::XSLT; > use C4::ShelfBrowser; >@@ -52,6 +51,7 @@ use C4::HTML5Media; > use C4::CourseReserves qw(GetItemCourseReservesInfo); > > use Koha::Virtualshelves; >+use Koha::Ratings; > > BEGIN { > if (C4::Context->preference('BakerTaylorEnabled')) { >@@ -1068,12 +1068,11 @@ if (C4::Context->preference("OPACURLOpenInNewWindow")) { > } > > if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) { >- my $rating = GetRating( $biblionumber, $borrowernumber ); >+ my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber }); >+ my $my_rating = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef; > $template->param( >- rating_value => $rating->{'rating_value'}, >- rating_total => $rating->{'rating_total'}, >- rating_avg => $rating->{'rating_avg'}, >- rating_avg_int => $rating->{'rating_avg_int'}, >+ ratings => $ratings, >+ my_rating => $my_rating, > borrowernumber => $borrowernumber > ); > } >diff --git a/opac/opac-ratings-ajax.pl b/opac/opac-ratings-ajax.pl >index a99a335..672e7f3 100755 >--- a/opac/opac-ratings-ajax.pl >+++ b/opac/opac-ratings-ajax.pl >@@ -33,7 +33,6 @@ use C4::Auth qw(:DEFAULT check_cookie_auth); > use C4::Context; > use C4::Debug; > use C4::Output qw(:html :ajax pagination_bar); >-use C4::Ratings; > > use Koha::Ratings; > >@@ -74,22 +73,25 @@ $rating_value //= ''; > > if ( $rating_value eq '' ) { > Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser } )->delete; >- $rating = Koha::Ratings->search({ biblionumber => $biblionumber })->get_rating; > } > > elsif ( $rating_value and !$rating_old_value ) { >- $rating = Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $loggedinuser, rating_value => $rating_value, })->store; >+ Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $loggedinuser, rating_value => $rating_value, })->store; > } > > elsif ( $rating_value ne $rating_old_value ) { >- $rating = Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser })->rating_value($rating_value)->store; >+ Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser })->rating_value($rating_value)->store; > } > >+my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber }); >+my $my_rating = $ratings->search({ borrowernumber => $loggedinuser })->next; >+my $avg = $ratings->get_avg_rating; >+ > my %js_reply = ( >- rating_total => $rating->{'rating_total'}, >- rating_avg => $rating->{'rating_avg'}, >- rating_avg_int => $rating->{'rating_avg_int'}, >- rating_value => $rating->{'rating_value'}, >+ rating_total => $ratings->count, >+ rating_avg => $avg, >+ rating_avg_int => sprintf("%.0f", $avg), >+ rating_value => $my_rating->rating_value, > auth_status => $auth_status, > > ); >diff --git a/opac/opac-ratings.pl b/opac/opac-ratings.pl >index 33d4aee..d936b13 100755 >--- a/opac/opac-ratings.pl >+++ b/opac/opac-ratings.pl >@@ -31,7 +31,6 @@ use CGI qw ( -utf8 ); > > use C4::Auth; > use C4::Context; >-use C4::Ratings; > use C4::Debug; > > use Koha::Ratings; >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index 64b8800..ca9935e 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -51,10 +51,10 @@ use C4::Koha; > use C4::Tags qw(get_tags); > use C4::Branch; # GetBranches > use C4::SocialData; >-use C4::Ratings; > use C4::External::OverDrive; > > use Koha::LibraryCategories; >+use Koha::Ratings; > > use POSIX qw(ceil floor strftime); > use URI::Escape; >@@ -695,11 +695,9 @@ for (my $i=0;$i<@servers;$i++) { > } > > if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { >- my $rating = GetRating( $res->{'biblionumber'}, $borrowernumber ); >- $res->{'rating_value'} = $rating->{'rating_value'}; >- $res->{'rating_total'} = $rating->{'rating_total'}; >- $res->{'rating_avg'} = $rating->{'rating_avg'}; >- $res->{'rating_avg_int'} = $rating->{'rating_avg_int'}; >+ my $ratings = Koha::Ratings->search({ biblionumber => $res->{biblionumber} }); >+ $res->{ratings} = $ratings; >+ $res->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef; > } > } > >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17089
:
54207
|
54208
|
54209
|
54210
|
54211
|
54212
|
54213
|
54214
|
54225
|
54230
|
54231
|
54232
|
54233
|
54234
|
54235
|
54236
|
54237
|
54238
|
54332
|
54333
|
54334
|
54335
|
54336
| 54337 |
54338
|
54339
|
54340
|
54341