Exemplo n.º 1
0
 /**
  * Saves item.
  *
  * @return bool
  */
 public function save()
 {
     if ($this->validate() == false) {
         return false;
     }
     if ($isNewItem = $this->item === null) {
         $this->item = $this->createItem($this->name);
     } else {
         $oldName = $this->item->name;
     }
     $this->item->name = $this->name;
     $this->item->description = $this->description;
     $this->item->data = $this->data == null ? null : Json::decode($this->data);
     $this->item->ruleName = empty($this->rule) ? null : $this->rule;
     if ($isNewItem) {
         \Yii::$app->session->setFlash('success', \Yii::t('rbac', 'Item has been created'));
         $this->manager->add($this->item);
     } else {
         \Yii::$app->session->setFlash('success', \Yii::t('rbac', 'Item has been updated'));
         $this->manager->update($oldName, $this->item);
     }
     $this->updateChildren();
     $this->manager->invalidateCache();
     return true;
 }
Exemplo n.º 2
0
 /**
  * Saves item.
  *
  * @return bool
  */
 public function save()
 {
     if ($this->validate() == false) {
         return false;
     }
     if ($isNewItem = $this->item === null) {
         $this->item = $this->createItem($this->name);
     } else {
         $oldName = $this->item->name;
     }
     $this->item->name = $this->name;
     $this->item->description = $this->description;
     if (!empty($this->rule)) {
         $rule = \Yii::createObject($this->rule);
         if (null === $this->manager->getRule($rule->name)) {
             $this->manager->add($rule);
         }
         $this->item->ruleName = $rule->name;
     } else {
         $this->item->ruleName = null;
     }
     if ($isNewItem) {
         \Yii::$app->session->setFlash('success', \Yii::t('rbac', 'Item has been created'));
         $this->manager->add($this->item);
     } else {
         \Yii::$app->session->setFlash('success', \Yii::t('rbac', 'Item has been updated'));
         $this->manager->update($oldName, $this->item);
     }
     $this->updateChildren();
     return true;
 }