Include profile fields in the users data feed

TypQxQ - February 24, 2008 - 10:53
Project:Exhibit
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Arto
Status:closed
Description

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:

<?php
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

<?php
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

#1

Arto - May 18, 2008 - 16:12
Title:List Users by roles and list Profile fields.» Include profile fields in the users data feed
Assigned to:TypQxQ» Anonymous

Thanks 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.

#2

Arto - May 18, 2008 - 16:19

Josh, 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.

#3

jhuckabee - May 18, 2008 - 20:07
Status:patch (to be ported)» needs review

Patch attached.

AttachmentSize
add_profile_fields_and_role_filtering.patch 2.36 KB

#4

Arto - June 2, 2008 - 10:09
Assigned to:Anonymous» Arto

Testing this patch now. The role limitation does not seem to work - looks like a bug in the JOIN. Will fix and commit shortly.

#5

Arto - June 2, 2008 - 11:12
Status:needs review» fixed

Patch applied in changeset [119021] and included in the 6.x-1.0-alpha1 snapshot. Thanks guys.

#6

Anonymous (not verified) - June 16, 2008 - 11:12
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.