State.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Indexer\Model\Mview\View;
  7. /**
  8. * @method \Magento\Indexer\Model\Mview\View\State setViewId(string $value)
  9. */
  10. class State extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\Mview\View\StateInterface
  11. {
  12. /**
  13. * Prefix of model events names
  14. *
  15. * @var string
  16. */
  17. protected $_eventPrefix = 'mview_state';
  18. /**
  19. * Parameter name in event
  20. *
  21. * @var string
  22. */
  23. protected $_eventObject = 'mview_state';
  24. /**
  25. * @param \Magento\Framework\Model\Context $context
  26. * @param \Magento\Framework\Registry $registry
  27. * @param \Magento\Indexer\Model\ResourceModel\Mview\View\State $resource
  28. * @param \Magento\Indexer\Model\ResourceModel\Mview\View\State\Collection $resourceCollection
  29. * @param array $data
  30. */
  31. public function __construct(
  32. \Magento\Framework\Model\Context $context,
  33. \Magento\Framework\Registry $registry,
  34. \Magento\Indexer\Model\ResourceModel\Mview\View\State $resource,
  35. \Magento\Indexer\Model\ResourceModel\Mview\View\State\Collection $resourceCollection,
  36. array $data = []
  37. ) {
  38. if (!isset($data['mode'])) {
  39. $data['mode'] = self::MODE_DISABLED;
  40. }
  41. if (!isset($data['status'])) {
  42. $data['status'] = self::STATUS_IDLE;
  43. }
  44. parent::__construct($context, $registry, $resource, $resourceCollection, $data);
  45. }
  46. /**
  47. * Fill object with state data by view ID
  48. *
  49. * @param string $viewId
  50. * @return $this
  51. */
  52. public function loadByView($viewId)
  53. {
  54. $this->load($viewId, 'view_id');
  55. if (!$this->getId()) {
  56. $this->setViewId($viewId);
  57. }
  58. return $this;
  59. }
  60. /**
  61. * Processing object before save data
  62. *
  63. * @return $this
  64. */
  65. public function beforeSave()
  66. {
  67. $this->setUpdated(time());
  68. return parent::beforeSave();
  69. }
  70. /**
  71. * Get state view ID
  72. *
  73. * @return string
  74. */
  75. public function getViewId()
  76. {
  77. return $this->getData('view_id');
  78. }
  79. /**
  80. * Get state mode
  81. *
  82. * @return string
  83. */
  84. public function getMode()
  85. {
  86. return $this->getData('mode');
  87. }
  88. /**
  89. * Set state mode
  90. *
  91. * @param string $mode
  92. * @return $this
  93. */
  94. public function setMode($mode)
  95. {
  96. $this->setData('mode', $mode);
  97. return $this;
  98. }
  99. /**
  100. * Get state status
  101. *
  102. * @return string
  103. */
  104. public function getStatus()
  105. {
  106. return $this->getData('status');
  107. }
  108. /**
  109. * Set state status
  110. *
  111. * @param string $status
  112. * @return $this
  113. */
  114. public function setStatus($status)
  115. {
  116. $this->setData('status', $status);
  117. return $this;
  118. }
  119. /**
  120. * Get state updated time
  121. *
  122. * @return string
  123. */
  124. public function getUpdated()
  125. {
  126. return $this->getData('updated');
  127. }
  128. /**
  129. * Set state updated time
  130. *
  131. * @param string|int|\DateTimeInterface $updated
  132. * @return $this
  133. */
  134. public function setUpdated($updated)
  135. {
  136. $this->setData('updated', $updated);
  137. return $this;
  138. }
  139. /**
  140. * Get state version ID
  141. *
  142. * @return string
  143. */
  144. public function getVersionId()
  145. {
  146. return $this->getData('version_id');
  147. }
  148. /**
  149. * Set state version ID
  150. *
  151. * @param int $versionId
  152. * @return $this
  153. */
  154. public function setVersionId($versionId)
  155. {
  156. $this->setData('version_id', $versionId);
  157. return $this;
  158. }
  159. }