Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
|
Public Member Functions | |
__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 () | |
Data Fields | |
const | SORT_ORDER_ASC = 'ASC' |
const | SORT_ORDER_DESC = 'DESC' |
Protected Member Functions | |
_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 | |
$_items = [] | |
$_itemObjectClass = \Magento\Framework\DataObject::class | |
$_orders = [] | |
$_filters = [] | |
$_isFiltersRendered = false | |
$_curPage = 1 | |
$_pageSize = false | |
$_totalRecords | |
$_isCollectionLoaded | |
$_flags = [] | |
$_entityFactory | |
Data collection
TODO: Refactor use of \Magento\Framework\Option\ArrayInterface in library.
@api
Definition at line 19 of file Collection.php.
__construct | ( | EntityFactoryInterface | $entityFactory | ) |
EntityFactoryInterface | $entityFactory |
Definition at line 105 of file Collection.php.
__sleep | ( | ) |
__wakeup | ( | ) |
Init not serializable fields
Definition at line 904 of file Collection.php.
|
protected |
Add item that has no id to collection
\Magento\Framework\DataObject | $item |
Definition at line 422 of file Collection.php.
|
protected |
Retrieve item id
\Magento\Framework\DataObject | $item |
Definition at line 434 of file Collection.php.
|
protected |
|
protected |
|
protected |
|
protected |
Set collection loading status flag
bool | $flag |
Definition at line 228 of file Collection.php.
|
protected |
Convert items array to array for select options
return items array array( $index => array( 'value' => mixed 'label' => mixed ) )
string | $valueField | |
string | $labelField | |
array | $additional |
Definition at line 760 of file Collection.php.
|
protected |
Convert items array to hash for select options
return items hash array($value => $label)
string | $valueField | |
string | $labelField |
Definition at line 801 of file Collection.php.
addFieldToFilter | ( | $field, | |
$condition | |||
) |
Add field filter to collection
If $condition integer or string - exact value will be filtered ('eq' condition)
If $condition is array - one of the following structures is expected:
If non matched - sequential parallel arrays are expected and OR conditions will be built using above mentioned structure.
Example:$field = ['age', 'name']; $condition = [42, ['like' => 'Mage']];The above would find where age equal to 42 OR name like Mage%.
string | array | $field | |
string | int | array | $condition |
Definition at line 170 of file Collection.php.
addFilter | ( | $field, | |
$value, | |||
$type = 'and' |
|||
) |
Add collection filter
string | $field | |
string | $value | |
string | $type | and|or|string |
Definition at line 118 of file Collection.php.
addItem | ( | \Magento\Framework\DataObject | $item | ) |
Adding item to item array
\Magento\Framework\DataObject | $item |
Definition at line 399 of file Collection.php.
clear | ( | ) |
Clear collection
Definition at line 483 of file Collection.php.
count | ( | ) |
Retrieve count of collection loaded items
Definition at line 841 of file Collection.php.
distinct | ( | $flag | ) |
Set select distinct
bool | $flag |
Definition at line 662 of file Collection.php.
each | ( | $objMethod, | |
$args = [] |
|||
) |
Call method or callback on each item in the collection.
string | array | \Closure | $objMethod | |
array | $args |
Definition at line 524 of file Collection.php.
getAllIds | ( | ) |
Retrieve ids of all items
Definition at line 444 of file Collection.php.
getColumnValues | ( | $colName | ) |
Retrieve field values from all items
string | $colName |
Definition at line 342 of file Collection.php.
getCurPage | ( | $displacement = 0 | ) |
Get current collection page
int | $displacement |
Definition at line 240 of file Collection.php.
getFilter | ( | $field | ) |
Search for a filter by specified field
Multiple filters can be matched if an array is specified:
string|string[] | $field |
Definition at line 187 of file Collection.php.
getFirstItem | ( | ) |
Retrieve collection first item
Definition at line 297 of file Collection.php.
getFlag | ( | $flag | ) |
Retrieve Flag
string | $flag |
Definition at line 853 of file Collection.php.
getItemByColumnValue | ( | $column, | |
$value | |||
) |
Search first item by field value
string | $column | |
mixed | $value |
Definition at line 380 of file Collection.php.
getItemById | ( | $idValue | ) |
Retrieve item by id
mixed | $idValue |
Definition at line 816 of file Collection.php.
getItems | ( | ) |
Retrieve collection items
Definition at line 330 of file Collection.php.
getItemsByColumnValue | ( | $column, | |
$value | |||
) |
Search all items by field value
string | $column | |
mixed | $value |
Definition at line 360 of file Collection.php.
getIterator | ( | ) |
Implementation of \IteratorAggregate::getIterator()
Definition at line 830 of file Collection.php.
getLastItem | ( | ) |
Retrieve collection last item
Definition at line 314 of file Collection.php.
getLastPageNumber | ( | ) |
getNewEmptyItem | ( | ) |
Retrieve collection empty item
Definition at line 620 of file Collection.php.
getPageSize | ( | ) |
getSize | ( | ) |
Retrieve collection all items count
Definition at line 283 of file Collection.php.
hasFlag | ( | $flag | ) |
isLoaded | ( | ) |
Retrieve collection loading status
Definition at line 217 of file Collection.php.
Load data
bool | $printQuery | |
bool | $logQuery |
Definition at line 687 of file Collection.php.
Load data
bool | $printQuery | |
bool | $logQuery |
Definition at line 675 of file Collection.php.
Load data with filter in place
bool | $printQuery | |
bool | $logQuery |
Definition at line 699 of file Collection.php.
removeAllItems | ( | ) |
removeItemByKey | ( | $key | ) |
Remove item from collection by item key
mixed | $key |
Definition at line 459 of file Collection.php.
setCurPage | ( | $page | ) |
setDataToAll | ( | $key, | |
$value = null |
|||
) |
Setting data for all collection items
mixed | $key | |
mixed | $value |
Definition at line 548 of file Collection.php.
setFlag | ( | $flag, | |
$value = null |
|||
) |
Set Flag
string | $flag | |
bool | null | $value |
Definition at line 865 of file Collection.php.
setItemObjectClass | ( | $className | ) |
Set collection item class name
string | $className |
Definition at line 606 of file Collection.php.
setOrder | ( | $field, | |
$direction = self::SORT_ORDER_DESC |
|||
) |
Set select order
string | $field | |
string | $direction |
Definition at line 593 of file Collection.php.
setPageSize | ( | $size | ) |
Set collection page size
int | $size |
Definition at line 580 of file Collection.php.
toArray | ( | $arrRequiredFields = [] | ) |
Convert collection to array
array | $arrRequiredFields |
Definition at line 732 of file Collection.php.
toOptionArray | ( | ) |
Implements OptionSourceInterface.
Definition at line 778 of file Collection.php.
toOptionHash | ( | ) |
Definition at line 786 of file Collection.php.
toXml | ( | ) |
walk | ( | $callback, | |
array | $args = [] |
||
) |
Walk through the collection and run model method or external callback with optional arguments
Returns array with results of callback for each item
callable | $callback | |
array | $args |
Definition at line 500 of file Collection.php.
|
protected |
Definition at line 65 of file Collection.php.
|
protected |
Definition at line 100 of file Collection.php.
|
protected |
Definition at line 51 of file Collection.php.
|
protected |
Definition at line 95 of file Collection.php.
|
protected |
Definition at line 88 of file Collection.php.
|
protected |
Definition at line 58 of file Collection.php.
|
protected |
Definition at line 37 of file Collection.php.
|
protected |
Definition at line 30 of file Collection.php.
|
protected |
Definition at line 44 of file Collection.php.
|
protected |
Definition at line 74 of file Collection.php.
|
protected |
Definition at line 81 of file Collection.php.
const SORT_ORDER_ASC = 'ASC' |
Definition at line 21 of file Collection.php.
const SORT_ORDER_DESC = 'DESC' |
Definition at line 23 of file Collection.php.