Collection.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Model\ResourceModel\Oauth\Token;
  7. /**
  8. * OAuth token resource collection model
  9. */
  10. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  11. {
  12. /**
  13. * Initialize collection model
  14. *
  15. * @return void
  16. */
  17. protected function _construct()
  18. {
  19. $this->_init(
  20. \Magento\Integration\Model\Oauth\Token::class,
  21. \Magento\Integration\Model\ResourceModel\Oauth\Token::class
  22. );
  23. }
  24. /**
  25. * Load collection with consumer data
  26. *
  27. * Method use for show applications list (token-consumer)
  28. *
  29. * @return $this
  30. */
  31. public function joinConsumerAsApplication()
  32. {
  33. $select = $this->getSelect();
  34. $select->joinLeft(
  35. ['c' => $this->getTable('oauth_consumer')],
  36. 'c.entity_id = main_table.consumer_id',
  37. 'name'
  38. );
  39. return $this;
  40. }
  41. /**
  42. * Add filter by admin ID
  43. *
  44. * @param int $adminId
  45. * @return $this
  46. */
  47. public function addFilterByAdminId($adminId)
  48. {
  49. $this->addFilter('main_table.admin_id', $adminId);
  50. return $this;
  51. }
  52. /**
  53. * Add filter by customer ID
  54. *
  55. * @param int $customerId
  56. * @return $this
  57. */
  58. public function addFilterByCustomerId($customerId)
  59. {
  60. $this->addFilter('main_table.customer_id', $customerId);
  61. return $this;
  62. }
  63. /**
  64. * Add filter by consumer ID
  65. *
  66. * @param int $consumerId
  67. * @return $this
  68. */
  69. public function addFilterByConsumerId($consumerId)
  70. {
  71. $this->addFilter('main_table.consumer_id', $consumerId);
  72. return $this;
  73. }
  74. /**
  75. * Add filter by type
  76. *
  77. * @param string $type
  78. * @return $this
  79. */
  80. public function addFilterByType($type)
  81. {
  82. $this->addFilter('main_table.type', $type);
  83. return $this;
  84. }
  85. /**
  86. * Add filter by ID
  87. *
  88. * @param array|int $tokenId
  89. * @return $this
  90. */
  91. public function addFilterById($tokenId)
  92. {
  93. $this->addFilter('main_table.entity_id', ['in' => $tokenId], 'public');
  94. return $this;
  95. }
  96. /**
  97. * Add filter by "Is Revoked" status
  98. *
  99. * @param bool|int $flag
  100. * @return $this
  101. */
  102. public function addFilterByRevoked($flag)
  103. {
  104. $this->addFilter('main_table.revoked', (int)$flag, 'public');
  105. return $this;
  106. }
  107. }