forked from modxcms/revolution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getlist.class.php
131 lines (108 loc) · 4.45 KB
/
getlist.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* Gets a list of ACLs.
*
* @param string $type The type of ACL object
* @param string $target (optional) The target of the ACL. Defauls to 0.
* @param string $principal_class The class_key for the principal. Defaults to
* modUserGroup.
* @param string $principal (optional) The principal ID. Defaults to 0.
*
* @param integer $start (optional) The record to start at. Defaults to 0.
* @param integer $limit (optional) The number of records to limit to. Defaults
* to 10.
* @param string $sort (optional) The column to sort by.
* @param string $dir (optional) The direction of the sort. Defaults to ASC.
*
* @package modx
* @subpackage processors.security.access
*/
class modSecurityAccessGetListProcessor extends modObjectGetListProcessor {
public $permission = 'access_permissions';
public $languageTopics = array('access');
public $defaultSortField = 'target';
public function initialize() {
$this->setDefaultProperties(array(
'limit' => 10,
'target' => 0,
'principal_class' => 'modUserGroup',
'principal' => 0,
));
$this->classKey = $this->getProperty('type');
if (!$this->classKey) {
return $this->modx->lexicon('access_type_err_ns');
}
return parent::initialize();
}
public function prepareQueryBeforeCount(xPDOQuery $c) {
$c->select($this->modx->getSelectColumns($this->classKey, $this->classKey, ''));
if ($this->getProperty('target')) {
$c->where(array('target' => $this->getProperty('target')));
}
$c->where(array('principal_class' => $this->getProperty('principal_class')));
if ($this->getProperty('principal')) {
$c->where(array('principal' => $this->getProperty('principal')));
}
return $c;
}
public function getData() {
$data = array();
$limit = intval($this->getProperty('limit'));
$start = intval($this->getProperty('start'));
$c = $this->modx->newQuery($this->classKey);
$c = $this->prepareQueryBeforeCount($c);
$data['total'] = $this->modx->getCount($this->classKey,$c);
$sort = $this->getProperty('sort');
if ($sort) {
$c->sortby($sort, $this->getProperty('dir'));
}
$sortArray = array(
'target' => 'ASC',
'principal_class' => 'DESC',
'principal' => 'ASC',
'authority' => 'ASC',
'policy' => 'ASC',
);
foreach ($sortArray as $sortKey => $sortDir) {
if ($sort != $sortKey) {
$c->sortby($sortKey, $sortDir);
}
}
if ($limit > 0) {
$c->limit($limit,$start);
}
$data['results'] = $this->modx->getCollectionGraph($this->classKey, '{"Target":{},"Policy":{}}', $c);
return $data;
}
public function prepareRow(xPDOObject $object) {
$principal = $this->modx->getObject($object->get('principal_class'), $object->get('principal'));
if (!$principal) {
$principal = $this->modx->newObject($object->get('principal_class'), array('name' => '(anonymous)'));
}
$policyName = !empty($object->Policy) ? $object->Policy->get('name') : $this->modx->lexicon('no_policy_option');
if ($object->Target) {
$targetName = ($this->classKey == 'modAccessContext') ? $object->Target->get('key') : $object->Target->get('name');
} else {
$targetName = '(anonymous)';
}
$objArray = array(
'id' => $object->get('id'),
'target' => $object->get('target'),
'target_name' => $targetName,
'principal_class' => $object->get('principal_class'),
'principal' => $object->get('principal'),
'principal_name' => $principal->get('name'),
'authority' => $object->get('authority'),
'policy' => $object->get('policy'),
'policy_name' => $policyName,
);
if (isset($object->_fieldMeta['context_key'])) {
$objArray['context_key'] = $object->get('context_key');
}
// Prevent default Admin ACL from edit and remove
$objArray['cls'] = (($object->get('target') == 'mgr') && ($principal->get('name') == 'Administrator') &&
($policyName == 'Administrator') && ($object->get('authority') == 0)) ? '' : 'pedit premove';
return $objArray;
}
}
return 'modSecurityAccessGetListProcessor';