[Patches] [PATCH] Bug 1623 - Provide view of approved comments

koha-patchbot at kohaaloha.com koha-patchbot at kohaaloha.com
Sun Dec 4 15:05:03 NZDT 2011


From: Owen Leonard <oleonard at myacpl.org>
Date: Mon, 28 Nov 2011 08:35:21 -0500
Subject: [PATCH] Bug 1623 - Provide view of approved comments

This patch creates two tabs on the comments administration page:
one for approved comments and one for unapproved comments. Each
display is paginated according to the numSearchResults preference.
The list of approved comments has, instead of a link to approve,
a link to unapprove.

The JavaScript table sorter has been removed since it doesn't make
sense to sort individual pages of a multi-page result set.

Signed-off-by: Chris Cormack <chrisc at catalyst.net.nz>
---
 C4/Review.pm                                       |   23 ++++++++++++-
 .../prog/en/modules/reviews/reviewswaiting.tt      |   35 ++++++++-----------
 reviews/reviewswaiting.pl                          |   17 ++++++++-
 3 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/C4/Review.pm b/C4/Review.pm
index f94dbc8..3009b34 100644
--- a/C4/Review.pm
+++ b/C4/Review.pm
@@ -30,7 +30,7 @@ BEGIN {
 	require Exporter;
 	@ISA    = qw(Exporter);
 	@EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
-		getreviews getallreviews approvereview deletereview);
+		getreviews getallreviews approvereview unapprovereview deletereview);
 }
 
 =head1 NAME
@@ -91,11 +91,12 @@ sub updatereview {
 }
 
 sub numberofreviews {
+    my ($status) = @_;
     my $dbh            = C4::Context->dbh;
     my $query          =
       "SELECT count(*) FROM reviews WHERE approved=?";
     my $sth = $dbh->prepare($query);
-    $sth->execute( 1 );
+    $sth->execute( $status );
   return $sth->fetchrow;
 }
 
@@ -148,6 +149,24 @@ sub approvereview {
     $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);
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt
index 3d7bb22..a1dabbd 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt
@@ -1,29 +1,13 @@
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha › Tools › Comments waiting for Approval</title>
+<title>Koha › Tools › Comments › [% IF ( status ) %] Approved comments[% ELSE %] Comments awaiting moderation[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
-<script type="text/javascript">//<![CDATA[
-$(document).ready(function() {
-$.tablesorter.addParser({
-    id: 'articles', 
-    is: function(s) {return false;  }, 
-    format: function(s) { return s.toLowerCase().replace(/^(the|an|a) /,''); }, 
-    type: 'text' 
-});
-	$("#commentst").tablesorter({
-		sortList: [[0,0]],
-		headers: { 1: {sorter: 'articles'},2: { sorter: false },3: { sorter: false }}
-	}); 
-}); 
-//]]>
-</script>
 </head>
 <body>
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-search.inc' %]
 
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
-› Comments Awaiting Moderation</div>
+› <a href="/cgi-bin/koha/reviews/reviewswaiting.pl">Comments</a> ›[% IF ( status ) %] Approved comments[% ELSE %] Comments awaiting moderation[% END %]</div>
 
 <div id="doc3" class="yui-t2">
    
@@ -33,6 +17,14 @@ $.tablesorter.addParser({
 
 <h1>Comments</h1>
 
+<!-- The manual invoice and credit buttons -->
+<div class="toptabs">
+<ul class="ui-tabs-nav">
+    [% IF ( status ) %]<li class="ui-tabs-selected">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/reviews/reviewswaiting.pl?status=1">Approved comments</a></li>
+    [% IF ( status ) %]<li>[% ELSE %]<li class="ui-tabs-selected">[% END %]<a href="/cgi-bin/koha/reviews/reviewswaiting.pl" >Comments awaiting moderation</a></li>
+</ul>
+<div class="tabs-container">
+
 [% IF ( reviews ) %]
 <table id="commentst">
     <thead><tr>
@@ -61,15 +53,18 @@ $.tablesorter.addParser({
             [% review.review |html %]
         </td>
         <td>
-            <a href="/cgi-bin/koha/reviews/reviewswaiting.pl?op=approve&reviewid=[% review.reviewid %]">Approve</a> |
+            [% IF ( status ) %]<a href="/cgi-bin/koha/reviews/reviewswaiting.pl?op=unapprove&reviewid=[% review.reviewid %]">Unapprove</a>[% ELSE %]<a href="/cgi-bin/koha/reviews/reviewswaiting.pl?op=approve&reviewid=[% review.reviewid %]">Approve</a>[% END %] |
             <a href="/cgi-bin/koha/reviews/reviewswaiting.pl?op=delete&reviewid=[% review.reviewid %]">Delete</a>
         </td>
     </tr>
     [% END %]</tbody>
 </table>
+ <div class="pages">[% pagination_bar %]</div>
 [% ELSE %]
-<b>No comments to moderate</b>
+[% IF ( status ) %]<p><b>No comments have been approved.</b></p>[% ELSE %]<p><b>No comments to moderate.</b></p>[% END %]
 [% END %]
+</div>
+</div>
 
 </div>
 </div>
diff --git a/reviews/reviewswaiting.pl b/reviews/reviewswaiting.pl
index 4d28a96..7107216 100755
--- a/reviews/reviewswaiting.pl
+++ b/reviews/reviewswaiting.pl
@@ -39,16 +39,23 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 );
 
 my $op       = $query->param('op') || '';
+my $status   = $query->param('status') || 0;
 my $reviewid = $query->param('reviewid');
+my $offset   = $query->param('offset') || 0;
+my $count    = C4::Context->preference('numSearchResults') || 20;
+my $total    = numberofreviews($status);
 
 if ( $op eq 'approve' ) {
     approvereview($reviewid);
 }
+elsif ( $op eq 'unapprove' ) {
+    unapprovereview($reviewid);
+}
 elsif ( $op eq 'delete' ) {
     deletereview($reviewid);
 }
 
-my $reviews = getallreviews(0);
+my $reviews = getallreviews($status,$offset,$count);
 
 foreach ( @$reviews ) {
     my $borrowernumber = $_->{borrowernumber};
@@ -60,6 +67,12 @@ foreach ( @$reviews ) {
     $_->{firstname}   = $borrowerData->{'firstname'};
 }
 
-$template->param( reviews => $reviews );
+my $url = "/cgi-bin/koha/reviews/reviewswaiting.pl?status=$status";
+
+$template->param(
+    status => $status,
+    reviews => $reviews,
+    pagination_bar => pagination_bar( $url, ( int( $total / $count ) ) + ( ( $total % $count ) > 0 ? 1 : 0 ), $offset, "offset" )
+);
 
 output_html_with_http_headers $query, $cookie, $template->output;
-- 
1.7.5.4


More information about the Patches mailing list