more XHTML corrections for new circ reports
[koha.git] / C4 / Review.pm
blob3d0da03e5781338a32e613bc346f52b088ec4538
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
20 use strict;
21 use C4::Context;
23 use vars qw($VERSION @ISA @EXPORT);
25 BEGIN {
26 # set the version for version checking
27 $VERSION = 3.00;
28 require Exporter;
29 @ISA = qw(Exporter);
30 @EXPORT = qw(getreview savereview updatereview numberofreviews
31 getreviews getallreviews approvereview 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($biblionumber);
46 my $reviews=getreviews($biblionumber);
47 my $reviews=getallreviews($status);
49 =head1 DESCRIPTION
51 Review.pm provides many routines for manipulating reviews.
53 =head1 FUNCTIONS
55 =head2 getreview
57 $review = getreview($biblionumber,$borrowernumber);
59 Takes a borrowernumber and a biblionumber and returns the review of that biblio
61 =cut
63 sub getreview {
64 my ( $biblionumber, $borrowernumber ) = @_;
65 my $dbh = C4::Context->dbh;
66 my $query =
67 "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?";
68 my $sth = $dbh->prepare($query);
69 $sth->execute( $biblionumber, $borrowernumber );
70 my $review = $sth->fetchrow_hashref();
71 $sth->finish();
72 return $review;
75 sub savereview {
76 my ( $biblionumber, $borrowernumber, $review ) = @_;
77 my $dbh = C4::Context->dbh;
78 my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
79 review,approved,datereviewed) VALUES
80 (?,?,?,0,now())";
81 my $sth = $dbh->prepare($query);
82 $sth->execute( $borrowernumber, $biblionumber, $review);
83 $sth->finish();
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 );
92 $sth->finish();
95 sub numberofreviews {
96 my ($biblionumber) = @_;
97 my $dbh = C4::Context->dbh;
98 my $query =
99 "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
100 my $sth = $dbh->prepare($query);
101 $sth->execute( $biblionumber, 1 );
102 my $count = $sth->fetchrow_hashref;
104 $sth->finish();
105 return ( $count->{'count(*)'} );
108 sub getreviews {
109 my ( $biblionumber, $approved ) = @_;
110 my $dbh = C4::Context->dbh;
111 my $query =
112 "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
113 my $sth = $dbh->prepare($query) || warn $dbh->err_str;
114 $sth->execute( $biblionumber, $approved );
115 my @results;
116 while ( my $data = $sth->fetchrow_hashref() ) {
117 push @results, $data;
119 $sth->finish();
120 return ( \@results );
123 sub getallreviews {
124 my ($status) = @_;
125 my $dbh = C4::Context->dbh;
126 my $query =
127 "SELECT * FROM reviews WHERE approved=? order by datereviewed desc";
128 my $sth = $dbh->prepare($query);
129 $sth->execute($status);
130 my @results;
131 while ( my $data = $sth->fetchrow_hashref() ) {
132 push @results, $data;
134 $sth->finish();
135 return ( \@results );
138 =head2 approvereview
140 approvereview($reviewid);
142 Takes a reviewid and marks that review approved
144 =cut
146 sub approvereview {
147 my ($reviewid) = @_;
148 my $dbh = C4::Context->dbh();
149 my $query = "UPDATE reviews
150 SET approved=?
151 WHERE reviewid=?";
152 my $sth = $dbh->prepare($query);
153 $sth->execute( 1, $reviewid );
154 $sth->finish();
157 =head2 deletereview
159 deletereview($reviewid);
161 Takes a reviewid and deletes it
163 =cut
165 sub deletereview {
166 my ($reviewid) = @_;
167 my $dbh = C4::Context->dbh();
168 my $query = "DELETE FROM reviews
169 WHERE reviewid=?";
170 my $sth = $dbh->prepare($query);
171 $sth->execute($reviewid);
172 $sth->finish();
176 __END__
178 =head1 AUTHOR
180 Koha Team
182 =cut