HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
RAuthItemBehavior.php
Go to the documentation of this file.
1 <?php
10 class RAuthItemBehavior extends CBehavior
11 {
15  public $userId;
19  public $parent;
23  public $childCount;
24 
31  public function __construct($userId = null, CAuthItem $parent = null)
32  {
33  $this->userId = $userId;
34  $this->parent = $parent;
35  }
36 
42  public function getNameText()
43  {
44  return (Rights::module()->displayDescription === true && $this->owner->description !== null) ? $this->owner->description : $this->owner->name;
45  }
46 
52  public function getNameLink()
53  {
54  return CHtml::link($this->getNameText(), array(
55  'authItem/update',
56  'name' => urlencode($this->owner->name),
57  ));
58  }
59 
65  public function getGridNameLink()
66  {
67  $markup = CHtml::link($this->owner->name, array(
68  'authItem/update',
69  'name' => urlencode($this->owner->name),
70  ));
71 
72  $markup .= $this->childCount();
73  $markup .= $this->sortableId();
74 
75  return $markup;
76  }
77 
83  public function childCount()
84  {
85  if ($this->childCount === null) {
86  $this->childCount = count($this->owner->getChildren());
87  }
88 
89  return $this->childCount>0 ? ' [ <span class="child-count">'.$this->childCount.'</span> ]' : '';
90  }
91 
97  public function sortableId()
98  {
99  return ' <span class="auth-item-name" style="display:none;">'.$this->owner->name.'</span>';
100  }
101 
107  public function getTypeText()
108  {
109  return Rights::getAuthItemTypeName($this->owner->type);
110  }
111 
117  public function getDeleteOperationLink()
118  {
119  return CHtml::linkButton(Rights::t('core', 'Delete'), array(
120  'submit' => array('authItem/delete', 'name' => urlencode($this->owner->name)),
121  'confirm' => Rights::t('core', 'Are you sure you want to delete this operation?'),
122  'class' => 'delete-link',
123  'csrf' => Yii::app()->request->enableCsrfValidation,
124  ));
125  }
126 
132  public function getDeleteTaskLink()
133  {
134  return CHtml::linkButton(Rights::t('core', 'Delete'), array(
135  'submit' => array('authItem/delete', 'name' => urlencode($this->owner->name)),
136  'confirm' => Rights::t('core', 'Are you sure you want to delete this task?'),
137  'class' => 'delete-link',
138  'csrf' => Yii::app()->request->enableCsrfValidation,
139  ));
140  }
141 
147  public function getDeleteRoleLink()
148  {
149  // We do not want to show the delete link for the superuser role.
150  if ($this->owner->name !== Rights::module()->superuserName) {
151  return CHtml::linkButton(Rights::t('core', 'Delete'), array(
152  'submit' => array('authItem/delete', 'name' => urlencode($this->owner->name)),
153  'confirm' => Rights::t('core', 'Are you sure you want to delete this role?'),
154  'class' => 'delete-link',
155  'csrf' => Yii::app()->request->enableCsrfValidation,
156  ));
157  }
158  }
159 
165  public function getRemoveParentLink()
166  {
167  return CHtml::linkButton(Rights::t('core', 'Remove'), array(
168  'submit' => array('authItem/removeChild', 'name' => urlencode($this->owner->name), 'child' => urlencode($this->parent->name)),
169  'class' => 'remove-link',
170  'csrf' => Yii::app()->request->enableCsrfValidation,
171  ));
172  }
173 
179  public function getRemoveChildLink()
180  {
181  return CHtml::linkButton(Rights::t('core', 'Remove'), array(
182  'submit' => array('authItem/removeChild', 'name' => urlencode($this->parent->name), 'child' => urlencode($this->owner->name)),
183  'class' => 'remove-link',
184  'csrf' => Yii::app()->request->enableCsrfValidation,
185  ));
186  }
187 
193  public function getRevokeAssignmentLink()
194  {
195  return CHtml::linkButton(Rights::t('core', 'Revoke'), array(
196  'submit' => array('assignment/revoke', 'id' => $this->userId, 'name' => urlencode($this->owner->name)),
197  'class' => 'revoke-link',
198  'csrf' => Yii::app()->request->enableCsrfValidation,
199  ));
200  }
201 
209  public function getRevokePermissionLink(CAuthItem $role)
210  {
211  $csrf = Rights::getDataCsrf();
212 
213  return CHtml::link(Rights::t('core', 'Revoke'), '#', array(
214  'onclick' => "
215  jQuery.ajax({
216  type:'POST',
217  url:'".Yii::app()->controller->createUrl('authItem/revoke', array(
218  'name' => urlencode($role->name),
219  'child' => urlencode($this->owner->name),
220  ))."',
221  data:{ ajax:1 $csrf },
222  success:function() {
223  $('#permissions').load('".Yii::app()->controller->createUrl('authItem/permissions')."', { ajax:1 $csrf });
224  }
225  });
226 
227  return false;
228  ",
229  'class' => 'revoke-link',
230  ));
231  }
232 
240  public function getAssignPermissionLink(CAuthItem $role)
241  {
242  $csrf = Rights::getDataCsrf();
243 
244  return CHtml::link(Rights::t('core', 'Assign'), '#', array(
245  'onclick' => "
246  jQuery.ajax({
247  type:'POST',
248  url:'".Yii::app()->controller->createUrl('authItem/assign', array(
249  'name' => urlencode($role->name),
250  'child' => urlencode($this->owner->name),
251  ))."',
252  data:{ ajax:1 $csrf },
253  success:function() {
254  $('#permissions').load('".Yii::app()->controller->createUrl('authItem/permissions')."', { ajax:1 $csrf });
255  }
256  });
257 
258  return false;
259  ",
260  'class' => 'assign-link',
261  ));
262  }
263 
272  public function getInheritedPermissionText($parents, $displayType = false)
273  {
274  $items = array();
275  foreach ($parents as $itemName => $item) {
276  $itemMarkup = $item->getNameText();
277 
278  if ($displayType === true) {
279  $itemMarkup .= ' ('.Rights::getAuthItemTypeName($item->type).')';
280  }
281 
282  $items[] = $itemMarkup;
283  }
284 
285  return '<span class="inherited-item" title="'.implode('<br />', $items).'">'.Rights::t('core', 'Inherited').' *</span>';
286  }
287 }