Skip to content

Commit

Permalink
magento#26986 Remove "feature" that overrides the currentPage value
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Feb 23, 2020
1 parent a6f76f3 commit b254764
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions lib/internal/Magento/Framework/Data/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

namespace Magento\Framework\Data;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Option\ArrayInterface;

/**
Expand All @@ -25,7 +28,7 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
/**
* Collection items
*
* @var \Magento\Framework\DataObject[]
* @var DataObject[]
*/
protected $_items = [];

Expand All @@ -34,7 +37,7 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
*
* @var string
*/
protected $_itemObjectClass = \Magento\Framework\DataObject::class;
protected $_itemObjectClass = DataObject::class;

/**
* Order configuration
Expand All @@ -46,7 +49,7 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
/**
* Filters configuration
*
* @var \Magento\Framework\DataObject[]
* @var DataObject[]
*/
protected $_filters = [];

Expand Down Expand Up @@ -117,7 +120,7 @@ public function __construct(EntityFactoryInterface $entityFactory)
*/
public function addFilter($field, $value, $type = 'and')
{
$filter = new \Magento\Framework\DataObject();
$filter = new DataObject();
// implements ArrayAccess
$filter['field'] = $field;
$filter['value'] = $value;
Expand Down Expand Up @@ -163,9 +166,9 @@ public function addFilter($field, $value, $type = 'and')
*
* @param string|array $field
* @param string|int|array $condition
* @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected.
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected.
*/
public function addFieldToFilter($field, $condition)
{
Expand All @@ -182,7 +185,7 @@ public function addFieldToFilter($field, $condition)
* - array() -- get all filters
*
* @param string|string[] $field
* @return \Magento\Framework\DataObject|\Magento\Framework\DataObject[]|void
* @return DataObject|DataObject[]|void
*/
public function getFilter($field)
{
Expand Down Expand Up @@ -234,18 +237,16 @@ protected function _setIsLoaded($flag = true)
/**
* Get current collection page
*
* @param int $displacement
* @param int $displacement
* @return int
*/
public function getCurPage($displacement = 0)
{
if ($this->_curPage + $displacement < 1) {
return 1;
} elseif ($this->_curPage + $displacement > $this->getLastPageNumber()) {
return $this->getLastPageNumber();
} else {
return $this->_curPage + $displacement;
}

return $this->_curPage + $displacement;
}

/**
Expand All @@ -260,9 +261,9 @@ public function getLastPageNumber()
return 1;
} elseif ($this->_pageSize) {
return (int)ceil($collectionSize / $this->_pageSize);
} else {
return 1;
}

return 1;
}

/**
Expand Down Expand Up @@ -292,7 +293,7 @@ public function getSize()
/**
* Retrieve collection first item
*
* @return \Magento\Framework\DataObject
* @return DataObject
*/
public function getFirstItem()
{
Expand All @@ -309,7 +310,7 @@ public function getFirstItem()
/**
* Retrieve collection last item
*
* @return \Magento\Framework\DataObject
* @return DataObject
*/
public function getLastItem()
{
Expand All @@ -325,7 +326,7 @@ public function getLastItem()
/**
* Retrieve collection items
*
* @return \Magento\Framework\DataObject[]
* @return DataObject[]
*/
public function getItems()
{
Expand All @@ -336,7 +337,7 @@ public function getItems()
/**
* Retrieve field values from all items
*
* @param string $colName
* @param string $colName
* @return array
*/
public function getColumnValues($colName)
Expand All @@ -353,8 +354,8 @@ public function getColumnValues($colName)
/**
* Search all items by field value
*
* @param string $column
* @param mixed $value
* @param string $column
* @param array $value
* @return array
*/
public function getItemsByColumnValue($column, $value)
Expand All @@ -373,9 +374,9 @@ public function getItemsByColumnValue($column, $value)
/**
* Search first item by field value
*
* @param string $column
* @param mixed $value
* @return \Magento\Framework\DataObject || null
* @param string $column
* @param string|int $value
* @return DataObject|null
*/
public function getItemByColumnValue($column, $value)
{
Expand All @@ -392,11 +393,11 @@ public function getItemByColumnValue($column, $value)
/**
* Adding item to item array
*
* @param \Magento\Framework\DataObject $item
* @param DataObject $item
* @return $this
* @throws \Exception
*/
public function addItem(\Magento\Framework\DataObject $item)
public function addItem(DataObject $item)
{
$itemId = $this->_getItemId($item);

Expand All @@ -417,7 +418,7 @@ public function addItem(\Magento\Framework\DataObject $item)
/**
* Add item that has no id to collection
*
* @param \Magento\Framework\DataObject $item
* @param DataObject $item
* @return $this
*/
protected function _addItem($item)
Expand All @@ -429,10 +430,10 @@ protected function _addItem($item)
/**
* Retrieve item id
*
* @param \Magento\Framework\DataObject $item
* @return mixed
* @param DataObject $item
* @return string|int
*/
protected function _getItemId(\Magento\Framework\DataObject $item)
protected function _getItemId(DataObject $item)
{
return $item->getId();
}
Expand All @@ -454,7 +455,7 @@ public function getAllIds()
/**
* Remove item from collection by item key
*
* @param mixed $key
* @param string $key
* @return $this
*/
public function removeItemByKey($key)
Expand Down Expand Up @@ -542,8 +543,8 @@ public function each($objMethod, $args = [])
/**
* Setting data for all collection items
*
* @param mixed $key
* @param mixed $value
* @param string $key
* @param string|int|null $value
* @return $this
*/
public function setDataToAll($key, $value = null)
Expand Down Expand Up @@ -606,7 +607,7 @@ public function setOrder($field, $direction = self::SORT_ORDER_DESC)
*/
public function setItemObjectClass($className)
{
if (!is_a($className, \Magento\Framework\DataObject::class, true)) {
if (!is_a($className, DataObject::class, true)) {
throw new \InvalidArgumentException($className . ' does not extend \Magento\Framework\DataObject');
}
$this->_itemObjectClass = $className;
Expand All @@ -616,7 +617,7 @@ public function setItemObjectClass($className)
/**
* Retrieve collection empty item
*
* @return \Magento\Framework\DataObject
* @return DataObject
*/
public function getNewEmptyItem()
{
Expand Down Expand Up @@ -748,8 +749,8 @@ public function toArray($arrRequiredFields = [])
* Return items array
* array(
* $index => array(
* 'value' => mixed
* 'label' => mixed
* 'value' => string
* 'label' => string
* )
* )
*
Expand Down Expand Up @@ -815,8 +816,8 @@ protected function _toOptionHash($valueField = 'id', $labelField = 'name')
/**
* Retrieve item by id
*
* @param mixed $idValue
* @return \Magento\Framework\DataObject
* @param string|int $idValue
* @return DataObject
*/
public function getItemById($idValue)
{
Expand Down Expand Up @@ -910,7 +911,7 @@ public function __sleep()
*/
public function __wakeup()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$objectManager = ObjectManager::getInstance();
$this->_entityFactory = $objectManager->get(EntityFactoryInterface::class);
}
}

0 comments on commit b254764

Please sign in to comment.