mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 17:27:36 +00:00
Fixing resetState methods so that the object's state is the same as it was when first constructed
199 lines
5.3 KiB
PHP
199 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
namespace Magento\Cms\Model\ResourceModel\Block\Grid;
|
|
|
|
use Magento\Framework\Api\Search\SearchResultInterface;
|
|
use Magento\Framework\Api\Search\AggregationInterface;
|
|
use Magento\Cms\Model\ResourceModel\Block\Collection as BlockCollection;
|
|
use Magento\Framework\App\ObjectManager;
|
|
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
|
|
use Magento\Framework\Data\Collection\EntityFactoryInterface;
|
|
use Magento\Framework\DB\Adapter\AdapterInterface;
|
|
use Magento\Framework\EntityManager\MetadataPool;
|
|
use Magento\Framework\Event\ManagerInterface;
|
|
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
|
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
/**
|
|
* Collection for displaying grid of cms blocks
|
|
*/
|
|
class Collection extends BlockCollection implements SearchResultInterface
|
|
{
|
|
/**
|
|
* @var TimezoneInterface
|
|
*/
|
|
private $timeZone;
|
|
|
|
/**
|
|
* @var AggregationInterface
|
|
*/
|
|
protected $aggregations;
|
|
|
|
/** @var string */
|
|
private $model;
|
|
|
|
/** @var string */
|
|
private $resourceModel;
|
|
|
|
/**
|
|
* @param EntityFactoryInterface $entityFactory
|
|
* @param LoggerInterface $logger
|
|
* @param FetchStrategyInterface $fetchStrategy
|
|
* @param ManagerInterface $eventManager
|
|
* @param StoreManagerInterface $storeManager
|
|
* @param MetadataPool $metadataPool
|
|
* @param string $mainTable
|
|
* @param string $eventPrefix
|
|
* @param string $eventObject
|
|
* @param string $resourceModel
|
|
* @param string $model
|
|
* @param AdapterInterface|string|null $connection
|
|
* @param AbstractDb $resource
|
|
* @param TimezoneInterface|null $timeZone
|
|
*
|
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
|
*/
|
|
public function __construct(
|
|
EntityFactoryInterface $entityFactory,
|
|
LoggerInterface $logger,
|
|
FetchStrategyInterface $fetchStrategy,
|
|
ManagerInterface $eventManager,
|
|
StoreManagerInterface $storeManager,
|
|
MetadataPool $metadataPool,
|
|
$mainTable,
|
|
$eventPrefix,
|
|
$eventObject,
|
|
$resourceModel,
|
|
$model = \Magento\Framework\View\Element\UiComponent\DataProvider\Document::class,
|
|
$connection = null,
|
|
AbstractDb $resource = null,
|
|
TimezoneInterface $timeZone = null
|
|
) {
|
|
$this->resourceModel = $resourceModel;
|
|
$this->model = $model;
|
|
parent::__construct(
|
|
$entityFactory,
|
|
$logger,
|
|
$fetchStrategy,
|
|
$eventManager,
|
|
$storeManager,
|
|
$metadataPool,
|
|
$connection,
|
|
$resource
|
|
);
|
|
$this->_eventPrefix = $eventPrefix;
|
|
$this->_eventObject = $eventObject;
|
|
$this->_init($this->model, $this->resourceModel);
|
|
$this->setMainTable($mainTable);
|
|
$this->timeZone = $timeZone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function _resetState(): void
|
|
{
|
|
parent::_resetState();
|
|
$this->_init($this->model, $this->resourceModel);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function addFieldToFilter($field, $condition = null)
|
|
{
|
|
if ($field === 'creation_time' || $field === 'update_time') {
|
|
if (is_array($condition)) {
|
|
foreach ($condition as $key => $value) {
|
|
$condition[$key] = $this->timeZone->convertConfigTimeToUtc($value);
|
|
}
|
|
}
|
|
}
|
|
|
|
return parent::addFieldToFilter($field, $condition);
|
|
}
|
|
|
|
/**
|
|
* Get aggregation interface instance
|
|
*
|
|
* @return AggregationInterface
|
|
*/
|
|
public function getAggregations()
|
|
{
|
|
return $this->aggregations;
|
|
}
|
|
|
|
/**
|
|
* Set aggregation interface instance
|
|
*
|
|
* @param AggregationInterface $aggregations
|
|
* @return $this
|
|
*/
|
|
public function setAggregations($aggregations)
|
|
{
|
|
$this->aggregations = $aggregations;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get search criteria.
|
|
*
|
|
* @return \Magento\Framework\Api\SearchCriteriaInterface|null
|
|
*/
|
|
public function getSearchCriteria()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Set search criteria.
|
|
*
|
|
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
|
|
* @return $this
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
*/
|
|
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get total count.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getTotalCount()
|
|
{
|
|
return $this->getSize();
|
|
}
|
|
|
|
/**
|
|
* Set total count.
|
|
*
|
|
* @param int $totalCount
|
|
* @return $this
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
*/
|
|
public function setTotalCount($totalCount)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set items list.
|
|
*
|
|
* @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
|
|
* @return $this
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
*/
|
|
public function setItems(array $items = null)
|
|
{
|
|
return $this;
|
|
}
|
|
}
|