Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/amasty/feed/Model/Field/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/amasty/feed/Model/Field/Condition.php
<?php
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Product Feed for Magento 2
 */

namespace Amasty\Feed\Model\Field;

use Amasty\Feed\Model\Config\Source\CustomFieldType;
use Magento\Framework\Model\AbstractModel;

/**
 * Class Conditions
 * Used for conditions block in Condition-Based Attributes
 *
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class Condition extends AbstractModel
{
    /**#@+
     * Table columns
     */
    public const COLUMN_CONDITION = 'conditions_serialized';
    public const COLUMN_RESULT = 'result_serialized';
    public const COLUMN_FIELD_ID = 'feed_field_id';
    /**#@-*/

    /**
     * Index for result array
     */
    public const RESULT_KEY = 'result';

    /**
     * @var \Magento\Framework\Json\Helper\Data
     */
    private $jsonHelper;

    /**
     * @var \Amasty\Feed\Model\Rule\Rule
     */
    private $ruleModel;

    /**
     * @var \Amasty\Feed\Model\Rule\RuleFactory
     */
    private $ruleFactory;

    public function __construct(
        \Magento\Framework\Json\Helper\Data $jsonHelper,
        \Amasty\Feed\Model\Rule\RuleFactory $ruleFactory,
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        $data = []
    ) {
        $this->jsonHelper = $jsonHelper;
        $this->ruleFactory = $ruleFactory;

        parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    }

    /**
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
     */
    protected function _construct()
    {
        $this->_init(ResourceModel\Condition::class);
        $this->setIdFieldName('entity_id');
    }

    /**
     * Initialize Promo Rules Model for conditions
     */
    private function initRules()
    {
        if (!$this->ruleModel) {
            $this->ruleModel = $this->ruleFactory->create();
            $this->ruleModel->loadPost($this->getData());
        }
    }

    /**
     * @param string $formName
     *
     * @return string
     */
    public function getConditionsFieldSetId($formName = '')
    {
        return $formName . 'rule_conditions_fieldset_' . $this->getId();
    }

    /**
     * @return \Magento\Rule\Model\Condition\Combine
     */
    public function getConditions()
    {
        $this->initRules();

        return $this->ruleModel->getConditions();
    }

    /**
     * @param \Magento\Rule\Model\Condition\Combine $conditions
     */
    public function setCondition($conditions)
    {
        $this->initRules();

        $this->ruleModel->setConditions($conditions);
    }

    /**
     * @return array
     */
    public function getFieldConditions()
    {
        $this->initRules();

        return $this->ruleModel->getConditions()->asArray();
    }

    /**
     * @return array
     */
    public function getFieldResult()
    {
        $result = $this->getData(self::COLUMN_RESULT);
        if (!$result) {
            return [];
        }

        return $this->jsonHelper->jsonDecode($result);
    }

    /**
     * @param array $data
     *
     * @return $this
     */
    public function loadPost(array $data)
    {
        if (isset($data[self::RESULT_KEY])) {
            $entityType = $data[self::RESULT_KEY]['entity_type'] ?? null;
            if ($entityType == CustomFieldType::CUSTOM_TEXT) {
                if (isset($data[self::RESULT_KEY]['custom_text'])) {
                    $data[self::RESULT_KEY]['modify'] = $data[self::RESULT_KEY]['custom_text'];
                }
            }

            if (in_array($entityType, [CustomFieldType::CUSTOM_TEXT, CustomFieldType::MERGED_ATTRIBUTES])) {
                $data[self::RESULT_KEY]['attribute'] = '';
            }

            if ($entityType != CustomFieldType::MERGED_ATTRIBUTES) {
                unset($data[self::RESULT_KEY]['merged_text']);
            }

            unset($data[self::RESULT_KEY]['entity_type']);
            unset($data[self::RESULT_KEY]['custom_text']);

            if (!isset($data[self::RESULT_KEY]['modify'])) {
                $data[self::RESULT_KEY]['modify'] = '';
            }

            $this->setData(self::COLUMN_RESULT, $this->jsonHelper->jsonEncode($data[self::RESULT_KEY]));
            unset($data[self::RESULT_KEY]);
        }

        $this->initRules();
        $this->ruleModel->loadPost($data);
        $this->setData($this->ruleModel->getData());

        return $this;
    }

    /**
     * @param int $fieldId
     *
     * @return $this
     */
    public function beforeSaveCondition($fieldId)
    {
        $this->initRules();

        $this->ruleModel->beforeSave();
        $this->setData(self::COLUMN_CONDITION, $this->ruleModel->getData(self::COLUMN_CONDITION));
        $this->setFeedFieldId($fieldId);

        return $this;
    }

    /**
     * @return int
     */
    public function getFeedFieldId()
    {
        return $this->getData(self::COLUMN_FIELD_ID);
    }

    /**
     * @param int $fieldId
     */
    public function setFeedFieldId($fieldId)
    {
        $this->setData(self::COLUMN_FIELD_ID, $fieldId);
    }
}

Spamworldpro Mini