Bugzilla – Attachment 51198 Details for
Bug 15839
Move the reviews related code to Koha::Reviews
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15839: Koha::Reviews - Remove getreviews
Bug-15839-KohaReviews---Remove-getreviews.patch (text/plain), 12.84 KB, created by
Jonathan Druart
on 2016-05-04 16:19:31 UTC
(
hide
)
Description:
Bug 15839: Koha::Reviews - Remove getreviews
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-05-04 16:19:31 UTC
Size:
12.84 KB
patch
obsolete
>From 442b0beb551169a9bc78c133a53dacaeee2fee54 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 16 Feb 2016 15:09:01 +0000 >Subject: [PATCH] Bug 15839: Koha::Reviews - Remove getreviews >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >The C4::Reviews::getreviews subroutine retrieved the reviews for a given >record, depending on their status. >This can be achieve with a call to Koha::Reviews->search. >There were 2 calls to this subroutine. The one from opac-ISBDdetail.pl >does not look in used: the reviews are not display on this page. It >certainly comes from an old copy/paste from opac-detail.pl. >The one from opac-detail only asked for the approved reviews. So the >logged in user does not see its own review if it is pending approval. >Actually this pending approval review is only displayed when the user >submits it (because of a unecessary complex text replacement done in >JS). >With this patch, the approved reviews AND the unaproved review from the >logged in user will be displayed. >It will allow a future enhancement to add a way to delete our own >reviews. > >Moreover, the reviews were retrieved even if they were not displayed (if >reviewson is off), it's now fixed. > >Signed-off-by: Marc Véron <veron@veron.ch> >--- > C4/Review.pm | 21 +------ > .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 12 ++-- > .../opac-tmpl/bootstrap/en/modules/opac-review.tt | 37 +----------- > opac/opac-ISBDdetail.pl | 14 +---- > opac/opac-detail.pl | 67 ++++++++++++---------- > 5 files changed, 49 insertions(+), 102 deletions(-) > >diff --git a/C4/Review.pm b/C4/Review.pm >index 5d56396..6f40ec1 100644 >--- a/C4/Review.pm >+++ b/C4/Review.pm >@@ -28,7 +28,7 @@ BEGIN { > require Exporter; > @ISA = qw(Exporter); > @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber >- getreviews getallreviews approvereview unapprovereview deletereview); >+ getallreviews approvereview unapprovereview deletereview); > } > > =head1 NAME >@@ -44,7 +44,6 @@ C4::Review - Perl Module containing routines for dealing with reviews of items > updatereview($biblionumber,$borrowernumber,$review); > my $count=numberofreviews($status); > my $count=numberofreviewsbybiblionumber($biblionumber); >- my $reviews=getreviews($biblionumber, $status); > my $reviews=getallreviews($status, [$offset], [$row_count]); > > =head1 DESCRIPTION >@@ -140,24 +139,6 @@ sub numberofreviewsbybiblionumber { > return $sth->fetchrow; > } > >-=head2 getreviews >- >- my $reviews=getreviews($biblionumber, $status); >- >-Return all reviews where in the 'reviews' database : >-'biblionumber' = $biblionumber and 'approved' = $status >- >-=cut >- >-sub getreviews { >- my ( $biblionumber, $approved ) = @_; >- my $dbh = C4::Context->dbh; >- my $query = "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc"; >- my $sth = $dbh->prepare($query); >- $sth->execute( $biblionumber, $approved ); >- return $sth->fetchall_arrayref( {} ); >-} >- > =head2 getallreviews > > my $reviews=getallreviews($status, [$offset], [$row_count]); >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 fe72d01..cf9b5e2 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >@@ -888,12 +888,16 @@ > <div id="newcomment"></div> > [% IF ( reviews ) %] > [% FOREACH review IN reviews %] >- [% IF ( review.your_comment ) %] >+ [% IF review.borrowernumber == borrowernumber %] > <div class="commentline yours" id="c[% review.reviewid %]"> > [% IF ( review.avatarurl ) %] > <img class="avatar" src="[% review.avatarurl %]" height="80" width="80" alt="" /> > [% END %] >- <h5>Your comment</h5> >+ [% IF review.approved %] >+ <h5>Your comment</h5> >+ [% ELSE %] >+ <h5>Your comment (preview, pending approval)</h5> >+ [% END %] > <small>[% review.datereviewed | $KohaDates %]</small> > <p> > [% FILTER html_break %] >@@ -930,7 +934,7 @@ > [% END %] > </p> > </div> <!-- / .commentline --> >- [% END # / IF review.your_comment %] >+ [% END %] > [% END # / FOREACH reviews %] > [% ELSE %] > <p>There are no comments for this item.</p> >@@ -939,7 +943,7 @@ > [% IF ( loggedinusername ) %] > [% UNLESS ( loggedincommenter ) %] > <div id="addcomment"> <a href="#" onclick="Dopop('/cgi-bin/koha/opac-review.pl?biblionumber=[% biblionumber %]'); return false;"> >- Post or edit your comments on this item. >+ Post your comments on this item. > </a></div> > [% END %] > [% ELSE %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-review.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-review.tt >index 44792a5..c5ecd82 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-review.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-review.tt >@@ -61,41 +61,8 @@ > <script type="text/javascript"> > //<![CDATA[ > $(document).ready(function() { >- var inject_old = function(comment) { >- [% IF ( reviewid ) %] >- [% IF ( cgi_debug ) %]alert(_("injecting OLD comment: ")+comment);[% END %] >- parent.opener.$('#c[% reviewid %] p').prev("small").prev("h5").html(_("Your edited comment (preview, pending approval)")); >- parent.opener.$('#c[% reviewid %] p').html(comment); >- parent.opener.$('#c[% reviewid %] p').append(" <a href=\"#comment\" onclick=\"Dopop(\'/cgi-bin/koha/opac-review.pl?biblionumber=[% biblionumber | uri %]&reviewid=[% reviewid | uri%]\');\">"+_("Edit")+"<\/a>"); >- [% END %] >- return 1; >- }; >- var inject_new = function(comment) { >- [% IF ( cgi_debug ) %]alert(_("injecting NEW comment: ") +comment);[% END %] >- parent.opener.$('#newcomment').attr("class","yours"); >- parent.opener.$('#newcomment').html( >- "<h5>" + _("Your comment (preview, pending approval)") + "<\/h5>" + >- "<p>"+comment+"<\/p>" + >- "<a href=\"#comment\" onclick=\"Dopop(\'/cgi-bin/koha/opac-review.pl?biblionumber=[% biblionumber |uri%]\');\">"+_("Edit")+"<\/a><\/p>" >- ); >- parent.opener.$("#addcomment").prev("p").remove(); >- parent.opener.$("#addcomment").remove(); >- }; >- [% IF ( clean_review ) %] >- var clean_review = "[% clean_review |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"; // TMPL var must not contain " quotes. >- [% IF ( reviewid ) %] >- inject_old(clean_review); >- [% ELSE %] >- inject_new(clean_review); >- [% END %] >- [% END %] >- [% IF ( WINDOW_CLOSE ) %] >- [% IF ( ERRORS ) %] >- // flash this page, then close. Change warning in template if you change this value. >- setTimeout("window.close()",5000); >- [% ELSE %] >- window.close(); >- [% END %] >+ [% IF WINDOW_CLOSE %] >+ window.close(); > [% END %] > }); > //]]> >diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl >index 49d7ce7..fec4b67 100755 >--- a/opac/opac-ISBDdetail.pl >+++ b/opac/opac-ISBDdetail.pl >@@ -51,11 +51,11 @@ use C4::Biblio; > use C4::Items; > use C4::Reserves; > use C4::Acquisition; >-use C4::Review; > use C4::Serials; # uses getsubscriptionfrom biblionumber > use C4::Koha; > use C4::Members; # GetMember > >+ > my $query = CGI->new(); > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { >@@ -163,24 +163,12 @@ for my $itm (@items) { > unless $allow_onshelf_holds; > } > >-my $reviews = getreviews( $biblionumber, 1 ); >-foreach ( @$reviews ) { >- my $borrower_number_review = $_->{borrowernumber}; >- my $borrowerData = GetMember('borrowernumber' =>$borrower_number_review); >- # setting some borrower info into this hash >- $_->{title} = $borrowerData->{'title'}; >- $_->{surname} = $borrowerData->{'surname'}; >- $_->{firstname} = $borrowerData->{'firstname'}; >-} >- >- > $template->param( > RequestOnOpac => C4::Context->preference("RequestOnOpac"), > AllowOnShelfHolds => $allow_onshelf_holds, > norequests => $norequests, > ISBD => $res, > biblionumber => $biblionumber, >- reviews => $reviews, > ); > > #Search for title in links >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 98afe3e..0960900 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -52,6 +52,7 @@ use C4::HTML5Media; > use C4::CourseReserves qw(GetItemCourseReservesInfo); > > use Koha::Virtualshelves; >+use Koha::Reviews; > > BEGIN { > if (C4::Context->preference('BakerTaylorEnabled')) { >@@ -789,39 +790,45 @@ $template->param( > ocoins => GetCOinSBiblio($record), > ); > >-my $libravatar_enabled = 0; >-if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) { >- eval { >- require Libravatar::URL; >- Libravatar::URL->import(); >- }; >- if (!$@ ) { >- $libravatar_enabled = 1; >+my ( $loggedincommenter, $reviews ); >+if ( C4::Context->preference('reviewson') ) { >+ $reviews = Koha::Reviews->search( >+ { >+ biblionumber => $biblionumber, >+ -or => { approved => 1, borrowernumber => $borrowernumber } >+ }, >+ { >+ order_by => { -desc => 'datereviewed' } >+ } >+ )->unblessed; >+ my $libravatar_enabled = 0; >+ if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto') ) { >+ eval { >+ require Libravatar::URL; >+ Libravatar::URL->import(); >+ }; >+ if ( !$@ ) { >+ $libravatar_enabled = 1; >+ } > } >-} >- >-my $reviews = getreviews( $biblionumber, 1 ); >-my $loggedincommenter; >- >- >- >+ for my $review (@$reviews) { >+ my $borrowerData = GetMember( 'borrowernumber' => $review->{borrowernumber} ); >+ >+ # setting some borrower info into this hash >+ $review->{title} = $borrowerData->{'title'}; >+ $review->{surname} = $borrowerData->{'surname'}; >+ $review->{firstname} = $borrowerData->{'firstname'}; >+ if ( $libravatar_enabled and $borrowerData->{'email'} ) { >+ $review->{avatarurl} = libravatar_url( email => $borrowerData->{'email'}, https => $ENV{HTTPS} ); >+ } >+ $review->{userid} = $borrowerData->{'userid'}; >+ $review->{cardnumber} = $borrowerData->{'cardnumber'}; > >-foreach ( @$reviews ) { >- my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber}); >- # setting some borrower info into this hash >- $_->{title} = $borrowerData->{'title'}; >- $_->{surname} = $borrowerData->{'surname'}; >- $_->{firstname} = $borrowerData->{'firstname'}; >- if ($libravatar_enabled and $borrowerData->{'email'}) { >- $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS}); >+ if ( $borrowerData->{'borrowernumber'} eq $borrowernumber ) { >+ $review->{your_comment} = 1; >+ $loggedincommenter = 1; >+ } > } >- $_->{userid} = $borrowerData->{'userid'}; >- $_->{cardnumber} = $borrowerData->{'cardnumber'}; >- >- if ($borrowerData->{'borrowernumber'} eq $borrowernumber) { >- $_->{your_comment} = 1; >- $loggedincommenter = 1; >- } > } > > if ( C4::Context->preference("OPACISBD") ) { >-- >2.7.0
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 15839
:
48166
|
48167
|
48168
|
48169
|
48170
|
48171
|
48172
|
48173
|
48174
|
48175
|
48176
|
48280
|
48281
|
48282
|
48283
|
48284
|
48285
|
48286
|
48287
|
48288
|
48289
|
48290
|
51197
|
51198
|
51199
|
51200
|
51201
|
51202
|
51203
|
51204
|
51205
|
51206
|
51207
|
53794
|
53795
|
53796
|
53797
|
53798
|
53799
|
53800
|
53801
|
53802
|
53803
|
53804
|
53805
|
53806
|
53807