[vhffs-dev] [1090] User search use new functions.

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


Revision: 1090
Author:   beuss
Date:     2007-11-21 05:56:42 +0000 (Wed, 21 Nov 2007)

Log Message:
-----------
User search use new functions.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/User.pm
    trunk/vhffs-public/usersearch.pl


Modified: trunk/vhffs-api/src/Vhffs/Panel/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/User.pm	2007-11-18 11:20:40 UTC (rev 1089)
+++ trunk/vhffs-api/src/Vhffs/Panel/User.pm	2007-11-21 05:56:42 UTC (rev 1090)
@@ -84,23 +84,12 @@
 
 sub get_last_users
 {
-	my $vhffs = shift;
-	my @users;
+	my $main = shift;
 
-	return if ( !defined $vhffs );
+	return if ( !defined $main );
 
 	my $sql = 'SELECT uid, username, firstname, lastname FROM vhffs_users ORDER BY date_creation DESC LIMIT 10';
-    my $sth = $vhffs->get_db_object->prepare($sql);
-    $sth->execute();
-    $sql = 'SELECT g.groupname FROM vhffs_groups g INNER JOIN vhffs_user_group ug ON ug.gid = g.gid WHERE ug.uid = ? AND g.groupname != ?';
-    my $ssth = $vhffs->get_db_object->prepare($sql);
-    while(my $row = $sth->fetchrow_hashref) {
-        $ssth->execute($row->{uid}, $row->{username});
-        $row->{groups} = $ssth->fetchall_arrayref({});
-        push @users, $row;
-    }
-
-    return \@users;
+    return fetch_users_and_groups($main, $sql);
 }
 
 sub search {
@@ -138,6 +127,7 @@
     my $select_clause = 'SELECT u.uid, u.username, u.firstname, u.lastname';
     my $restriction = ' FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE o.state = ?';
     my @params;
+    push @params, Vhffs::Constants::ACTIVATED;
 
     if(defined $username) {
         # usernames are enforced in lowercase
@@ -155,25 +145,28 @@
         push @params, '%'.$lastname.'%';
     }
 
-    my $order = ' ORDER BY u.username LIMIT ? OFFSET ?';
-    push @params, $count, $start;
+    my $order = ' ORDER BY u.username';
 
-    my $dbh = $main->get_db_object;
-    my $sth = $dbh->prepare($select_clause.$restriction.$order);
+    return Vhffs::Panel::Commons::fetch_slice_and_count($main, $select_clause, $restriction, $order, $start, $count, \@params, \&fetch_users_and_groups);
+}
+
+sub fetch_users_and_groups {
+    my ($main, $sql, @params) = @_;
     my @users;
-    $sth->execute( Vhffs::Constants::ACTIVATED, @params );
-    my $sql = 'SELECT g.groupname FROM vhffs_groups g INNER JOIN vhffs_user_group ug ON ug.gid = g.gid WHERE ug.uid = ? AND g.groupname != ?';
+
+    my $dbh = $main->get_db_object;
+    my $sth = $dbh->prepare($sql);
+    $sth->execute( @params );
+    $sql = 'SELECT g.groupname FROM vhffs_groups g INNER JOIN vhffs_user_group ug ON ug.gid = g.gid WHERE ug.uid = ? AND g.groupname != ?';
     my $ssth = $dbh->prepare($sql);
     while(my $row = $sth->fetchrow_hashref) {
        $ssth->execute($row->{uid}, $row->{username});
        $row->{groups} = $ssth->fetchall_arrayref({});
        push @users, $row;
     }
-    $result->{users} = \@users;
-    $select_clause = 'SELECT COUNT(*)';
-    pop @params; pop @params;
-    ($result->{total_count}) = @{$dbh->selectrow_arrayref($select_clause.$restriction, undef, Vhffs::Constants::ACTIVATED, @params)};
-    return $result;
+
+    return \@users;
+
 }
 
 sub set_lang

Modified: trunk/vhffs-public/usersearch.pl
===================================================================
--- trunk/vhffs-public/usersearch.pl	2007-11-18 11:20:40 UTC (rev 1089)
+++ trunk/vhffs-public/usersearch.pl	2007-11-21 05:56:42 UTC (rev 1090)
@@ -77,7 +77,7 @@
         { username => $username, firstname => $firstname, lastname => $lastname});
     $template->param( USE_AVATAR => $panel->use_users_avatars );
     $template->param( TEXT_TITLE => sprintf( gettext('%d user(s) found'), $result->{total_count} ) );
-    $template->param( USERS => $result->{users} );
+    $template->param( USERS => $result->{data} );
 }
 
 $panel->light( $template );


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