HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
RPermissionDataProvider.php
Go to the documentation of this file.
1 <?php
10 class RPermissionDataProvider extends CDataProvider
11 {
16  public $displayParentType = false;
17 
18  private $_authorizer;
19  private $_roles;
20  private $_items;
21  private $_permissions;
22  private $_parents;
23 
32  public function __construct($id, $config = array())
33  {
34  $this->setId($id);
35 
36  foreach ($config as $key => $value) {
37  $this->$key = $value;
38  }
39 
40  $this->init();
41  }
42 
46  public function init()
47  {
48  $this->_authorizer = Rights::getAuthorizer();
49 
50  // Set properties and generate the data
51  $this->setRoles();
52  $this->setItems();
53  $this->setPermissions();
54  $this->setParents();
55  $this->generateData();
56  }
57 
61  protected function setRoles()
62  {
63  $this->_roles = $this->_authorizer->getRoles(false);
64  }
65 
69  public function getRoles()
70  {
71  return $this->_roles;
72  }
73 
77  protected function setItems()
78  {
79  $type = array(CAuthItem::TYPE_OPERATION, CAuthItem::TYPE_TASK);
80  $this->_items = $this->_authorizer->getAuthItems($type);
81  }
82 
86  protected function setPermissions()
87  {
88  $allPermissions = $this->_authorizer->getPermissions();
89 
90  $permissions = array();
91  foreach ($this->_roles as $roleName => $role) {
92  $permissions[ $roleName ] = array();
93  foreach ($this->_items as $itemName => $item) {
94  $permissions[ $roleName ][ $itemName ] = $this->_authorizer->hasPermission($itemName, null, $allPermissions[ $roleName ]);
95  }
96  }
97 
98  // Set the permission property
99  $this->_permissions = $permissions;
100  }
101 
105  protected function setParents()
106  {
107  $parents = array();
108  foreach ($this->_permissions as $roleName => $rolePermissions) {
109  foreach ($rolePermissions as $itemName => $permission) {
110  if ($permission === Rights::PERM_INHERITED) {
111  $parents[ $roleName ][ $itemName ] = $this->_authorizer->getAuthItemParents($itemName, null, $roleName, true);
112  }
113  }
114  }
115 
116  // Set the parents property
117  $this->_parents = $parents;
118  }
119 
123  protected function generateData()
124  {
125  $data = array();
126  $permissions = $this->_permissions;
127  $parents = $this->_parents;
128  foreach ($this->_items as $itemName => $item) {
129  $row = array();
130  $row['description'] = $item->getNameLink();
131 
132  foreach ($this->_roles as $roleName => $role) {
133  // Item is directly assigned to the role
134  if ($permissions[ $roleName ][ $itemName ] === Rights::PERM_DIRECT) {
135  $permissionColumn = $item->getRevokePermissionLink($role);
136  }
137  // Item is inherited by the role from one of its children
138  elseif ($permissions[ $roleName ][ $itemName ] === Rights::PERM_INHERITED && isset($parents[ $roleName ][ $itemName ]) === true) {
139  $permissionColumn = $item->getInheritedPermissionText($parents[ $roleName ][ $itemName ], $this->displayParentType);
140  }
141  // Item is not assigned to the role
142  else {
143  $permissionColumn = $item->getAssignPermissionLink($role);
144  }
145 
146  // Populate role column
147  $row[ strtolower($roleName) ] = isset($permissionColumn) === true ? $permissionColumn : '';
148  }
149 
150  // Append the row to data
151  $data[] = $row;
152  }
153 
154  $this->setData($data);
155  }
156 
162  protected function fetchData()
163  {
164  return $this->getData();
165  }
166 
172  protected function fetchKeys()
173  {
174  $keys = array();
175  foreach ($this->getData() as $key => $value) {
176  $keys[] = $key;
177  }
178 
179  return $keys;
180  }
181 
187  protected function calculateTotalItemCount()
188  {
189  return count($this->getData());
190  }
191 }