ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
<?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\Ui\DataProvider\AbstractListing;
|
||||
|
||||
use Magento\Framework\Api\Filter;
|
||||
use Magento\Ui\DataProvider\AbstractDataProvider;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class DataProvider extends AbstractDataProvider
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Ui\DataProvider\AddFieldToCollectionInterface[]
|
||||
*/
|
||||
private $addFieldStrategies;
|
||||
|
||||
/**
|
||||
* @var \Magento\Ui\DataProvider\AddFilterToCollectionInterface[]
|
||||
*/
|
||||
private $addFilterStrategies;
|
||||
|
||||
/**
|
||||
* AbstractDataProvider constructor.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $primaryFieldName
|
||||
* @param string $requestFieldName
|
||||
* @param array $addFieldStrategies
|
||||
* @param array $addFilterStrategies
|
||||
* @param array $meta
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
$name,
|
||||
$primaryFieldName,
|
||||
$requestFieldName,
|
||||
array $addFieldStrategies = [],
|
||||
array $addFilterStrategies = [],
|
||||
array $meta = [],
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
|
||||
$this->addFieldStrategies = $addFieldStrategies;
|
||||
$this->addFilterStrategies = $addFilterStrategies;
|
||||
}
|
||||
/**
|
||||
* Get data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
if (! $this->getCollection()->isLoaded()) {
|
||||
$this->getCollection()->load();
|
||||
}
|
||||
|
||||
$items = $this->getCollection()->toArray();
|
||||
$items = array_map(static function ($item) {
|
||||
$item['id'] = $item['entity_id'];
|
||||
$item['id_field_name'] = 'id';
|
||||
return $item;
|
||||
}, $items);
|
||||
|
||||
return [
|
||||
'totalRecords' => $this->getCollection()->getSize(),
|
||||
'items' => array_values($items),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add field to select
|
||||
*
|
||||
* @param string|array $field
|
||||
* @param string|null $alias
|
||||
* @return void
|
||||
*/
|
||||
public function addField($field, $alias = null)
|
||||
{
|
||||
if (isset($this->addFieldStrategies[$field])) {
|
||||
$this->addFieldStrategies[$field]->addField($this->getCollection(), $field, $alias);
|
||||
} else {
|
||||
parent::addField($field, $alias);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
if (isset($this->addFilterStrategies[$filter->getField()])) {
|
||||
$this->addFilterStrategies[$filter->getField()]
|
||||
->addFilter(
|
||||
$this->getCollection(),
|
||||
$filter->getField(),
|
||||
[$filter->getConditionType() => $filter->getValue()]
|
||||
);
|
||||
} else {
|
||||
parent::addFilter($filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user