![]() 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/base/Controller/Adminhtml/Notification/ |
<?php /** * @author Amasty Team * @copyright Copyright (c) Amasty (https://www.amasty.com) * @package Magento 2 Base Package */ namespace Amasty\Base\Controller\Adminhtml\Notification; use Amasty\Base\Model\Config; use Magento\Backend\App\Action; use Magento\Framework\Controller\Result\Redirect; class Frequency extends Action { /** * @var Config */ private $config; /** * @var \Amasty\Base\Model\Source\Frequency */ private $frequency; public function __construct( Action\Context $context, Config $config, \Amasty\Base\Model\Source\Frequency $frequency ) { parent::__construct($context); $this->config = $config; $this->frequency = $frequency; } /** * @return Redirect */ public function execute() { $action = $this->getRequest()->getParam('action'); switch ($action) { case 'less': $this->increaseFrequency(); break; case 'more': $this->decreaseFrequency(); break; default: $this->messageManager->addErrorMessage( __( 'An error occurred while changing the frequency.' ) ); } $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setRefererUrl(); } protected function _isAllowed() { return $this->_authorization->isAllowed( 'Amasty_Base::config' ); } protected function decreaseFrequency() { $currentValue = $this->config->getCurrentFrequencyValue(); $allValues = $this->frequency->toOptionArray(); $resultValue = null; foreach ($allValues as $option) { if ($option['value'] != $currentValue) { $resultValue = $option['value']; } else { if ($resultValue) { $this->config->changeFrequency((int)$resultValue); } break; } } $this->messageManager->addSuccessMessage( __( 'You will get more messages of this type. Notification frequency has been updated.' ) ); } protected function increaseFrequency() { $currentValue = $this->config->getCurrentFrequencyValue(); $allValues = $this->frequency->toOptionArray(); $resultValue = null; foreach ($allValues as $option) { if ($option['value'] == $currentValue) { $resultValue = $option['value']; } if ($resultValue && $option['value'] != $resultValue) { $this->config->changeFrequency((int)$option['value']);//save next option break; } } $this->messageManager->addSuccessMessage( __( 'You will get less messages of this type. Notification frequency has been updated.' ) ); } }