Users.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\User\Block\Role\Tab;
  7. class Users extends \Magento\Backend\Block\Widget\Tabs
  8. {
  9. /**
  10. * User model factory
  11. *
  12. * @var \Magento\User\Model\ResourceModel\User\CollectionFactory
  13. */
  14. protected $_userCollectionFactory;
  15. /**
  16. * @param \Magento\Backend\Block\Template\Context $context
  17. * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
  18. * @param \Magento\Backend\Model\Auth\Session $authSession
  19. * @param \Magento\User\Model\ResourceModel\User\CollectionFactory $userCollectionFactory
  20. * @param array $data
  21. */
  22. public function __construct(
  23. \Magento\Backend\Block\Template\Context $context,
  24. \Magento\Framework\Json\EncoderInterface $jsonEncoder,
  25. \Magento\Backend\Model\Auth\Session $authSession,
  26. \Magento\User\Model\ResourceModel\User\CollectionFactory $userCollectionFactory,
  27. array $data = []
  28. ) {
  29. // _userCollectionFactory is used in parent::__construct
  30. $this->_userCollectionFactory = $userCollectionFactory;
  31. parent::__construct($context, $jsonEncoder, $authSession, $data);
  32. }
  33. /**
  34. * Class constructor
  35. *
  36. * @return void
  37. */
  38. protected function _construct()
  39. {
  40. parent::_construct();
  41. $roleId = $this->getRequest()->getParam('rid', false);
  42. /** @var \Magento\User\Model\ResourceModel\User\Collection $users */
  43. $users = $this->_userCollectionFactory->create()->load();
  44. $this->setTemplate('Magento_User::role/users.phtml')
  45. ->assign('users', $users->getItems())
  46. ->assign('roleId', $roleId);
  47. }
  48. /**
  49. * @return $this
  50. */
  51. protected function _prepareLayout()
  52. {
  53. $this->setChild(
  54. 'userGrid',
  55. $this->getLayout()->createBlock(\Magento\User\Block\Role\Grid\User::class, 'roleUsersGrid')
  56. );
  57. return parent::_prepareLayout();
  58. }
  59. /**
  60. * @return string
  61. */
  62. public function getGridHtml()
  63. {
  64. return $this->getChildHtml('userGrid');
  65. }
  66. }