1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_user_roles.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Field handler to provide a list of roles.
|
10
|
*
|
11
|
* @ingroup views_field_handlers
|
12
|
*/
|
13
|
class views_handler_field_user_roles extends views_handler_field_prerender_list {
|
14
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function construct() {
|
19
|
parent::construct();
|
20
|
$this->additional_fields['uid'] = array('table' => 'users', 'field' => 'uid');
|
21
|
}
|
22
|
|
23
|
/**
|
24
|
* {@inheritdoc}
|
25
|
*/
|
26
|
public function query() {
|
27
|
$this->add_additional_fields();
|
28
|
$this->field_alias = $this->aliases['uid'];
|
29
|
}
|
30
|
|
31
|
/**
|
32
|
* {@inheritdoc}
|
33
|
*/
|
34
|
public function pre_render(&$values) {
|
35
|
$uids = array();
|
36
|
$this->items = array();
|
37
|
|
38
|
foreach ($values as $result) {
|
39
|
$uids[] = $this->get_value($result, NULL, TRUE);
|
40
|
}
|
41
|
|
42
|
if ($uids) {
|
43
|
$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 (:uids) ORDER BY r.name",
|
44
|
array(':uids' => $uids));
|
45
|
foreach ($result as $role) {
|
46
|
$this->items[$role->uid][$role->rid]['role'] = check_plain($role->name);
|
47
|
$this->items[$role->uid][$role->rid]['rid'] = $role->rid;
|
48
|
}
|
49
|
}
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* {@inheritdoc}
|
54
|
*/
|
55
|
public function render_item($count, $item) {
|
56
|
return $item['role'];
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* {@inheritdoc}
|
61
|
*/
|
62
|
public function document_self_tokens(&$tokens) {
|
63
|
$tokens['[' . $this->options['id'] . '-role' . ']'] = t('The name of the role.');
|
64
|
$tokens['[' . $this->options['id'] . '-rid' . ']'] = t('The role ID of the role.');
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* {@inheritdoc}
|
69
|
*/
|
70
|
public function add_self_tokens(&$tokens, $item) {
|
71
|
if (!empty($item['role'])) {
|
72
|
$tokens['[' . $this->options['id'] . '-role' . ']'] = $item['role'];
|
73
|
$tokens['[' . $this->options['id'] . '-rid' . ']'] = $item['rid'];
|
74
|
}
|
75
|
}
|
76
|
|
77
|
}
|