Mage_Adminhtml_Api_UserController Class Reference

Inheritance diagram for Mage_Adminhtml_Api_UserController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 indexAction ()
 newAction ()
 editAction ()
 saveAction ()
 deleteAction ()
 rolesGridAction ()
 roleGridAction ()

Protected Member Functions

 _initAction ()
 _isAllowed ()


Detailed Description

Definition at line 26 of file UserController.php.


Member Function Documentation

_initAction (  )  [protected]

Definition at line 29 of file UserController.php.

00030     {
00031         $this->loadLayout()
00032             ->_setActiveMenu('api/users')
00033             ->_addBreadcrumb($this->__('Web Services'), $this->__('Web Services'))
00034             ->_addBreadcrumb($this->__('Permissions'), $this->__('Permissions'))
00035             ->_addBreadcrumb($this->__('Users'), $this->__('Users'))
00036         ;
00037         return $this;
00038     }

_isAllowed (  )  [protected]

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 162 of file UserController.php.

00163     {
00164         return Mage::getSingleton('admin/session')->isAllowed('api/users');
00165     }

deleteAction (  ) 

Definition at line 118 of file UserController.php.

00119     {
00120         if ($id = $this->getRequest()->getParam('user_id')) {
00121 
00122             try {
00123                 $model = Mage::getModel('api/user');
00124                 $model->setId($id);
00125                 $model->delete();
00126                 Mage::getSingleton('adminhtml/session')->addSuccess($this->__('User was successfully deleted'));
00127                 $this->_redirect('*/*/');
00128                 return;
00129             }
00130             catch (Exception $e) {
00131                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00132                 $this->_redirect('*/*/edit', array('user_id' => $this->getRequest()->getParam('user_id')));
00133                 return;
00134             }
00135         }
00136         Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find a user to delete'));
00137         $this->_redirect('*/*/');
00138     }

editAction (  ) 

Definition at line 52 of file UserController.php.

00053     {
00054         $id = $this->getRequest()->getParam('user_id');
00055         $model = Mage::getModel('api/user');
00056 
00057         if ($id) {
00058             $model->load($id);
00059             if (! $model->getId()) {
00060                 Mage::getSingleton('adminhtml/session')->addError($this->__('This user no longer exists'));
00061                 $this->_redirect('*/*/');
00062                 return;
00063             }
00064         }
00065         // Restore previously entered form data from session
00066         $data = Mage::getSingleton('adminhtml/session')->getUserData(true);
00067         if (!empty($data)) {
00068             $model->setData($data);
00069         }
00070 
00071         Mage::register('api_user', $model);
00072 
00073         $this->_initAction()
00074             ->_addBreadcrumb($id ? $this->__('Edit User') : $this->__('New User'), $id ? $this->__('Edit User') : $this->__('New User'))
00075             ->_addContent($this->getLayout()->createBlock('adminhtml/api_user_edit')->setData('action', $this->getUrl('*/api_user/save')))
00076             ->_addLeft($this->getLayout()->createBlock('adminhtml/api_user_edit_tabs'));
00077 
00078         $this->_addJs($this->getLayout()->createBlock('adminhtml/template')->setTemplate('api/user_roles_grid_js.phtml'));
00079         $this->renderLayout();
00080     }

indexAction (  ) 

Definition at line 40 of file UserController.php.

00041     {
00042         $this->_initAction()
00043             ->_addContent($this->getLayout()->createBlock('adminhtml/api_user'))
00044             ->renderLayout();
00045     }

newAction (  ) 

Definition at line 47 of file UserController.php.

00048     {
00049         $this->_forward('edit');
00050     }

roleGridAction (  ) 

Definition at line 153 of file UserController.php.

00154     {
00155         $this->getResponse()
00156             ->setBody($this->getLayout()
00157             ->createBlock('adminhtml/api_user_grid')
00158             ->toHtml()
00159         );
00160     }

rolesGridAction (  ) 

Definition at line 140 of file UserController.php.

00141     {
00142         $id = $this->getRequest()->getParam('user_id');
00143         $model = Mage::getModel('api/user');
00144 
00145         if ($id) {
00146             $model->load($id);
00147         }
00148 
00149         Mage::register('api_user', $model);
00150         $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/api_user_edit_tab_roles')->toHtml());
00151     }

saveAction (  ) 

Definition at line 82 of file UserController.php.

00083     {
00084         if ($data = $this->getRequest()->getPost()) {
00085             $model = Mage::getModel('api/user');
00086             $model->setData($data);
00087             try {
00088                 $model->save();
00089                 if ( $uRoles = $this->getRequest()->getParam('roles', false) ) {
00090                     /*parse_str($uRoles, $uRoles);
00091                     $uRoles = array_keys($uRoles);*/
00092                     if ( 1 == sizeof($uRoles) ) {
00093                         $model->setRoleIds($uRoles)
00094                             ->setRoleUserId($model->getUserId())
00095                             ->saveRelations();
00096                     } else if ( sizeof($uRoles) > 1 ) {
00097                         //@FIXME: stupid fix of previous multi-roles logic.
00098                         //@TODO:  make proper DB upgrade in the future revisions.
00099                         $rs = array();
00100                         $rs[0] = $uRoles[0];
00101                         $model->setRoleIds( $rs )->setRoleUserId( $model->getUserId() )->saveRelations();
00102                     }
00103                 }
00104                 Mage::getSingleton('adminhtml/session')->addSuccess($this->__('User was successfully saved'));
00105                 Mage::getSingleton('adminhtml/session')->setUserData(false);
00106                 $this->_redirect('*/*/edit', array('user_id' => $model->getUserId()));
00107                 return;
00108             } catch (Exception $e) {
00109                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00110                 Mage::getSingleton('adminhtml/session')->setUserData($data);
00111                 $this->_redirect('*/*/edit', array('user_id' => $model->getUserId()));
00112                 return;
00113             }
00114         }
00115         $this->_redirect('*/*/');
00116     }


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