Bug 15128: Revert Display all purchase suggestions whether or not suggestion was...
[koha.git] / C4 / Review.pm
blob5d56396f2178d725f80e4e2772626a36c6039242
1 package C4::Review;
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>.
20 use strict;
21 use warnings;
23 use C4::Context;
25 use vars qw(@ISA @EXPORT);
27 BEGIN {
28 require Exporter;
29 @ISA = qw(Exporter);
30 @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
31 getreviews getallreviews approvereview unapprovereview deletereview);
34 =head1 NAME
36 C4::Review - Perl Module containing routines for dealing with reviews of items
38 =head1 SYNOPSIS
40 use C4::Review;
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]);
50 =head1 DESCRIPTION
52 Review.pm provides many routines for manipulating reviews.
54 =head1 FUNCTIONS
56 =head2 getreview
58 $review = getreview($biblionumber,$borrowernumber);
60 Takes a borrowernumber and a biblionumber and returns the review of that biblio
62 =cut
64 sub getreview {
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();
73 =head2 savereview
75 savereview($biblionumber,$borrowernumber, $review);
77 Save a review in the 'reviews' database
79 =cut
81 sub savereview {
82 my ( $biblionumber, $borrowernumber, $review ) = @_;
83 my $dbh = C4::Context->dbh;
84 my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
85 review,approved,datereviewed) VALUES
86 (?,?,?,0,now())";
87 my $sth = $dbh->prepare($query);
88 $sth->execute( $borrowernumber, $biblionumber, $review );
91 =head2 updatereview
93 updateview($biblionumber,$borrowernumber, $review);
95 Update the review description in the 'reviews' database
97 =cut
99 sub updatereview {
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)
114 =cut
116 sub numberofreviews {
117 my ($param) = @_;
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
132 =cut
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;
143 =head2 getreviews
145 my $reviews=getreviews($biblionumber, $status);
147 Return all reviews where in the 'reviews' database :
148 'biblionumber' = $biblionumber and 'approved' = $status
150 =cut
152 sub getreviews {
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( {} );
161 =head2 getallreviews
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)
171 =cut
173 sub getallreviews {
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( {} );
183 =head2 approvereview
185 approvereview($reviewid);
187 Takes a reviewid and marks that review approved
189 =cut
191 sub approvereview {
192 my ($reviewid) = @_;
193 my $dbh = C4::Context->dbh();
194 my $query = "UPDATE reviews
195 SET approved=?
196 WHERE reviewid=?";
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
207 =cut
209 sub unapprovereview {
210 my ($reviewid) = @_;
211 my $dbh = C4::Context->dbh();
212 my $query = "UPDATE reviews
213 SET approved=?
214 WHERE reviewid=?";
215 my $sth = $dbh->prepare($query);
216 $sth->execute( 0, $reviewid );
219 =head2 deletereview
221 deletereview($reviewid);
223 Takes a reviewid and deletes it
225 =cut
227 sub deletereview {
228 my ($reviewid) = @_;
229 my $dbh = C4::Context->dbh();
230 my $query = "DELETE FROM reviews
231 WHERE reviewid=?";
232 my $sth = $dbh->prepare($query);
233 $sth->execute($reviewid);
237 __END__
239 =head1 AUTHOR
241 Koha Team
243 =cut