~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to sites/all/modules/views/modules/user/views_handler_field_user_roles.inc

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: views_handler_field_user_roles.inc,v 1.1 2008/09/03 19:21:30 merlinofchaos Exp $
 
3
/**
 
4
 * Field handler to provide a list of roles.
 
5
 */
 
6
class views_handler_field_user_roles extends views_handler_field_prerender_list {
 
7
  function construct() {
 
8
    parent::construct();
 
9
    $this->additional_fields['uid'] = array('table' => 'users', 'field' => 'uid');
 
10
  }
 
11
 
 
12
  function query() {
 
13
    $this->add_additional_fields();
 
14
    $this->field_alias = $this->aliases['uid'];
 
15
  }
 
16
 
 
17
  function pre_render($values) {
 
18
    $uids = array();
 
19
    $this->items = array();
 
20
 
 
21
    foreach ($values as $result) {
 
22
      $uids[] = $result->{$this->aliases['uid']};
 
23
    }
 
24
 
 
25
    if ($uids) {
 
26
      $result = db_query("SELECT u.uid, u.rid, r.name FROM {role} r INNER JOIN {users_roles} u ON u.rid = r.rid WHERE u.uid IN (" . implode(', ', $uids) . ") ORDER BY r.name");
 
27
      while ($role = db_fetch_object($result)) {
 
28
        $this->items[$role->uid][$role->rid] = check_plain($role->name);
 
29
      }
 
30
    }
 
31
  }
 
32
}