Bug 19808: Handle deleted reviewers gracefully - opac-detail
authorVictor Grousset <victor.grousset@biblibre.com>
Fri, 15 Dec 2017 14:22:24 +0000 (15:22 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Dec 2017 14:07:37 +0000 (11:07 -0300)
And other display issues when the patron was NULL.
Which allows to keep the review even if it has no patron.
Because it might be useful.

For example when disconnected, the borrowernumber is null. So the
comments from deleted patrons were displayed as if the disconnected
user wrote them. So it had the edit button...

And fix borrowernumber not being passed to the template when
OpacStarRatings was false.

Test plan
1. Log in as a patron
2. Leave a comment/review on a record
3. Librarian: approve this comment
4. Delete the borrower
5. See the record (opac:/cgi-bin/koha/opac-detail.pl?biblionumber=RELEVANT_BIB_NUMBER)
6. Then you should see an error
7. Apply this patch
8. Refresh the page
9. Then you should see the record page with the comment

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Jon Knight <J.P.Knight@lboro.ac.uk>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
opac/opac-detail.pl

index e87d152..5fcb9f3 100644 (file)
                             <div id="newcomment"></div>
                                 [% IF ( reviews ) %]
                                     [% FOREACH review IN reviews %]
-                                        [% IF review.borrowernumber == borrowernumber %]
+                                        [% IF borrowernumber && 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="" />
                                             </div>
                                         [% ELSE %]
                                             <div class="commentline">
-                                                [% IF ( ShowReviewer != "none" ) %]
+                                                [% IF ( ShowReviewer != "none" && review.patron) %]
+
                                                     [% IF ( review.avatarurl ) %]
                                                         <img class="avatar" src="[% review.avatarurl %]" height="80" width="80" alt="" />
                                                     [% END %]
                                                     [% SWITCH ShowReviewer %]
                                                     [% CASE 'full' %]
-                                                        <h5>Comment by [% review.title %] [% review.firstname %] [% review.surname %]</h5>
+                                                        <h5>Comment by [% review.patron.title %] [% review.patron.firstname %] [% review.patron.surname %]</h5>
                                                     [% CASE 'first' %]
-                                                        <h5>Comment by [% review.firstname %]</h5>
+                                                        <h5>Comment by [% review.patron.firstname %]</h5>
                                                     [% CASE 'surname' %]
-                                                        <h5>Comment by [% review.surname %]</h5>
+                                                        <h5>Comment by [% review.patron.surname %]</h5>
                                                     [% CASE 'firstandinitial' %]
-                                                        <h5>Comment by [% review.firstname %] [% review.surname|truncate(2,'.') %]</h5>
+                                                        <h5>Comment by [% review.patron.firstname %] [% review.patron.surname|truncate(2,'.') %]</h5>
                                                     [% CASE 'username' %]
-                                                        <h5>Comment by [% review.userid %]</h5>
+                                                        <h5>Comment by [% review.patron.userid %]</h5>
                                                     [% END %]
+
                                                     <small>[% review.datereviewed | $KohaDates %]</small>
-                                                [% ELSIF ( ShowReviewer == "none") %]
+                                                [% ELSE %]
                                                     <h5>Patron comment on [% review.datereviewed | $KohaDates %]</h5>
-                                                [% END # / IF ShowReviewer != "none"%]
+                                                [% END # / IF ShowReviewer != "none" && review.patron %]
                                                 <p>
                                                   [% FILTER html_break %]
                                                   [% review.review |html %]
index 819e426..745c49c 100755 (executable)
@@ -844,17 +844,12 @@ if ( C4::Context->preference('reviewson') ) {
         my $patron = Koha::Patrons->find( $review->{borrowernumber} );
 
         # setting some borrower info into this hash
-        $review->{title}     = $patron->title;
-        $review->{surname}   = $patron->surname;
-        $review->{firstname} = $patron->firstname;
-        if ( $libravatar_enabled and $patron->email ) {
+        $review->{patron} = $patron;
+        if ( $libravatar_enabled and $patron and $patron->email ) {
             $review->{avatarurl} = libravatar_url( email => $patron->email, https => $ENV{HTTPS} );
         }
-        $review->{userid}     = $patron->userid;
-        $review->{cardnumber} = $patron->cardnumber;
 
-        if ( $patron->borrowernumber eq $borrowernumber ) {
-            $review->{your_comment} = 1;
+        if ( $patron and $patron->borrowernumber eq $borrowernumber ) {
             $loggedincommenter = 1;
         }
     }
@@ -1102,13 +1097,14 @@ if (C4::Context->preference("OPACURLOpenInNewWindow")) {
     $template->param(covernewwindow => 'false');
 }
 
+$template->param(borrowernumber => $borrowernumber);
+
 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
     my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber });
     my $my_rating = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
     $template->param(
         ratings => $ratings,
         my_rating => $my_rating,
-        borrowernumber => $borrowernumber
     );
 }