Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
AbstractCollection Class Reference
Inheritance diagram for AbstractCollection:
Collection AbstractCollection AbstractDb SourceProviderInterface Collection ArrayInterface CollectionDataSourceInterface OptionSourceInterface ArgumentInterface Collection AbstractCollection AbstractCollection Collection Collection Collection Collection Collection

Public Member Functions

 setSelectCountSql (\Magento\Framework\DB\Select $countSelect)
 
 getSelectCountSql ()
 
 addAttributeToSelect ($attribute)
 
 addAttributeToFilter ($attribute, $condition=null)
 
 addAttributeToSort ($attribute, $dir='asc')
 
 setPage ($pageNum, $pageSize)
 
 getAllIds ($limit=null, $offset=null)
 
 getSearchCriteria ()
 
 setSearchCriteria (\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria=null)
 
 getTotalCount ()
 
 setTotalCount ($totalCount)
 
 setItems (array $items=null)
 
- Public Member Functions inherited from Collection
 __construct (\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, Snapshot $entitySnapshot, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource=null)
 
 fetchItem ()
 
- Public Member Functions inherited from AbstractCollection
 __construct (\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource=null)
 
 getMainTable ()
 
 setMainTable ($table)
 
 getSelect ()
 
 addFieldToSelect ($field, $alias=null)
 
 addExpressionFieldToSelect ($alias, $expression, $fields)
 
 removeFieldFromSelect ($field, $isAlias=false)
 
 removeAllFieldsFromSelect ()
 
 setModel ($model)
 
 getModelName ()
 
 setResourceModel ($model)
 
 getResourceModelName ()
 
 getResource ()
 
 getTable ($table)
 
 getAllIds ()
 
 join ($table, $cond, $cols=' *')
 
 setResetItemsDataChanged ($flag)
 
 resetItemsDataChanged ()
 
 save ()
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractDb
 __construct (EntityFactoryInterface $entityFactory, Logger $logger, FetchStrategyInterface $fetchStrategy, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null)
 
 getResource ()
 
 addBindParam ($name, $value)
 
 getIdFieldName ()
 
 setConnection (\Magento\Framework\DB\Adapter\AdapterInterface $conn)
 
 getSelect ()
 
 getConnection ()
 
 getSize ()
 
 getSelectCountSql ()
 
 getSelectSql ($stringMode=false)
 
 setOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 addOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 unshiftOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 addFieldToFilter ($field, $condition=null)
 
 distinct ($flag)
 
 load ($printQuery=false, $logQuery=false)
 
 loadWithFilter ($printQuery=false, $logQuery=false)
 
 fetchItem ()
 
 getData ()
 
 resetData ()
 
 loadData ($printQuery=false, $logQuery=false)
 
 printLogQuery ($printQuery=false, $logQuery=false, $sql=null)
 
 addFilterToMap ($filter, $alias, $group='fields')
 
 __clone ()
 
 joinExtensionAttribute (JoinDataInterface $join, JoinProcessorInterface $extensionAttributesJoinProcessor)
 
 getItemObjectClass ()
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from Collection
 __construct (EntityFactoryInterface $entityFactory)
 
 addFilter ($field, $value, $type='and')
 
 addFieldToFilter ($field, $condition)
 
 getFilter ($field)
 
 isLoaded ()
 
 getCurPage ($displacement=0)
 
 getLastPageNumber ()
 
 getPageSize ()
 
 getSize ()
 
 getFirstItem ()
 
 getLastItem ()
 
 getItems ()
 
 getColumnValues ($colName)
 
 getItemsByColumnValue ($column, $value)
 
 getItemByColumnValue ($column, $value)
 
 addItem (\Magento\Framework\DataObject $item)
 
 getAllIds ()
 
 removeItemByKey ($key)
 
 removeAllItems ()
 
 clear ()
 
 walk ($callback, array $args=[])
 
 each ($objMethod, $args=[])
 
 setDataToAll ($key, $value=null)
 
 setCurPage ($page)
 
 setPageSize ($size)
 
 setOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 setItemObjectClass ($className)
 
 getNewEmptyItem ()
 
 distinct ($flag)
 
 loadData ($printQuery=false, $logQuery=false)
 
 load ($printQuery=false, $logQuery=false)
 
 loadWithFilter ($printQuery=false, $logQuery=false)
 
 toXml ()
 
 toArray ($arrRequiredFields=[])
 
 toOptionArray ()
 
 toOptionHash ()
 
 getItemById ($idValue)
 
 getIterator ()
 
 count ()
 
 getFlag ($flag)
 
 setFlag ($flag, $value=null)
 
 hasFlag ($flag)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from SourceProviderInterface
 getIdFieldName ()
 
 addFieldToFilter ($attribute, $condition=null)
 

Protected Member Functions

 _attributeToField ($attribute)
 
 _getAllIdsSelect ($limit=null, $offset=null)
 
- Protected Member Functions inherited from Collection
 beforeAddLoadedItem (\Magento\Framework\DataObject $item)
 
- Protected Member Functions inherited from AbstractCollection
 _construct ()
 
 _initSelect ()
 
 _initSelectFields ()
 
 _getInitialFieldsToSelect ()
 
 _initInitialFieldsToSelect ()
 
 _init ($model, $resourceModel)
 
 _beforeLoad ()
 
 _afterLoad ()
 
- Protected Member Functions inherited from AbstractDb
 _setIdFieldName ($fieldName)
 
 _getItemId (\Magento\Framework\DataObject $item)
 
 _renderFilters ()
 
 _renderFiltersBefore ()
 
 _translateCondition ($field, $condition)
 
 _getMappedField ($field)
 
 _getMapper ()
 
 _getConditionSql ($fieldName, $condition)
 
 _getConditionFieldName ($fieldName)
 
 _renderOrders ()
 
 _renderLimit ()
 
 _beforeLoad ()
 
 beforeAddLoadedItem (\Magento\Framework\DataObject $item)
 
 _toOptionArray ($valueField=null, $labelField='name', $additional=[])
 
 _toOptionHash ($valueField=null, $labelField='name')
 
 _afterLoadData ()
 
 _afterLoad ()
 
 _logQuery ($sql)
 
 _reset ()
 
 _fetchAll (Select $select)
 
 _initSelect ()
 
- Protected Member Functions inherited from Collection
 _setIsLoaded ($flag=true)
 
 _addItem ($item)
 
 _getItemId (\Magento\Framework\DataObject $item)
 
 _renderFilters ()
 
 _renderOrders ()
 
 _renderLimit ()
 
 _toOptionArray ($valueField='id', $labelField='name', $additional=[])
 
 _toOptionHash ($valueField='id', $labelField='name')
 

Protected Attributes

 $_countSelect
 
 $searchCriteria
 
- Protected Attributes inherited from Collection
 $entitySnapshot
 
- Protected Attributes inherited from AbstractCollection
 $_model
 
 $_resourceModel
 
 $_resource
 
 $_fieldsToSelect = null
 
 $_initialFieldsToSelect = null
 
 $_fieldsToSelectChanged = false
 
 $_joinedTables = []
 
 $_mainTable = null
 
 $_resetItemsDataChanged = false
 
 $_eventPrefix = ''
 
 $_eventObject = ''
 
 $_eventManager = null
 
- Protected Attributes inherited from AbstractDb
 $_conn
 
 $_select
 
 $_idFieldName
 
 $_bindParams = []
 
 $_data = null
 
 $_map = null
 
 $_fetchStmt = null
 
 $_isOrdersRendered = false
 
 $_logger
 
 $extensionAttributesJoinProcessor
 
- Protected Attributes inherited from Collection
 $_items = []
 
 $_itemObjectClass = \Magento\Framework\DataObject::class
 
 $_orders = []
 
 $_filters = []
 
 $_isFiltersRendered = false
 
 $_curPage = 1
 
 $_pageSize = false
 
 $_totalRecords
 
 $_isCollectionLoaded
 
 $_flags = []
 
 $_entityFactory
 

Additional Inherited Members

- Data Fields inherited from Collection
const SORT_ORDER_ASC = 'ASC'
 
const SORT_ORDER_DESC = 'DESC'
 

Detailed Description

Flat sales abstract collection

@api @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 15 of file AbstractCollection.php.

Member Function Documentation

◆ _attributeToField()

_attributeToField (   $attribute)
protected

Check if $attribute is \Magento\Eav\Model\Entity\Attribute and convert to string field name

Parameters
string | \Magento\Eav\Model\Entity\Attribute$attribute
Returns
string
Exceptions

Definition at line 59 of file AbstractCollection.php.

60  {
61  $field = false;
62  if (is_string($attribute)) {
63  $field = $attribute;
64  } elseif ($attribute instanceof \Magento\Eav\Model\Entity\Attribute) {
65  $field = $attribute->getAttributeCode();
66  }
67  if (!$field) {
68  throw new \Magento\Framework\Exception\LocalizedException(__('We cannot determine the field name.'));
69  }
70  return $field;
71  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13

◆ _getAllIdsSelect()

_getAllIdsSelect (   $limit = null,
  $offset = null 
)
protected

Create all ids retrieving select with limitation Backward compatibility with EAV collection

Parameters
int$limit
int$offset
Returns
\Magento\Eav\Model\Entity\Collection\AbstractCollection

Definition at line 136 of file AbstractCollection.php.

137  {
138  $idsSelect = clone $this->getSelect();
139  $idsSelect->reset(\Magento\Framework\DB\Select::ORDER);
140  $idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
141  $idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
142  $idsSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
143  $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table');
144  $idsSelect->limit($limit, $offset);
145  return $idsSelect;
146  }
const ORDER
Definition: Select.php:54
const COLUMNS
Definition: Select.php:48
const LIMIT_OFFSET
Definition: Select.php:56
const LIMIT_COUNT
Definition: Select.php:55

◆ addAttributeToFilter()

addAttributeToFilter (   $attribute,
  $condition = null 
)

Specify collection select filter by attribute value Backward compatibility with EAV collection

Parameters
string | \Magento\Eav\Model\Entity\Attribute$attribute
array | int | string | null$condition
Returns
$this

Definition at line 94 of file AbstractCollection.php.

◆ addAttributeToSelect()

addAttributeToSelect (   $attribute)

Add attribute to select result set. Backward compatibility with EAV collection

Parameters
string$attribute
Returns
$this

Definition at line 80 of file AbstractCollection.php.

◆ addAttributeToSort()

addAttributeToSort (   $attribute,
  $dir = 'asc' 
)

Specify collection select order by attribute value Backward compatibility with EAV collection

Parameters
string$attribute
string$dir
Returns
$this

Definition at line 108 of file AbstractCollection.php.

109  {
110  $this->addOrder($this->_attributeToField($attribute), $dir);
111  return $this;
112  }
addOrder($field, $direction=self::SORT_ORDER_DESC)
Definition: AbstractDb.php:286

◆ getAllIds()

getAllIds (   $limit = null,
  $offset = null 
)

Retrieve all ids for collection Backward compatibility with EAV collection

Parameters
int$limit
int$offset
Returns
array

Definition at line 156 of file AbstractCollection.php.

157  {
158  return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);
159  }

◆ getSearchCriteria()

getSearchCriteria ( )

Get search criteria.

Returns
\Magento\Framework\Api\SearchCriteriaInterface|null

Definition at line 166 of file AbstractCollection.php.

◆ getSelectCountSql()

getSelectCountSql ( )

get select count sql

Returns
\Magento\Framework\DB\Select

Definition at line 44 of file AbstractCollection.php.

45  {
46  if (!$this->_countSelect instanceof \Magento\Framework\DB\Select) {
47  $this->setSelectCountSql(parent::getSelectCountSql());
48  }
49  return $this->_countSelect;
50  }
setSelectCountSql(\Magento\Framework\DB\Select $countSelect)

◆ getTotalCount()

getTotalCount ( )

Get total count.

Returns
int

Definition at line 189 of file AbstractCollection.php.

190  {
191  return $this->getSize();
192  }

◆ setItems()

setItems ( array  $items = null)

Set items list.

Parameters

Definition at line 212 of file AbstractCollection.php.

213  {
214  if (!$items) {
215  return $this;
216  }
217  foreach ($items as $item) {
218  $this->addItem($item);
219  }
220  return $this;
221  }
addItem(\Magento\Framework\DataObject $item)
Definition: Collection.php:399
$items

◆ setPage()

setPage (   $pageNum,
  $pageSize 
)

Set collection page start and records to show Backward compatibility with EAV collection

Parameters
int$pageNum
int$pageSize
Returns
$this

Definition at line 122 of file AbstractCollection.php.

123  {
124  $this->setCurPage($pageNum)->setPageSize($pageSize);
125  return $this;
126  }

◆ setSearchCriteria()

setSearchCriteria ( \Magento\Framework\Api\SearchCriteriaInterface  $searchCriteria = null)

Set search criteria.

Parameters
\Magento\Framework\Api\SearchCriteriaInterface$searchCriteria
Returns
$this @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 178 of file AbstractCollection.php.

179  {
180  $this->searchCriteria = $searchCriteria;
181  return $this;
182  }

◆ setSelectCountSql()

setSelectCountSql ( \Magento\Framework\DB\Select  $countSelect)

Set select count sql

Parameters
\Magento\Framework\DB\Select$countSelect
Returns
$this

Definition at line 33 of file AbstractCollection.php.

34  {
35  $this->_countSelect = $countSelect;
36  return $this;
37  }

◆ setTotalCount()

setTotalCount (   $totalCount)

Set total count.

Parameters
int$totalCount
Returns
$this @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 201 of file AbstractCollection.php.

202  {
203  return $this;
204  }

Field Documentation

◆ $_countSelect

$_countSelect
protected

Definition at line 20 of file AbstractCollection.php.

◆ $searchCriteria

$searchCriteria
protected

Definition at line 25 of file AbstractCollection.php.


The documentation for this class was generated from the following file: