Bug 1861: DBRev 3.19.00.003
[koha.git] / C4 / Review.pm
blobdd989ed68996a5fdc97e2146ef416d0eb629df79
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
23 use C4::Context;
25 use vars qw($VERSION @ISA @EXPORT);
27 BEGIN {
28 # set the version for version checking
29 $VERSION = 3.07.00.049;
30 require Exporter;
31 @ISA = qw(Exporter);
32 @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
33 getreviews getallreviews approvereview unapprovereview deletereview);
36 =head1 NAME
38 C4::Review - Perl Module containing routines for dealing with reviews of items
40 =head1 SYNOPSIS
42 use C4::Review;
44 my $review=getreview($biblionumber,$borrowernumber);
45 savereview($biblionumber,$borrowernumber,$review);
46 updatereview($biblionumber,$borrowernumber,$review);
47 my $count=numberofreviews($status);
48 my $count=numberofreviewsbybiblionumber($biblionumber);
49 my $reviews=getreviews($biblionumber);
50 my $reviews=getallreviews($status);
52 =head1 DESCRIPTION
54 Review.pm provides many routines for manipulating reviews.
56 =head1 FUNCTIONS
58 =head2 getreview
60 $review = getreview($biblionumber,$borrowernumber);
62 Takes a borrowernumber and a biblionumber and returns the review of that biblio
64 =cut
66 sub getreview {
67 my ( $biblionumber, $borrowernumber ) = @_;
68 my $dbh = C4::Context->dbh;
69 my $query =
70 "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?";
71 my $sth = $dbh->prepare($query);
72 $sth->execute( $biblionumber, $borrowernumber );
73 return $sth->fetchrow_hashref();
76 sub savereview {
77 my ( $biblionumber, $borrowernumber, $review ) = @_;
78 my $dbh = C4::Context->dbh;
79 my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
80 review,approved,datereviewed) VALUES
81 (?,?,?,0,now())";
82 my $sth = $dbh->prepare($query);
83 $sth->execute( $borrowernumber, $biblionumber, $review);
86 sub updatereview {
87 my ( $biblionumber, $borrowernumber, $review ) = @_;
88 my $dbh = C4::Context->dbh;
89 my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0 WHERE borrowernumber=? and biblionumber=?";
90 my $sth = $dbh->prepare($query);
91 $sth->execute( $review, $borrowernumber, $biblionumber );
94 sub numberofreviews {
95 my ($param) = @_;
96 my $status = (defined($param) ? $param : 1);
97 my $dbh = C4::Context->dbh;
98 my $query =
99 "SELECT count(*) FROM reviews WHERE approved=?";
100 my $sth = $dbh->prepare($query);
101 $sth->execute( $status );
102 return $sth->fetchrow;
105 sub numberofreviewsbybiblionumber {
106 my ($biblionumber) = @_;
107 my $dbh = C4::Context->dbh;
108 my $query =
109 "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
110 my $sth = $dbh->prepare($query);
111 $sth->execute( $biblionumber, 1 );
112 return $sth->fetchrow;
115 sub getreviews {
116 my ( $biblionumber, $approved ) = @_;
117 my $dbh = C4::Context->dbh;
118 my $query =
119 "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
120 my $sth = $dbh->prepare($query) || warn $dbh->err_str;
121 $sth->execute( $biblionumber, $approved );
122 return $sth->fetchall_arrayref({});
125 sub getallreviews {
126 my ($status, $offset, $row_count) = @_;
127 my @params = ($status,($offset ? $offset : 0),($row_count ? $row_count : 20));
128 my $dbh = C4::Context->dbh;
129 my $query =
130 "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?";
131 my $sth = $dbh->prepare($query) || warn $dbh->err_str;
132 $sth->execute(@params);
133 return $sth->fetchall_arrayref({});
136 =head2 approvereview
138 approvereview($reviewid);
140 Takes a reviewid and marks that review approved
142 =cut
144 sub approvereview {
145 my ($reviewid) = @_;
146 my $dbh = C4::Context->dbh();
147 my $query = "UPDATE reviews
148 SET approved=?
149 WHERE reviewid=?";
150 my $sth = $dbh->prepare($query);
151 $sth->execute( 1, $reviewid );
154 =head2 unapprovereview
156 unapprovereview($reviewid);
158 Takes a reviewid and marks that review as not approved
160 =cut
162 sub unapprovereview {
163 my ($reviewid) = @_;
164 my $dbh = C4::Context->dbh();
165 my $query = "UPDATE reviews
166 SET approved=?
167 WHERE reviewid=?";
168 my $sth = $dbh->prepare($query);
169 $sth->execute( 0, $reviewid );
172 =head2 deletereview
174 deletereview($reviewid);
176 Takes a reviewid and deletes it
178 =cut
180 sub deletereview {
181 my ($reviewid) = @_;
182 my $dbh = C4::Context->dbh();
183 my $query = "DELETE FROM reviews
184 WHERE reviewid=?";
185 my $sth = $dbh->prepare($query);
186 $sth->execute($reviewid);
190 __END__
192 =head1 AUTHOR
194 Koha Team
196 =cut