setId('permissionsUserRolesGrid'); $this->setDefaultSort('sort_order'); $this->setDefaultDir('asc'); //$this->setDefaultFilter(array('assigned_user_role'=>1)); $this->setTitle(Mage::helper('adminhtml')->__('User Roles Information')); $this->setUseAjax(true); } protected function _addColumnFilterToCollection($column) { if ($column->getId() == 'assigned_user_role') { $userRoles = $this->_getSelectedRoles(); if (empty($userRoles)) { $userRoles = 0; } if ($column->getFilter()->getValue()) { $this->getCollection()->addFieldToFilter('role_id', array('in'=>$userRoles)); } else { if($userRoles) { $this->getCollection()->addFieldToFilter('role_id', array('nin'=>$userRoles)); } } } else { parent::_addColumnFilterToCollection($column); } return $this; } protected function _prepareCollection() { $collection = Mage::getResourceModel('admin/role_collection'); $collection->setRolesFilter(); $this->setCollection($collection); return parent::_prepareCollection(); } protected function _prepareColumns() { $this->addColumn('assigned_user_role', array( 'header_css_class' => 'a-center', 'header' => Mage::helper('adminhtml')->__('Assigned'), 'type' => 'radio', 'html_name' => 'roles[]', 'values' => $this->_getSelectedRoles(), 'align' => 'center', 'index' => 'role_id' )); /*$this->addColumn('role_id', array( 'header' =>Mage::helper('adminhtml')->__('Role ID'), 'index' =>'role_id', 'align' => 'right', 'width' => '50px' ));*/ $this->addColumn('role_name', array( 'header' =>Mage::helper('adminhtml')->__('Role Name'), 'index' =>'role_name' )); return parent::_prepareColumns(); } public function getGridUrl() { return $this->getUrl('*/*/rolesGrid', array('user_id' => Mage::registry('permissions_user')->getUserId())); } protected function _getSelectedRoles($json=false) { if ( $this->getRequest()->getParam('user_roles') != "" ) { return $this->getRequest()->getParam('user_roles'); } /* @var $user Mage_Admin_Model_User */ $user = Mage::registry('permissions_user'); //checking if we have this data and we //don't need load it through resource model if ($user->hasData('roles')) { $uRoles = $user->getData('roles'); } else { $uRoles = $user->getRoles(); } if ($json) { $jsonRoles = Array(); foreach($uRoles as $urid) $jsonRoles[$urid] = 0; return Mage::helper('core')->jsonEncode((object)$jsonRoles); } else { return $uRoles; } } }