1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_user_permissions.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Field handler to provide a list of permissions.
|
10
|
*
|
11
|
* @ingroup views_field_handlers
|
12
|
*/
|
13
|
class views_handler_field_user_permissions 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
|
// Get a list of all the modules implementing a hook_permission() and
|
44
|
// sort by display name.
|
45
|
$module_info = system_get_info('module');
|
46
|
$modules = array();
|
47
|
foreach (module_implements('permission') as $module) {
|
48
|
$modules[$module] = $module_info[$module]['name'];
|
49
|
}
|
50
|
asort($modules);
|
51
|
|
52
|
$permissions = module_invoke_all('permission');
|
53
|
|
54
|
$result = db_query("SELECT u.uid, u.rid, rp.permission FROM {role_permission} rp INNER JOIN {users_roles} u ON u.rid = rp.rid WHERE u.uid IN (:uids) AND rp.module IN (:modules) ORDER BY rp.permission",
|
55
|
array(':uids' => $uids, ':modules' => array_keys($modules)));
|
56
|
|
57
|
foreach ($result as $perm) {
|
58
|
$this->items[$perm->uid][$perm->permission]['permission'] = $permissions[$perm->permission]['title'];
|
59
|
}
|
60
|
}
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* {@inheritdoc}
|
65
|
*/
|
66
|
public function render_item($count, $item) {
|
67
|
return $item['permission'];
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
*
|
72
|
*/
|
73
|
// function document_self_tokens(&$tokens) {
|
74
|
// $tokens['[' . $this->options['id'] . '-role' . ']'] = t('The name of the role.');
|
75
|
// $tokens['[' . $this->options['id'] . '-rid' . ']'] = t('The role ID of the role.');
|
76
|
// }
|
77
|
|
78
|
/**
|
79
|
*
|
80
|
*/
|
81
|
// function add_self_tokens(&$tokens, $item) {
|
82
|
// $tokens['[' . $this->options['id'] . '-role' . ']'] = $item['role'];
|
83
|
// $tokens['[' . $this->options['id'] . '-rid' . ']'] = $item['rid'];
|
84
|
// }
|
85
|
|
86
|
}
|