File Coverage

File:C4/Review.pm
Coverage:21.0%

linestmtbrancondsubtimecode
1package 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
17# with Koha; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
3
3
3
25071
18
87
use strict;
21
3
3
3
27
15
278
use warnings;
22
23
3
3
3
199
35
81
use C4::Context;
24
25
3
3
3
15
3
313
use vars qw($VERSION @ISA @EXPORT);
26
27BEGIN {
28        # set the version for version checking
29
3
6
        $VERSION = 3.00;
30
3
11
        require Exporter;
31
3
32
        @ISA = qw(Exporter);
32
3
2340
        @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
33                getreviews getallreviews approvereview unapprovereview deletereview);
34}
35
36 - 64
=head1 NAME

C4::Review - Perl Module containing routines for dealing with reviews of items

=head1 SYNOPSIS

  use C4::Review;

  my $review=getreview($biblionumber,$borrowernumber);
  savereview($biblionumber,$borrowernumber,$review);
  updatereview($biblionumber,$borrowernumber,$review);
  my $count=numberofreviews($status);
  my $count=numberofreviewsbybiblionumber($biblionumber);
  my $reviews=getreviews($biblionumber);
  my $reviews=getallreviews($status);

=head1 DESCRIPTION

Review.pm provides many routines for manipulating reviews.

=head1 FUNCTIONS

=head2 getreview

  $review = getreview($biblionumber,$borrowernumber);

Takes a borrowernumber and a biblionumber and returns the review of that biblio

=cut
65
66sub getreview {
67
0
    my ( $biblionumber, $borrowernumber ) = @_;
68
0
    my $dbh = C4::Context->dbh;
69
0
    my $query =
70      "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?";
71
0
    my $sth = $dbh->prepare($query);
72
0
    $sth->execute( $biblionumber, $borrowernumber );
73
0
    return $sth->fetchrow_hashref();
74}
75
76sub savereview {
77
0
    my ( $biblionumber, $borrowernumber, $review ) = @_;
78
0
    my $dbh = C4::Context->dbh;
79
0
    my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
80        review,approved,datereviewed) VALUES
81  (?,?,?,0,now())";
82
0
    my $sth = $dbh->prepare($query);
83
0
    $sth->execute( $borrowernumber, $biblionumber, $review);
84}
85
86sub updatereview {
87
0
    my ( $biblionumber, $borrowernumber, $review ) = @_;
88
0
    my $dbh = C4::Context->dbh;
89
0
    my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0 WHERE borrowernumber=? and biblionumber=?";
90
0
    my $sth = $dbh->prepare($query);
91
0
    $sth->execute( $review, $borrowernumber, $biblionumber );
92}
93
94sub numberofreviews {
95
0
    my ($param) = @_;
96
0
    my $status = (defined($param) ? $param : 1);
97
0
    my $dbh = C4::Context->dbh;
98
0
    my $query =
99      "SELECT count(*) FROM reviews WHERE approved=?";
100
0
    my $sth = $dbh->prepare($query);
101
0
    $sth->execute( $status );
102
0
  return $sth->fetchrow;
103}
104
105sub numberofreviewsbybiblionumber {
106
0
    my ($biblionumber) = @_;
107
0
    my $dbh = C4::Context->dbh;
108
0
    my $query =
109      "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
110
0
    my $sth = $dbh->prepare($query);
111
0
    $sth->execute( $biblionumber, 1 );
112
0
        return $sth->fetchrow;
113}
114
115sub getreviews {
116
0
    my ( $biblionumber, $approved ) = @_;
117
0
    my $dbh = C4::Context->dbh;
118
0
    my $query =
119"SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
120
0
    my $sth = $dbh->prepare($query) || warn $dbh->err_str;
121
0
    $sth->execute( $biblionumber, $approved );
122
0
        return $sth->fetchall_arrayref({});
123}
124
125sub getallreviews {
126
0
    my ($status, $offset, $row_count) = @_;
127
0
    my @params = ($status,($offset ? $offset : 0),($row_count ? $row_count : 20));
128
0
    my $dbh = C4::Context->dbh;
129
0
    my $query =
130      "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?";
131
0
    my $sth = $dbh->prepare($query) || warn $dbh->err_str;
132
0
    $sth->execute(@params);
133
0
        return $sth->fetchall_arrayref({});
134}
135
136 - 142
=head2 approvereview

  approvereview($reviewid);

Takes a reviewid and marks that review approved

=cut
143
144sub approvereview {
145
0
    my ($reviewid) = @_;
146
0
    my $dbh = C4::Context->dbh();
147
0
    my $query = "UPDATE reviews
148               SET approved=?
149               WHERE reviewid=?";
150
0
    my $sth = $dbh->prepare($query);
151
0
    $sth->execute( 1, $reviewid );
152}
153
154 - 160
=head2 unapprovereview

  unapprovereview($reviewid);

Takes a reviewid and marks that review as not approved

=cut
161
162sub unapprovereview {
163
0
    my ($reviewid) = @_;
164
0
    my $dbh = C4::Context->dbh();
165
0
    my $query = "UPDATE reviews
166               SET approved=?
167               WHERE reviewid=?";
168
0
    my $sth = $dbh->prepare($query);
169
0
    $sth->execute( 0, $reviewid );
170}
171
172 - 178
=head2 deletereview

  deletereview($reviewid);

Takes a reviewid and deletes it

=cut
179
180sub deletereview {
181
0
    my ($reviewid) = @_;
182
0
    my $dbh = C4::Context->dbh();
183
0
    my $query = "DELETE FROM reviews
184               WHERE reviewid=?";
185
0
    my $sth = $dbh->prepare($query);
186
0
    $sth->execute($reviewid);
187}
188
1891;