Documentation

Collection
in package
implements IteratorAggregate, Countable

Table of Contents

Interfaces

IteratorAggregate
Countable

Constants

SORT_ORDER_ASC  : mixed = 'ASC'
SORT_ORDER_DESC  : mixed = 'DESC'

Properties

$_cacheKey  : mixed
$_cacheLifetime  : mixed
$_cacheTags  : mixed
$_curPage  : int|null
Current page number for items pager
$_filters  : array<string|int, mixed>
Filters configuration
$_flags  : array<string|int, mixed>
Additional collection flags
$_isCollectionLoaded  : bool
Loading state flag
$_isFiltersRendered  : bool
Filter rendered flag
$_itemObjectClass  : string
Item object class name
$_items  : array<string|int, mixed>
Collection items
$_orders  : array<string|int, mixed>
Order configuration
$_pageSize  : int|false|null
Pager page size
$_totalRecords  : int|null
Total items number

Methods

__construct()  : mixed
addFilter()  : $this
Add collection filter
addItem()  : $this
Adding item to item array
clear()  : $this
Clear collection
count()  : int
Retrieve count of collection loaded items
distinct()  : $this
Set select distinct
each()  : void
getAllIds()  : array<string|int, mixed>
Retrieve ids of all tems
getCacheKey()  : string
getCacheLifetime()  : int
getCacheTags()  : array<string|int, mixed>
getColumnValues()  : array<string|int, mixed>
Retrieve field values from all items
getCurPage()  : int
Get current collection page
getFilter()  : DataObject|array<string|int, mixed>|null
Search for a filter by specified field
getFirstItem()  : DataObject
Retrieve collection first item
getFlag()  : mixed
Retrieve Flag
getItemByColumnValue()  : DataObject|null
Search first item by field value
getItemById()  : DataObject|null
Retrieve item by id
getItems()  : array<string|int, mixed>
Retrieve collection items
getItemsByColumnValue()  : array<string|int, mixed>
Search all items by field value
getIterator()  : mixed
Implementation of IteratorAggregate::getIterator()
getLastItem()  : DataObject
Retrieve collection last item
getLastPageNumber()  : int
Retrieve collection last page number
getNewEmptyItem()  : DataObject
Retrieve collection empty item
getPageSize()  : int
Retrieve collection page size
getSize()  : int
Retrieve collection all items count
hasFlag()  : bool
Has Flag
isLoaded()  : bool
Retrieve collection loading status
load()  : $this
Load data
loadData()  : $this
Load data
removeItemByKey()  : $this
Remove item from collection by item key
setCacheKey()  : $this
setCacheTags()  : $this
setCurPage()  : $this
Set current page
setDataToAll()  : $this
Setting data for all collection items
setFlag()  : $this
Set Flag
setItemObjectClass()  : $this
Set collection item class name
setOrder()  : $this
Set select order
setPageSize()  : $this
Set collection page size
toArray()  : array<string|int, mixed>
Convert collection to array
toOptionArray()  : array<string|int, mixed>
toOptionHash()  : array<string|int, mixed>
toXml()  : string
Convert collection to XML
walk()  : array<string|int, mixed>
Walk through the collection and run model method or external callback with optional arguments
_addItem()  : $this
Add item that has no id to collection
_getItemId()  : mixed
Retrieve item id
_renderFilters()  : Collection
Render sql select conditions
_renderLimit()  : Collection
Render sql select limit
_renderOrders()  : Collection
Render sql select orders
_setIsLoaded()  : $this
Set collection loading status flag
_toOptionArray()  : array<string|int, mixed>
Convert items array to array for select options
_toOptionHash()  : array<string|int, mixed>
Convert items array to hash for select options

Constants

SORT_ORDER_ASC

public mixed SORT_ORDER_ASC = 'ASC'

SORT_ORDER_DESC

public mixed SORT_ORDER_DESC = 'DESC'

Properties

$_cacheLifetime

protected mixed $_cacheLifetime = 86400

$_curPage

Current page number for items pager

protected int|null $_curPage = 1

$_filters

Filters configuration

protected array<string|int, mixed> $_filters = []

$_flags

Additional collection flags

protected array<string|int, mixed> $_flags = []

$_isCollectionLoaded

Loading state flag

protected bool $_isCollectionLoaded

$_isFiltersRendered

Filter rendered flag

protected bool $_isFiltersRendered = false

$_itemObjectClass

Item object class name

protected string $_itemObjectClass = \Maho\DataObject::class

$_items

Collection items

protected array<string|int, mixed> $_items = []

$_orders

Order configuration

protected array<string|int, mixed> $_orders = []

$_pageSize

Pager page size

protected int|false|null $_pageSize = false

if page size is false, then we works with all items

$_totalRecords

Total items number

protected int|null $_totalRecords

Methods

addFilter()

Add collection filter

public addFilter(string $field, string|array<string|int, mixed> $value[, string $type = 'and' ]) : $this
Parameters
$field : string
$value : string|array<string|int, mixed>
$type : string = 'and'

and|or|string

Return values
$this

clear()

Clear collection

public clear() : $this
Return values
$this

count()

Retrieve count of collection loaded items

public count() : int
Attributes
#[Override]
#[ReturnTypeWillChange]
Return values
int

distinct()

Set select distinct

public distinct(bool $flag) : $this
Parameters
$flag : bool
Return values
$this

each()

public each(callable $obj_method[, array<string|int, mixed> $args = [] ]) : void
Parameters
$obj_method : callable
$args : array<string|int, mixed> = []

getAllIds()

Retrieve ids of all tems

public getAllIds() : array<string|int, mixed>
Return values
array<string|int, mixed>

getCacheKey()

public getCacheKey() : string
Return values
string

getCacheLifetime()

public getCacheLifetime() : int
Return values
int

getCacheTags()

public getCacheTags() : array<string|int, mixed>
Return values
array<string|int, mixed>

getColumnValues()

Retrieve field values from all items

public getColumnValues(string $colName) : array<string|int, mixed>
Parameters
$colName : string
Return values
array<string|int, mixed>

getCurPage()

Get current collection page

public getCurPage([int $displacement = 0 ]) : int
Parameters
$displacement : int = 0
Return values
int

getFilter()

Search for a filter by specified field

public getFilter(string|array<string|int, mixed> $field) : DataObject|array<string|int, mixed>|null

Multiple filters can be matched if an array is specified:

  • 'foo' -- get the first filter with field name 'foo'
  • array('foo') -- get all filters with field name 'foo'
  • array('foo', 'bar') -- get all filters with field name 'foo' or 'bar'
  • array() -- get all filters
Parameters
$field : string|array<string|int, mixed>
Return values
DataObject|array<string|int, mixed>|null

getFlag()

Retrieve Flag

public getFlag(string $flag) : mixed
Parameters
$flag : string

getItemByColumnValue()

Search first item by field value

public getItemByColumnValue(string $column, mixed $value) : DataObject|null
Parameters
$column : string
$value : mixed
Return values
DataObject|null

getItems()

Retrieve collection items

public getItems() : array<string|int, mixed>
Return values
array<string|int, mixed>

getItemsByColumnValue()

Search all items by field value

public getItemsByColumnValue(string $column, mixed $value) : array<string|int, mixed>
Parameters
$column : string
$value : mixed
Return values
array<string|int, mixed>

getIterator()

Implementation of IteratorAggregate::getIterator()

public getIterator() : mixed
Attributes
#[Override]
#[ReturnTypeWillChange]

getLastPageNumber()

Retrieve collection last page number

public getLastPageNumber() : int
Return values
int

getPageSize()

Retrieve collection page size

public getPageSize() : int
Return values
int

getSize()

Retrieve collection all items count

public getSize() : int
Return values
int

hasFlag()

Has Flag

public hasFlag(string $flag) : bool
Parameters
$flag : string
Return values
bool

isLoaded()

Retrieve collection loading status

public isLoaded() : bool
Return values
bool

load()

Load data

public load([bool $printQuery = false ][, bool $logQuery = false ]) : $this
Parameters
$printQuery : bool = false
$logQuery : bool = false
Return values
$this

loadData()

Load data

public loadData([bool $printQuery = false ][, bool $logQuery = false ]) : $this
Parameters
$printQuery : bool = false
$logQuery : bool = false
Return values
$this

removeItemByKey()

Remove item from collection by item key

public removeItemByKey(mixed $key) : $this
Parameters
$key : mixed
Return values
$this

setCacheKey()

public setCacheKey(string $key) : $this
Parameters
$key : string
Return values
$this

setCacheTags()

public setCacheTags(array<string|int, mixed> $tags) : $this
Parameters
$tags : array<string|int, mixed>
Return values
$this

setCurPage()

Set current page

public setCurPage(int|null $page) : $this
Parameters
$page : int|null
Return values
$this

setDataToAll()

Setting data for all collection items

public setDataToAll(mixed $key[, mixed $value = null ]) : $this
Parameters
$key : mixed
$value : mixed = null
Return values
$this

setFlag()

Set Flag

public setFlag(string $flag[, mixed $value = null ]) : $this
Parameters
$flag : string
$value : mixed = null
Return values
$this

setItemObjectClass()

Set collection item class name

public setItemObjectClass(string $className) : $this
Parameters
$className : string
Return values
$this

setOrder()

Set select order

public setOrder(string $field[, string $direction = self::SORT_ORDER_DESC ]) : $this
Parameters
$field : string
$direction : string = self::SORT_ORDER_DESC
Return values
$this

setPageSize()

Set collection page size

public setPageSize(int|null $size) : $this
Parameters
$size : int|null
Return values
$this

toArray()

Convert collection to array

public toArray([array<string|int, mixed> $arrRequiredFields = [] ]) : array<string|int, mixed>
Parameters
$arrRequiredFields : array<string|int, mixed> = []
Return values
array<string|int, mixed>

toOptionArray()

public toOptionArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

toOptionHash()

public toOptionHash() : array<string|int, mixed>
Return values
array<string|int, mixed>

toXml()

Convert collection to XML

public toXml() : string
Return values
string

walk()

Walk through the collection and run model method or external callback with optional arguments

public walk(string|callable $callback[, array<string|int, mixed> $args = [] ]) : array<string|int, mixed>

Returns array with results of callback for each item

Parameters
$callback : string|callable
$args : array<string|int, mixed> = []
Return values
array<string|int, mixed>

_setIsLoaded()

Set collection loading status flag

protected _setIsLoaded([bool $flag = true ]) : $this
Parameters
$flag : bool = true
Return values
$this

_toOptionArray()

Convert items array to array for select options

protected _toOptionArray([string $valueField = 'id' ][, string $labelField = 'name' ][, array<string|int, mixed> $additional = [] ]) : array<string|int, mixed>

return items array array( $index => array( 'value' => mixed 'label' => mixed ) )

Parameters
$valueField : string = 'id'
$labelField : string = 'name'
$additional : array<string|int, mixed> = []
Return values
array<string|int, mixed>

_toOptionHash()

Convert items array to hash for select options

protected _toOptionHash([string $valueField = 'id' ][, string $labelField = 'name' ]) : array<string|int, mixed>

return items hash array($value => $label)

Parameters
$valueField : string = 'id'
$labelField : string = 'name'
Return values
array<string|int, mixed>
On this page

Search results