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/app/code/Soon/Faq/Model/System/Config/Backend/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Soon/Faq/Model/System/Config/Backend/CategoryPrefixDynamic.php
<?php
/**
 * This file is part of Soon_Faq for Magento2.
 *
 * @license All rights reserved
 * @author Krzysztof Majkowski <[email protected]>
 * @category Soon
 * @package Soon_Faq
 * @copyright Copyright (c) 2017 Agence Soon (http://www.agence-soon.fr)
 */

namespace Soon\Faq\Model\System\Config\Backend;

use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Value;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Math\Random;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;

/**
 * Class CategoryPrefixDynamic
 * @package Soon\Faq\Model\System\Config\Backend
 */
class CategoryPrefixDynamic extends Value
{
    /**
     * @var Random
     */
    private $mathRandom = null;

    /**
     * @param Context $context
     * @param Registry $registry
     * @param ScopeConfigInterface $config
     * @param TypeListInterface $cacheTypeList
     * @param AbstractResource $resource
     * @param AbstractDb $resourceCollection
     * @param array $data
     */
    public function __construct(
        Context $context,
        Registry $registry,
        ScopeConfigInterface $config,
        TypeListInterface $cacheTypeList,
        AbstractResource $resource = null,
        AbstractDb $resourceCollection = null,
        array $data = []
    )
    {
        parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
        $this->mathRandom = new Random();
    }

    /**
     * Unserialize data after load
     */
    protected function _afterLoad()
    {
        if ($this->getValue()) {
            $value = unserialize($this->getValue());
            $result = [];

            foreach ($value as $store => $prefix) {
                $resultId = $this->mathRandom->getUniqueHash('_');
                $result[$resultId] = ['store' => $store, 'prefix' => $prefix];
            }

            $this->setValue($result);
        }
    }

    /**
     * Serialize data before save
     */
    public function beforeSave()
    {
        $value = $this->getValue();
        $data = [];

        foreach ($value as $fields) {
            if (is_array($fields) && isset($fields['store']) &&
                (!isset($data[$fields['store']]) || empty($data[$fields['store']]))
            ) {
                $data[$fields['store']] = $fields['prefix'];
            }
        }

        $this->setValue(serialize($data));
    }
}

Spamworldpro Mini