X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FReview.pm;h=5d56396f2178d725f80e4e2772626a36c6039242;hb=eb04d174d91201b05b6e348dc672f9351dc0aaf0;hp=f94dbc89872ddd995fc43fd68fd9379abc1893dd;hpb=03890c90ac41f66b2de04d0280e2e96a0d2e8be8;p=koha.git diff --git a/C4/Review.pm b/C4/Review.pm index f94dbc8987..5d56396f21 100644 --- a/C4/Review.pm +++ b/C4/Review.pm @@ -4,33 +4,31 @@ package C4::Review; # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; use warnings; use C4::Context; -use vars qw($VERSION @ISA @EXPORT); +use vars qw(@ISA @EXPORT); BEGIN { - # set the version for version checking - $VERSION = 3.00; - require Exporter; - @ISA = qw(Exporter); - @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber - getreviews getallreviews approvereview deletereview); + require Exporter; + @ISA = qw(Exporter); + @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber + getreviews getallreviews approvereview unapprovereview deletereview); } =head1 NAME @@ -44,9 +42,10 @@ C4::Review - Perl Module containing routines for dealing with reviews of items my $review=getreview($biblionumber,$borrowernumber); savereview($biblionumber,$borrowernumber,$review); updatereview($biblionumber,$borrowernumber,$review); - my $count=numberofreviews($biblionumber); - my $reviews=getreviews($biblionumber); - my $reviews=getallreviews($status); + my $count=numberofreviews($status); + my $count=numberofreviewsbybiblionumber($biblionumber); + my $reviews=getreviews($biblionumber, $status); + my $reviews=getallreviews($status, [$offset], [$row_count]); =head1 DESCRIPTION @@ -65,69 +64,120 @@ Takes a borrowernumber and a biblionumber and returns the review of that biblio sub getreview { my ( $biblionumber, $borrowernumber ) = @_; my $dbh = C4::Context->dbh; - my $query = - "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?"; - my $sth = $dbh->prepare($query); + 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); + +Save a review in the 'reviews' database + +=cut + sub savereview { my ( $biblionumber, $borrowernumber, $review ) = @_; my $dbh = C4::Context->dbh; my $query = "INSERT INTO reviews (borrowernumber,biblionumber, - review,approved,datereviewed) VALUES + review,approved,datereviewed) VALUES (?,?,?,0,now())"; my $sth = $dbh->prepare($query); - $sth->execute( $borrowernumber, $biblionumber, $review); + $sth->execute( $borrowernumber, $biblionumber, $review ); } +=head2 updatereview + + updateview($biblionumber,$borrowernumber, $review); + +Update the review description in the 'reviews' database + +=cut + sub updatereview { my ( $biblionumber, $borrowernumber, $review ) = @_; my $dbh = C4::Context->dbh; my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0 WHERE borrowernumber=? and biblionumber=?"; - my $sth = $dbh->prepare($query); + my $sth = $dbh->prepare($query); $sth->execute( $review, $borrowernumber, $biblionumber ); } +=head2 numberofreviews + + my $count=numberofreviews( [$status] ); + +Return the number of reviews where in the 'reviews' database : 'approved' = $status +(By default $status = 1) + +=cut + sub numberofreviews { - my $dbh = C4::Context->dbh; - my $query = - "SELECT count(*) FROM reviews WHERE approved=?"; - my $sth = $dbh->prepare($query); - $sth->execute( 1 ); - return $sth->fetchrow; + my ($param) = @_; + my $status = ( defined($param) ? $param : 1 ); + my $dbh = C4::Context->dbh; + my $query = "SELECT count(*) FROM reviews WHERE approved=?"; + my $sth = $dbh->prepare($query); + $sth->execute($status); + return $sth->fetchrow; } +=head2 numberofreviewsbybiblionumber + + my $count=numberofreviewsbybiblionumber($biblionumber); + +Return the number of reviews approved for a given biblionumber + +=cut + sub numberofreviewsbybiblionumber { my ($biblionumber) = @_; my $dbh = C4::Context->dbh; - my $query = - "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?"; - my $sth = $dbh->prepare($query); + my $query = "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?"; + my $sth = $dbh->prepare($query); $sth->execute( $biblionumber, 1 ); - return $sth->fetchrow; + 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) || warn $dbh->err_str; + 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({}); + return $sth->fetchall_arrayref( {} ); } +=head2 getallreviews + + my $reviews=getallreviews($status, [$offset], [$row_count]); + +Return all reviews where in the 'reviews' database : 'approved' = $status + +If offset and row_count are fiven, it's return all reviews between the +$offset position and the ($offset + $row_count) position. +(By default : $offset = 0 and $row_count = 20) + +=cut + sub getallreviews { - my ($status, $offset, $row_count) = @_; - my @params = ($status,($offset ? $offset : 0),($row_count ? $row_count : 20)); - my $dbh = C4::Context->dbh; - my $query = - "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?"; - my $sth = $dbh->prepare($query) || warn $dbh->err_str; + my ( $status, $offset, $row_count ) = @_; + my @params = ( $status, ( $offset ? $offset : 0 ), ( $row_count ? $row_count : 20 ) ); + my $dbh = C4::Context->dbh; + my $query = "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?"; + my $sth = $dbh->prepare($query); $sth->execute(@params); - return $sth->fetchall_arrayref({}); + return $sth->fetchall_arrayref( {} ); } =head2 approvereview @@ -148,6 +198,24 @@ sub approvereview { $sth->execute( 1, $reviewid ); } +=head2 unapprovereview + + unapprovereview($reviewid); + +Takes a reviewid and marks that review as not approved + +=cut + +sub unapprovereview { + my ($reviewid) = @_; + my $dbh = C4::Context->dbh(); + my $query = "UPDATE reviews + SET approved=? + WHERE reviewid=?"; + my $sth = $dbh->prepare($query); + $sth->execute( 0, $reviewid ); +} + =head2 deletereview deletereview($reviewid);