Mage_Adminhtml_Permissions_RoleController Class Reference

Inheritance diagram for Mage_Adminhtml_Permissions_RoleController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 indexAction ()
 roleGridAction ()
 editRoleAction ()
 deleteAction ()
 saveRoleAction ()
 editrolegridAction ()

Protected Member Functions

 _initAction ()
 _initRole ($requestVariable= 'rid')
 _deleteUserFromRole ($userId, $roleId)
 _addUserToRole ($userId, $roleId)
 _isAllowed ()


Detailed Description

Definition at line 34 of file RoleController.php.


Member Function Documentation

_addUserToRole ( userId,
roleId 
) [protected]

Definition at line 181 of file RoleController.php.

00182     {
00183         $user = Mage::getModel("admin/user")->load($userId);
00184         $user->setRoleId($roleId)->setUserId($userId);
00185 
00186         if( $user->roleUserExists() === true ) {
00187             return false;
00188         } else {
00189             $user->add();
00190             return true;
00191         }
00192     }

_deleteUserFromRole ( userId,
roleId 
) [protected]

Definition at line 167 of file RoleController.php.

00168     {
00169         try {
00170             Mage::getModel("admin/user")
00171                 ->setRoleId($roleId)
00172                 ->setUserId($userId)
00173                 ->deleteFromRole();
00174         } catch (Exception $e) {
00175             throw $e;
00176             return false;
00177         }
00178         return true;
00179     }

_initAction (  )  [protected]

Definition at line 37 of file RoleController.php.

00038     {
00039         $this->loadLayout();
00040         $this->_setActiveMenu('system/acl');
00041         $this->_addBreadcrumb($this->__('System'), $this->__('System'));
00042         $this->_addBreadcrumb($this->__('Permissions'), $this->__('Permissions'));
00043         $this->_addBreadcrumb($this->__('Roles'), $this->__('Roles'));
00044         return $this;
00045     }

_initRole ( requestVariable = 'rid'  )  [protected]

Definition at line 47 of file RoleController.php.

00048     {
00049         Mage::register('current_role', Mage::getModel('admin/roles')->load($this->getRequest()->getParam($requestVariable)));
00050         return Mage::registry('current_role');
00051     }

_isAllowed (  )  [protected]

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 194 of file RoleController.php.

00195     {
00196         return Mage::getSingleton('admin/session')->isAllowed('system/acl/roles');
00197     }

deleteAction (  ) 

Definition at line 92 of file RoleController.php.

00093     {
00094         $rid = $this->getRequest()->getParam('rid', false);
00095         $currentUser = Mage::getModel('admin/user')->setId(Mage::getSingleton('admin/session')->getUser()->getId());
00096         if ( in_array($rid, $currentUser->getRoles()) ) {
00097             Mage::getSingleton('adminhtml/session')->addError($this->__('You can not delete self assigned roles.'));
00098             $this->_redirect('*/*/editrole', array('rid' => $rid));
00099             return;
00100         }
00101 
00102         try {
00103             Mage::getModel("admin/roles")->setId($rid)->delete();
00104             Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Role successfully deleted.'));
00105         } catch (Exception $e) {
00106             Mage::getSingleton('adminhtml/session')->addError($this->__('Error while deleting this role. Please try again later.'));
00107         }
00108 
00109         $this->_redirect("*/*/");
00110     }

editRoleAction (  ) 

Definition at line 66 of file RoleController.php.

00067     {
00068         $role = $this->_initRole();
00069         $this->_initAction();
00070 
00071         if ($role->getId()) {
00072             $breadCrumb      = $this->__('Edit Role');
00073             $breadCrumbTitle = $this->__('Edit Role');
00074         } else {
00075             $breadCrumb = $this->__('Add new Role');
00076             $breadCrumbTitle = $this->__('Add new Role');
00077         }
00078         $this->_addBreadcrumb($breadCrumb, $breadCrumbTitle);
00079 
00080         $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
00081 
00082         $this->_addContent(
00083             $this->getLayout()->createBlock('adminhtml/permissions_buttons')
00084                 ->setRoleId($role->getId())
00085                 ->setRoleInfo($role)
00086                 ->setTemplate('permissions/roleinfo.phtml')
00087         );
00088         $this->_addJs($this->getLayout()->createBlock('adminhtml/template')->setTemplate('permissions/role_users_grid_js.phtml'));
00089         $this->renderLayout();
00090     }

editrolegridAction (  ) 

Definition at line 162 of file RoleController.php.

00163     {
00164         $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/permissions_role_grid_user')->toHtml());
00165     }

indexAction (  ) 

Definition at line 53 of file RoleController.php.

00054     {
00055         $this->_initAction();
00056 
00057         $this->renderLayout();
00058     }

roleGridAction (  ) 

Definition at line 60 of file RoleController.php.

00061     {
00062         $this->loadLayout();
00063         $this->getResponse()->setBody($this->getLayout()->getBlock('adminhtml.permission.role.grid')->toHtml());
00064     }

saveRoleAction (  ) 

Definition at line 112 of file RoleController.php.

00113     {
00114         $rid        = $this->getRequest()->getParam('role_id', false);
00115         $resource   = explode(',', $this->getRequest()->getParam('resource', false));
00116         $roleUsers  = $this->getRequest()->getParam('in_role_user', null);
00117         parse_str($roleUsers, $roleUsers);
00118         $roleUsers = array_keys($roleUsers);
00119 
00120         $isAll = $this->getRequest()->getParam('all');
00121         if ($isAll)
00122             $resource = array("all");
00123 
00124         try {
00125             $role = Mage::getModel("admin/roles")
00126                     ->setId($rid)
00127                     ->setName($this->getRequest()->getParam('rolename', false))
00128                     ->setPid($this->getRequest()->getParam('parent_id', false))
00129                     ->setRoleType('G');
00130             Mage::dispatchEvent('admin_permissions_role_prepare_save', array('object' => $role, 'request' => $this->getRequest()));
00131             $role->save();
00132 
00133             Mage::getModel("admin/rules")
00134                 ->setRoleId($role->getId())
00135                 ->setResources($resource)
00136                 ->saveRel();
00137 
00138             $oldRoleUsers = Mage::getModel("admin/roles")->setId($role->getId())->getRoleUsers($role);
00139             if ( sizeof($oldRoleUsers) > 0 ) {
00140                 foreach($oldRoleUsers as $oUid) {
00141                     $this->_deleteUserFromRole($oUid, $role->getId());
00142                 }
00143             }
00144             if ( $roleUsers ) {
00145                 foreach ($roleUsers as $nRuid) {
00146                     $this->_addUserToRole($nRuid, $role->getId());
00147                 }
00148             }
00149             $rid = $role->getId();
00150             Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Role successfully saved.'));
00151         } catch (Mage_Core_Exception $e) {
00152             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00153         } catch (Exception $e) {
00154             Mage::getSingleton('adminhtml/session')->addError($this->__('Error while saving this role. Please try again later.'));
00155         }
00156 
00157         //$this->getResponse()->setRedirect($this->getUrl("*/*/editrole/rid/$rid"));
00158         $this->_redirect('*/*/editrole', array('rid' => $rid));
00159         return;
00160     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:14 2009 for Magento by  doxygen 1.5.8