Exemplo n.º 1
0
 /** @inheritdoc */
 protected function validateValue($value)
 {
     if (!is_array($value)) {
         return [\Yii::t('rbac', 'Invalid value'), []];
     }
     foreach ($value as $val) {
         if ($this->manager->getItem($val) == null) {
             return [\Yii::t('rbac', 'There is neither role nor permission with name "{0}"', [$val]), []];
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Updates auth assignments for user.
  * @return boolean
  */
 public function updateAssignments()
 {
     if (!$this->validate()) {
         return false;
     }
     if (!is_array($this->items)) {
         $this->items = [];
     }
     $assignedItems = $this->manager->getItemsByUser($this->user_id);
     $assignedItemsNames = array_keys($assignedItems);
     foreach (array_diff($assignedItemsNames, $this->items) as $item) {
         $this->manager->revoke($assignedItems[$item], $this->user_id);
     }
     foreach (array_diff($this->items, $assignedItemsNames) as $item) {
         $this->manager->assign($this->manager->getItem($item), $this->user_id);
     }
     $this->updated = true;
     return true;
 }
Exemplo n.º 3
0
 /**
  * Updated items children.
  */
 protected function updateChildren()
 {
     $children = $this->manager->getChildren($this->item->name);
     $childrenNames = array_keys($children);
     if (is_array($this->children)) {
         // remove children that
         foreach (array_diff($childrenNames, $this->children) as $item) {
             $this->manager->removeChild($this->item, $children[$item]);
         }
         // add new children
         foreach (array_diff($this->children, $childrenNames) as $item) {
             $this->manager->addChild($this->item, $this->manager->getItem($item));
         }
     } else {
         $this->manager->removeChildren($this->item);
     }
 }