Collection.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Authorization\Model\ResourceModel\Role;
  7. use Magento\Authorization\Model\Acl\Role\Group as RoleGroup;
  8. /**
  9. * Admin role collection
  10. *
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  15. {
  16. /**
  17. * Initialize resource model
  18. *
  19. * @return void
  20. */
  21. protected function _construct()
  22. {
  23. $this->_init(\Magento\Authorization\Model\Role::class, \Magento\Authorization\Model\ResourceModel\Role::class);
  24. }
  25. /**
  26. * Add user filter
  27. *
  28. * @param int $userId
  29. * @param string $userType
  30. * @return $this
  31. */
  32. public function setUserFilter($userId, $userType)
  33. {
  34. $this->addFieldToFilter('user_id', $userId);
  35. $this->addFieldToFilter('user_type', $userType);
  36. return $this;
  37. }
  38. /**
  39. * Set roles filter
  40. *
  41. * @return $this
  42. */
  43. public function setRolesFilter()
  44. {
  45. $this->addFieldToFilter('role_type', RoleGroup::ROLE_TYPE);
  46. return $this;
  47. }
  48. /**
  49. * Convert to option array
  50. *
  51. * @return array
  52. */
  53. public function toOptionArray()
  54. {
  55. return $this->_toOptionArray('role_id', 'role_name');
  56. }
  57. }