コード例 #1
0
 public function actionRbacAuthItemUpdate($id)
 {
     $aiModel = Yii::app()->user->rbac->getAuthItem($id);
     if ($aiModel == null) {
         throw new CrugeException("el item de autenticacion senalado no existe");
     }
     $editor = new CrugeAuthItemEditor('update');
     $editor->isNewRecord = false;
     $editor->name = $aiModel->name;
     $editor->description = $aiModel->description;
     $editor->businessRule = $aiModel->bizRule;
     $editor->categoria = Yii::app()->user->rbac->getAuthItemTypeName($aiModel->type);
     if (isset($_POST['CrugeAuthItemEditor'])) {
         if (isset($_POST['volver'])) {
             if ($aiModel->type == CAuthItem::TYPE_ROLE) {
                 $this->redirect(array('rbaclistroles'));
             }
             if ($aiModel->type == CAuthItem::TYPE_TASK) {
                 $this->redirect(array('rbaclisttasks'));
             }
             if ($aiModel->type == CAuthItem::TYPE_OPERATION) {
                 $this->redirect(array('rbaclistops'));
             }
         }
         $editor->attributes = $_POST['CrugeAuthItemEditor'];
         if ($editor->validate()) {
             // la guarda de regreso al aiModel
             //                ($aiModel);//model antiguo
             //                ($editor->attributes);//model nuevo
             try {
                 $oldRol = $aiModel->name;
                 $newRol = $editor->name;
                 $oldName = $aiModel->name;
                 $aiModel->name = $editor->name;
                 $aiModel->description = $editor->description;
                 $aiModel->bizRule = $editor->businessRule;
                 Yii::app()->user->rbac->saveAuthItem($aiModel, $oldName);
             } catch (CDbException $exc) {
                 // busca los usuario y elmina los de la tabla
                 $lista = $this->setNombreRol($oldRol, $newRol);
                 Yii::app()->user->rbac->saveAuthItem($aiModel, $oldName);
                 //actualiza
                 foreach ($lista as $key => $value) {
                     CrugeUtil::insertUsersRol($value['userid'], $value['bizrule'], $value['data'], $value['itemname']);
                 }
             }
             // se va de vuelta a la lista de donde vino
             if ($aiModel->type == CAuthItem::TYPE_ROLE) {
                 $this->redirect(array('rbaclistroles'));
             }
             if ($aiModel->type == CAuthItem::TYPE_TASK) {
                 $this->redirect(array('rbaclisttasks'));
             }
             if ($aiModel->type == CAuthItem::TYPE_OPERATION) {
                 $this->redirect(array('rbaclistops'));
             }
         }
     }
     $this->render('rbacauthitemupdate', array('model' => $editor));
 }