212 lines
6.6 KiB
PHP
212 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* @package Plumrocket_CookieConsent
|
|
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
|
* @license https://plumrocket.com/license End-user License Agreement
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Plumrocket\CookieConsent\Helper\Config;
|
|
|
|
use Magento\Framework\App\Helper\AbstractHelper;
|
|
use Magento\Framework\App\Helper\Context;
|
|
use Plumrocket\Base\Model\ConfigUtils;
|
|
use Plumrocket\CookieConsent\Model\Config\Source\SettingsPanelDisplayStyle;
|
|
|
|
/**
|
|
* @since 1.0.0
|
|
*/
|
|
class SettingsBar extends AbstractHelper
|
|
{
|
|
public const XML_PATH_DISPLAY_STYLE = 'pr_cookie/settings_bar/display_style';
|
|
public const XML_PATH_OVERVIEW_TITLE = 'pr_cookie/settings_bar/overview_title';
|
|
public const XML_PATH_OVERVIEW_TEXT = 'pr_cookie/settings_bar/overview_text';
|
|
public const XML_PATH_TEXT_COLOR = 'pr_cookie/settings_bar/text_color';
|
|
public const XML_PATH_BACKGROUND_COLOR = 'pr_cookie/settings_bar/background_color';
|
|
|
|
public const XML_PATH_CONSENT_TITLE = 'pr_cookie/settings_bar/header';
|
|
public const XML_PATH_ESSENTIAL_CATEGORY_STATUS = 'pr_cookie/settings_bar/essential_category_status';
|
|
public const XML_PATH_SHOW_COOKIE_DETAILS = 'pr_cookie/settings_bar/show_details';
|
|
public const XML_PATH_COOKIE_DETAILS_LINK = 'pr_cookie/settings_bar/cookie_details_link';
|
|
|
|
public const XML_PATH_ACCEPT_BUTTON_GROUP = 'pr_cookie/settings_bar/accept_button';
|
|
public const XML_PATH_DECLINE_BUTTON_GROUP = 'pr_cookie/settings_bar/decline_button';
|
|
public const XML_PATH_CONFIRM_BUTTON_GROUP = 'pr_cookie/settings_bar/confirm_button';
|
|
|
|
/**
|
|
* @var \Plumrocket\Base\Model\ConfigUtils
|
|
*/
|
|
private $configUtils;
|
|
|
|
/**
|
|
* @param \Magento\Framework\App\Helper\Context $context
|
|
* @param \Plumrocket\Base\Model\ConfigUtils $configUtils
|
|
*/
|
|
public function __construct(
|
|
Context $context,
|
|
ConfigUtils $configUtils
|
|
) {
|
|
parent::__construct($context);
|
|
$this->configUtils = $configUtils;
|
|
}
|
|
|
|
/**
|
|
* Retrieve display style of panel.
|
|
*
|
|
* @param int|string|null $store
|
|
* @return string
|
|
*/
|
|
public function getDisplayStyle($store = null): string
|
|
{
|
|
return (string) $this->configUtils->getStoreConfig(self::XML_PATH_DISPLAY_STYLE, $store)
|
|
?: SettingsPanelDisplayStyle::LEFT_BAR;
|
|
}
|
|
|
|
/**
|
|
* Get overview title.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return string
|
|
*/
|
|
public function getOverviewTitle($store = null, ?string $scope = null): string
|
|
{
|
|
return (string) $this->configUtils->getConfig(self::XML_PATH_OVERVIEW_TITLE, $store, $scope);
|
|
}
|
|
|
|
/**
|
|
* Get overview text.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return string
|
|
*/
|
|
public function getOverviewText($store = null, ?string $scope = null): string
|
|
{
|
|
return (string) $this->configUtils->getConfig(self::XML_PATH_OVERVIEW_TEXT, $store, $scope);
|
|
}
|
|
|
|
/**
|
|
* Get panel text color.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return string
|
|
*/
|
|
public function getTextColor($store = null, ?string $scope = null): string
|
|
{
|
|
return (string) $this->configUtils->getConfig(self::XML_PATH_TEXT_COLOR, $store, $scope);
|
|
}
|
|
|
|
/**
|
|
* Get panel background color.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return string
|
|
*/
|
|
public function getBackgroundColor($store = null, ?string $scope = null): string
|
|
{
|
|
return (string) $this->configUtils->getConfig(self::XML_PATH_BACKGROUND_COLOR, $store, $scope);
|
|
}
|
|
|
|
/**
|
|
* Get Consent Settings Header.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return string
|
|
*/
|
|
public function getConsentPreferencesHeader($store = null, ?string $scope = null): string
|
|
{
|
|
return trim((string) $this->configUtils->getConfig(self::XML_PATH_CONSENT_TITLE, $store, $scope));
|
|
}
|
|
|
|
/**
|
|
* Get status title.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return string
|
|
*/
|
|
public function getEssentialCategoryStatus($store = null, ?string $scope = null): string
|
|
{
|
|
return trim((string) $this->configUtils->getConfig(self::XML_PATH_ESSENTIAL_CATEGORY_STATUS, $store, $scope));
|
|
}
|
|
|
|
/**
|
|
* Check if if can show cookie details.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return bool
|
|
*/
|
|
public function canShowCookieDetails($store = null, ?string $scope = null): bool
|
|
{
|
|
return $this->configUtils->isSetFlag(self::XML_PATH_SHOW_COOKIE_DETAILS, $store, $scope);
|
|
}
|
|
|
|
/**
|
|
* Get Cookie Details Title.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return string
|
|
*/
|
|
public function getCookieDetailsLinkTitle($store = null, ?string $scope = null): string
|
|
{
|
|
return trim((string) $this->configUtils->getConfig(self::XML_PATH_COOKIE_DETAILS_LINK, $store, $scope));
|
|
}
|
|
|
|
/**
|
|
* Get configs for accept button.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return array
|
|
*/
|
|
public function getAcceptButtonConfig($store = null, ?string $scope = null): array
|
|
{
|
|
return (array) $this->configUtils->getConfig(self::XML_PATH_ACCEPT_BUTTON_GROUP, $store, $scope);
|
|
}
|
|
|
|
/**
|
|
* Get configs for decline button.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return array
|
|
*/
|
|
public function getDeclineButtonConfig($store = null, ?string $scope = null): array
|
|
{
|
|
return (array) $this->configUtils->getConfig(self::XML_PATH_DECLINE_BUTTON_GROUP, $store, $scope);
|
|
}
|
|
|
|
/**
|
|
* Get configs for confirm button.
|
|
*
|
|
* @param string|int|null $store
|
|
* @param string|null $scope
|
|
* @return array
|
|
*/
|
|
public function getConfirmButtonConfig($store = null, ?string $scope = null): array
|
|
{
|
|
return (array) $this->configUtils->getConfig(self::XML_PATH_CONFIRM_BUTTON_GROUP, $store, $scope);
|
|
}
|
|
|
|
/**
|
|
* Get template for settings panel.
|
|
*
|
|
* @param string|int|null $store
|
|
* @return string
|
|
*/
|
|
public function getJsComponentTemplate($store = null): string
|
|
{
|
|
if ($this->getDisplayStyle($store) === SettingsPanelDisplayStyle::ACCORDION_POPUP) {
|
|
return 'Plumrocket_CookieConsent/settings/accordion-popup';
|
|
}
|
|
return 'Plumrocket_CookieConsent/settings/left-bar';
|
|
}
|
|
}
|