Bug 15839: Koha::Reviews - Remove getreview
[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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use strict;
21 use warnings;
22
23 use C4::Context;
24
25 use vars qw(@ISA @EXPORT);
26
27 BEGIN {
28     require Exporter;
29     @ISA    = qw(Exporter);
30     @EXPORT = qw(savereview updatereview numberofreviews numberofreviewsbybiblionumber);
31 }
32
33 =head1 NAME
34
35 C4::Review - Perl Module containing routines for dealing with reviews of items
36
37 =head1 SYNOPSIS
38
39   use C4::Review;
40
41   savereview($biblionumber,$borrowernumber,$review);
42   updatereview($biblionumber,$borrowernumber,$review);
43   my $count=numberofreviews($status);
44   my $count=numberofreviewsbybiblionumber($biblionumber);
45
46 =head1 DESCRIPTION
47
48 Review.pm provides many routines for manipulating reviews.
49
50 =head1 FUNCTIONS
51
52 =head2 savereview
53
54   savereview($biblionumber,$borrowernumber, $review);
55
56 Save a review in the 'reviews' database
57
58 =cut
59
60 sub savereview {
61     my ( $biblionumber, $borrowernumber, $review ) = @_;
62     my $dbh   = C4::Context->dbh;
63     my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
64   review,approved,datereviewed) VALUES
65   (?,?,?,0,now())";
66     my $sth = $dbh->prepare($query);
67     $sth->execute( $borrowernumber, $biblionumber, $review );
68 }
69
70 =head2 updatereview
71
72   updateview($biblionumber,$borrowernumber, $review);
73
74 Update the review description in the 'reviews' database
75
76 =cut
77
78 sub updatereview {
79     my ( $biblionumber, $borrowernumber, $review ) = @_;
80     my $dbh   = C4::Context->dbh;
81     my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0  WHERE borrowernumber=? and biblionumber=?";
82     my $sth   = $dbh->prepare($query);
83     $sth->execute( $review, $borrowernumber, $biblionumber );
84 }
85
86 =head2 numberofreviews
87
88   my $count=numberofreviews( [$status] );
89
90 Return the number of reviews where in the 'reviews' database : 'approved' = $status
91 (By default $status = 1)
92
93 =cut
94
95 sub numberofreviews {
96     my ($param) = @_;
97     my $status = ( defined($param) ? $param : 1 );
98     my $dbh    = C4::Context->dbh;
99     my $query  = "SELECT count(*) FROM reviews WHERE approved=?";
100     my $sth    = $dbh->prepare($query);
101     $sth->execute($status);
102     return $sth->fetchrow;
103 }
104
105 =head2 numberofreviewsbybiblionumber
106
107   my $count=numberofreviewsbybiblionumber($biblionumber);
108
109 Return the number of reviews approved for a given biblionumber
110
111 =cut
112
113 sub numberofreviewsbybiblionumber {
114     my ($biblionumber) = @_;
115     my $dbh            = C4::Context->dbh;
116     my $query          = "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
117     my $sth            = $dbh->prepare($query);
118     $sth->execute( $biblionumber, 1 );
119     return $sth->fetchrow;
120 }
121
122 1;
123 __END__
124
125 =head1 AUTHOR
126
127 Koha Team
128
129 =cut