| @@ 194-216 (lines=23) @@ | ||
| 191 | * @param array $items |
|
| 192 | * @return int |
|
| 193 | */ |
|
| 194 | public function addChildren($items) |
|
| 195 | { |
|
| 196 | $manager = Configs::authManager(); |
|
| 197 | $success = 0; |
|
| 198 | if ($this->_item) { |
|
| 199 | foreach ($items as $name) { |
|
| 200 | $child = $manager->getPermission($name); |
|
| 201 | if ($this->type == Item::TYPE_ROLE && $child === null) { |
|
| 202 | $child = $manager->getRole($name); |
|
| 203 | } |
|
| 204 | try { |
|
| 205 | $manager->addChild($this->_item, $child); |
|
| 206 | $success++; |
|
| 207 | } catch (\Exception $exc) { |
|
| 208 | Yii::error($exc->getMessage(), __METHOD__); |
|
| 209 | } |
|
| 210 | } |
|
| 211 | } |
|
| 212 | if ($success > 0) { |
|
| 213 | Helper::invalidate(); |
|
| 214 | } |
|
| 215 | return $success; |
|
| 216 | } |
|
| 217 | ||
| 218 | /** |
|
| 219 | * Remove an item as a child of another item. |
|
| @@ 223-245 (lines=23) @@ | ||
| 220 | * @param array $items |
|
| 221 | * @return int |
|
| 222 | */ |
|
| 223 | public function removeChildren($items) |
|
| 224 | { |
|
| 225 | $manager = Configs::authManager(); |
|
| 226 | $success = 0; |
|
| 227 | if ($this->_item !== null) { |
|
| 228 | foreach ($items as $name) { |
|
| 229 | $child = $manager->getPermission($name); |
|
| 230 | if ($this->type == Item::TYPE_ROLE && $child === null) { |
|
| 231 | $child = $manager->getRole($name); |
|
| 232 | } |
|
| 233 | try { |
|
| 234 | $manager->removeChild($this->_item, $child); |
|
| 235 | $success++; |
|
| 236 | } catch (\Exception $exc) { |
|
| 237 | Yii::error($exc->getMessage(), __METHOD__); |
|
| 238 | } |
|
| 239 | } |
|
| 240 | } |
|
| 241 | if ($success > 0) { |
|
| 242 | Helper::invalidate(); |
|
| 243 | } |
|
| 244 | return $success; |
|
| 245 | } |
|
| 246 | ||
| 247 | /** |
|
| 248 | * Get items |
|