Bookmark.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Model;
  7. use Magento\Framework\Api\AttributeValueFactory;
  8. use Magento\Framework\Api\ExtensionAttributesFactory;
  9. use Magento\Framework\Json\DecoderInterface;
  10. use Magento\Framework\Model\AbstractExtensibleModel;
  11. use Magento\Framework\Model\Context;
  12. use Magento\Framework\Registry;
  13. use Magento\Ui\Api\Data\BookmarkInterface;
  14. use Magento\Ui\Model\ResourceModel\Bookmark\Collection;
  15. use Magento\Ui\Model\ResourceModel\Bookmark as ResourceBookmark;
  16. /**
  17. * Domain class Bookmark
  18. * @codeCoverageIgnore
  19. */
  20. class Bookmark extends AbstractExtensibleModel implements BookmarkInterface
  21. {
  22. /**
  23. * @var DecoderInterface
  24. * @deprecated 101.1.0
  25. */
  26. protected $jsonDecoder;
  27. /**
  28. * @var \Magento\Framework\Serialize\Serializer\Json
  29. */
  30. private $serializer;
  31. /**
  32. * @param Context $context
  33. * @param Registry $registry
  34. * @param ExtensionAttributesFactory $extensionFactory
  35. * @param AttributeValueFactory $customAttributeFactory
  36. * @param ResourceBookmark $resource
  37. * @param Collection $resourceCollection
  38. * @param DecoderInterface $jsonDecoder
  39. * @param array $data
  40. * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
  41. * @throws \RuntimeException
  42. */
  43. public function __construct(
  44. Context $context,
  45. Registry $registry,
  46. ExtensionAttributesFactory $extensionFactory,
  47. AttributeValueFactory $customAttributeFactory,
  48. ResourceBookmark $resource,
  49. Collection $resourceCollection,
  50. DecoderInterface $jsonDecoder,
  51. array $data = [],
  52. \Magento\Framework\Serialize\Serializer\Json $serializer = null
  53. ) {
  54. $this->jsonDecoder = $jsonDecoder;
  55. $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
  56. ->get(\Magento\Framework\Serialize\Serializer\Json::class);
  57. parent::__construct(
  58. $context,
  59. $registry,
  60. $extensionFactory,
  61. $customAttributeFactory,
  62. $resource,
  63. $resourceCollection,
  64. $data
  65. );
  66. }
  67. /**
  68. * Get Id
  69. *
  70. * @return int
  71. */
  72. public function getId()
  73. {
  74. return $this->getData(self::BOOKMARK_ID);
  75. }
  76. /**
  77. * Get user Id
  78. *
  79. * @return int
  80. */
  81. public function getUserId()
  82. {
  83. return $this->getData(self::USER_ID);
  84. }
  85. /**
  86. * Get namespace
  87. *
  88. * @return string
  89. */
  90. public function getNamespace()
  91. {
  92. return $this->getData(self::BOOKMARKSPACE);
  93. }
  94. /**
  95. * Get identifier
  96. *
  97. * @return string
  98. */
  99. public function getIdentifier()
  100. {
  101. return $this->getData(self::IDENTIFIER);
  102. }
  103. /**
  104. * Is current
  105. *
  106. * @return bool
  107. */
  108. public function isCurrent()
  109. {
  110. return (bool)$this->getData(self::CURRENT);
  111. }
  112. /**
  113. * Get title
  114. *
  115. * @return string
  116. */
  117. public function getTitle()
  118. {
  119. return $this->getData(self::TITLE);
  120. }
  121. /**
  122. * Get config
  123. *
  124. * @return array
  125. */
  126. public function getConfig()
  127. {
  128. $config = $this->getData(self::CONFIG);
  129. if ($config) {
  130. return $this->serializer->unserialize($config);
  131. }
  132. return [];
  133. }
  134. /**
  135. * Get created at
  136. *
  137. * @return string
  138. */
  139. public function getCreatedAt()
  140. {
  141. return $this->getData(self::CREATED_AT);
  142. }
  143. /**
  144. * Get updated at
  145. *
  146. * @return string
  147. */
  148. public function getUpdatedAt()
  149. {
  150. return $this->getData(self::UPDATED_AT);
  151. }
  152. /**
  153. * Set Id
  154. *
  155. * @param int $id
  156. * @return $this
  157. */
  158. public function setId($id)
  159. {
  160. return $this->setData(self::BOOKMARK_ID, $id);
  161. }
  162. /**
  163. * Set user Id
  164. *
  165. * @param int $userId
  166. * @return $this
  167. */
  168. public function setUserId($userId)
  169. {
  170. return $this->setData(self::USER_ID, $userId);
  171. }
  172. /**
  173. * Set namespace
  174. *
  175. * @param string $namespace
  176. * @return $this
  177. */
  178. public function setNamespace($namespace)
  179. {
  180. return $this->setData(self::BOOKMARKSPACE, $namespace);
  181. }
  182. /**
  183. * Set identifier
  184. *
  185. * @param string $identifier
  186. * @return $this
  187. */
  188. public function setIdentifier($identifier)
  189. {
  190. return $this->setData(self::IDENTIFIER, $identifier);
  191. }
  192. /**
  193. * Set current
  194. *
  195. * @param bool $isCurrent
  196. * @return $this
  197. */
  198. public function setCurrent($isCurrent)
  199. {
  200. return $this->setData(self::CURRENT, $isCurrent);
  201. }
  202. /**
  203. * Set title
  204. *
  205. * @param string $title
  206. * @return $this
  207. */
  208. public function setTitle($title)
  209. {
  210. return $this->setData(self::TITLE, $title);
  211. }
  212. /**
  213. * Set config
  214. *
  215. * @param string $config
  216. * @return $this
  217. */
  218. public function setConfig($config)
  219. {
  220. return $this->setData(self::CONFIG, $config);
  221. }
  222. /**
  223. * Set created at
  224. *
  225. * @param string $createdAt
  226. * @return $this
  227. */
  228. public function setCreatedAt($createdAt)
  229. {
  230. return $this->setData(self::CREATED_AT, $createdAt);
  231. }
  232. /**
  233. * Set updated at
  234. *
  235. * @param string $updatedAt
  236. * @return $this
  237. */
  238. public function setUpdatedAt($updatedAt)
  239. {
  240. return $this->setData(self::UPDATED_AT, $updatedAt);
  241. }
  242. /**
  243. * {@inheritdoc}
  244. *
  245. * @return \Magento\Ui\Api\Data\BookmarkExtensionInterface|null
  246. */
  247. public function getExtensionAttributes()
  248. {
  249. return $this->_getExtensionAttributes();
  250. }
  251. /**
  252. * {@inheritdoc}
  253. *
  254. * @param \Magento\Ui\Api\Data\BookmarkExtensionInterface $extensionAttributes
  255. * @return $this
  256. */
  257. public function setExtensionAttributes(\Magento\Ui\Api\Data\BookmarkExtensionInterface $extensionAttributes)
  258. {
  259. return $this->_setExtensionAttributes($extensionAttributes);
  260. }
  261. }