Integration.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Model;
  7. /**
  8. * Integration model.
  9. *
  10. * @method \string getName()
  11. * @method Integration setName(\string $name)
  12. * @method \string getEmail()
  13. * @method Integration setEmail(\string $email)
  14. * @method Integration setStatus(\int $value)
  15. * @method \int getSetupType()
  16. * @method Integration setSetupType(\int $value)
  17. * @method Integration setConsumerId(\string $consumerId)
  18. * @method \string getConsumerId()
  19. * @method \string getEndpoint()
  20. * @method Integration setEndpoint(\string $endpoint)
  21. * @method \string getIdentityLinkUrl()
  22. * @method Integration setIdentityLinkUrl(\string $identityLinkUrl)
  23. * @method \string getCreatedAt()
  24. * @method Integration setCreatedAt(\string $createdAt)
  25. * @method \string getUpdatedAt()
  26. * @method Integration setUpdatedAt(\string $createdAt)
  27. * @api
  28. * @since 100.0.2
  29. */
  30. class Integration extends \Magento\Framework\Model\AbstractModel
  31. {
  32. /**#@+
  33. * Integration Status values
  34. */
  35. const STATUS_INACTIVE = 0;
  36. const STATUS_ACTIVE = 1;
  37. const STATUS_RECREATED = 2;
  38. /**#@-*/
  39. /**#@+
  40. * Integration setup type
  41. */
  42. const TYPE_MANUAL = 0;
  43. const TYPE_CONFIG = 1;
  44. /**#@-*/
  45. /**#@+
  46. * Integration data key constants.
  47. */
  48. const ID = 'integration_id';
  49. const NAME = 'name';
  50. const EMAIL = 'email';
  51. const ENDPOINT = 'endpoint';
  52. const IDENTITY_LINK_URL = 'identity_link_url';
  53. const SETUP_TYPE = 'setup_type';
  54. const CONSUMER_ID = 'consumer_id';
  55. const STATUS = 'status';
  56. /**#@-*/
  57. /**
  58. * @param \Magento\Framework\Model\Context $context
  59. * @param \Magento\Framework\Registry $registry
  60. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  61. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  62. * @param array $data
  63. */
  64. public function __construct(
  65. \Magento\Framework\Model\Context $context,
  66. \Magento\Framework\Registry $registry,
  67. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  68. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  69. array $data = []
  70. ) {
  71. parent::__construct($context, $registry, $resource, $resourceCollection, $data);
  72. }
  73. /**
  74. * Initialize resource model
  75. *
  76. * @return void
  77. */
  78. protected function _construct()
  79. {
  80. parent::_construct();
  81. $this->_init(\Magento\Integration\Model\ResourceModel\Integration::class);
  82. }
  83. /**
  84. * Load integration by oAuth consumer ID.
  85. *
  86. * @param int $consumerId
  87. * @return $this
  88. */
  89. public function loadByConsumerId($consumerId)
  90. {
  91. return $this->load($consumerId, self::CONSUMER_ID);
  92. }
  93. /**
  94. * Load active integration by oAuth consumer ID.
  95. *
  96. * @param int $consumerId
  97. * @return $this
  98. */
  99. public function loadActiveIntegrationByConsumerId($consumerId)
  100. {
  101. $integrationData = $this->getResource()->selectActiveIntegrationByConsumerId($consumerId);
  102. $this->setData($integrationData ? $integrationData : []);
  103. return $this;
  104. }
  105. /**
  106. * Get integration status. Cast to the type of STATUS_* constants in order to make strict comparison valid.
  107. *
  108. * @return int
  109. * @api
  110. */
  111. public function getStatus()
  112. {
  113. return (int)$this->getData(self::STATUS);
  114. }
  115. }