123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\CheckoutAgreements\Model;
- use Magento\CheckoutAgreements\Api\Data\AgreementInterface;
- class Agreement extends \Magento\Framework\Model\AbstractExtensibleModel implements AgreementInterface
- {
- /**
- * Allowed CSS units for height field
- *
- * @var array
- */
- protected $allowedCssUnits = ['px', 'pc', 'pt', 'ex', 'em', 'mm', 'cm', 'in', '%'];
- /**
- * @return void
- * @codeCoverageIgnore
- */
- protected function _construct()
- {
- $this->_init(\Magento\CheckoutAgreements\Model\ResourceModel\Agreement::class);
- }
- /**
- * @param \Magento\Framework\DataObject $agreementData
- * @return array|bool
- */
- public function validateData($agreementData)
- {
- $errors = [];
- $contentHeight = $agreementData->getContentHeight();
- if ($contentHeight !== ''
- && !preg_match('/^[0-9]*\.*[0-9]+(' . implode("|", $this->allowedCssUnits) . ')?$/', $contentHeight)
- ) {
- $errors[] = "Please input a valid CSS-height. For example 100px or 77pt or 20em or .5ex or 50%.";
- }
- return (count($errors)) ? $errors : true;
- }
- /**
- * Processing object before save data
- *
- * @return $this
- */
- public function beforeSave()
- {
- if ($this->getContentHeight() == 0) {
- $this->setContentHeight(''); //converting zero Content-Height
- }
- if ($this->getContentHeight()
- && !preg_match('/(' . implode("|", $this->allowedCssUnits) . ')/', $this->getContentHeight())
- ) {
- $contentHeight = $this->getContentHeight() . 'px'; //setting default units for Content-Height
- $this->setContentHeight($contentHeight);
- }
- return parent::beforeSave();
- }
- //@codeCoverageIgnoreStart
- /**
- * @inheritdoc
- */
- public function getAgreementId()
- {
- return $this->getData(self::AGREEMENT_ID);
- }
- /**
- * @inheritdoc
- */
- public function setAgreementId($id)
- {
- return $this->setData(self::AGREEMENT_ID, $id);
- }
- /**
- * @inheritdoc
- */
- public function getName()
- {
- return $this->getData(self::NAME);
- }
- /**
- * @inheritdoc
- */
- public function setName($name)
- {
- return $this->setData(self::NAME, $name);
- }
- /**
- * @inheritdoc
- */
- public function getContent()
- {
- return $this->getData(self::CONTENT);
- }
- /**
- * @inheritdoc
- */
- public function setContent($content)
- {
- return $this->setData(self::CONTENT, $content);
- }
- /**
- * @inheritdoc
- */
- public function getContentHeight()
- {
- return $this->getData(self::CONTENT_HEIGHT);
- }
- /**
- * @inheritdoc
- */
- public function setContentHeight($height)
- {
- return $this->setData(self::CONTENT_HEIGHT, $height);
- }
- /**
- * @inheritdoc
- */
- public function getCheckboxText()
- {
- return $this->getData(self::CHECKBOX_TEXT);
- }
- /**
- * @inheritdoc
- */
- public function setCheckboxText($text)
- {
- return $this->setData(self::CHECKBOX_TEXT, $text);
- }
- /**
- * @inheritdoc
- */
- public function getIsActive()
- {
- return $this->getData(self::IS_ACTIVE);
- }
- /**
- * @inheritdoc
- */
- public function setIsActive($status)
- {
- return $this->setData(self::IS_ACTIVE, $status);
- }
- /**
- * @inheritdoc
- */
- public function getIsHtml()
- {
- return $this->getData(self::IS_HTML);
- }
- /**
- * @inheritdoc
- */
- public function setIsHtml($isHtml)
- {
- return $this->setData(self::IS_HTML, $isHtml);
- }
- /**
- * @inheritdoc
- */
- public function getMode()
- {
- return $this->getData(self::MODE);
- }
- /**
- * @inheritdoc
- */
- public function setMode($mode)
- {
- return $this->setData(self::MODE, $mode);
- }
- /**
- * {@inheritdoc}
- *
- * @return \Magento\CheckoutAgreements\Api\Data\AgreementExtensionInterface|null
- */
- public function getExtensionAttributes()
- {
- return $this->_getExtensionAttributes();
- }
- /**
- * {@inheritdoc}
- *
- * @param \Magento\CheckoutAgreements\Api\Data\AgreementExtensionInterface $extensionAttributes
- * @return $this
- */
- public function setExtensionAttributes(
- \Magento\CheckoutAgreements\Api\Data\AgreementExtensionInterface $extensionAttributes
- ) {
- return $this->_setExtensionAttributes($extensionAttributes);
- }
- //@codeCoverageIgnoreEnd
- }
|