[vhffs-dev] [1082] Added pagination to all groups list.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1082
Author:   beuss
Date:     2007-11-15 12:07:07 +0000 (Thu, 15 Nov 2007)

Log Message:
-----------
Added pagination to all groups list.
Fixed a bug in pagination where << and >> were displayed even when only one page was available.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Commons.pm
    trunk/vhffs-api/src/Vhffs/Panel/Group.pm
    trunk/vhffs-public/allgroups.pl
    trunk/vhffs-public/templates/groupslist.tmpl


Modified: trunk/vhffs-api/src/Vhffs/Panel/Commons.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Commons.pm	2007-11-15 06:27:58 UTC (rev 1081)
+++ trunk/vhffs-api/src/Vhffs/Panel/Commons.pm	2007-11-15 12:07:07 UTC (rev 1082)
@@ -93,10 +93,10 @@
 sub paginate($$$$$) {
     my ($template, $current_page, $total_count, $items_per_page, $url_params) = @_;
     die('Attempted to paginate without pagination template') unless($template->query(name => 'PAGINATION'));
-    $template->param(PAGINATION => 1);
     my $max_pages = int( ($total_count + ($items_per_page - 1)) / $items_per_page );
     if($max_pages > 1) {
         my @params;
+        $template->param(PAGINATION => 1);
         foreach my $key (keys %$url_params) {
             my $value = $url_params->{$key};
             push @params, $key.'='.$value unless($value =~ /^\s*$/);

Modified: trunk/vhffs-api/src/Vhffs/Panel/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Group.pm	2007-11-15 06:27:58 UTC (rev 1081)
+++ trunk/vhffs-api/src/Vhffs/Panel/Group.pm	2007-11-15 12:07:07 UTC (rev 1082)
@@ -163,19 +163,24 @@
 }
 
 sub get_groups_starting_with {
-    my ($main, $letter) = @_;
+    my ($main, $letter, $starting, $count) = @_;
     my @params;
 
-    my $sql = 'SELECT g.gid, g.groupname, g.realname, o.description FROM vhffs_groups g LEFT OUTER JOIN vhffs_users u ON u.username=g.groupname INNER JOIN vhffs_object o ON o.object_id=g.object_id WHERE o.state=? AND u.username IS NULL';
+    my $select_clause = 'SELECT g.gid, g.groupname, g.realname, o.description';
+    my $sql = ' FROM vhffs_groups g LEFT OUTER JOIN vhffs_users u ON u.username=g.groupname INNER JOIN vhffs_object o ON o.object_id=g.object_id WHERE o.state=? AND u.username IS NULL';
     push @params, Vhffs::Constants::ACTIVATED;
     if(defined $letter) {
         $sql .=  ' AND SUBSTR(g.groupname, 1, 1) = ?';
         push @params, $letter;
     }
     
-    $sql .= ' ORDER BY g.groupname';
+    my $order_clause = ' ORDER BY g.groupname LIMIT '.$count.' OFFSET '.$starting;
 
-    return fetch_groups_and_users($main, $sql, @params);
+    my $result = {};
+    $result->{groups} = fetch_groups_and_users($main, $select_clause.$sql.$order_clause, @params);
+    my $dbh = $main->get_db_object;
+    ($result->{total_count}) = @{$dbh->selectrow_arrayref('SELECT COUNT(*)'.$sql, undef, @params)};
+    return $result;
 }
 
 sub fetch_groups_and_users {

Modified: trunk/vhffs-public/allgroups.pl
===================================================================
--- trunk/vhffs-public/allgroups.pl	2007-11-15 06:27:58 UTC (rev 1081)
+++ trunk/vhffs-public/allgroups.pl	2007-11-15 12:07:07 UTC (rev 1082)
@@ -38,6 +38,7 @@
 use Locale::gettext;
 
 use lib '%VHFFS_LIB_DIR%';
+use Vhffs::Panel::Commons;
 use Vhffs::Panel::Group;
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Template;
@@ -51,24 +52,27 @@
 
 $panel->check_public();
 
-my $subtemplate;
-my $template;
-my $group;
 my $letter = $cgi->param('letter');
 my $used_letters = Vhffs::Panel::Group::get_used_letters($vhffs);
 $letter = $used_letters->[0]{letter} unless(defined $letter || !defined $used_letters->[0]);
 undef $letter if( $letter eq 'all');
-my $groups = Vhffs::Panel::Group::get_groups_starting_with( $vhffs , $letter );
-my $output_final="";
-my $maintemplate = new Vhffs::Panel::Template( filename => $templatedir."/public/groupslist.tmpl", die_on_bad_params => 0, loop_context_vars => 1 );
 
+my $page = $cgi->param('page');
+$page = 1 unless(defined $page);
+my $per_page_count = 10;
+
+my $result = Vhffs::Panel::Group::get_groups_starting_with( $vhffs , $letter, ($page - 1) *  $per_page_count, $per_page_count);
+my $template = new Vhffs::Panel::Template( filename => $templatedir."/public/groupslist.tmpl", die_on_bad_params => 0, loop_context_vars => 1 );
+
 my $hostname = $vhffs->get_config->get_host_name;
 
-$maintemplate->param( URL_PANEL => $vhffs->get_config->get_panel->{'url'} );
-$maintemplate->param( TEXT_TITLE => sprintf( gettext("All groups on %s") , $hostname ) );
-$maintemplate->param( LETTERS => $used_letters );
-$maintemplate->param( ALL => gettext('All') );
-$maintemplate->param( GROUPS => $groups );
+Vhffs::Panel::Commons::paginate($template, $page, $result->{total_count}, $per_page_count, { letter => (defined($letter) ? $letter : 'all') });
 
-$panel->light( $maintemplate );
+$template->param( URL_PANEL => $vhffs->get_config->get_panel->{'url'} );
+$template->param( TEXT_TITLE => sprintf( gettext("All groups on %s") , $hostname ) );
+$template->param( LETTERS => $used_letters );
+$template->param( ALL => gettext('All') );
+$template->param( GROUPS => $result->{groups} );
+
+$panel->light( $template );
 $panel->display;

Modified: trunk/vhffs-public/templates/groupslist.tmpl
===================================================================
--- trunk/vhffs-public/templates/groupslist.tmpl	2007-11-15 06:27:58 UTC (rev 1081)
+++ trunk/vhffs-public/templates/groupslist.tmpl	2007-11-15 12:07:07 UTC (rev 1082)
@@ -9,10 +9,11 @@
 </TMPL_LOOP>
 [<a href="/allgroups.pl?letter=all"><TMPL_VAR ESCAPE=1 NAME="ALL"></a>]
 </p>
+</TMPL_IF>
+<TMPL_INCLUDE NAME="misc/pagination.tmpl">
 <TMPL_IF NAME="MESSAGE">
 <p style="text-align:center;font-weight:bold;"><TMPL_VAR ESCAPE=1 NAME="MESSAGE"></p>
 </TMPL_IF>
-</TMPL_IF>
 <TMPL_LOOP NAME="GROUPS">
 <TMPL_INCLUDE NAME="misc/groupinfo.tmpl">
 </TMPL_LOOP>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/