Display newly joined users at the top by default?

mr.andrey - July 7, 2007 - 23:56
Project:Site User List
Version:5.x-1.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:pukku
Status:postponed
Description

Hello,

Is there a way to display the newly joined users at the top of the list by default? Sort it by the joined date descending?

Thanks,
Andrey.

#1

Rain - July 11, 2007 - 04:02

Same question here...

#2

pukku - July 11, 2007 - 13:10
Category:support request» feature request
Assigned to:Anonymous» pukku
Status:active» postponed

Right now, no. I will look at this after I get one more planned feature put in place.

Ricky

#3

mr.andrey - September 26, 2007 - 19:06

Meanwhile, here's a patch to do this the manual way.

This patch will:
* list newest joined users on the top
* remove user with id=1 from the list (admin)

--- .../sites/all/modules/site_user_list/site_user_list.module     2007-07-29 14:31:25.000000000 -0700
+++ site_user_list.module       2007-09-26 11:51:00.000000000 -0700
@@ -688,8 +688,10 @@ function site_user_list_build() {

   // never include user 0, who exists in the database for the anonymous user
   $where = array(
-    '(u.uid != 0)',
+    '(u.uid != 0 AND u.uid != 1)', // !custom
   );
+  $order = " ORDER BY u.uid desc"; // !custom

   // if we don't include blocked users, we need to filter on status = not blocked
   if (!variable_get('site_user_list_include_blocked_users', 0)) {
@@ -723,7 +725,7 @@ function site_user_list_build() {
   // build the SQL query that we'll use
   $internal_sql = "SELECT DISTINCT " . implode(", ", $cols) . " "
                 . "FROM " . implode(" ", $joins) . " "
-                . "WHERE " . implode(" AND ", $where)
+                . "WHERE " . implode(" AND ", $where) . $order
                 ;

   // now that we've got the query, save what ever we need
@@ -885,6 +887,8 @@ function site_user_list_form() {
   $joins = array();
   $where = array();
   $descriptions = array();
+  $where[] = "`@uid` != 1"; // !custom
+  $order = " ORDER BY `@uid` desc"; // !custom

   $restrictions = module_invoke_all('site_user_list_restrict', $_REQUEST['s']);
   foreach ($restrictions as $module => $module_restrictions) {
@@ -903,7 +907,7 @@ function site_user_list_form() {
   $sql = 'SELECT DISTINCT ' . implode(", ", $select) . ' '
        . 'FROM ' . $select_from . ' as cd '
        . implode(' ', $joins) . ' '
-       . (count($where) ? 'WHERE ' . implode(' AND ', $where) : '')
+       . (count($where) ? 'WHERE ' . implode(' AND ', $where) : '') . $order
        ;
   $sql .= tablesort_sql($display_header);

Note: I'm not sure what the first part of it does, but the second one is what changes the listing. I just added the changes to the first one for consistency - it's probably used somewhere important.

#4

pukku - September 26, 2007 - 19:21

Hi!

1) You can either exclude uid=1 in site_user_list_build(), or exclude uid=1 in site_user_list_form(). You shouldn't need to do both. If you exclude the user in site_user_list_build(), the user will never be returned as a result of the view or sub-select, or will never be put into the table when it is created. If you exclude the user in site_user_list_form(), the admin user will be in the tabel/view/sub-select query, but will be filtered out afterwords. I suggest keeping it in site_user_list_build(). I might also reword it as '(u.uid not in (0, 1))'.

2) Are you sure that you can continue to sort columns by clicking on them with the change you made? It seems to me that you're going to wind up with two 'ORDER BY' clauses, which would be bad. Instead, you should probably do something like

if (!empty($_REQUEST['sort'])) {
  $sql .= tablesort_sql($display_headers);
}
else {
  $sql .= $order;
}

HTH,
Ricky

#5

mr.andrey - September 26, 2007 - 22:30

Thanks for the sorting tip, Ricky, that is exactly what I had in mind.

I tried excluding the uid=1 in the site_user_list_build only (using your suggested query), but it didn't seem to have any effect.

I did take out the $order from the site_user_list_build - there seems to be no need for it there.

Best,
Andrey.

#6

pukku - September 27, 2007 - 12:56

Did you force a rebuild of the [query|view|table] after you modified site_user_list_build()? If you didn't, then it would have had no effect.

Ricky

#7

mr.andrey - September 27, 2007 - 22:01

Thanks again, Ricky for pointing this out.

I had to go to site_user_list/rebuild for changes to apply fully.

Here is the final patch to hide uid=1 and list new users at the top:

--- site_user_list.module.init  2007-09-26 12:15:44.000000000 -0700
+++ site_user_list.module       2007-09-27 14:52:08.000000000 -0700
@@ -688,7 +688,8 @@ function site_user_list_build() {

   // never include user 0, who exists in the database for the anonymous user
   $where = array(
-    '(u.uid != 0)',
+    '(u.uid not in (0, 1))',
   );

   // if we don't include blocked users, we need to filter on status = not blocked
@@ -905,7 +906,13 @@ function site_user_list_form() {
        . implode(' ', $joins) . ' '
        . (count($where) ? 'WHERE ' . implode(' AND ', $where) : '')
        ;
-  $sql .= tablesort_sql($display_header);
+  $order = " ORDER BY `@uid` desc";
+  if (!empty($_REQUEST['sort'])) {
+    $sql .= tablesort_sql($display_header);
+  } else {
+    $sql .= $order;
+  }

   $res = db_query($sql);

#8

WiredEscape - March 1, 2008 - 20:20

Thanks Andrey & Ricky.

Subscribing

#9

WiredEscape - March 1, 2008 - 23:16

The module now has the ability to hide uid=1 with out hacking the module. It is not clearly documented so I thought I'd provide some directions.

HTH,
Doug
---------------------------------------------
Hiding user profiles on a user list

The 'Site User List' module allows hiding specified users from a custom user list. The module is easy to setup and only requires the profiles module of the Drupal optional core modules.

NOTE: Although the modules does 'hide' the selected user, it does not prevent a knowledgeable user from accessing the user's profile by just changing the user id number in the url.

'Site User List' module setup Instructions:

1) enable 'Profile' in core optional modules.
2) install 'Site User List' module and configure as per readme file.
3) set permission for 'view site user list' on 'Administer/user management/access control'.

NOTE: do not use the 'Excluded Users' module. As noted in the 'Site User List' module issues this module is depreciated. The functionality of the 'Excluded Users' module is now built into the 'Site User List' module. It is not well documented so here is how to set it up:

Exclude specific user:

  • Go to 'Administer/user management/profiles'. Add a new custom field with checkbox type for the user profile. Title the field 'Hide profile', name the field 'profile_hide_profile', and create category called 'Profile settings' for the field.
  • Go to the 'Administration/Site configuration/Site User List' and the 'User exclusion settings' option will now show up on the Profile tab. Choose whether to exclude based on checked vs. not-checked status of the checkbox field.
  • To exclude a user go their profile and checkmark the 'Hide profile' option.

Tips:
You will need to manually rebuild the table, view, or query after configuration changes. This is done by going to /site_user_list/rebuild which is available from the Site User List config page.

Misc:
Management of all users is still available to admins through 'Administer/user management/users' section.

#10

pukku - March 4, 2008 - 01:23

Thanks for writing this up!

Ricky

 
 

Drupal is a registered trademark of Dries Buytaert.