/app/code/core/Mage/Adminhtml/Block/Api/Role/Grid/User.php

https://bitbucket.org/acidel/buykoala · PHP · 182 lines · 117 code · 17 blank · 48 comment · 15 complexity · 2c4a5cb729656061968f14d11cfc73e3 MD5 · raw file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Adminhtml
  23. * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Acl role user grid
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Api_Role_Grid_User extends Mage_Adminhtml_Block_Widget_Grid
  34. {
  35. public function __construct()
  36. {
  37. parent::__construct();
  38. $this->setDefaultSort('role_user_id');
  39. $this->setDefaultDir('asc');
  40. $this->setId('roleUserGrid');
  41. $this->setDefaultFilter(array('in_role_users'=>1));
  42. $this->setUseAjax(true);
  43. }
  44. protected function _addColumnFilterToCollection($column)
  45. {
  46. if ($column->getId() == 'in_role_users') {
  47. $inRoleIds = $this->_getUsers();
  48. if (empty($inRoleIds)) {
  49. $inRoleIds = 0;
  50. }
  51. if ($column->getFilter()->getValue()) {
  52. $this->getCollection()->addFieldToFilter('user_id', array('in'=>$inRoleIds));
  53. }
  54. else {
  55. if($inRoleIds) {
  56. $this->getCollection()->addFieldToFilter('user_id', array('nin'=>$inRoleIds));
  57. }
  58. }
  59. }
  60. else {
  61. parent::_addColumnFilterToCollection($column);
  62. }
  63. return $this;
  64. }
  65. protected function _prepareCollection()
  66. {
  67. $roleId = $this->getRequest()->getParam('rid');
  68. Mage::register('RID', $roleId);
  69. $collection = Mage::getModel('api/roles')->getUsersCollection();
  70. $this->setCollection($collection);
  71. return parent::_prepareCollection();
  72. }
  73. protected function _prepareColumns()
  74. {
  75. $this->addColumn('in_role_users', array(
  76. 'header_css_class' => 'a-center',
  77. 'type' => 'checkbox',
  78. 'name' => 'in_role_users',
  79. 'values' => $this->_getUsers(),
  80. 'align' => 'center',
  81. 'index' => 'user_id'
  82. ));
  83. $this->addColumn('role_user_id', array(
  84. 'header' =>Mage::helper('adminhtml')->__('User ID'),
  85. 'width' =>5,
  86. 'align' =>'left',
  87. 'sortable' =>true,
  88. 'index' =>'user_id'
  89. ));
  90. $this->addColumn('role_user_username', array(
  91. 'header' =>Mage::helper('adminhtml')->__('User Name'),
  92. 'align' =>'left',
  93. 'index' =>'username'
  94. ));
  95. $this->addColumn('role_user_firstname', array(
  96. 'header' =>Mage::helper('adminhtml')->__('First Name'),
  97. 'align' =>'left',
  98. 'index' =>'firstname'
  99. ));
  100. $this->addColumn('role_user_lastname', array(
  101. 'header' =>Mage::helper('adminhtml')->__('Last Name'),
  102. 'align' =>'left',
  103. 'index' =>'lastname'
  104. ));
  105. $this->addColumn('role_user_email', array(
  106. 'header' =>Mage::helper('adminhtml')->__('Email'),
  107. 'width' =>40,
  108. 'align' =>'left',
  109. 'index' =>'email'
  110. ));
  111. $this->addColumn('role_user_is_active', array(
  112. 'header' => Mage::helper('adminhtml')->__('Status'),
  113. 'index' => 'is_active',
  114. 'align' =>'left',
  115. 'type' => 'options',
  116. 'options' => array('1' => Mage::helper('adminhtml')->__('Active'), '0' => Mage::helper('adminhtml')->__('Inactive')),
  117. ));
  118. /*
  119. $this->addColumn('grid_actions',
  120. array(
  121. 'header'=>Mage::helper('adminhtml')->__('Actions'),
  122. 'width'=>5,
  123. 'sortable'=>false,
  124. 'filter' =>false,
  125. 'type' => 'action',
  126. 'actions' => array(
  127. array(
  128. 'caption' => Mage::helper('adminhtml')->__('Remove'),
  129. 'onClick' => 'role.deleteFromRole($role_id);'
  130. )
  131. )
  132. )
  133. );
  134. */
  135. return parent::_prepareColumns();
  136. }
  137. public function getGridUrl()
  138. {
  139. $roleId = $this->getRequest()->getParam('rid');
  140. return $this->getUrl('*/*/editrolegrid', array('rid' => $roleId));
  141. }
  142. protected function _getUsers($json=false)
  143. {
  144. if ( $this->getRequest()->getParam('in_role_user') != "" ) {
  145. return $this->getRequest()->getParam('in_role_user');
  146. }
  147. $roleId = ( $this->getRequest()->getParam('rid') > 0 ) ? $this->getRequest()->getParam('rid') : Mage::registry('RID');
  148. $users = Mage::getModel('api/roles')->setId($roleId)->getRoleUsers();
  149. if (sizeof($users) > 0) {
  150. if ( $json ) {
  151. $jsonUsers = Array();
  152. foreach($users as $usrid) $jsonUsers[$usrid] = 0;
  153. return Mage::helper('core')->jsonEncode((object)$jsonUsers);
  154. } else {
  155. return array_values($users);
  156. }
  157. } else {
  158. if ( $json ) {
  159. return '{}';
  160. } else {
  161. return array();
  162. }
  163. }
  164. }
  165. }