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