Beispiel #1
0
 /**
  * Updates an authorization item.
  */
 public function actionUpdate()
 {
     // Get the authorization item
     $model = $this->loadModel();
     $itemName = $model->getName();
     // Create the authorization item form
     $formModel = new AuthItemForm('update');
     if (isset($_POST['AuthItemForm']) === true) {
         $formModel->attributes = $_POST['AuthItemForm'];
         if ($formModel->validate() === true) {
             // Update the item and load it
             $this->_authorizer->updateAuthItem($itemName, $formModel->name, $formModel->description, $formModel->bizRule, $formModel->data);
             $item = $this->_authorizer->authManager->getAuthItem($formModel->name);
             $item = $this->_authorizer->attachAuthItemBehavior($item);
             // Set a flash message for updating the item
             Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', ':name updated.', array(':name' => $item->getNameText())));
             // Redirect to the correct destination
             $this->redirect(Yii::app()->user->getRightsReturnUrl(array('authItem/permissions')));
         }
     }
     $type = Rights::getValidChildTypes($model->type);
     $exclude = array($this->module->superuserName);
     $childSelectOptions = Rights::getParentAuthItemSelectOptions($model, $type, $exclude);
     if ($childSelectOptions !== array()) {
         $childFormModel = new AuthChildForm();
         // Child form is submitted and data is valid
         if (isset($_POST['AuthChildForm']) === true) {
             $childFormModel->attributes = $_POST['AuthChildForm'];
             if ($childFormModel->validate() === true) {
                 // Add the child and load it
                 $this->_authorizer->authManager->addItemChild($itemName, $childFormModel->itemname);
                 $child = $this->_authorizer->authManager->getAuthItem($childFormModel->itemname);
                 $child = $this->_authorizer->attachAuthItemBehavior($child);
                 // Set a flash message for adding the child
                 Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', 'Child :name added.', array(':name' => $child->getNameText())));
                 // Reidrect to the same page
                 $this->redirect(array('authItem/update', 'name' => urlencode($itemName)));
             }
         }
     } else {
         $childFormModel = null;
     }
     // Set the values for the form fields
     $formModel->name = $model->name;
     $formModel->description = $model->description;
     $formModel->type = $model->type;
     $formModel->bizRule = $model->bizRule !== 'NULL' ? $model->bizRule : '';
     $formModel->data = $model->data !== null ? serialize($model->data) : '';
     $parentDataProvider = new RAuthItemParentDataProvider($model);
     $childDataProvider = new RAuthItemChildDataProvider($model);
     // Render the view
     $this->render('update', array('model' => $model, 'formModel' => $formModel, 'childFormModel' => $childFormModel, 'childSelectOptions' => $childSelectOptions, 'parentDataProvider' => $parentDataProvider, 'childDataProvider' => $childDataProvider));
 }
 /**
  * Updates an authorization item.
  */
 public function actionUpdate()
 {
     // Get the authorization item
     $model = $this->loadModel();
     // Create the authorization item form
     $form = new CForm('rights.views.authItem.authItemForm', new AuthItemForm('update'));
     // Form is submitted and data is valid
     if ($form->submitted() === true && $form->validate() === true) {
         // Update the item and load it
         $this->_authorizer->updateAuthItem($_GET['name'], $form->model->name, $form->model->description, $form->model->bizRule, $form->model->data);
         $item = $this->_authorizer->authManager->getAuthItem($form->model->name);
         $item = $this->_authorizer->attachAuthItemBehavior($item);
         // Set a flash message for updating the item
         Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', ':name updated.', array(':name' => $item->getNameText())));
         // Redirect to the correct destination
         $this->redirect(array(isset($_GET['redirect']) === true ? urldecode($_GET['redirect']) : 'authItem/permissions'));
     }
     // Create a form to add children to the authorization item
     $type = Rights::getValidChildTypes($model->type);
     $exclude = array($this->module->superuserName);
     $selectOptions = Rights::getParentAuthItemSelectOptions($model, $type, $exclude);
     if ($selectOptions !== array()) {
         // Create the child form
         $childForm = new CForm(array('elements' => array('name' => array('label' => false, 'type' => 'dropdownlist', 'items' => $selectOptions)), 'buttons' => array('submit' => array('type' => 'submit', 'label' => Rights::t('core', 'Add')))), new AuthChildForm());
         // Child form is submitted and data is valid
         if ($childForm->submitted() === true && $childForm->validate() === true) {
             // Add the child and load it
             $this->_authorizer->authManager->addItemChild($_GET['name'], $childForm->model->name);
             $child = $this->_authorizer->authManager->getAuthItem($childForm->model->name);
             $child = $this->_authorizer->attachAuthItemBehavior($child);
             // Set a flash message for adding the child
             Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', 'Child :name added.', array(':name' => $child->getNameText())));
             // Reidrect to the same page
             $this->redirect(array('authItem/update', 'name' => $_GET['name']));
         }
     } else {
         $childForm = null;
     }
     // Set the values for the form fields
     $form->model->name = $model->name;
     $form->model->description = $model->description;
     $form->model->type = $model->type;
     $form->model->bizRule = $model->bizRule !== 'NULL' ? $model->bizRule : '';
     $form->model->data = $model->data !== null ? serialize($model->data) : '';
     $parentDataProvider = new AuthItemParentDataProvider($model);
     $childDataProvider = new AuthItemChildDataProvider($model);
     // Render the view
     $this->render('update', array('model' => $model, 'parentDataProvider' => $parentDataProvider, 'childDataProvider' => $childDataProvider, 'form' => $form, 'childForm' => $childForm));
 }