Mage_Adminhtml_Api_RoleController Class Reference

Inheritance diagram for Mage_Adminhtml_Api_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 ()
 _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 176 of file RoleController.php.

00177     {
00178         $user = Mage::getModel("api/user")->load($userId);
00179         $user->setRoleId($roleId)->setUserId($userId);
00180 
00181         if( $user->roleUserExists() === true ) {
00182             return false;
00183         } else {
00184             $user->add();
00185             return true;
00186         }
00187     }

_deleteUserFromRole ( userId,
roleId 
) [protected]

Definition at line 162 of file RoleController.php.

00163     {
00164         try {
00165             Mage::getModel("api/user")
00166                 ->setRoleId($roleId)
00167                 ->setUserId($userId)
00168                 ->deleteFromRole();
00169         } catch (Exception $e) {
00170             throw $e;
00171             return false;
00172         }
00173         return true;
00174     }

_initAction (  )  [protected]

Definition at line 37 of file RoleController.php.

00038     {
00039         $this->loadLayout();
00040         $this->_setActiveMenu('api/roles');
00041         $this->_addBreadcrumb($this->__('Web services'), $this->__('Web services'));
00042         $this->_addBreadcrumb($this->__('Permissions'), $this->__('Permissions'));
00043         $this->_addBreadcrumb($this->__('Roles'), $this->__('Roles'));
00044         return $this;
00045     }

_isAllowed (  )  [protected]

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 189 of file RoleController.php.

00190     {
00191         return Mage::getSingleton('admin/session')->isAllowed('api/roles');
00192     }

deleteAction (  ) 

Definition at line 95 of file RoleController.php.

00096     {
00097         $rid = $this->getRequest()->getParam('rid', false);
00098 
00099         try {
00100             Mage::getModel("api/roles")->setId($rid)->delete();
00101             Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Role successfully deleted.'));
00102         } catch (Exception $e) {
00103             Mage::getSingleton('adminhtml/session')->addError($this->__('Error while deleting this role. Please try again later.'));
00104         }
00105 
00106         $this->_redirect("*/*/");
00107     }

editRoleAction (  ) 

Definition at line 65 of file RoleController.php.

00066     {
00067         $this->_initAction();
00068 
00069         $roleId = $this->getRequest()->getParam('rid');
00070         if( intval($roleId) > 0 ) {
00071             $breadCrumb = $this->__('Edit Role');
00072             $breadCrumbTitle = $this->__('Edit Role');
00073         } else {
00074             $breadCrumb = $this->__('Add new Role');
00075             $breadCrumbTitle = $this->__('Add new Role');
00076         }
00077         $this->_addBreadcrumb($breadCrumb, $breadCrumbTitle);
00078 
00079         $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
00080 
00081         $this->_addLeft(
00082             $this->getLayout()->createBlock('adminhtml/api_editroles')
00083         );
00084         $resources = Mage::getModel('api/roles')->getResourcesList();
00085         $this->_addContent(
00086             $this->getLayout()->createBlock('adminhtml/api_buttons')
00087                 ->setRoleId($roleId)
00088                 ->setRoleInfo(Mage::getModel('api/roles')->load($roleId))
00089                 ->setTemplate('api/roleinfo.phtml')
00090         );
00091         $this->_addJs($this->getLayout()->createBlock('adminhtml/template')->setTemplate('api/role_users_grid_js.phtml'));
00092         $this->renderLayout();
00093     }

editrolegridAction (  ) 

Definition at line 157 of file RoleController.php.

00158     {
00159         $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/api_role_grid_user')->toHtml());
00160     }

indexAction (  ) 

Definition at line 47 of file RoleController.php.

00048     {
00049         $this->_initAction();
00050 
00051         $this->_addContent($this->getLayout()->createBlock('adminhtml/api_roles'));
00052 
00053         $this->renderLayout();
00054     }

roleGridAction (  ) 

Definition at line 56 of file RoleController.php.

00057     {
00058         $this->getResponse()
00059             ->setBody($this->getLayout()
00060             ->createBlock('adminhtml/api_grid_role')
00061             ->toHtml()
00062         );
00063     }

saveRoleAction (  ) 

Definition at line 109 of file RoleController.php.

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


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

Generated on Sat Jul 4 17:22:41 2009 for Magento by  doxygen 1.5.8