Browse Source

Bug 15839: Koha::Reviews - Remove approvereview & unapprovereview

This patch adds 2 new methods to Koha::Review: approve and unapprove.

Signed-off-by: Marc Veron <veron@veron.ch>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
16.11.x
Jonathan Druart 8 years ago
committed by Kyle M Hall
parent
commit
eb950f4cc4
  1. 38
      C4/Review.pm
  2. 26
      Koha/Review.pm
  3. 6
      reviews/reviewswaiting.pl
  4. 9
      t/db_dependent/Koha/Reviews.t

38
C4/Review.pm

@ -28,7 +28,7 @@ BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
approvereview unapprovereview deletereview);
deletereview);
}
=head1 NAME
@ -138,42 +138,6 @@ sub numberofreviewsbybiblionumber {
return $sth->fetchrow;
}
=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 unapprovereview
unapprovereview($reviewid);
Takes a reviewid and marks that review as not approved
=cut
sub unapprovereview {
my ($reviewid) = @_;
my $dbh = C4::Context->dbh();
my $query = "UPDATE reviews
SET approved=?
WHERE reviewid=?";
my $sth = $dbh->prepare($query);
$sth->execute( 0, $reviewid );
}
=head2 deletereview
deletereview($reviewid);

26
Koha/Review.pm

@ -33,6 +33,32 @@ Koha::Review - Koha Review Object class
=cut
=head3 approve
$review->approve
Approve a review
=cut
sub approve {
my ( $self ) = @_;
$self->approved(1)->store;
}
=head3 unapprove
$review->unapprove
Unapprove a review
=cut
sub unapprove {
my ( $self ) = @_;
$self->approved(0)->store;
}
=head3 type
=cut

6
reviews/reviewswaiting.pl

@ -46,10 +46,12 @@ my $count = C4::Context->preference('numSearchResults') || 20;
my $total = numberofreviews($status);
if ( $op eq 'approve' ) {
approvereview($reviewid);
my $review = Koha::Reviews->find( $reviewid );
$review->approve if $review;
}
elsif ( $op eq 'unapprove' ) {
unapprovereview($reviewid);
my $review = Koha::Reviews->find( $reviewid );
$review->unapprove if $review;
}
elsif ( $op eq 'delete' ) {
deletereview($reviewid);

9
t/db_dependent/Koha/Reviews.t

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 4;
use Test::More tests => 7;
use Koha::Review;
use Koha::Reviews;
@ -36,6 +36,7 @@ my $patron_2 = $builder->build({ source => 'Borrower' });
my $biblio_1 = $builder->build({ source => 'Biblio' });
my $biblio_2 = $builder->build({ source => 'Biblio' });
my $nb_of_reviews = Koha::Reviews->search->count;
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count;
my $new_review_1_1 = Koha::Review->new({
borrowernumber => $patron_1->{borrowernumber},
biblionumber => $biblio_1->{biblionumber},
@ -55,6 +56,12 @@ my $new_review_2_1 = Koha::Review->new({
like( $new_review_1_1->reviewid, qr|^\d+$|, 'Adding a new review should have set the reviewid');
is( Koha::Reviews->search->count, $nb_of_reviews + 3, 'The 3 reviews should have been added' );
is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews, 'There should not be new approved reviews' );
$new_review_1_1->approve;
is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews + 1, 'There should be 1 new approved review' );
$new_review_1_1->unapprove;
is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews, 'There should not be any new approved review anymore' );
my $retrieved_review_1_1 = Koha::Reviews->find( $new_review_1_1->reviewid );
is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id should return the correct review' );

Loading…
Cancel
Save