Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, I did a little coding, I'm not a programmer anymore and am verry rusty, but here is an implementation so you can include fields from Profiles and only list users with a specific role:
In exhibit_core.pages.ing:
function exhibit_core_get_users($role, $options = array()) { $types =
array('user' => array('label' => t('User'), 'pluralLabel' => t('Users')));
$fields = array( 'created' => array('valueType' => 'date'), 'access' =>
array('valueType' => 'date'), 'login' => array('valueType' => 'date'),
'url' => array('valueType' => 'url'), );
// Make sure the current user is allowed to see user profile information.
if (!user_access('access user profiles'))
return exhibit_json(array(), $types, $fields);
// If
if( $role != null)
{
$result = db_query("SELECT u.* FROM {users} u , {users_roles} ur, {role} r where r.name='%s' AND r.rid=ur.rid AND u.uid = ur.uid;", $role);
}
else
{
$result = db_query('SELECT u.uid FROM {users} u WHERE u.status = 1 ORDER BY u.name');
}
$items = array();
while ($user = db_fetch_object($result)) {
$user = user_load($user->uid);
$userdata = array(
'type' => 'user',
'id' => 'user/' . $user->uid,
'label' => $user->name, // TODO: use profile fields if possible
'name' => $user->name,
'mail' => $user->mail,
'created' => gmstrftime(EXHIBIT_DATE_FORMAT, $user->created),
'access' => gmstrftime(EXHIBIT_DATE_FORMAT, $user->access),
'login' => gmstrftime(EXHIBIT_DATE_FORMAT, $user->login),
'language' => $user->language, // TODO: should probably be language label, not ID
'roles' => array_values($user->roles),
'url' => url('user/' . $user->uid, array('absolute' => TRUE)),
);
// visibility = 3 : Public field, content shown on profile page and on member list pages.
$result2 = db_query('SELECT f.name name, v.value value FROM profile_values v, profile_fields f WHERE v.fid = f.fid AND v.uid = %d AND f.visibility = 3', $user->uid);
while ($row = db_fetch_array($result2)) {
if($row['name'] != null && $row['value'] != null) {
$userdata[$row['name']] = $row['value'];
}
}
$items[] = exhibit_compact_item($userdata);
}
return exhibit_json($items, $types, $fields);
}
Also needed is to change in exhibit_core.module
function exhibit_core_menu() {
return array(
'exhibit/drupal/users' => array(
'type' => MENU_CALLBACK,
'access arguments' => array('access exhibits'),
'page callback' => 'exhibit_core_callback',
'page arguments' => array('exhibit_core_get_users', 3),
'file' => 'exhibit_core.pages.inc',
),
);
}
Hope you can make some use of it...
/Andrei
Comment | File | Size | Author |
---|---|---|---|
#3 | add_profile_fields_and_role_filtering.patch | 2.36 KB | jhuckabee |
Comments
Comment #1
Arto CreditAttribution: Arto commentedThanks for the contribution, Andrei. I believe that Josh is currently looking into rolling this functionality, based on your code, into a patch against the latest development snapshot.
Comment #2
Arto CreditAttribution: Arto commentedJosh, there are two separate feature requests here: only list users with specific roles, and include profile fields in the data feed. I think the latter is the more important feature, and has a clear-cut implementation.
As for the former (role limitations), I think that could be implemented in the form of a URL query argument, the absence of which didn't filter the users, and the presence of which would filter based on e.g. the textual role ID passed as a parameter. For example: exhibit/drupal/users?role=administrator. You can find a relevant example in the Exhibit Views submodule.
Comment #3
jhuckabee CreditAttribution: jhuckabee commentedPatch attached.
Comment #4
Arto CreditAttribution: Arto commentedTesting this patch now. The role limitation does not seem to work - looks like a bug in the JOIN. Will fix and commit shortly.
Comment #5
Arto CreditAttribution: Arto commentedPatch applied in changeset [119021] and included in the 6.x-1.0-alpha1 snapshot. Thanks guys.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.