View | Details | Raw Unified | Return to bug 17089
Collapse All | Expand All

(-)a/Koha/Ratings.pm (+19 lines)
Lines 35-40 Koha::Ratings - Koha Rating Object set class Link Here
35
35
36
=cut
36
=cut
37
37
38
=head3 get_avg_rating
39
40
=cut
41
42
sub get_avg_rating {
43
    my ( $self ) = @_;
44
45
    my $sum   = $self->_resultset->get_column('rating_value')->sum();
46
    my $total = $self->count();
47
48
    my $avg = 0;
49
    if ( $sum and $total ) {
50
        eval { $avg = $sum / $total };
51
    }
52
    $avg = sprintf( "%.1f", $avg );
53
54
    return $avg;
55
}
56
38
=head3 type
57
=head3 type
39
58
40
=cut
59
=cut
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (-9 / +10 lines)
Lines 1-3 Link Here
1
[% USE Math %]
1
[% USE Koha %]
2
[% USE Koha %]
2
[% USE KohaDates %]
3
[% USE KohaDates %]
3
[% USE Branches %]
4
[% USE Branches %]
Lines 468-477 Link Here
468
                        <form method="post" action="/cgi-bin/koha/opac-ratings.pl">
469
                        <form method="post" action="/cgi-bin/koha/opac-ratings.pl">
469
                            <div class="results_summary ratings">
470
                            <div class="results_summary ratings">
470
471
472
                                [% SET rating_avg = ratings.get_avg_rating() %]
473
                                [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %]
471
                                [% FOREACH i  IN [ 1 2 3 4 5  ] %]
474
                                [% FOREACH i  IN [ 1 2 3 4 5  ] %]
472
                                    [% IF rating_avg == i && borrowernumber %]
475
                                    [% IF rating_avg_int == i && borrowernumber %]
473
                                        <input class="auto-submit-star" type="radio" name="rating"  value="[% i %]"  checked="checked" />
476
                                        <input class="auto-submit-star" type="radio" name="rating"  value="[% i %]"  checked="checked" />
474
                                    [% ELSIF rating_avg == i %]
477
                                    [% ELSIF rating_avg_int == i %]
475
                                        <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" checked="checked" disabled="disabled" />
478
                                        <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" checked="checked" disabled="disabled" />
476
                                    [% ELSIF borrowernumber  %]
479
                                    [% ELSIF borrowernumber  %]
477
                                        <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" />
480
                                        <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" />
Lines 483-501 Link Here
483
                                <!-- define some hidden vars for ratings -->
486
                                <!-- define some hidden vars for ratings -->
484
487
485
                                <input  type="hidden" name='biblionumber'  value="[% biblionumber %]" />
488
                                <input  type="hidden" name='biblionumber'  value="[% biblionumber %]" />
486
                                <input  type="hidden" name='rating_value' id='rating_value' value="[% rating_value %]" />
489
                                <input  type="hidden" name='rating_value' id='rating_value' value="[% my_rating.rating_value %]" />
487
                                <input  type="hidden" name='rating_total' id='rating_total' value="[% rating_total %]" />
488
                                <input  type="hidden" name='rating_avg_int' id='rating_avg_int' value="[% rating_avg_int %]" />
489
490
490
                                [% UNLESS ( rating_readonly ) %]&nbsp;  <input name="rate_button" type="submit" value="Rate me" />[% END %]&nbsp;
491
                                [% UNLESS ( rating_readonly ) %]&nbsp;  <input name="rate_button" type="submit" value="Rate me" />[% END %]&nbsp;
491
492
492
                                [% IF ( rating_value ) %]
493
                                [% IF my_rating %]
493
                                    <span id="rating_value_text">your rating: [% rating_value %], </span>
494
                                    <span id="rating_value_text">your rating: [% my_rating.rating_value %], </span>
494
                                [% ELSE %]
495
                                [% ELSE %]
495
                                    <span id="rating_value_text"></span>
496
                                    <span id="rating_value_text"></span>
496
                                [% END %]
497
                                [% END %]
497
498
498
                                <span id="rating_text">average rating: [% rating_avg_int %] ([% rating_total %] votes)</span>
499
                                <span id="rating_text">average rating: [% rating_avg %] ([% ratings.count %] votes)</span>
499
                            </div>
500
                            </div>
500
                        </form>
501
                        </form>
501
                    [% END # / IF OpacStarRatings != 'disable' %]
502
                    [% END # / IF OpacStarRatings != 'disable' %]
Lines 1597-1603 Link Here
1597
                    $("#rating_value_text").text('');
1598
                    $("#rating_value_text").text('');
1598
                  }
1599
                  }
1599
1600
1600
                  $("#rating_text").text(_("average rating: ") + data.rating_avg_int + " (" + data.rating_total + ' ' + _("votes") + ")");
1601
                  $("#rating_text").text(_("average rating: ") + data.rating_avg + " (" + data.rating_total + ' ' + _("votes") + ")");
1601
1602
1602
                }
1603
                }
1603
              }, "json");
1604
              }, "json");
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt (-7 / +6 lines)
Lines 468-486 Link Here
468
468
469
                                                [% IF ( OpacStarRatings == 'all' ) %]
469
                                                [% IF ( OpacStarRatings == 'all' ) %]
470
                                                    <div class="results_summary ratings">
470
                                                    <div class="results_summary ratings">
471
                                                      [% SET rating_avg = SEARCH_RESULT.ratings.get_avg_rating() %]
472
                                                      [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %]
471
                                                        [% FOREACH i  IN [ 1 2 3 4 5  ] %]
473
                                                        [% FOREACH i  IN [ 1 2 3 4 5  ] %]
472
                                                            [% IF ( SEARCH_RESULT.rating_avg == i ) %]
474
                                                            [% IF rating_avg_int == i %]
473
                                                                <input class="star" type="radio"  name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" checked="checked" disabled="disabled"   />
475
                                                                <input class="star" type="radio"  name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" checked="checked" disabled="disabled"   />
474
                                                            [% ELSE   %]
476
                                                            [% ELSE %]
475
                                                                <input class="star" type="radio"  name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" disabled="disabled"   />
477
                                                                <input class="star" type="radio"  name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" disabled="disabled"   />
476
                                                            [% END %]
478
                                                            [% END %]
477
                                                        [% END %]
479
                                                        [% END %]
478
480
479
                                                        <input type="hidden" name="biblionumber"  value="[% SEARCH_RESULT.biblionumber %]" />
481
                                                        [% IF SEARCH_RESULT.ratings.count > 0  %]
480
                                                        <input type="hidden" name="loggedinuser"  value="[% loggedinuser %]" />
482
                                                            <span id="rating_total_[% SEARCH_RESULT.biblionumber %]">&nbsp;&nbsp;([% SEARCH_RESULT.ratings.count %] votes)</span>
481
482
                                                        [% IF SEARCH_RESULT.rating_total && SEARCH_RESULT.rating_total > 0  %]
483
                                                            <span id="rating_total_[% SEARCH_RESULT.biblionumber %]">&nbsp;&nbsp;([% SEARCH_RESULT.rating_total %] votes)</span>
484
                                                        [% ELSE %]
483
                                                        [% ELSE %]
485
                                                            <br />
484
                                                            <br />
486
                                                        [% END %]
485
                                                        [% END %]
(-)a/opac/opac-detail.pl (-6 / +5 lines)
Lines 37-43 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn); Link Here
37
use C4::External::Amazon;
37
use C4::External::Amazon;
38
use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
38
use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
39
use C4::Review;
39
use C4::Review;
40
use C4::Ratings;
41
use C4::Members;
40
use C4::Members;
42
use C4::XSLT;
41
use C4::XSLT;
43
use C4::ShelfBrowser;
42
use C4::ShelfBrowser;
Lines 52-57 use C4::HTML5Media; Link Here
52
use C4::CourseReserves qw(GetItemCourseReservesInfo);
51
use C4::CourseReserves qw(GetItemCourseReservesInfo);
53
52
54
use Koha::Virtualshelves;
53
use Koha::Virtualshelves;
54
use Koha::Ratings;
55
55
56
BEGIN {
56
BEGIN {
57
	if (C4::Context->preference('BakerTaylorEnabled')) {
57
	if (C4::Context->preference('BakerTaylorEnabled')) {
Lines 1068-1079 if (C4::Context->preference("OPACURLOpenInNewWindow")) { Link Here
1068
}
1068
}
1069
1069
1070
if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1070
if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1071
    my $rating = GetRating( $biblionumber, $borrowernumber );
1071
    my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber });
1072
    my $my_rating = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
1072
    $template->param(
1073
    $template->param(
1073
        rating_value   => $rating->{'rating_value'},
1074
        ratings => $ratings,
1074
        rating_total   => $rating->{'rating_total'},
1075
        my_rating => $my_rating,
1075
        rating_avg     => $rating->{'rating_avg'},
1076
        rating_avg_int => $rating->{'rating_avg_int'},
1077
        borrowernumber => $borrowernumber
1076
        borrowernumber => $borrowernumber
1078
    );
1077
    );
1079
}
1078
}
(-)a/opac/opac-ratings-ajax.pl (-8 / +10 lines)
Lines 33-39 use C4::Auth qw(:DEFAULT check_cookie_auth); Link Here
33
use C4::Context;
33
use C4::Context;
34
use C4::Debug;
34
use C4::Debug;
35
use C4::Output qw(:html :ajax pagination_bar);
35
use C4::Output qw(:html :ajax pagination_bar);
36
use C4::Ratings;
37
36
38
use Koha::Ratings;
37
use Koha::Ratings;
39
38
Lines 74-95 $rating_value //= ''; Link Here
74
73
75
if ( $rating_value eq '' ) {
74
if ( $rating_value eq '' ) {
76
    Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser } )->delete;
75
    Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser } )->delete;
77
    $rating = Koha::Ratings->search({ biblionumber => $biblionumber })->get_rating;
78
}
76
}
79
77
80
elsif ( $rating_value and !$rating_old_value ) {
78
elsif ( $rating_value and !$rating_old_value ) {
81
    $rating = Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $loggedinuser, rating_value => $rating_value, })->store;
79
    Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $loggedinuser, rating_value => $rating_value, })->store;
82
}
80
}
83
81
84
elsif ( $rating_value ne $rating_old_value ) {
82
elsif ( $rating_value ne $rating_old_value ) {
85
    $rating = Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser })->rating_value($rating_value)->store;
83
    Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser })->rating_value($rating_value)->store;
86
}
84
}
87
85
86
my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber });
87
my $my_rating = $ratings->search({ borrowernumber => $loggedinuser })->next;
88
my $avg = $ratings->get_avg_rating;
89
88
my %js_reply = (
90
my %js_reply = (
89
    rating_total   => $rating->{'rating_total'},
91
    rating_total   => $ratings->count,
90
    rating_avg     => $rating->{'rating_avg'},
92
    rating_avg     => $avg,
91
    rating_avg_int => $rating->{'rating_avg_int'},
93
    rating_avg_int => sprintf("%.0f", $avg),
92
    rating_value   => $rating->{'rating_value'},
94
    rating_value   => $my_rating->rating_value,
93
    auth_status    => $auth_status,
95
    auth_status    => $auth_status,
94
96
95
);
97
);
(-)a/opac/opac-ratings.pl (-1 lines)
Lines 31-37 use CGI qw ( -utf8 ); Link Here
31
31
32
use C4::Auth;
32
use C4::Auth;
33
use C4::Context;
33
use C4::Context;
34
use C4::Ratings;
35
use C4::Debug;
34
use C4::Debug;
36
35
37
use Koha::Ratings;
36
use Koha::Ratings;
(-)a/opac/opac-search.pl (-7 / +4 lines)
Lines 51-60 use C4::Koha; Link Here
51
use C4::Tags qw(get_tags);
51
use C4::Tags qw(get_tags);
52
use C4::Branch; # GetBranches
52
use C4::Branch; # GetBranches
53
use C4::SocialData;
53
use C4::SocialData;
54
use C4::Ratings;
55
use C4::External::OverDrive;
54
use C4::External::OverDrive;
56
55
57
use Koha::LibraryCategories;
56
use Koha::LibraryCategories;
57
use Koha::Ratings;
58
58
59
use POSIX qw(ceil floor strftime);
59
use POSIX qw(ceil floor strftime);
60
use URI::Escape;
60
use URI::Escape;
Lines 695-705 for (my $i=0;$i<@servers;$i++) { Link Here
695
            }
695
            }
696
696
697
            if ( C4::Context->preference('OpacStarRatings') eq 'all' ) {
697
            if ( C4::Context->preference('OpacStarRatings') eq 'all' ) {
698
                my $rating = GetRating( $res->{'biblionumber'}, $borrowernumber );
698
                my $ratings = Koha::Ratings->search({ biblionumber => $res->{biblionumber} });
699
                $res->{'rating_value'}  = $rating->{'rating_value'};
699
                $res->{ratings} = $ratings;
700
                $res->{'rating_total'}  = $rating->{'rating_total'};
700
                $res->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
701
                $res->{'rating_avg'}    = $rating->{'rating_avg'};
702
                $res->{'rating_avg_int'} = $rating->{'rating_avg_int'};
703
            }
701
            }
704
        }
702
        }
705
703
706
- 

Return to bug 17089