Role.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Authorization\Model;
  7. /**
  8. * Admin Role Model
  9. *
  10. * @api
  11. * @method int getParentId()
  12. * @method \Magento\Authorization\Model\Role setParentId(int $value)
  13. * @method int getTreeLevel()
  14. * @method \Magento\Authorization\Model\Role setTreeLevel(int $value)
  15. * @method int getSortOrder()
  16. * @method \Magento\Authorization\Model\Role setSortOrder(int $value)
  17. * @method string getRoleType()
  18. * @method \Magento\Authorization\Model\Role setRoleType(string $value)
  19. * @method int getUserId()
  20. * @method \Magento\Authorization\Model\Role setUserId(int $value)
  21. * @method string getUserType()
  22. * @method \Magento\Authorization\Model\Role setUserType(string $value)
  23. * @method string getRoleName()
  24. * @method \Magento\Authorization\Model\Role setRoleName(string $value)
  25. * @api
  26. * @since 100.0.2
  27. */
  28. class Role extends \Magento\Framework\Model\AbstractModel
  29. {
  30. /**
  31. * @var string
  32. */
  33. protected $_eventPrefix = 'authorization_roles';
  34. /**
  35. * @param \Magento\Framework\Model\Context $context
  36. * @param \Magento\Framework\Registry $registry
  37. * @param \Magento\Authorization\Model\ResourceModel\Role $resource
  38. * @param \Magento\Authorization\Model\ResourceModel\Role\Collection $resourceCollection
  39. * @param array $data
  40. */
  41. public function __construct(
  42. \Magento\Framework\Model\Context $context,
  43. \Magento\Framework\Registry $registry,
  44. \Magento\Authorization\Model\ResourceModel\Role $resource,
  45. \Magento\Authorization\Model\ResourceModel\Role\Collection $resourceCollection,
  46. array $data = []
  47. ) {
  48. parent::__construct($context, $registry, $resource, $resourceCollection, $data);
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function __sleep()
  54. {
  55. $properties = parent::__sleep();
  56. return array_diff($properties, ['_resource', '_resourceCollection']);
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function __wakeup()
  62. {
  63. parent::__wakeup();
  64. $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  65. $this->_resource = $objectManager->get(\Magento\Authorization\Model\ResourceModel\Role::class);
  66. $this->_resourceCollection = $objectManager->get(
  67. \Magento\Authorization\Model\ResourceModel\Role\Collection::class
  68. );
  69. }
  70. /**
  71. * Class constructor
  72. *
  73. * @return void
  74. */
  75. protected function _construct()
  76. {
  77. $this->_init(\Magento\Authorization\Model\ResourceModel\Role::class);
  78. }
  79. /**
  80. * Update object into database
  81. *
  82. * @return $this
  83. */
  84. public function update()
  85. {
  86. $this->getResource()->update($this);
  87. return $this;
  88. }
  89. /**
  90. * Return users for role
  91. *
  92. * @return array
  93. */
  94. public function getRoleUsers()
  95. {
  96. return $this->getResource()->getRoleUsers($this);
  97. }
  98. }