IMPORTANT: Paul, I've removed the decode_char routine because it's no
[koha.git] / C4 / Review.pm
1 package C4::Review;
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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
19
20 use strict;
21 require Exporter;
22 use C4::Context;
23
24 use vars qw($VERSION @ISA @EXPORT);
25
26 $VERSION = 0.01;
27
28 =head1 NAME
29
30 C4::Review - Perl Module containing routines for dealing with reviews of items
31
32 =head1 SYNOPSIS
33
34   use C4::Review;
35
36
37   my $review=getreview($biblionumber,$borrowernumber);
38   savereview($biblionumber,$borrowernumber,$review);
39   updatereview($biblionumber,$borrowernumber,$review);
40   my $count=numberofreviews($biblionumber);
41   my $reviews=getreviews($biblionumber);
42   my $reviews=getallreviews($status);
43
44 =head1 DESCRIPTION
45
46 Review.pm provides many routines for manipulating reviews.
47
48 =head1 FUNCTIONS
49
50 =over 2
51
52 =cut
53
54 @ISA = qw(Exporter);
55 @EXPORT = qw(getreview savereview updatereview numberofreviews
56     getreviews getallreviews                    );
57
58 use vars qw();
59
60 my $DEBUG = 0;
61
62 =head2 getreview
63
64   $review = getreview($biblionumber,$borrowernumber);
65
66 Takes a borrowernumber and a biblionumber and returns the review of that biblio
67
68
69 =cut
70
71 sub getreview {
72     my ($biblionumber,$borrowernumber) = @_;
73     my $dbh=C4::Context->dbh;
74     my $query="SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?";
75     my $sth=$dbh->prepare($query);
76     $sth->execute($biblionumber,$borrowernumber);
77     my $review = $sth->fetchrow_hashref();
78     $sth->finish();
79     return $review;
80     }
81
82 sub savereview {
83     my ($biblionumber,$borrowernumber,$review) = @_;
84     my $dbh=C4::Context->dbh;
85     my $query="INSERT INTO reviews (borrowernumber,biblionumber,
86         review,approved,datereviewed) VALUES 
87   (?,?,?,?,now())";
88     my $sth=$dbh->prepare($query);
89     $sth->execute($borrowernumber,$biblionumber,$review,0);
90     $sth->finish();
91     }
92
93 sub updatereview {
94     my ($biblionumber,$borrowernumber,$review) = @_;
95     my $dbh=C4::Context->dbh;
96     my $query="UPDATE reviews SET review=?,datereviewed=now(),approved=?
97   WHERE borrowernumber=? and biblionumber=?";
98     my $sth=$dbh->prepare($query);
99     $sth->execute($review,0,$borrowernumber,$biblionumber);
100     $sth->finish();
101     
102     }
103
104 sub numberofreviews {
105     my ($biblionumber)=@_;
106     my $dbh=C4::Context->dbh;
107     my $query="SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
108     my $sth=$dbh->prepare($query);
109     $sth->execute($biblionumber,1);
110     my $count=$sth->fetchrow_hashref;
111     
112     $sth->finish();
113     return ($count->{'count(*)'});
114 }
115
116 sub getreviews {
117     my ($biblionumber,$approved)=@_;
118     my $dbh=C4::Context->dbh;
119     my $query="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     my @results;
123     while (my $data=$sth->fetchrow_hashref()){
124         push @results,$data;
125         }
126     $sth->finish();
127     return(\@results);
128 }
129
130 sub getallreviews {
131     my ($status) =@_;
132     my $dbh=C4::Context->dbh;
133     my $query="SELECT * FROM reviews WHERE approved=? order by datereviewed desc";
134     my $sth=$dbh->prepare($query);
135     $sth->execute($status);
136     my @results;
137     while (my $data=$sth->fetchrow_hashref()){
138         push @results,$data;
139         }
140     $sth->finish();
141     return(\@results);
142 }    
143 1;
144 __END__
145
146 =back
147
148 =head1 AUTHOR
149
150 Koha Team
151
152 =cut