ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Model\Cookie\Attribute;
|
||||
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
|
||||
class DurationDecorator implements OptionSourceInterface
|
||||
{
|
||||
public const PERIOD_DAYS = 'days';
|
||||
public const PERIOD_HOURS = 'hours';
|
||||
public const PERIOD_MINUTES = 'minutes';
|
||||
public const PERIOD_SECONDS = 'seconds';
|
||||
|
||||
public const DURATION_PERIOD = 'duration-period';
|
||||
|
||||
public const PERIODS = [
|
||||
self::PERIOD_DAYS => 86400,
|
||||
self::PERIOD_HOURS => 3600,
|
||||
self::PERIOD_MINUTES => 60,
|
||||
];
|
||||
|
||||
/**
|
||||
* Serialize two duration fields into one
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function serializeParams(array $data): array
|
||||
{
|
||||
if ($data[CookieInterface::DURATION]) {
|
||||
$duration = $data[CookieInterface::DURATION];
|
||||
$period = $data[self::DURATION_PERIOD];
|
||||
switch ($period) {
|
||||
case self::PERIOD_DAYS:
|
||||
$data[CookieInterface::DURATION] = self::PERIODS[self::PERIOD_DAYS] * $duration;
|
||||
break;
|
||||
case self::PERIOD_HOURS:
|
||||
$data[CookieInterface::DURATION] = self::PERIODS[self::PERIOD_HOURS] * $duration;
|
||||
break;
|
||||
case self::PERIOD_MINUTES:
|
||||
$data[CookieInterface::DURATION] = self::PERIODS[self::PERIOD_MINUTES] * $duration;
|
||||
break;
|
||||
case self::PERIOD_SECONDS:
|
||||
$data[CookieInterface::DURATION] = $duration;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unset($data[self::DURATION_PERIOD]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function unserializeParams(array $data): array
|
||||
{
|
||||
return array_merge($data, $this->getValues(
|
||||
(int) ($data[CookieInterface::DURATION] ?? 0)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate values for 'duration' and 'duration-select'
|
||||
*
|
||||
* @param int $durationInSeconds
|
||||
* @return array
|
||||
*/
|
||||
private function getValues(int $durationInSeconds): array
|
||||
{
|
||||
if ($durationInSeconds) {
|
||||
foreach (self::PERIODS as $optionName => $periodInSeconds) {
|
||||
if (! ($durationInSeconds % $periodInSeconds)) {
|
||||
return [
|
||||
CookieInterface::DURATION => $durationInSeconds / $periodInSeconds,
|
||||
self::DURATION_PERIOD => $optionName,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
CookieInterface::DURATION => $durationInSeconds,
|
||||
self::DURATION_PERIOD => self::PERIOD_SECONDS,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
CookieInterface::DURATION => 0,
|
||||
self::DURATION_PERIOD => self::PERIOD_DAYS,
|
||||
];
|
||||
}
|
||||
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => self::PERIOD_SECONDS,
|
||||
'label' => __('seconds')
|
||||
],
|
||||
[
|
||||
'value' => self::PERIOD_MINUTES,
|
||||
'label' => __('minutes')
|
||||
],
|
||||
[
|
||||
'value' => self::PERIOD_HOURS,
|
||||
'label' => __('hours')
|
||||
],
|
||||
[
|
||||
'value' => self::PERIOD_DAYS,
|
||||
'label' => __('days')
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Model\Cookie\Attribute\Source;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource as EavAbstractSource;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CategoryKey extends EavAbstractSource
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
|
||||
*/
|
||||
private $categoryRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
private $optionHash;
|
||||
|
||||
/**
|
||||
* CategoryKey constructor.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $categoryRepository
|
||||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
*/
|
||||
public function __construct(
|
||||
CategoryRepositoryInterface $categoryRepository,
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
) {
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAllOptions(): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($this->toOptionHash() as $key => $value) {
|
||||
$result[] = [
|
||||
'value' => $key,
|
||||
'label' => $value,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of options
|
||||
*
|
||||
* @return array Format: array(array('<value>' => '<label>'), ...)
|
||||
*/
|
||||
public function toOptionHash(): array
|
||||
{
|
||||
if (null === $this->optionHash) {
|
||||
$categories = $this->categoryRepository
|
||||
->getList($this->searchCriteriaBuilder->create())
|
||||
->getItems();
|
||||
|
||||
$this->optionHash = ['' => __('--Please Select--')];
|
||||
foreach ($categories as $category) {
|
||||
$this->optionHash[$category->getKey()] = $category->getName();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->optionHash;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Model\Cookie\Attribute\Source;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource as EavAbstractSource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Type extends EavAbstractSource
|
||||
{
|
||||
public const TYPE_FIRST = 'first';
|
||||
public const TYPE_THIRD = 'third';
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAllOptions(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => self::TYPE_FIRST,
|
||||
'label' => __('1st Party')
|
||||
],
|
||||
[
|
||||
'value' => self::TYPE_THIRD,
|
||||
'label' => __('3rd Party')
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user