Pagination, search & username link patches

TfR75 - July 31, 2007 - 16:19
Project:Site User List
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community
Description

The user list for my site is growing and at one point it will become too long to be displayed on a single page. Would it be possible to break the user list into smaller pages, let's say after 50 users or so? Ideally, the site admin could choose when to have the page break, but even a standard page break after 30, 50 or 100 users would be very helpful. (I use the table or subselect query as the views option does not work on my site).

#1

TfR75 - September 8, 2007 - 12:50
Title:set page break for user list» Pagination for Site User List

changed the title so that it is easier to understand

#2

ajayg - February 18, 2008 - 18:58

Any update on this? I love this module but wondering why such a basic feature is missing. I have same problem as yours.

#3

pukku - February 19, 2008 - 15:14

Right now, I haven't had any time to work on Site User List because I've had other priorities at work. Hopefully in March I will be able to spend some more time on this.

However, I'm don't know if I will support a pager or not. The reason I wrote this module in the first place was because I wanted a user list _without_ a pager -- all of the other modules at that time required a pager. So the reason that a pager is missing is because that's the whole purpose of the module.

When I rewrite it next, I will see if I can fit a pager in, but I don't know.

#4

kiran_lakhotia - March 12, 2008 - 16:50

Hi,

I have added a little code to make the pagination an optional feature. To include this add the following code to site_user_list.module:

In the function site_user_list_admin_settings_form:

<?php
  
function site_user_list_admin_settings_form(){
      ....
     
$form['display_elements_fs']['pager_form'] = array(
     
'#type' => 'fieldset',
     
'#title' => t('Pager'),
     
'#weight' => variable_get('site_user_list_p_limit', 0),
      );
    
$form['display_elements_fs']['pager_form']['site_user_list_p_limit'] = array(
    
'#type' => 'select',
    
'#title' => t('Pagination Limit'),
    
'#default_value' => variable_get('site_user_list_p_limit', 0),
    
'#options' => array("0" => 0, "30" => 30, "50" => 50, "100" => 100)
    );
    ...
?>

This will allow you to control how many users to display in the list. If you set the limit to "0" all users will be displayed.

Add the following line to site_user_list_admin_settings_form_submit:

<?php
  
function site_user_list_admin_settings_form_submit($form_id, $data) {
      ....
     
variable_set('site_user_list_p_limit', $data['site_user_list_p_limit']);
      ....
?>

In the function site_user_list_form:

<?php
  
function site_user_list_form() {
      ....
     include_once (
'includes/pager.inc'); //at top
    
....
     if(
variable_get('site_user_list_p_limit', 0)){  //just after building sql query
      
$res = pager_query($sql, variable_get('site_user_list_p_limit', 0));
     }else {
      
$res = db_query($sql);
     }
     ....
     if(
variable_get('site_user_list_p_limit', 0)){ //just before return $form
      
$form['pagination'] = array(
      
'#type' => 'markup',
      
'#value' => theme('pager')
       );
     }
     ....
?>

#5

kiran_lakhotia - March 12, 2008 - 16:55

While doing the above I also added a little code to make the name "link-able" (same effect as if the user was to click the view link), although this requires you don't change the template column in the site_user_list_fields table from the default.

change line 977 in site_user_list.module from

<?php

   $row
[] = strtr($fields[$f]['template'], $r);
?>

to

<?php
  
if((($r['@uid'] == $user->uid) || ($can_view)) && strcmp($fields[$f]['template'], "@name") == 0){
     
$row[] = l(strtr($fields[$f]['template'], $r), "user/" . $r['@uid']);
   }else {
     
$row[] = strtr($fields[$f]['template'], $r);
   }
?>

#6

kiran_lakhotia - March 13, 2008 - 12:20

For our site we wanted a different behaviour for the search options on the site_user_list page. We wanted the "Search Options" to be expanded by default, and also have a single text box to do a "quick search". So what I've done is this.

- made the "Search Options" collapse/expand by default an optional feature in the admin settings
- created a single line text box for all searches. If a user does not select any of the profile chechboxes (the "Advanced" options will be then be collapsed), entering a search term has the effect as if a user had selected all the search options. If a user expands the "Advanced" options, only the selected fields are searched. (see attached snapshot for an example)

To implement this requires a few changes here and there, if anyone is interested I'll post the code.

Kiran

AttachmentSize
snapshot.JPG 40.1 KB

#7

kingandy - March 31, 2008 - 10:08

Kiran's code works perfectly - though I'd make one tiny performance tweak (put the include_once inside the if(variable_get('site_user_list_p_limit', 0)){} clause so it doesn't necessarily get included when it isn't required). Other than that, it's smashing :D

#8

kiran_lakhotia - April 17, 2008 - 12:08
Status:active» needs review

here is the patch (including kingandy's improvement) which adds pagination to the site_user_list module

edit:

(see post below from 17th April 2008)

#9

kiran_lakhotia - April 17, 2008 - 12:09

here is the patch which also makes the names of users clickable as described in my comment on the 12th march (see above)

edit:

(see post below from 17th April 2008)

#10

kiran_lakhotia - April 17, 2008 - 12:09

here is a patch to only contain one search field and have the option (via the site administration) to always show the search options expanded. If a user searches without ticking any boxes in the "Advanced Contact Info" section, the search behaves as if all boxes had been checked.

edit:

(see post below from 17th April 2008)

#11

TfR75 - April 3, 2008 - 09:23

I have installed and tested the patches and they all work great, with one exception. When no fields (such as "user name") are selected in the search box, search does not work and returns the following error message:

    * user warning: Unknown column 'cd.' in 'where clause' query: SELECT COUNT(*) FROM (SELECT DISTINCT u.uid as `@uid`, t_1.value as `@profile_firstname`, t_2.value as `@profile_name`, t_10.value as `@profile_research`, u.name as `@name` FROM users as u LEFT OUTER JOIN profile_values as t_1 on (u.uid = t_1.uid and t_1.fid = 1) LEFT OUTER JOIN profile_values as t_2 on (u.uid = t_2.uid and t_2.fid = 2) LEFT OUTER JOIN profile_values as t_10 on (u.uid = t_10.uid and t_10.fid = 10) WHERE (u.uid != 0) AND (u.status = 1)) as cd WHERE ((cd.`` like '%history%') or (cd.`@name` like '%history%') or (cd.`` like '%history%') or (cd.`@profile_firstname` like '%history%') or (cd.`@profile_name` like '%history%') or (cd.`` like '%history%') or (cd.`` like '%history%') or (cd.`` like '%history%') or (cd.`` like '%history%') or (cd.`` like '%history%') or (cd.`@profile_research` like '%history%') or (cd.`` like '%history%')) in /var/www/drupal/includes/database.mysql.inc on line 172.
    * user warning: Unknown column 'cd.' in 'where clause' query: SELECT DISTINCT `@uid`, `@name`, `@profile_firstname`, `@profile_name`, `@profile_research` FROM (SELECT DISTINCT u.uid as `@uid`, t_1.value as `@profile_firstname`, t_2.value as `@profile_name`, t_10.value as `@profile_research`, u.name as `@name` FROM users as u LEFT OUTER JOIN profile_values as t_1 on (u.uid = t_1.uid and t_1.fid = 1) LEFT OUTER JOIN profile_values as t_2 on (u.uid = t_2.uid and t_2.fid = 2) LEFT OUTER JOIN profile_values as t_10 on (u.uid = t_10.uid and t_10.fid = 10) WHERE (u.uid != 0) AND (u.status = 1)) as cd WHERE ((cd.`` like '%history%') or (cd.`@name` like '%history%') or (cd.`` like '%history%') or (cd.`@profile_firstname` like '%history%') or (cd.`@profile_name` like '%history%') or (cd.`` like '%history%') or (cd.`` like '%history%') or (cd.`` like '%history%') or (cd.`` like '%history%') or (cd.`` like '%history%') or (cd.`@profile_research` like '%history%') or (cd.`` like '%history%')) ORDER BY `@name` ASC LIMIT 0, 100 in /var/www/drupal/includes/database.mysql.inc on line 172.

#12

husztisanyi - April 3, 2008 - 14:02
Title:Pagination for Site User List» Roles slow the Site User List

If I set the user's roles at Settings/Fields/Available Columns to 'displayed by default', this setting very slow down the listing.
Could you solve this?

#13

mr.andrey - April 3, 2008 - 16:57

The pagination patch is awesome, thanks!

Love & Light,
Andrey.

#14

kiran_lakhotia - April 17, 2008 - 12:08

Hi TfR75,

you're right there was a missing if statement. In the function "profile_site_user_list_restrict" it didn't check the return value of "db_fetch_array" call when constructing the "or" clauses of the SQL statement, indicating which columns to search.

Kiran

#15

kiran_lakhotia - April 17, 2008 - 12:07

dear all,

it seems my patching skills were more than crap. I don't know if the previously submitted patches work, some are derf. incomplete. I have attached the three standalone patches, which I tested and they should work.

pagination.patch adds pagination to the site user list module

search.patch changes the search functionality as described previously

username.patch makes the username a clickable link to a users' profile

Kiran

AttachmentSize
pagination.patch 1.98 KB
search.patch 6.27 KB
username.patch 711 bytes

#16

TfR75 - April 17, 2008 - 13:31
Status:needs review» reviewed & tested by the community

These patches work fine on our site. Great work, Kiran!

#17

marvil07 - May 26, 2008 - 15:44

Pagination patch on comment 15 works

#18

WiredEscape - April 12, 2009 - 01:24
Title:Roles slow the Site User List» Pagination, search & username link patches

Changed title to reflect issue focus

#12 @husztisany should create a new issue rather than changing title.

 
 

Drupal is a registered trademark of Dries Buytaert.