From 48fe93e945a3fcb55adaa17a44bd5963c5a9f3f4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 Feb 2016 16:15:55 +0000 Subject: [PATCH] Bug 15839: Koha::Reviews - Remove getreview Note that this (biblionumber, borrowernumber) pair should be defined as a unique key at the DB level (FIXME added) Signed-off-by: Marc Veron Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- C4/Review.pm | 20 +------------------- opac/opac-review.pl | 11 +++++++---- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/C4/Review.pm b/C4/Review.pm index f5b97e6c02..0c27833090 100644 --- a/C4/Review.pm +++ b/C4/Review.pm @@ -27,7 +27,7 @@ use vars qw(@ISA @EXPORT); BEGIN { require Exporter; @ISA = qw(Exporter); - @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber); + @EXPORT = qw(savereview updatereview numberofreviews numberofreviewsbybiblionumber); } =head1 NAME @@ -38,7 +38,6 @@ C4::Review - Perl Module containing routines for dealing with reviews of items use C4::Review; - my $review=getreview($biblionumber,$borrowernumber); savereview($biblionumber,$borrowernumber,$review); updatereview($biblionumber,$borrowernumber,$review); my $count=numberofreviews($status); @@ -50,23 +49,6 @@ Review.pm provides many routines for manipulating reviews. =head1 FUNCTIONS -=head2 getreview - - $review = getreview($biblionumber,$borrowernumber); - -Takes a borrowernumber and a biblionumber and returns the review of that biblio - -=cut - -sub getreview { - my ( $biblionumber, $borrowernumber ) = @_; - my $dbh = C4::Context->dbh; - my $query = "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?"; - my $sth = $dbh->prepare($query); - $sth->execute( $biblionumber, $borrowernumber ); - return $sth->fetchrow_hashref(); -} - =head2 savereview savereview($biblionumber,$borrowernumber, $review); diff --git a/opac/opac-review.pl b/opac/opac-review.pl index 43705e3852..fd3491ae76 100755 --- a/opac/opac-review.pl +++ b/opac/opac-review.pl @@ -17,8 +17,7 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; +use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth; use C4::Koha; @@ -27,6 +26,7 @@ use C4::Review; use C4::Biblio; use C4::Scrubber; use C4::Debug; +use Koha::Reviews; my $query = new CGI; my $biblionumber = $query->param('biblionumber'); @@ -43,7 +43,8 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( # FIXME: need to allow user to delete their own comment(s) my $biblio = GetBiblioData($biblionumber); -my $savedreview = getreview($biblionumber,$borrowernumber); +# FIXME biblionumber, borrowernumber should be a unique key of reviews +my $savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next; my ($clean, @errors); if (defined $review) { if ($review !~ /\S/) { @@ -70,10 +71,12 @@ if (defined $review) { } (@errors ) and $template->param( ERRORS=>\@errors); ($cgi_debug) and $template->param(cgi_debug=>1 ); +$review = $clean; +$review ||= $savedreview->review if $savedreview; $template->param( 'biblionumber' => $biblionumber, 'borrowernumber' => $borrowernumber, - 'review' => $clean || $savedreview->{'review'}, + 'review' => $review, 'reviewid' => scalar $query->param('reviewid') || 0, 'title' => $biblio->{'title'}, ); -- 2.39.5