Message.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\GiftMessage\Model;
  7. use Magento\Framework\Api\AttributeValueFactory;
  8. /**
  9. * Gift Message model
  10. *
  11. * @api
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @since 100.0.2
  14. */
  15. class Message extends \Magento\Framework\Model\AbstractExtensibleModel implements
  16. \Magento\GiftMessage\Api\Data\MessageInterface
  17. {
  18. /**
  19. * @var \Magento\GiftMessage\Model\TypeFactory
  20. */
  21. protected $_typeFactory;
  22. /**
  23. * @param \Magento\Framework\Model\Context $context
  24. * @param \Magento\Framework\Registry $registry
  25. * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
  26. * @param AttributeValueFactory $customAttributeFactory
  27. * @param TypeFactory $typeFactory
  28. * @param \Magento\GiftMessage\Model\ResourceModel\Message $resource
  29. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  30. * @param array $data
  31. */
  32. public function __construct(
  33. \Magento\Framework\Model\Context $context,
  34. \Magento\Framework\Registry $registry,
  35. \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
  36. AttributeValueFactory $customAttributeFactory,
  37. \Magento\GiftMessage\Model\TypeFactory $typeFactory,
  38. \Magento\GiftMessage\Model\ResourceModel\Message $resource = null,
  39. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  40. array $data = []
  41. ) {
  42. $this->_typeFactory = $typeFactory;
  43. parent::__construct(
  44. $context,
  45. $registry,
  46. $extensionFactory,
  47. $customAttributeFactory,
  48. $resource,
  49. $resourceCollection,
  50. $data
  51. );
  52. }
  53. /**
  54. * @return void
  55. */
  56. protected function _construct()
  57. {
  58. $this->_init(\Magento\GiftMessage\Model\ResourceModel\Message::class);
  59. }
  60. /**
  61. * Return model from entity type
  62. *
  63. * @param string $type
  64. * @return mixed
  65. */
  66. public function getEntityModelByType($type)
  67. {
  68. return $this->_typeFactory->createType($type);
  69. }
  70. /**
  71. * Checks if the gift message is empty
  72. *
  73. * @return bool
  74. */
  75. public function isMessageEmpty()
  76. {
  77. return trim($this->getMessage()) == '';
  78. }
  79. //@codeCoverageIgnoreStart
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public function getGiftMessageId()
  84. {
  85. return $this->getData(self::GIFT_MESSAGE_ID);
  86. }
  87. /**
  88. * {@inheritdoc}
  89. */
  90. public function setGiftMessageId($id)
  91. {
  92. return $this->setData(self::GIFT_MESSAGE_ID, $id);
  93. }
  94. /**
  95. * {@inheritdoc}
  96. */
  97. public function getCustomerId()
  98. {
  99. return $this->getData(self::CUSTOMER_ID);
  100. }
  101. /**
  102. * {@inheritdoc}
  103. */
  104. public function setCustomerId($id)
  105. {
  106. return $this->setData(self::CUSTOMER_ID, $id);
  107. }
  108. /**
  109. * {@inheritdoc}
  110. */
  111. public function getSender()
  112. {
  113. return $this->getData(self::SENDER);
  114. }
  115. /**
  116. * {@inheritdoc}
  117. */
  118. public function setSender($sender)
  119. {
  120. return $this->setData(self::SENDER, $sender);
  121. }
  122. /**
  123. * {@inheritdoc}
  124. */
  125. public function getRecipient()
  126. {
  127. return $this->getData(self::RECIPIENT);
  128. }
  129. /**
  130. * {@inheritdoc}
  131. */
  132. public function setRecipient($recipient)
  133. {
  134. return $this->setData(self::RECIPIENT, $recipient);
  135. }
  136. /**
  137. * {@inheritdoc}
  138. */
  139. public function getMessage()
  140. {
  141. return $this->getData(self::MESSAGE);
  142. }
  143. /**
  144. * {@inheritdoc}
  145. */
  146. public function setMessage($message)
  147. {
  148. return $this->setData(self::MESSAGE, $message);
  149. }
  150. /**
  151. * Retrieve existing extension attributes object or create a new one.
  152. *
  153. * @return \Magento\GiftMessage\Api\Data\MessageExtensionInterface|null
  154. */
  155. public function getExtensionAttributes()
  156. {
  157. return $this->_getExtensionAttributes();
  158. }
  159. /**
  160. * Set an extension attributes object.
  161. *
  162. * @param \Magento\GiftMessage\Api\Data\MessageExtensionInterface $extensionAttributes
  163. * @return $this
  164. */
  165. public function setExtensionAttributes(\Magento\GiftMessage\Api\Data\MessageExtensionInterface $extensionAttributes)
  166. {
  167. return $this->_setExtensionAttributes($extensionAttributes);
  168. }
  169. //@codeCoverageIgnoreEnd
  170. }