3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use vars
qw(@ISA @EXPORT);
30 @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
31 getreviews getallreviews approvereview unapprovereview deletereview);
36 C4::Review - Perl Module containing routines for dealing with reviews of items
42 my $review=getreview($biblionumber,$borrowernumber);
43 savereview($biblionumber,$borrowernumber,$review);
44 updatereview($biblionumber,$borrowernumber,$review);
45 my $count=numberofreviews($status);
46 my $count=numberofreviewsbybiblionumber($biblionumber);
47 my $reviews=getreviews($biblionumber, $status);
48 my $reviews=getallreviews($status, [$offset], [$row_count]);
52 Review.pm provides many routines for manipulating reviews.
58 $review = getreview($biblionumber,$borrowernumber);
60 Takes a borrowernumber and a biblionumber and returns the review of that biblio
65 my ( $biblionumber, $borrowernumber ) = @_;
66 my $dbh = C4
::Context
->dbh;
67 my $query = "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?";
68 my $sth = $dbh->prepare($query);
69 $sth->execute( $biblionumber, $borrowernumber );
70 return $sth->fetchrow_hashref();
75 savereview($biblionumber,$borrowernumber, $review);
77 Save a review in the 'reviews' database
82 my ( $biblionumber, $borrowernumber, $review ) = @_;
83 my $dbh = C4
::Context
->dbh;
84 my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
85 review,approved,datereviewed) VALUES
87 my $sth = $dbh->prepare($query);
88 $sth->execute( $borrowernumber, $biblionumber, $review );
93 updateview($biblionumber,$borrowernumber, $review);
95 Update the review description in the 'reviews' database
100 my ( $biblionumber, $borrowernumber, $review ) = @_;
101 my $dbh = C4
::Context
->dbh;
102 my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0 WHERE borrowernumber=? and biblionumber=?";
103 my $sth = $dbh->prepare($query);
104 $sth->execute( $review, $borrowernumber, $biblionumber );
107 =head2 numberofreviews
109 my $count=numberofreviews( [$status] );
111 Return the number of reviews where in the 'reviews' database : 'approved' = $status
112 (By default $status = 1)
116 sub numberofreviews
{
118 my $status = ( defined($param) ?
$param : 1 );
119 my $dbh = C4
::Context
->dbh;
120 my $query = "SELECT count(*) FROM reviews WHERE approved=?";
121 my $sth = $dbh->prepare($query);
122 $sth->execute($status);
123 return $sth->fetchrow;
126 =head2 numberofreviewsbybiblionumber
128 my $count=numberofreviewsbybiblionumber($biblionumber);
130 Return the number of reviews approved for a given biblionumber
134 sub numberofreviewsbybiblionumber
{
135 my ($biblionumber) = @_;
136 my $dbh = C4
::Context
->dbh;
137 my $query = "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
138 my $sth = $dbh->prepare($query);
139 $sth->execute( $biblionumber, 1 );
140 return $sth->fetchrow;
145 my $reviews=getreviews($biblionumber, $status);
147 Return all reviews where in the 'reviews' database :
148 'biblionumber' = $biblionumber and 'approved' = $status
153 my ( $biblionumber, $approved ) = @_;
154 my $dbh = C4
::Context
->dbh;
155 my $query = "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
156 my $sth = $dbh->prepare($query);
157 $sth->execute( $biblionumber, $approved );
158 return $sth->fetchall_arrayref( {} );
163 my $reviews=getallreviews($status, [$offset], [$row_count]);
165 Return all reviews where in the 'reviews' database : 'approved' = $status
167 If offset and row_count are fiven, it's return all reviews between the
168 $offset position and the ($offset + $row_count) position.
169 (By default : $offset = 0 and $row_count = 20)
174 my ( $status, $offset, $row_count ) = @_;
175 my @params = ( $status, ( $offset ?
$offset : 0 ), ( $row_count ?
$row_count : 20 ) );
176 my $dbh = C4
::Context
->dbh;
177 my $query = "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?";
178 my $sth = $dbh->prepare($query);
179 $sth->execute(@params);
180 return $sth->fetchall_arrayref( {} );
185 approvereview($reviewid);
187 Takes a reviewid and marks that review approved
193 my $dbh = C4
::Context
->dbh();
194 my $query = "UPDATE reviews
197 my $sth = $dbh->prepare($query);
198 $sth->execute( 1, $reviewid );
201 =head2 unapprovereview
203 unapprovereview($reviewid);
205 Takes a reviewid and marks that review as not approved
209 sub unapprovereview
{
211 my $dbh = C4
::Context
->dbh();
212 my $query = "UPDATE reviews
215 my $sth = $dbh->prepare($query);
216 $sth->execute( 0, $reviewid );
221 deletereview($reviewid);
223 Takes a reviewid and deletes it
229 my $dbh = C4
::Context
->dbh();
230 my $query = "DELETE FROM reviews
232 my $sth = $dbh->prepare($query);
233 $sth->execute($reviewid);