[vhffs-dev] [1357] Last users is back

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


Revision: 1357
Author:   beuss
Date:     2009-03-09 19:11:46 +0100 (Mon, 09 Mar 2009)

Log Message:
-----------
Last users is back

Modified Paths:
--------------
    branches/vhffs-design/vhffs-api/src/Vhffs/Panel/User.pm
    branches/vhffs-design/vhffs-public/lastusers.pl
    branches/vhffs-design/vhffs-public/templates/Makefile.am
    branches/vhffs-design/vhffs-public/templates/parts/left-menu.tt

Added Paths:
-----------
    branches/vhffs-design/vhffs-public/templates/content/last-users.tt


Modified: branches/vhffs-design/vhffs-api/src/Vhffs/Panel/User.pm
===================================================================
--- branches/vhffs-design/vhffs-api/src/Vhffs/Panel/User.pm	2009-03-09 12:32:50 UTC (rev 1356)
+++ branches/vhffs-design/vhffs-api/src/Vhffs/Panel/User.pm	2009-03-09 18:11:46 UTC (rev 1357)
@@ -84,12 +84,22 @@
 
 sub get_last_users
 {
-	my $main = shift;
+	my ($main) = @_;
 
-	return if ( !defined $main );
-
-	my $sql = 'SELECT u.uid, u.username, u.firstname, u.lastname FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id=u.object_id WHERE o.state=? ORDER BY o.date_creation DESC LIMIT 10';
-    return fetch_users_and_groups($main, $sql, Vhffs::Constants::ACTIVATED);
+	my $sql = 'SELECT u.uid, u.username, u.firstname, u.lastname '.
+		'FROM vhffs_users u '.
+		'INNER JOIN vhffs_object o ON o.object_id=u.object_id '.
+		'WHERE o.state=? ORDER BY o.date_creation DESC LIMIT 10';
+	
+	my $dbh = $main->get_db_object();
+    
+    my $users = $dbh->selectall_hashref($sql, 'uid', undef, Vhffs::Constants::ACTIVATED);
+	
+	fill_groups($main, $users);
+	
+	my @val = values(%$users);
+	
+	return \@val;	
 }
 
 sub search {
@@ -155,16 +165,39 @@
 	
 	my ($count) = $dbh->selectrow_array('SELECT COUNT(*) '.$sql, undef, @params);
 	
+	fill_groups($main, $users);
+	
+	my @val = values(%$users);
+	
+	# We've to sort manualy since we use a hash
+	@val = sort { $a->{username} cmp $b->{username}} @val;
+	
+	return (\@val, $count);
+}
+
+=head2 fill_groups
+
+	Vhffs::Panel::User::fill_groups($main, $users);
+
+C<$users> is a HASHREF indexed by uid containing at least
+the C<uid> field. It is modified inplace to add a field
+C<groups> containing the names of the groups the user belongs
+to.
+
+=cut 
+
+sub fill_groups {
+	my ($main, $users) =@_;
+	
+	my $dbh = $main->get_db_object();
 	my @uids = ();
 	
 	foreach my $uid(keys(%$users)) {
 		push @uids, $uid;
 	}
 	
-	# OK, now fetch all groups in one shot
-	# we can't do this in the first query since
-	# we've a limit clause
-	$sql = 'SELECT g.groupname, u.uid FROM vhffs_groups g '.
+	# Fetch all groups in one shot
+	my $sql = 'SELECT g.groupname, u.uid FROM vhffs_groups g '.
 		'INNER JOIN vhffs_user_group ug ON ug.gid = g.gid '.
 		'INNER JOIN vhffs_users u ON u.uid = ug.uid '.
 		'WHERE g.groupname != u.username AND u.uid IN ( '.join(', ', @uids).') '.
@@ -179,13 +212,6 @@
 		}
 		push(@{$users->{$g->{uid}}{groups}}, $g->{groupname});
 	}
-	
-	my @val = values(%$users);
-	
-	# We've to sort manualy since we use a hash
-	@val = sort { $a->{username} cmp $b->{username}} @val;
-	
-	return (\@val, $count);
 }
 
 sub fetch_users_and_groups {

Modified: branches/vhffs-design/vhffs-public/lastusers.pl
===================================================================
--- branches/vhffs-design/vhffs-public/lastusers.pl	2009-03-09 12:32:50 UTC (rev 1356)
+++ branches/vhffs-design/vhffs-public/lastusers.pl	2009-03-09 18:11:46 UTC (rev 1357)
@@ -35,32 +35,18 @@
 use POSIX qw(locale_h);
 use locale;
 use Locale::gettext;
-use CGI;
 
 use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Template;
+
+use Vhffs::Panel::Public;
 use Vhffs::Panel::User;
 
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
+my $panel = new Vhffs::Panel::Public();
 
-my $vhffs = $panel->{'vhffs'};
-my $templatedir = $panel->{'templatedir'};
-my $cgi = $panel->{'cgi'};
+my $users = Vhffs::Panel::User::get_last_users($panel->{vhffs});
 
-$panel->check_public();
+use Data::Dumper;warn Dumper($users);
 
-my $template;
-my $users = Vhffs::Panel::User::get_last_users( $vhffs );
-my $hostname = $vhffs->get_config->get_host_name;
-
-
-$template = new Vhffs::Panel::Template( filename => $templatedir."/public/userslist.tmpl", global_var => 1, die_on_bad_params => 0, loop_context_vars => 1 );
-$template->param( TEXT_TITLE => sprintf( gettext("Last users on %s") , $hostname ) );
-$template->param( URL_PANEL => $vhffs->get_config->get_panel->{'url'} );
-$template->param( USE_AVATAR => $panel->use_users_avatars );
-$template->param( USERS => $users );
-
-$panel->light( $template );
-$panel->display;
+$panel->render('content/last-users.tt', {
+	users => $users
+});

Modified: branches/vhffs-design/vhffs-public/templates/Makefile.am
===================================================================
--- branches/vhffs-design/vhffs-public/templates/Makefile.am	2009-03-09 12:32:50 UTC (rev 1356)
+++ branches/vhffs-design/vhffs-public/templates/Makefile.am	2009-03-09 18:11:46 UTC (rev 1357)
@@ -5,6 +5,7 @@
 	common/pager.tt \
 	content/all-groups.tt \
 	content/last-groups.tt \
+	content/last-users.tt \
 	content/group-details.tt \
 	content/groupsearch-form.tt \
 	content/groupsearch-results.tt \

Added: branches/vhffs-design/vhffs-public/templates/content/last-users.tt
===================================================================
--- branches/vhffs-design/vhffs-public/templates/content/last-users.tt	                        (rev 0)
+++ branches/vhffs-design/vhffs-public/templates/content/last-users.tt	2009-03-09 18:11:46 UTC (rev 1357)
@@ -0,0 +1,5 @@
+<h1>[% 'Last users' | i18n %]</h1>
+
+[% FOREACH u = users %]
+[% INCLUDE 'parts/user-general.tt' %]
+[% END %]
\ No newline at end of file

Modified: branches/vhffs-design/vhffs-public/templates/parts/left-menu.tt
===================================================================
--- branches/vhffs-design/vhffs-public/templates/parts/left-menu.tt	2009-03-09 12:32:50 UTC (rev 1356)
+++ branches/vhffs-design/vhffs-public/templates/parts/left-menu.tt	2009-03-09 18:11:46 UTC (rev 1357)
@@ -9,5 +9,5 @@
 	<h2>[% 'Users' | i18n %]</h2>
 	<div class="menu">
 		<a href="/usersearch_form.pl" class="ajax">[% 'Search' | i18n %]</a>
-		<a href="/lastusers.pl">[% 'Last users' | i18n %]</a>
+		<a href="/lastusers.pl" class="ajax">[% 'Last users' | i18n %]</a>
 	</div>


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