ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsentPro
|
||||
* @copyright Copyright (c) 2025 Plumrocket Inc.
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsentPro\Model\Integration;
|
||||
|
||||
use Plumrocket\Base\Api\ConfigUtilsInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
use Plumrocket\GlobalPrivacyControl\Helper\Config as GlobalPrivacyControlConfig;
|
||||
use Plumrocket\CookieConsentPro\Model\Config\Source\CookieCategories;
|
||||
use \Plumrocket\CookieConsentPro\Model\Config\Source\GlobalPrivacyControl\CookieConsentBehavior;
|
||||
|
||||
/**
|
||||
* @since 1.0.1
|
||||
*/
|
||||
class GlobalPrivacyControl
|
||||
{
|
||||
public const XML_PATH_COOKIE_CONSENT_BEHAVIOR = 'pr_gpc/cookie_consent_management/behavior';
|
||||
public const XML_PATH_COOKIE_CATEGORIES_TO_DECLINE = 'pr_gpc/cookie_consent_management/categories_to_decline';
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsentPro\Model\Config\Source\CookieCategories
|
||||
*/
|
||||
private $cookieCategories;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config
|
||||
*/
|
||||
private $globalPrivacyControlConfig;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
|
||||
*/
|
||||
private $configUtils;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Plumrocket\CookieConsentPro\Model\Config\Source\CookieCategories $cookieCategories
|
||||
* @param \Plumrocket\GlobalPrivacyControl\Helper\Config $globalPrivacyControlConfig
|
||||
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
CookieCategories $cookieCategories,
|
||||
GlobalPrivacyControlConfig $globalPrivacyControlConfig,
|
||||
ConfigUtilsInterface $configUtils
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->cookieCategories = $cookieCategories;
|
||||
$this->globalPrivacyControlConfig = $globalPrivacyControlConfig;
|
||||
$this->configUtils = $configUtils;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
if (! $this->config->isModuleEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->globalPrivacyControlConfig->isModuleEnabled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $store
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldDeclineAllCategories($store = null): bool
|
||||
{
|
||||
return CookieConsentBehavior::DECLINE_ALL_CATEGORIES === $this->configUtils->getStoreConfig(self::XML_PATH_COOKIE_CONSENT_BEHAVIOR, $store);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get non-essential cookie categories to decline
|
||||
*
|
||||
* @param null $store
|
||||
* @return array
|
||||
*/
|
||||
public function getCategoriesToDecline($store = null): array
|
||||
{
|
||||
$categoriesToDecline = $this->shouldDeclineAllCategories()
|
||||
? array_keys($this->cookieCategories->toOptionHash())
|
||||
: $this->configUtils->prepareMultiselectValue(
|
||||
$this->configUtils->getStoreConfig(self::XML_PATH_COOKIE_CATEGORIES_TO_DECLINE, $store)
|
||||
);
|
||||
|
||||
$essentialCategories = [];
|
||||
foreach ($this->cookieCategories->toOptionArray() as $option) {
|
||||
if ($option['isEssential']) {
|
||||
$essentialCategories[] = $option['value'];
|
||||
}
|
||||
}
|
||||
|
||||
return array_diff($categoriesToDecline, $essentialCategories);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user