First, excellent work, and a great module! My question: Is there a way to display the user's role in the Site User List?

Comments

pukku’s picture

Assigned: Unassigned » pukku

Not right now. User roles aren't stored directly in an SQL table; they're serialized and stored in a data column, with a bunch of other info. This means that it isn't possible to grab this data in SQL, which is a requirement for Site User List. I have an idea of how this would be fixable: the module would need to implement hook_user, and turn the data into table data. Then, there is the issue of display — it would be easy to search by role, but as each role would be one column, displaying them gets more complicated.

user.module gets around this by using a pager, and only loading 10 users at once, so it can afford to run user_load; as a site gets larger, having user_load run on more and more users would slow it down far too much for site_user_list.module to be effective.

pukku’s picture

Status: Active » Fixed

Hi! The following solution isn't really the best way to do this; it could potentially slow down the site user list a lot (as it calls user_load on every user every time the site user list is viewed), but with the new codebase, this is at least theoretically possible. I suggest creating a small local module to provide this (see code below), but if you want to test it out, create a dummy profile field, and edit the template settings for that field (at admin/settings/site_user_list/fields). Set your field to be displayed, turn on eval for the template, and make the template be $tu = user_load(array('uid' => $r['@uid'])); return theme('item_list', $tu->roles);. If you want to do something else with the user object once you have it, then by all means do so...

A better way to do this would be to create a local module. (Warning: I haven't actually done the steps below, so I might have a mistake or two. If you run into problems, let me know...)

First, create a new directory called modules in the directory your settings.php is located in (unless such a directory already exists). Inside that directory create another directory called something like 'small_local_modules'. Inside that directory, create a file called 'site_user_list_role_column.info'. Make that file read:

name = Site user list Role column
description = provide a column which displays a users roles

Then, create a file called 'site_user_list_role_column.module'. The contents of that file should be


function site_user_list_role_column_site_user_list_fields() {
  return array(
    '@role_column' => array(
      'display_name' => 'User Roles',
      'description' => 'Displays the user\'s roles.  May slow things down a lot',
      'db_column' => '',
      'column_header' => 'Roles',
      'default_template' => '$tu = user_load(array("uid" => $r["@uid"])); return theme("item_list", $tu->roles);',
      'eval_template' => 1,
      'search_column' => '',
      'sort_column' => '',
    ),
  );
}

If you enable this local module, and go to admin/settings/site_user_list/fields, you should now see an available field called 'User Roles'. If you enable this field, it should display the roles.

BTW: this requires the most recent version of site_user_list, which was just uploaded to cvs. You may need to wait a bit for the tarballs to update properly.

anonymous562’s picture

Just updated to the latest CVS. I'm ready to get cracking on this, but you indicated to create a folder called 'modules' in the same place as my settings.php file. I can't locate this file...

pukku’s picture

Hi! This is located somewhere in your sites folder. If you're just using a default install of drupal, try sites/default. If you're hosted somewhere and they have multiple folders (besides 'all' and 'default') in the sites folder, it will depend on the name of your site...

pukku’s picture

BTW: if you can wait a few days, I might have an easier solution to creating your own columns in place.

Ricky

anonymous562’s picture

Got it. I can wait, no problem. Do you still want me to try out the code anyway, or are you going to ditch it in favor of something else?

pukku’s picture

Status: Fixed » Active

My plan is to provide a way for sites to create their own template columns without needing a local module. It's basically a generic version of the module I gave you.

If you want to try it and see if it works, that would be interesting, but if not, there's no real need...

Ricky

anonymous562’s picture

Works perfectly! This is great!! One small request: (if this is hard to do, please just say so, and it's fine). Is there a way to exclude the "authenticated user" role from being displayed? My site is going to be set that administrators approve all registrations, so EVERYONE will be an authenticated user, and I don't need to have that displayed.

Again, it's an extremely minor request, and I don't care one way or the other. But if it's a simple fix, just let me know. Thanks again!!

pukku’s picture

Well, the code I gave you was just a simple template kind of thing. The user's uid is in $r['@uid'], and I just run user_load() with the uid. This results in a user object. The template I gave you just passes the list of roles for that user directly to theme_item_list; you could do something else with it if you wanted to.

Note that this may become very slow as you get more and more users...

Ricky

anonymous562’s picture

I probably won't have more than 150 members or so, and they won't be accessing the list that often. I'm not too concerned.

How should I proceed with upgrades from now on? You said in a few days you'd be releasing code that might make this process more "built in" - so should I ditch the stuff I've done to this point, and just get your new code later?

pukku’s picture

Hi! What I'm planning on adding shortly is just a way to have extra, non-database columns added in, so that you can put your own templates in easily. When that happens, you can just configure a new template column, copy over the template, make sure it works, and then disable the local module you created. Then just go back to the settings to rebuild everything, and it will all be happy...

Ricky

pukku’s picture

Status: Active » Fixed

Hi! Actually, for handling roles, I've gone ahead and created a sub-module called site_user_list_roles, which handles working with roles. It's located in the same directory as site_user_list, so you'll either have to get the new files from CVS or wait a few hours for a new tarball.

Let me know if this does what you need...

Thanks,
Ricky

pukku’s picture

Status: Fixed » Closed (fixed)