TransformHtmlToXml() now checks from UNIMARC flavour, before inserting encoding info...
[koha.git] / C4 / Review.pm
blobcbcef6a15a3a87048a7eecf3e52f0a619e468be9
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 require Exporter;
22 use C4::Context;
24 use vars qw($VERSION @ISA @EXPORT);
26 # set the version for version checking
27 $VERSION = 3.00;
29 =head1 NAME
31 C4::Review - Perl Module containing routines for dealing with reviews of items
33 =head1 SYNOPSIS
35 use C4::Review;
38 my $review=getreview($biblionumber,$borrowernumber);
39 savereview($biblionumber,$borrowernumber,$review);
40 updatereview($biblionumber,$borrowernumber,$review);
41 my $count=numberofreviews($biblionumber);
42 my $reviews=getreviews($biblionumber);
43 my $reviews=getallreviews($status);
45 =head1 DESCRIPTION
47 Review.pm provides many routines for manipulating reviews.
49 =head1 FUNCTIONS
51 =cut
53 @ISA = qw(Exporter);
54 @EXPORT = qw(getreview savereview updatereview numberofreviews
55 getreviews getallreviews approvereview deletereview);
57 use vars qw();
59 my $DEBUG = 0;
61 =head2 getreview
63 $review = getreview($biblionumber,$borrowernumber);
65 Takes a borrowernumber and a biblionumber and returns the review of that biblio
68 =cut
70 sub getreview {
71 my ( $biblionumber, $borrowernumber ) = @_;
72 my $dbh = C4::Context->dbh;
73 my $query =
74 "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;
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();
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();
103 sub numberofreviews {
104 my ($biblionumber) = @_;
105 my $dbh = C4::Context->dbh;
106 my $query =
107 "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;
112 $sth->finish();
113 return ( $count->{'count(*)'} );
116 sub getreviews {
117 my ( $biblionumber, $approved ) = @_;
118 my $dbh = C4::Context->dbh;
119 my $query =
120 "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
121 my $sth = $dbh->prepare($query) || warn $dbh->err_str;
122 $sth->execute( $biblionumber, $approved );
123 my @results;
124 while ( my $data = $sth->fetchrow_hashref() ) {
125 push @results, $data;
127 $sth->finish();
128 return ( \@results );
131 sub getallreviews {
132 my ($status) = @_;
133 my $dbh = C4::Context->dbh;
134 my $query =
135 "SELECT * FROM reviews WHERE approved=? order by datereviewed desc";
136 my $sth = $dbh->prepare($query);
137 $sth->execute($status);
138 my @results;
139 while ( my $data = $sth->fetchrow_hashref() ) {
140 push @results, $data;
142 $sth->finish();
143 return ( \@results );
146 =head2 approvereview
148 approvereview($reviewid);
150 Takes a reviewid and marks that review approved
152 =cut
154 sub approvereview {
155 my ($reviewid) = @_;
156 my $dbh = C4::Context->dbh();
157 my $query = "UPDATE reviews
158 SET approved=?
159 WHERE reviewid=?";
160 my $sth = $dbh->prepare($query);
161 $sth->execute( 1, $reviewid );
162 $sth->finish();
165 =head2 deletereview
167 deletereview($reviewid);
169 Takes a reviewid and deletes it
171 =cut
173 sub deletereview {
174 my ($reviewid) = @_;
175 my $dbh = C4::Context->dbh();
176 my $query = "DELETE FROM reviews
177 WHERE reviewid=?";
178 my $sth = $dbh->prepare($query);
179 $sth->execute($reviewid);
180 $sth->finish();
184 __END__
186 =head1 AUTHOR
188 Koha Team
190 =cut