b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Glace / Lib01 / Model / Config / Backend /
Filename/home/dev2.destoffenstraat.com/app/code/Glace/Lib01/Model/Config/Backend/Unsubscribe.php
Size3.23 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified06-Apr-2021 18:06
Last accessed22-Aug-2025 17:20
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* @author Glace Team
* @copyright Copyright (c) 2019 Glace (https://www.glace.com)
* @package Glace_Lib01
*/


namespace Glace\Lib01\Model\Config\Backend;

use Glace\Lib01\Model\Source\NotificationType;

class Unsubscribe extends \Magento\Framework\App\Config\Value implements
\Magento\Framework\App\Config\Data\ProcessorInterface
{
const PATH_TO_FEED_IMAGES = 'https://notification.glace.com/';

/**
* @var \Glace\Lib01\Model\AdminNotification\Messages
*/
private $messageManager;

/**
* @var NotificationType
*/
private $notificationType;

public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
\Glace\Lib01\Model\AdminNotification\Messages $messageManager,
NotificationType $notificationType,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
$this->messageManager = $messageManager;
$this->notificationType = $notificationType;
}

public function afterSave()
{
if ($this->isValueChanged()) {
$value = explode(',', $this->getValue());
if (in_array(NotificationType::UNSUBSCRIBE_ALL, $value)) {
$changes = [NotificationType::UNSUBSCRIBE_ALL];
} else {
$oldValue = explode(',', $this->getOldValue());
$changes = array_diff($oldValue, $value);
$changes = array_diff($changes, [NotificationType::UNSUBSCRIBE_ALL]);
}

if (!empty($changes)) {
foreach ($changes as $change) {
$message = $this->generateMessage($change);
$this->messageManager->addMessage($message);
}
} else {
$this->messageManager->clear();
}
}

return parent::afterSave();
}

/**
* Process config value
*
* @param string $value
* @return string
*/
public function processValue($value)
{
return $value;
}

private function generateMessage($change)
{
$message = '';
$titles = $this->notificationType->toOptionArray();
foreach ($titles as $title) {
if ($title['value'] == $change) {
if ($change == NotificationType::UNSUBSCRIBE_ALL) {
$label = __('All Notifications');
} else {
$label = $title['label'];
}

$message = '<img src="' . $this->generateLink($change) .'"/><span>'
. __('You have successfully unsubscribed from %1.', $label) .'</span>';
break;
}
}

return $message;
}

private function generateLink($change)
{
$change = mb_strtolower($change);
return self::PATH_TO_FEED_IMAGES . $change . '.svg';
}
}