Adding basic get_filters to Tags, centralizing "counts" code for Terms Summary.
authorJoe Atzberger <joe.atzberger@liblime.com>
Tue, 27 May 2008 23:06:00 +0000 (18:06 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Thu, 29 May 2008 12:04:41 +0000 (07:04 -0500)
Signed-off-by: Joshua Ferraro <jmf@liblime.com>

C4/Tags.pm
tags/review.pl

index 68591b4..f706ffc 100644 (file)
@@ -26,7 +26,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 use vars qw($ext_dict $select_all @fields);
 
 BEGIN {
-       $VERSION = 0.02;
+       $VERSION = 0.03;
        @ISA = qw(Exporter);
        @EXPORT_OK = qw(
                &get_tag &get_tags &get_tag_rows
@@ -39,6 +39,8 @@ BEGIN {
                &blacklist
                &whitelist
                &is_approved
+               &approval_counts
+               &get_filters
        );
        # %EXPORT_TAGS = ();
        $ext_dict = C4::Context->preference('TagsExternalDictionary');
@@ -60,6 +62,36 @@ INIT {
        $select_all = "SELECT " . join(',',@fields) . "\n FROM   tags_all\n";
 }
 
+sub get_filters (;$) {
+       my $query = "SELECT * FROM tags_filters ";
+       my ($sth);
+       if (@_) {
+               $sth = C4::Context->dbh->prepare($query . " WHERE filter_id = ? ");
+               $sth->execute(shift);
+       } else {
+               $sth = C4::Context->dbh->prepare($query);
+               $sth->execute;
+       }
+       return $sth->fetchall_arrayref({});
+}
+
+#      (SELECT count(*) FROM tags_all     ) as tags_all,
+#      (SELECT count(*) FROM tags_index   ) as tags_index,
+
+sub approval_counts () { 
+       my $query = "SELECT
+               (SELECT count(*) FROM tags_approval WHERE approved= 1) as approved_count,
+               (SELECT count(*) FROM tags_approval WHERE approved=-1) as rejected_count,
+               (SELECT count(*) FROM tags_approval WHERE approved= 0) as unapproved_count
+       ";
+       my $sth = C4::Context->dbh->prepare($query);
+       $sth->execute;
+       my $result = $sth->fetchrow_hashref();
+       $result->{approved_total} = $result->{approved_count} + $result->{rejected_count} + $result->{unapproved_count};
+       $debug and warn "counts returned: " . Dumper $result;
+       return $result;
+}
+
 sub remove_tag ($;$) {
        my $tag_id  = shift or return undef;
        my $user_id = (@_) ? shift : undef;
index 010f133..f6e9501 100755 (executable)
@@ -26,29 +26,13 @@ use POSIX;
 use CGI;
 use CGI::Cookie; # need to check cookies before having CGI parse the POST request
 
-use C4::Auth qw(:DEFAULT check_cookie_auth);;
+use C4::Auth qw(:DEFAULT check_cookie_auth);
 use C4::Context;
 use C4::Dates qw(format_date format_date_in_iso);
 # use C4::Koha;
 use C4::Output 3.02 qw(:html :ajax pagination_bar);
 use C4::Debug;
-use C4::Tags 0.02 qw(get_tags get_approval_rows whitelist blacklist is_approved);
-
-sub counts () { 
-       my $query = "SELECT " .
-       #               (SELECT count(*) FROM tags_all     ) as tags_all,
-       #               (SELECT count(*) FROM tags_index   ) as tags_index,
-       "               (SELECT count(*) FROM tags_approval WHERE approved= 1) as approved_count,
-                       (SELECT count(*) FROM tags_approval WHERE approved=-1) as rejected_count,
-                       (SELECT count(*) FROM tags_approval WHERE approved= 0) as unapproved_count
-       ";
-       my $sth = C4::Context->dbh->prepare($query);
-       $sth->execute;
-       my $result = $sth->fetchrow_hashref();
-       $result->{approved_total} = $result->{approved_count} + $result->{rejected_count} + $result->{unapproved_count};
-       $debug and warn "counts returned: " . Dumper $result;
-       return $result;
-}
+use C4::Tags 0.03 qw(get_tags get_approval_rows approval_counts whitelist blacklist is_approved);
 
 my $script_name = "/cgi-bin/koha/tags/review.pl";
 my $needed_flags = { tools => 'moderate_comments' };   # FIXME: replace when more specific permission is created.
@@ -124,7 +108,7 @@ $borrowernumber == 0 and push @errors, {op_zero=>1};
        );
 }
 
-my $counts = &counts;
+my $counts = &approval_counts;
 foreach (keys %$counts) {
        $template->param($_ => $counts->{$_});
 }