Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/code/Magento/Review/Block/Adminhtml/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ protected function _construct()

/** @var $actionPager \Magento\Review\Helper\Action\Pager */
$actionPager = $this->_reviewActionPager;
$actionPager->setStorageId('reviews');

$reviewId = $this->getRequest()->getParam('id');
$prevId = $actionPager->getPreviousItemId($reviewId);
Expand Down
15 changes: 0 additions & 15 deletions app/code/Magento/Review/Block/Adminhtml/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,6 @@ protected function _construct()
$this->setDefaultSort('created_at');
}

/**
* Save search results
*
* @return \Magento\Backend\Block\Widget\Grid
*/
protected function _afterLoadCollection()
{
/** @var $actionPager \Magento\Review\Helper\Action\Pager */
$actionPager = $this->_reviewActionPager;
$actionPager->setStorageId('reviews');
$actionPager->setItems($this->getCollection()->getResultingIds());

return parent::_afterLoadCollection();
}

/**
* @inheritDoc
*/
Expand Down
127 changes: 30 additions & 97 deletions app/code/Magento/Review/Helper/Action/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,144 +6,77 @@

namespace Magento\Review\Helper\Action;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Review\Model\ResourceModel\Review\CollectionFactory;

/**
* Action pager helper for iterating over search results
*
* @api
* @since 100.0.2
*/
class Pager extends \Magento\Framework\App\Helper\AbstractHelper
class Pager extends AbstractHelper
{
const STORAGE_PREFIX = 'search_result_ids';

/**
* Storage id
*
* @var int
*/
protected $_storageId = null;

/**
* Array of items
* Review collection factory
*
* @var array
* @var CollectionFactory
*/
protected $_items = null;
protected $reviewCollectionFactory;

/**
* Backend session model
* Pager constructor.
*
* @var \Magento\Backend\Model\Session
*/
protected $_backendSession;

/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Backend\Model\Session $backendSession
* @param CollectionFactory $reviewCollectionFactory
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Backend\Model\Session $backendSession
CollectionFactory $reviewCollectionFactory
) {
$this->_backendSession = $backendSession;
parent::__construct($context);
$this->reviewCollectionFactory = $reviewCollectionFactory;
}

/**
* Set storage id
*
* @param int $storageId
* @return void
*/
public function setStorageId($storageId)
{
$this->_storageId = $storageId;
}

/**
* Set items to storage
*
* @param array $items
* @return $this
*/
public function setItems(array $items)
{
$this->_items = $items;
$this->_backendSession->setData($this->_getStorageKey(), $this->_items);

return $this;
}

/**
* Load stored items
*
* @return void
*/
protected function _loadItems()
{
if ($this->_items === null) {
$this->_items = (array)$this->_backendSession->getData($this->_getStorageKey());
}
}

/**
* Get next item id
* Get the next review id.
*
* @param int $id
* @return int|bool
* @return int|false
*/
public function getNextItemId($id)
{
$position = $this->_findItemPositionByValue($id);
if ($position === false || $position == count($this->_items) - 1) {
return false;
}

return $this->_items[$position + 1];
return $this->getRelativeReviewId($id, 'gt', 'ASC');
}

/**
* Get previous item id
* Get the previous review id.
*
* @param int $id
* @return int|bool
* @return int|false
*/
public function getPreviousItemId($id)
{
$position = $this->_findItemPositionByValue($id);
if ($position === false || $position == 0) {
return false;
}

return $this->_items[$position - 1];
return $this->getRelativeReviewId($id, 'lt', 'DESC');
}

/**
* Return item position based on passed in value
* Get the review id based on comparison and order.
*
* @param mixed $value
* @return int|bool
* @param int $id
* @param string $operator
* @param string $order
* @return int|false
*/
protected function _findItemPositionByValue($value)
private function getRelativeReviewId($id, $operator, $order)
{
$this->_loadItems();
return array_search($value, $this->_items);
}

/**
* Get storage key
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getStorageKey()
{
if (!$this->_storageId) {
throw new LocalizedException(__("The storage key wasn't set. Add the storage key and try again."));
}

return self::STORAGE_PREFIX . $this->_storageId;
$collection = $this->reviewCollectionFactory->create();
$collection->addFieldToFilter('main_table.review_id', [$operator => $id])
->setOrder('main_table.review_id', $order)
->setPageSize(1)
->setCurPage(1);

$item = $collection->getFirstItem();
return $item->getId() ? (int)$item->getId() : false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,30 +401,6 @@ public function getAllIds($limit = null, $offset = null)
return $this->getConnection()->fetchCol($idsSelect);
}

/**
* Get result sorted ids
*
* @return array
*/
public function getResultingIds()
{
$idsSelect = clone $this->getSelect();
$data = $this->getConnection()
->fetchAll(
$idsSelect
->reset(Select::LIMIT_COUNT)
->reset(Select::LIMIT_OFFSET)
->columns('rt.review_id')
);

return array_map(
function ($value) {
return $value['review_id'];
},
$data
);
}

/**
* Render SQL for retrieve product count
*
Expand Down
Loading