Review.pm - BEGIN block VERSION and vars related to export.
[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 use C4::Context;
22
23 use vars qw($VERSION @ISA @EXPORT);
24
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);
32 }
33
34 =head1 NAME
35
36 C4::Review - Perl Module containing routines for dealing with reviews of items
37
38 =head1 SYNOPSIS
39
40   use C4::Review;
41
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);
48
49 =head1 DESCRIPTION
50
51 Review.pm provides many routines for manipulating reviews.
52
53 =head1 FUNCTIONS
54
55 =head2 getreview
56
57   $review = getreview($biblionumber,$borrowernumber);
58
59 Takes a borrowernumber and a biblionumber and returns the review of that biblio
60
61 =cut
62
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;
73 }
74
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   (?,?,?,?,now())";
81     my $sth = $dbh->prepare($query);
82     $sth->execute( $borrowernumber, $biblionumber, $review, 0 );
83     $sth->finish();
84 }
85
86 sub updatereview {
87     my ( $biblionumber, $borrowernumber, $review ) = @_;
88     my $dbh   = C4::Context->dbh;
89     my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=?
90   WHERE borrowernumber=? and biblionumber=?";
91     my $sth = $dbh->prepare($query);
92     $sth->execute( $review, 0, $borrowernumber, $biblionumber );
93     $sth->finish();
94 }
95
96 sub numberofreviews {
97     my ($biblionumber) = @_;
98     my $dbh            = C4::Context->dbh;
99     my $query          =
100       "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
101     my $sth = $dbh->prepare($query);
102     $sth->execute( $biblionumber, 1 );
103     my $count = $sth->fetchrow_hashref;
104
105     $sth->finish();
106     return ( $count->{'count(*)'} );
107 }
108
109 sub getreviews {
110     my ( $biblionumber, $approved ) = @_;
111     my $dbh   = C4::Context->dbh;
112     my $query =
113 "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
114     my $sth = $dbh->prepare($query) || warn $dbh->err_str;
115     $sth->execute( $biblionumber, $approved );
116     my @results;
117     while ( my $data = $sth->fetchrow_hashref() ) {
118         push @results, $data;
119     }
120     $sth->finish();
121     return ( \@results );
122 }
123
124 sub getallreviews {
125     my ($status) = @_;
126     my $dbh      = C4::Context->dbh;
127     my $query    =
128       "SELECT * FROM reviews WHERE approved=? order by datereviewed desc";
129     my $sth = $dbh->prepare($query);
130     $sth->execute($status);
131     my @results;
132     while ( my $data = $sth->fetchrow_hashref() ) {
133         push @results, $data;
134     }
135     $sth->finish();
136     return ( \@results );
137 }
138
139 =head2 approvereview
140
141   approvereview($reviewid);
142
143 Takes a reviewid and marks that review approved
144
145 =cut
146
147 sub approvereview {
148     my ($reviewid) = @_;
149     my $dbh        = C4::Context->dbh();
150     my $query      = "UPDATE reviews
151                SET approved=?
152                WHERE reviewid=?";
153     my $sth = $dbh->prepare($query);
154     $sth->execute( 1, $reviewid );
155     $sth->finish();
156 }
157
158 =head2 deletereview
159
160   deletereview($reviewid);
161
162 Takes a reviewid and deletes it
163
164 =cut
165
166 sub deletereview {
167     my ($reviewid) = @_;
168     my $dbh        = C4::Context->dbh();
169     my $query      = "DELETE FROM reviews
170                WHERE reviewid=?";
171     my $sth = $dbh->prepare($query);
172     $sth->execute($reviewid);
173     $sth->finish();
174 }
175
176 1;
177 __END__
178
179 =head1 AUTHOR
180
181 Koha Team
182
183 =cut