View | Details | Raw Unified | Return to bug 15839
Collapse All | Expand All

(-)a/C4/Review.pm (-37 / +1 lines)
Lines 28-34 BEGIN { Link Here
28
    require Exporter;
28
    require Exporter;
29
    @ISA    = qw(Exporter);
29
    @ISA    = qw(Exporter);
30
    @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
30
    @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
31
      approvereview unapprovereview deletereview);
31
      deletereview);
32
}
32
}
33
33
34
=head1 NAME
34
=head1 NAME
Lines 138-179 sub numberofreviewsbybiblionumber { Link Here
138
    return $sth->fetchrow;
138
    return $sth->fetchrow;
139
}
139
}
140
140
141
=head2 approvereview
142
143
  approvereview($reviewid);
144
145
Takes a reviewid and marks that review approved
146
147
=cut
148
149
sub approvereview {
150
    my ($reviewid) = @_;
151
    my $dbh        = C4::Context->dbh();
152
    my $query      = "UPDATE reviews
153
               SET approved=?
154
               WHERE reviewid=?";
155
    my $sth = $dbh->prepare($query);
156
    $sth->execute( 1, $reviewid );
157
}
158
159
=head2 unapprovereview
160
161
  unapprovereview($reviewid);
162
163
Takes a reviewid and marks that review as not approved
164
165
=cut
166
167
sub unapprovereview {
168
    my ($reviewid) = @_;
169
    my $dbh        = C4::Context->dbh();
170
    my $query      = "UPDATE reviews
171
               SET approved=?
172
               WHERE reviewid=?";
173
    my $sth = $dbh->prepare($query);
174
    $sth->execute( 0, $reviewid );
175
}
176
177
=head2 deletereview
141
=head2 deletereview
178
142
179
  deletereview($reviewid);
143
  deletereview($reviewid);
(-)a/Koha/Review.pm (+26 lines)
Lines 33-38 Koha::Review - Koha Review Object class Link Here
33
33
34
=cut
34
=cut
35
35
36
=head3 approve
37
38
    $review->approve
39
40
Approve a review
41
42
=cut
43
44
sub approve {
45
    my ( $self ) = @_;
46
    $self->approved(1)->store;
47
}
48
49
=head3 unapprove
50
51
    $review->unapprove
52
53
Unapprove a review
54
55
=cut
56
57
sub unapprove {
58
    my ( $self ) = @_;
59
    $self->approved(0)->store;
60
}
61
36
=head3 type
62
=head3 type
37
63
38
=cut
64
=cut
(-)a/reviews/reviewswaiting.pl (-2 / +4 lines)
Lines 46-55 my $count = C4::Context->preference('numSearchResults') || 20; Link Here
46
my $total    = numberofreviews($status);
46
my $total    = numberofreviews($status);
47
47
48
if ( $op eq 'approve' ) {
48
if ( $op eq 'approve' ) {
49
    approvereview($reviewid);
49
    my $review = Koha::Reviews->find( $reviewid );
50
    $review->approve if $review;
50
}
51
}
51
elsif ( $op eq 'unapprove' ) {
52
elsif ( $op eq 'unapprove' ) {
52
    unapprovereview($reviewid);
53
    my $review = Koha::Reviews->find( $reviewid );
54
    $review->unapprove if $review;
53
}
55
}
54
elsif ( $op eq 'delete' ) {
56
elsif ( $op eq 'delete' ) {
55
    deletereview($reviewid);
57
    deletereview($reviewid);
(-)a/t/db_dependent/Koha/Reviews.t (-2 / +8 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 7;
23
23
24
use Koha::Review;
24
use Koha::Review;
25
use Koha::Reviews;
25
use Koha::Reviews;
Lines 36-41 my $patron_2 = $builder->build({ source => 'Borrower' }); Link Here
36
my $biblio_1 = $builder->build({ source => 'Biblio' });
36
my $biblio_1 = $builder->build({ source => 'Biblio' });
37
my $biblio_2 = $builder->build({ source => 'Biblio' });
37
my $biblio_2 = $builder->build({ source => 'Biblio' });
38
my $nb_of_reviews = Koha::Reviews->search->count;
38
my $nb_of_reviews = Koha::Reviews->search->count;
39
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count;
39
my $new_review_1_1 = Koha::Review->new({
40
my $new_review_1_1 = Koha::Review->new({
40
    borrowernumber => $patron_1->{borrowernumber},
41
    borrowernumber => $patron_1->{borrowernumber},
41
    biblionumber => $biblio_1->{biblionumber},
42
    biblionumber => $biblio_1->{biblionumber},
Lines 55-60 my $new_review_2_1 = Koha::Review->new({ Link Here
55
like( $new_review_1_1->reviewid, qr|^\d+$|, 'Adding a new review should have set the reviewid');
56
like( $new_review_1_1->reviewid, qr|^\d+$|, 'Adding a new review should have set the reviewid');
56
is( Koha::Reviews->search->count, $nb_of_reviews + 3, 'The 3 reviews should have been added' );
57
is( Koha::Reviews->search->count, $nb_of_reviews + 3, 'The 3 reviews should have been added' );
57
58
59
is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews, 'There should not be new approved reviews' );
60
$new_review_1_1->approve;
61
is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews + 1, 'There should be 1 new approved review' );
62
$new_review_1_1->unapprove;
63
is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews, 'There should not be any new approved review anymore' );
64
58
my $retrieved_review_1_1 = Koha::Reviews->find( $new_review_1_1->reviewid );
65
my $retrieved_review_1_1 = Koha::Reviews->find( $new_review_1_1->reviewid );
59
is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id should return the correct review' );
66
is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id should return the correct review' );
60
67
61
- 

Return to bug 15839