Koha/C4/Review.pm
Owen Leonard f36747f5e8 Fix for Bug 4473 - Recent comments view for the OPAC
- modifies opac-showreviews.pl to display recent comments for all
  titles, sorted in descending order by date.
- includes RSS feed
- includes (thanks to Chris N.):

[Enhancement][3.4] Add RFC822 Format to C4::Dates

This patch adds RFC822 formatting to C4::Dates. It also updates Dates.t
appropriately. Consult the POD for this module for how to use
this format.

Please note that this module *does not* handle TZ conversion at this point.
This means that the TZ portion of a RFC822 time will be truncated and the converted
time will be in the same TZ as was passed in. When generating an RFC822 time,
the local TZ offset will be included since none of the other supported formats
provide a means for including their TZ. This is not a problem introduced by the
addition of RFC822 formatting. Rather it is due to this module not having TZ
support to begin with.

Also note that the dow, moy abbreviations are English as required by
RFC822 section 3.3 (thanks to self for pointing that out).

Signed-off-by: Colin Campbell <colin.campbell@ptfs-europe.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
2010-12-13 09:43:01 +13:00

175 lines
4.7 KiB
Perl

package C4::Review;
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
use C4::Context;
use vars qw($VERSION @ISA @EXPORT);
BEGIN {
# set the version for version checking
$VERSION = 3.00;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
getreviews getallreviews approvereview deletereview);
}
=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($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
sub getreview {
my ( $biblionumber, $borrowernumber ) = @_;
my $dbh = C4::Context->dbh;
my $query =
"SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?";
my $sth = $dbh->prepare($query);
$sth->execute( $biblionumber, $borrowernumber );
return $sth->fetchrow_hashref();
}
sub savereview {
my ( $biblionumber, $borrowernumber, $review ) = @_;
my $dbh = C4::Context->dbh;
my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
review,approved,datereviewed) VALUES
(?,?,?,0,now())";
my $sth = $dbh->prepare($query);
$sth->execute( $borrowernumber, $biblionumber, $review);
}
sub updatereview {
my ( $biblionumber, $borrowernumber, $review ) = @_;
my $dbh = C4::Context->dbh;
my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0 WHERE borrowernumber=? and biblionumber=?";
my $sth = $dbh->prepare($query);
$sth->execute( $review, $borrowernumber, $biblionumber );
}
sub numberofreviews {
my $dbh = C4::Context->dbh;
my $query =
"SELECT count(*) FROM reviews WHERE approved=?";
my $sth = $dbh->prepare($query);
$sth->execute( 1 );
return $sth->fetchrow;
}
sub numberofreviewsbybiblionumber {
my ($biblionumber) = @_;
my $dbh = C4::Context->dbh;
my $query =
"SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
my $sth = $dbh->prepare($query);
$sth->execute( $biblionumber, 1 );
return $sth->fetchrow;
}
sub getreviews {
my ( $biblionumber, $approved ) = @_;
my $dbh = C4::Context->dbh;
my $query =
"SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
my $sth = $dbh->prepare($query) || warn $dbh->err_str;
$sth->execute( $biblionumber, $approved );
return $sth->fetchall_arrayref({});
}
sub getallreviews {
my ($status, $offset, $row_count) = @_;
my @params = ($status,($offset ? $offset : 0),($row_count ? $row_count : 20));
my $dbh = C4::Context->dbh;
my $query =
"SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?";
my $sth = $dbh->prepare($query) || warn $dbh->err_str;
$sth->execute(@params);
return $sth->fetchall_arrayref({});
}
=head2 approvereview
approvereview($reviewid);
Takes a reviewid and marks that review approved
=cut
sub approvereview {
my ($reviewid) = @_;
my $dbh = C4::Context->dbh();
my $query = "UPDATE reviews
SET approved=?
WHERE reviewid=?";
my $sth = $dbh->prepare($query);
$sth->execute( 1, $reviewid );
}
=head2 deletereview
deletereview($reviewid);
Takes a reviewid and deletes it
=cut
sub deletereview {
my ($reviewid) = @_;
my $dbh = C4::Context->dbh();
my $query = "DELETE FROM reviews
WHERE reviewid=?";
my $sth = $dbh->prepare($query);
$sth->execute($reviewid);
}
1;
__END__
=head1 AUTHOR
Koha Team
=cut