1 <?php
2 3 4 5 6 7 8
9 class RAuthItemBehavior extends CBehavior
10 {
11 12 13
14 public $userId;
15 16 17
18 public $parent;
19 20 21
22 public $childCount;
23
24 25 26 27 28
29 public function __construct($userId=null, CAuthItem $parent=null)
30 {
31 $this->userId = $userId;
32 $this->parent = $parent;
33 }
34
35 36 37 38
39 public function getNameText()
40 {
41 return (Rights::module()->displayDescription===true && $this->owner->description!==null) ? $this->owner->description : $this->owner->name;
42 }
43
44 45 46 47
48 public function getNameLink()
49 {
50 return CHtml::link($this->getNameText(), array(
51 'authItem/update',
52 'name'=>urlencode($this->owner->name),
53 ));
54 }
55
56 57 58 59
60 public function getGridNameLink()
61 {
62 $markup = CHtml::link($this->owner->name, array(
63 'authItem/update',
64 'name'=>urlencode($this->owner->name),
65 ));
66
67 $markup .= $this->childCount();
68 $markup .= $this->sortableId();
69
70 return $markup;
71 }
72
73 74 75 76
77 public function childCount()
78 {
79 if( $this->childCount===null )
80 $this->childCount = count($this->owner->getChildren());
81
82 return $this->childCount>0 ? ' [ <span class="child-count">'.$this->childCount.'</span> ]' : '';
83 }
84
85 86 87 88
89 public function sortableId()
90 {
91 return ' <span class="auth-item-name" style="display:none;">'.$this->owner->name.'</span>';
92 }
93
94 95 96 97
98 public function getTypeText()
99 {
100 return Rights::getAuthItemTypeName($this->owner->type);
101 }
102
103 104 105 106
107 public function getDeleteOperationLink()
108 {
109 return CHtml::linkButton(Rights::t('core', 'Delete'), array(
110 'submit'=>array('authItem/delete', 'name'=>urlencode($this->owner->name)),
111 'confirm'=>Rights::t('core', 'Are you sure you want to delete this operation?'),
112 'class'=>'delete-link',
113 'csrf'=>Yii::app()->request->enableCsrfValidation,
114 ));
115 }
116
117 118 119 120
121 public function getDeleteTaskLink()
122 {
123 return CHtml::linkButton(Rights::t('core', 'Delete'), array(
124 'submit'=>array('authItem/delete', 'name'=>urlencode($this->owner->name)),
125 'confirm'=>Rights::t('core', 'Are you sure you want to delete this task?'),
126 'class'=>'delete-link',
127 'csrf'=>Yii::app()->request->enableCsrfValidation,
128 ));
129 }
130
131 132 133 134
135 public function getDeleteRoleLink()
136 {
137
138 if( $this->owner->name!==Rights::module()->superuserName )
139 {
140 return CHtml::linkButton(Rights::t('core', 'Delete'), array(
141 'submit'=>array('authItem/delete', 'name'=>urlencode($this->owner->name)),
142 'confirm'=>Rights::t('core', 'Are you sure you want to delete this role?'),
143 'class'=>'delete-link',
144 'csrf'=>Yii::app()->request->enableCsrfValidation,
145 ));
146 }
147 }
148
149 150 151 152
153 public function getRemoveParentLink()
154 {
155 return CHtml::linkButton(Rights::t('core', 'Remove'), array(
156 'submit'=>array('authItem/removeChild', 'name'=>urlencode($this->owner->name), 'child'=>urlencode($this->parent->name)),
157 'class'=>'remove-link',
158 'csrf'=>Yii::app()->request->enableCsrfValidation,
159 ));
160 }
161
162 163 164 165
166 public function getRemoveChildLink()
167 {
168 return CHtml::linkButton(Rights::t('core', 'Remove'), array(
169 'submit'=>array('authItem/removeChild', 'name'=>urlencode($this->parent->name), 'child'=>urlencode($this->owner->name)),
170 'class'=>'remove-link',
171 'csrf'=>Yii::app()->request->enableCsrfValidation,
172 ));
173 }
174
175 176 177 178
179 public function getRevokeAssignmentLink()
180 {
181 return CHtml::linkButton(Rights::t('core', 'Revoke'), array(
182 'submit'=>array('assignment/revoke', 'id'=>$this->userId, 'name'=>urlencode($this->owner->name)),
183 'class'=>'revoke-link',
184 'csrf'=>Yii::app()->request->enableCsrfValidation,
185 ));
186 }
187
188 189 190 191 192
193 public function getRevokePermissionLink(CAuthItem $role)
194 {
195 $csrf = Rights::getDataCsrf();
196
197 return CHtml::link(Rights::t('core', 'Revoke'), '#', array(
198 'onclick'=>"
199 jQuery.ajax({
200 type:'POST',
201 url:'".Yii::app()->controller->createUrl('authItem/revoke', array(
202 'name'=>urlencode($role->name),
203 'child'=>urlencode($this->owner->name),
204 ))."',
205 data:{ ajax:1 $csrf },
206 success:function() {
207 $('#permissions').load('".Yii::app()->controller->createUrl('authItem/permissions')."', { ajax:1 $csrf });
208 }
209 });
210
211 return false;
212 ",
213 'class'=>'revoke-link',
214 ));
215 }
216
217 218 219 220 221
222 public function getAssignPermissionLink(CAuthItem $role)
223 {
224 $csrf = Rights::getDataCsrf();
225
226 return CHtml::link(Rights::t('core', 'Assign'), '#', array(
227 'onclick'=>"
228 jQuery.ajax({
229 type:'POST',
230 url:'".Yii::app()->controller->createUrl('authItem/assign', array(
231 'name'=>urlencode($role->name),
232 'child'=>urlencode($this->owner->name),
233 ))."',
234 data:{ ajax:1 $csrf },
235 success:function() {
236 $('#permissions').load('".Yii::app()->controller->createUrl('authItem/permissions')."', { ajax:1 $csrf });
237 }
238 });
239
240 return false;
241 ",
242 'class'=>'assign-link',
243 ));
244 }
245
246 247 248 249 250 251
252 public function getInheritedPermissionText($parents, $displayType=false)
253 {
254 $items = array();
255 foreach( $parents as $itemName=>$item )
256 {
257 $itemMarkup = $item->getNameText();
258
259 if( $displayType===true )
260 $itemMarkup .= ' ('.Rights::getAuthItemTypeName($item->type).')';
261
262 $items[] = $itemMarkup;
263 }
264
265 return '<span class="inherited-item" title="'.implode('<br />', $items).'">'.Rights::t('core', 'Inherited').' *</span>';
266 }
267 }
268