How to limit the users in the Avatar Gallery to a specified number. Also How to show only top contributors in Avatar gallery first. Can more blocks be added.

Thanks a lot for making this wonderful module. I just love it.

CommentFileSizeAuthor
#3 avatar_gallery.txt14.64 KBsdsheridan

Comments

1ns’s picture

As a quick&dirty fix you can hardcode it in the SQL in avatar_gallery.module
by changing:
< $result = db_query('SELECT uid,name,picture FROM {users} WHERE status != 0 and uid != 0 ORDER BY %s', $order);
---
with:
> $result = db_query('SELECT uid,name,picture FROM {users} WHERE status != 0 and uid != 0 ORDER BY %s LIMIT %s', $order, <MAX_THUMBS_VISIBLE>);

.. where <MAX_THUMBS_VISIBLE> is the number of avatars you want displayed.

For a nontrivial selection of avatars, you could change the SQL query here as well. As the 'number of contributions' isn't a simple field in the users table, I suppose you will need some creative table joining to get the query results you want.

taherk’s picture

Thanks this query worked. I am still showing blanks where the picture is default, anything that can we done to eliminate that ?

sdsheridan’s picture

StatusFileSize
new14.64 KB

Actually, there's an even more elegant way to do this, which means you don't have to hard-code anything. I just did it.

First, add this code to the avatar_gallery_admin_settings() function.

  $form['visual']['avatar_gallery_max_avatars'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum avatars to show'),
    '#size' => 5,
    '#maxlength' => 5,
    '#default_value' => variable_get('avatar_gallery_max_avatars', 100),
  );

I put it right at the top, so that it shows up at the top of the form.

Secondly, in the avatar_gallery_regenerate() function, modify it as follows:

function avatar_gallery_regenerate()
{
  $order = variable_get('avatar_gallery_ordering', 'uid DESC');
  $max_avatars = variable_get('avatar_gallery_max_avatars', 100);    // Retrieve the maximum number of avatars to show.

  $items = array();
//  $result = db_query('SELECT uid,name,picture FROM {users} WHERE status != 0 and uid != 0 ORDER BY %s', $order);  <-- This is the old line.
  $result = db_query('SELECT uid,name,picture FROM {users} WHERE status != 0 and uid != 0 ORDER BY %s LIMIT %s', $order, $max_avatars);

Once you do that, you can configure the number of avatars to show simply by changing the value on the settings page. I'm inherently lazy, so I hate changing code more times than I have to. :-)

I've attached my modified module in case anyone doesn't want to make the changes and just wants to use this. It has a txt extension, so just change it back to '.module' .

seanberto’s picture

Great hack. However, when I set the max allowed value to 10, I get a "invalid argument foreach" error at line 301 when I try to regenerate the avatar. This doesn't happen when I set the max allowed value to 100 - which is more than the number of users I have in the system.

Any thoughts?

-s

sdsheridan’s picture

Very odd. I've got mine set to 24, and it's working fine so far... but i have only 8 test users on the site at the moment. Line 301 of which module / file?

coupet’s picture

Can we submit this as a patch ?

Darly

sdsheridan’s picture

I've been using it consistently on a site with the maximum number set to 18, and there are more than 18 members, and all is well (for me, anyway). Using Drupal 5.2, my hack to the module above, and MySQL. It is working as expected on production, test, and development instances, so... :-)

pfournier’s picture

Status: Active » Fixed

The user limit has been implemented in the 5.x-1.x-dev version of May 6, 2008 (n fact there is a limit in the number of rows).

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.