Hi there,
I am developing a site, where I want to have registered users, but have a 'team' role, for just a few of my users.
I want to be able to have a block or list, like the users block, but that only shows my 'team' role. I cant for the life of me work out how to make a view, or flexinode to show that content,.

site - http://www.riverkore.com/h2o

I have found snippit that wouldl let me decide which roles are viewable, but this does not quite work. I want a list of 'all users' and a list of just my team.

thanks

Allan

Comments

Barry Pretsell’s picture

Not exactly sure what you want to output regarding the team role, but this may get you started.

I had a similar problem, don't think views will do it since everything in views has to link back to a node so user roles kind of goes against the grain. I used a block of php with SQL to join uid to user_roles table then joined those rid values to roles table.

Something like this in a block would list users with the team role

<?php

$result = db_query("SELECT users.name
FROM users
LEFT JOIN users_roles ON users.uid = users_roles.uid
LEFT JOIN role ON users_roles.rid = role.rid
WHERE role.name = 'team'");

while ($t = db_fetch_object($result)) {
	print "<p>" . $t->name . "</p>";
}
?>
seaneffel’s picture

This is so close to what I am looking for, I can taste it.

How can I get your snippet to pull values of custom profile fields?

Then how can we make this a module, its so elegant.

Barry Pretsell’s picture

Here you go

<?php

$result = db_query("SELECT users.name, 
profile_fields.title, 
profile_values.value
FROM users
LEFT JOIN users_roles ON users.uid = users_roles.uid
LEFT JOIN role ON users_roles.rid = role.rid
LEFT JOIN profile_values ON users.uid = profile_values.uid
LEFT JOIN profile_fields ON profile_values.fid = profile_fields.fid
LIMIT 0 , 30
");

while ($t = db_fetch_object($result)) {
    print t($t->name . ',' . $t->title . ',' . $t->value);
}
?>

check out the handbook for examples of how to write modules.

Barry Pretsell’s picture

remove that line otherwise you'll only return a maxium of 30 rows.

seaneffel’s picture

Is there a simple way to use your code for sorting/filtering profiles to display the custom profile_listing.tpl.php formatting that I already have in my theme directory? This is based on the how-to here:

http://drupal.org/node/35728

Basically instead of calling individual fields for the found profiles, calling up the profile template file. What do you think?

allankayak’s picture

So you mean past this code into a new block?

I am trying this, I pasted teh code in, changed the name to may role name, got the filter turned off, and tried a just PHP filter, but all my block does it print the code, not the list?

(very new to PHP)

Am I missing something?

Allan

http://www.riverkore.com/h2o

Barry Pretsell’s picture

Look under the text area where you pasted the code, expand the Input Format, then select php.
text fields are filtered HTML by default, so you just need to change to php and it'll work

Christefano-oldaccount’s picture

This PHP snippet looks like it will do exactly what you're looking for:

http://drupal.org/node/63422