PHP Class Webiny\Component\Entity\EntityCollection

Inheritance: implements IteratorAggregate, implements ArrayAccess, implements Countable, use trait Webiny\Component\Mongo\MongoTrait, use trait Webiny\Component\StdLib\StdLibTrait
Show file Open project: Webiny/Framework

Public Methods

Method Description
__construct ( string $entityClass, array $data = [], array $parameters = [] )
__toString ( ) : mixed | null | string Get string of masked entity values when array of instances is being converted to string
contains ( string | AbstractEntity $item ) : boolean Check if given item is already in the data set.
NOTE: this triggers loading of data from database if not yet loaded
count ( ) : mixed Count items in entity collection
delete ( ) : boolean Delete all items in the result set (WARNING: removes data from database)
first ( ) : AbstractEntity | null Gets first entity in collection
getData ( ) : array Get collection data
getIterator ( )
getLimit ( )
getOffset ( )
last ( ) : AbstractEntity | null Gets last entity in collection
offsetExists ( $offset )
offsetGet ( $offset )
offsetSet ( $offset, $value )
offsetUnset ( $offset )
randomize ( ) Shuffle values (useful when you want to fetch a random value)
removeItem ( $item ) Remove item from data set
toArray ( string $fields = '' ) : array Convert EntityCollection to array.
totalCount ( ) : mixed Count total number of items in collection

Protected Methods

Method Description
normalizeValue ( array | AbstractEntity $item, boolean $fromDb = false ) : AbstractEntity Normalize value to always be an instance of AbstractEntity

Method Details

__construct() public method

public __construct ( string $entityClass, array $data = [], array $parameters = [] )
$entityClass string Entity class
$data array Array of data to be converted to EntityCollection
$parameters array Parameters used to load given data

__toString() public method

Get string of masked entity values when array of instances is being converted to string
public __toString ( ) : mixed | null | string
return mixed | null | string

contains() public method

TODO: unittest
public contains ( string | AbstractEntity $item ) : boolean
$item string | AbstractEntity ID or AbstractEntity instance
return boolean

count() public method

Count items in entity collection
public count ( ) : mixed
return mixed

delete() public method

Delete all items in the result set (WARNING: removes data from database)
public delete ( ) : boolean
return boolean

first() public method

Gets first entity in collection
public first ( ) : AbstractEntity | null
return AbstractEntity | null

getData() public method

Get collection data
public getData ( ) : array
return array

getIterator() public method

public getIterator ( )

getLimit() public method

public getLimit ( )

getOffset() public method

public getOffset ( )

last() public method

Gets last entity in collection
public last ( ) : AbstractEntity | null
return AbstractEntity | null

normalizeValue() protected method

Normalize value to always be an instance of AbstractEntity
protected normalizeValue ( array | AbstractEntity $item, boolean $fromDb = false ) : AbstractEntity
$item array | AbstractEntity
$fromDb boolean Is $item coming from DB
return AbstractEntity

offsetExists() public method

public offsetExists ( $offset )

offsetGet() public method

public offsetGet ( $offset )

offsetSet() public method

public offsetSet ( $offset, $value )

offsetUnset() public method

public offsetUnset ( $offset )

randomize() public method

Shuffle values (useful when you want to fetch a random value)
public randomize ( )

removeItem() public method

Remove item from data set
public removeItem ( $item )
$item

toArray() public method

Each AbstractEntity wil be converted to array using $fields which can be defined as a comma-separated keys, or as a function which will be ran with each entity - this gives the possibility to return different data sets depending on the given function
public toArray ( string $fields = '' ) : array
$fields string List of fields to extract
return array

totalCount() public method

TODO: unittest
public totalCount ( ) : mixed
return mixed