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