Agreement.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CheckoutAgreements\Model;
  7. use Magento\CheckoutAgreements\Api\Data\AgreementInterface;
  8. class Agreement extends \Magento\Framework\Model\AbstractExtensibleModel implements AgreementInterface
  9. {
  10. /**
  11. * Allowed CSS units for height field
  12. *
  13. * @var array
  14. */
  15. protected $allowedCssUnits = ['px', 'pc', 'pt', 'ex', 'em', 'mm', 'cm', 'in', '%'];
  16. /**
  17. * @return void
  18. * @codeCoverageIgnore
  19. */
  20. protected function _construct()
  21. {
  22. $this->_init(\Magento\CheckoutAgreements\Model\ResourceModel\Agreement::class);
  23. }
  24. /**
  25. * @param \Magento\Framework\DataObject $agreementData
  26. * @return array|bool
  27. */
  28. public function validateData($agreementData)
  29. {
  30. $errors = [];
  31. $contentHeight = $agreementData->getContentHeight();
  32. if ($contentHeight !== ''
  33. && !preg_match('/^[0-9]*\.*[0-9]+(' . implode("|", $this->allowedCssUnits) . ')?$/', $contentHeight)
  34. ) {
  35. $errors[] = "Please input a valid CSS-height. For example 100px or 77pt or 20em or .5ex or 50%.";
  36. }
  37. return (count($errors)) ? $errors : true;
  38. }
  39. /**
  40. * Processing object before save data
  41. *
  42. * @return $this
  43. */
  44. public function beforeSave()
  45. {
  46. if ($this->getContentHeight() == 0) {
  47. $this->setContentHeight(''); //converting zero Content-Height
  48. }
  49. if ($this->getContentHeight()
  50. && !preg_match('/(' . implode("|", $this->allowedCssUnits) . ')/', $this->getContentHeight())
  51. ) {
  52. $contentHeight = $this->getContentHeight() . 'px'; //setting default units for Content-Height
  53. $this->setContentHeight($contentHeight);
  54. }
  55. return parent::beforeSave();
  56. }
  57. //@codeCoverageIgnoreStart
  58. /**
  59. * @inheritdoc
  60. */
  61. public function getAgreementId()
  62. {
  63. return $this->getData(self::AGREEMENT_ID);
  64. }
  65. /**
  66. * @inheritdoc
  67. */
  68. public function setAgreementId($id)
  69. {
  70. return $this->setData(self::AGREEMENT_ID, $id);
  71. }
  72. /**
  73. * @inheritdoc
  74. */
  75. public function getName()
  76. {
  77. return $this->getData(self::NAME);
  78. }
  79. /**
  80. * @inheritdoc
  81. */
  82. public function setName($name)
  83. {
  84. return $this->setData(self::NAME, $name);
  85. }
  86. /**
  87. * @inheritdoc
  88. */
  89. public function getContent()
  90. {
  91. return $this->getData(self::CONTENT);
  92. }
  93. /**
  94. * @inheritdoc
  95. */
  96. public function setContent($content)
  97. {
  98. return $this->setData(self::CONTENT, $content);
  99. }
  100. /**
  101. * @inheritdoc
  102. */
  103. public function getContentHeight()
  104. {
  105. return $this->getData(self::CONTENT_HEIGHT);
  106. }
  107. /**
  108. * @inheritdoc
  109. */
  110. public function setContentHeight($height)
  111. {
  112. return $this->setData(self::CONTENT_HEIGHT, $height);
  113. }
  114. /**
  115. * @inheritdoc
  116. */
  117. public function getCheckboxText()
  118. {
  119. return $this->getData(self::CHECKBOX_TEXT);
  120. }
  121. /**
  122. * @inheritdoc
  123. */
  124. public function setCheckboxText($text)
  125. {
  126. return $this->setData(self::CHECKBOX_TEXT, $text);
  127. }
  128. /**
  129. * @inheritdoc
  130. */
  131. public function getIsActive()
  132. {
  133. return $this->getData(self::IS_ACTIVE);
  134. }
  135. /**
  136. * @inheritdoc
  137. */
  138. public function setIsActive($status)
  139. {
  140. return $this->setData(self::IS_ACTIVE, $status);
  141. }
  142. /**
  143. * @inheritdoc
  144. */
  145. public function getIsHtml()
  146. {
  147. return $this->getData(self::IS_HTML);
  148. }
  149. /**
  150. * @inheritdoc
  151. */
  152. public function setIsHtml($isHtml)
  153. {
  154. return $this->setData(self::IS_HTML, $isHtml);
  155. }
  156. /**
  157. * @inheritdoc
  158. */
  159. public function getMode()
  160. {
  161. return $this->getData(self::MODE);
  162. }
  163. /**
  164. * @inheritdoc
  165. */
  166. public function setMode($mode)
  167. {
  168. return $this->setData(self::MODE, $mode);
  169. }
  170. /**
  171. * {@inheritdoc}
  172. *
  173. * @return \Magento\CheckoutAgreements\Api\Data\AgreementExtensionInterface|null
  174. */
  175. public function getExtensionAttributes()
  176. {
  177. return $this->_getExtensionAttributes();
  178. }
  179. /**
  180. * {@inheritdoc}
  181. *
  182. * @param \Magento\CheckoutAgreements\Api\Data\AgreementExtensionInterface $extensionAttributes
  183. * @return $this
  184. */
  185. public function setExtensionAttributes(
  186. \Magento\CheckoutAgreements\Api\Data\AgreementExtensionInterface $extensionAttributes
  187. ) {
  188. return $this->_setExtensionAttributes($extensionAttributes);
  189. }
  190. //@codeCoverageIgnoreEnd
  191. }