Stripping CVS keywords
[project/views.git] / modules / user / views_handler_field_user_roles.inc
1 <?php
2 /**
3 * Field handler to provide a list of roles.
4 */
5 class views_handler_field_user_roles extends views_handler_field_prerender_list {
6 function construct() {
7 parent::construct();
8 $this->additional_fields['uid'] = array('table' => 'users', 'field' => 'uid');
9 }
10
11 function query() {
12 $this->add_additional_fields();
13 $this->field_alias = $this->aliases['uid'];
14 }
15
16 function pre_render($values) {
17 $uids = array();
18 $this->items = array();
19
20 foreach ($values as $result) {
21 $uids[] = $result->{$this->aliases['uid']};
22 }
23
24 if ($uids) {
25 $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");
26 while ($role = db_fetch_object($result)) {
27 $this->items[$role->uid][$role->rid]['role'] = check_plain($role->name);
28 $this->items[$role->uid][$role->rid]['rid'] = $role->rid;
29 }
30 }
31 }
32
33 function render_item($count, $item) {
34 return $item['role'];
35 }
36
37 function document_self_tokens(&$tokens) {
38 $tokens['[' . $this->options['id'] . '-role' . ']'] = t('The name of the role.');
39 $tokens['[' . $this->options['id'] . '-rid' . ']'] = t('The role ID of the role.');
40 }
41
42 function add_self_tokens(&$tokens, $item) {
43 $tokens['[' . $this->options['id'] . '-role' . ']'] = $item['role'];
44 $tokens['[' . $this->options['id'] . '-rid' . ']'] = $item['rid'];
45 }
46 }