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/extmag/shiplab/Block/Adminhtml/Configuration/Scope/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/shiplab/Block/Adminhtml/Configuration/Scope/Switcher.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\Shiplab\Block\Adminhtml\Configuration\Scope;

use Extmag\Shiplab\Model\ConfigurationCountry;
use Extmag\Shiplab\Model\ConfigurationCountryFactory;
use Extmag\Shiplab\Model\ConfigurationDirection;
use Extmag\Shiplab\Model\ConfigurationDirectionFactory;
use Extmag\Shiplab\Model\ConfigurationStore;
use Extmag\Shiplab\Model\ConfigurationStoreFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;

/**
 * Scope switcher block
 *
 * @api
 * @since 100.0.2
 */
class Switcher extends Template
{
    /**
     * URL for store switcher hint
     */
    const HINT_URL = 'https://extmag.com/help-configuration-scope';

    /**
     * Name of store variable
     *
     * @var string
     */
    protected $_defaultStoreVarName = 'store';

    /**
     * Name of direction variable
     *
     * @var string
     */
    protected $_defaultDirectionVarName = 'direction';

    /**
     * Name of country variable
     *
     * @var string
     */
    protected $_defaultCountryVarName = 'country';

    /**
     * @var array
     */
    protected $_storeIds;

    /**
     * @var bool
     */
    protected $_hasDefaultOption = true;

    /**
     * Block template filename
     *
     * @var string
     */
    protected $_template = 'Extmag_Shiplab::configuration/scope/switcher.phtml';

    /**
     * Store Factory
     *
     * @var ConfigurationStoreFactory
     */
    protected $_storeFactory;

    /**
     * Direction factory
     *
     * @var ConfigurationDirectionFactory
     */
    protected $_directionFactory;

    /**
     * Country Factory
     *
     * @var ConfigurationCountryFactory
     */
    protected $_countryFactory;

    /**
     * @param Context $context
     * @param ConfigurationStoreFactory $storeFactory
     * @param ConfigurationDirectionFactory $directionFactory
     * @param ConfigurationCountryFactory $countryFactory
     * @param array $data
     */
    public function __construct(
        Context                       $context,
        ConfigurationStoreFactory     $storeFactory,
        ConfigurationDirectionFactory $directionFactory,
        ConfigurationCountryFactory   $countryFactory,
        array                         $data = []
    ) {
        parent::__construct($context, $data);
        $this->_directionFactory = $directionFactory;
        $this->_countryFactory = $countryFactory;
        $this->_storeFactory = $storeFactory;
    }

    /**
     * @return bool
     */
    public function hasScopeSelected()
    {
        return $this->getCountryId() !== null || $this->getDirectionId() !== null || $this->getStoreId() !== null;
    }

    /**
     * @return int|null
     */
    public function getCountryId()
    {
        if (!$this->hasData('country_id')) {
            $this->setData('country_id', (int)$this->getRequest()->getParam($this->getCountryVarName()));
        }
        return $this->getData('country_id');
    }

    /**
     * @return string
     */
    public function getCountryVarName()
    {
        if ($this->hasData('direction_var_name')) {
            return (string)$this->getData('direction_var_name');
        } else {
            return $this->_defaultCountryVarName;
        }
    }

    /**
     * @return int|null
     */
    public function getDirectionId()
    {
        if (!$this->hasData('direction_id')) {
            $this->setData('direction_id', (int)$this->getRequest()->getParam($this->getDirectionVarName()));
        }
        return $this->getData('direction_id');
    }

    /**
     * @return string
     */
    public function getDirectionVarName()
    {
        if ($this->hasData('direction_var_name')) {
            return (string)$this->getData('direction_var_name');
        } else {
            return $this->_defaultDirectionVarName;
        }
    }

    /**
     * @return int|null
     */
    public function getStoreId()
    {
        if (!$this->hasData('store_id')) {
            $this->setData('store_id', (int)$this->getRequest()->getParam($this->getStoreVarName()));
        }

        return $this->getData('store_id');
    }

    /**
     * @return string
     */
    public function getStoreVarName()
    {
        if ($this->hasData('store_var_name')) {
            return (string)$this->getData('store_var_name');
        } else {
            return $this->_defaultStoreVarName;
        }
    }

    /**
     * @return string
     */
    public function getCurrentSelectionName()
    {
        if (!($name = $this->getCurrentCountryName())) {
            if (!($name = $this->getCurrentDirectionName())) {
                if (!($name = $this->getCurrentStoreName())) {
                    $name = $this->getDefaultSelectionName();
                }
            }
        }

        return $name;
    }

    /**
     * @return string
     */
    public function getCurrentCountryName()
    {
        if ($this->getCountryId() !== null) {
            $store = $this->_countryFactory->create();
            $store->load($this->getCountryId());
            if ($store->getId()) {
                return $store->getTitle();
            }
        }

        return "";
    }

    /**
     * @return string
     */
    public function getCurrentDirectionName()
    {
        if ($this->getDirectionId() !== null) {
            $group = $this->_directionFactory->create();
            $group->load($this->getDirectionId());
            if ($group->getId()) {
                return $group->getTitle();
            }
        }

        return "";
    }

    /**
     * @return string
     */
    public function getCurrentStoreName()
    {
        if ($this->getStoreId() !== null) {
            $store = $this->_storeFactory->create();
            $store->load($this->getStoreId());
            if ($store->getId()) {
                return $store->getTitle();
            }
        }

        return "";
    }

    /**
     * @param string $varName
     * @return $this
     */
    public function setStoreVarName($varName)
    {
        $this->setData('store_var_name', $varName);
        return $this;
    }

    /**
     * @param ConfigurationStore $store
     * @return bool
     */
    public function isStoreSelected(ConfigurationStore $store)
    {
        return $this->getStoreId() === $store->getId() && $this->getDirectionId() === null;
    }

    /**
     * @return ConfigurationStore[]
     */
    public function getStores()
    {
        $stores = $this->getStoreList();
        if ($storeIds = $this->getStoreIds()) {
            $stores = array_intersect_key($stores, array_flip($storeIds));
        }
        return $stores;
    }

    protected function getStoreList()
    {
        $stores = [];
        $storesCollection = $this->_storeFactory->create()->getCollection();
        if ($storesCollection && count($storesCollection) > 0) {
            foreach ($storesCollection as $store) {
                $stores[$store->getId()] = $store;
            }
        }
        return $stores;
    }

    /**
     * @param string $varName
     * @return $this
     */
    public function setDirectionVarName($varName)
    {
        $this->setData('direction_var_name', $varName);
        return $this;
    }

    /**
     * @param ConfigurationDirection $direction
     * @return bool
     */
    public function isDirectionSelected(ConfigurationDirection $direction)
    {
        return $this->getDirectionId() === $direction->getId() && $this->getDirectionId() === null;
    }

    /**
     * @param ConfigurationStore $store
     * @return ConfigurationDirection[]
     */
    public function getDirections($store)
    {
        $directions = $this->getDirectionList($store);
        if ($directionIds = $this->getDirectionIds()) {
            $directions = array_intersect_key($directions, array_flip($directionIds));
        }
        return $directions;
    }

    protected function getDirectionList($store)
    {
        $directions = [];
        $directionsCollection = $this->_directionFactory->create()->getCollection()
            ->addFieldToFilter('store_id', $store->getId());
        if ($directionsCollection && count($directionsCollection) > 0) {
            foreach ($directionsCollection as $direction) {
                $directions[$direction->getId()] = $direction;
            }
        }
        return $directions;
    }

    /**
     * @param string $varName
     * @return $this
     */
    public function setCountryVarName($varName)
    {
        $this->setData('country_type_var_name', $varName);
        return $this;
    }

    /**
     * @param ConfigurationCountry $country
     * @return bool
     */
    public function isCountrySelected(ConfigurationCountry $country)
    {
        return $this->getCountryId() === $country->getId();
    }

    /**
     * @param ConfigurationDirection $direction
     * @return ConfigurationCountry[]
     */
    public function getCountries($direction)
    {
        $countries = $this->getCountryList($direction);
        if ($countryIds = $this->getCountryIds()) {
            $countries = array_intersect_key($countries, array_flip($countryIds));
        }
        return $countries;
    }

    protected function getCountryList($direction)
    {
        $countries = [];
        $countriesCollection = $this->_countryFactory->create()->getCollection()
            ->addFieldToFilter('direction_id', $direction->getId());
        if ($countriesCollection && count($countriesCollection) > 0) {
            foreach ($countriesCollection as $country) {
                $countries[$country->getId()] = $country;
            }
        }
        return $countries;
    }

    /**
     * Set/Get whether the switcher should show default option
     *
     * @param bool $hasDefaultOption
     * @return bool
     */
    public function hasDefaultOption($hasDefaultOption = null)
    {
        if (null !== $hasDefaultOption) {
            $this->_hasDefaultOption = $hasDefaultOption;
        }
        return $this->_hasDefaultOption;
    }

    /**
     * Return store switcher hint html
     *
     * @return string
     */
    public function getHintHtml()
    {
        /*$html = '';
        $url = $this->getHintUrl();
        if ($url) {
            $html = '<div class="admin__field-tooltip tooltip">' . '<a' . ' href="' . $this->escapeUrl($url)
                . '"' . ' onclick="this.target=\'_blank\'"' . ' title="' . __(
                    'What is this?'
                ) . '"' . ' class="admin__field-tooltip-action action-help"><span>' . __(
                    'What is this?'
                ) . '</span></a></span>' . ' </div>';
        }
        return $html;*/
        return "";
    }

    /**
     * Return url for store switcher hint
     *
     * @return string
     */
    public function getHintUrl()
    {
        return self::HINT_URL;
    }

    /**
     * Get whether iframe is being used
     *
     * @return bool
     */
    public function isUsingIframe()
    {
        if ($this->hasData('is_using_iframe')) {
            return (bool)$this->getData('is_using_iframe');
        }
        return false;
    }

    /**
     * @return string
     */
    public function getSwitchUrl()
    {
        if ($url = $this->getData('switch_url')) {
            return $url;
        }
        return $this->getUrl(
            '*/*/*',
            [
                '_current' => true,
                $this->getCountryVarName() => null,
                $this->getDirectionVarName() => null,
                $this->getStoreVarName() => null,
            ]
        );
    }

    /**
     * @return void
     */
    protected function _construct()
    {
        parent::_construct();

        $this->setUseConfirm(true);
        $this->setUseAjax(true);

        $this->setShowManageStoresLink(0);

        if (!$this->hasData('switch_stores')) {
            $this->setSwitchStores(false);
        }
        if (!$this->hasData('switch_directions')) {
            $this->setSwitchDirections(false);
        }
        if (!$this->hasData('switch_country')) {
            $this->setSwitchCountriesViews(true);
        }
        $this->setDefaultSelectionName(__('All Store Views'));
    }
}

Spamworldpro Mini