class Collection extends Module implements ArrayAccess, IteratorAggregate, Countable

Properties

protected $itemStack

Methods

__construct($itemStack = [])

No description

push(object $obj)

Push a foundry\model object onto the stack

mixed
pop(int $count = 0)

Remove and return the last object in the stack

mixed
peekBack(int $count = 0)

Return the last model on the stack, but don't remove it

object
first()

Allows the collection to behave somewhat like a query operation.

unshift(object $obj)

Push a foundry\model object into the front of the stack

mixed
shift(int $count = 0)

Remove and return the first item from the stack

mixed
peekFront(int $count = 0)

Return, but don't remove, the first item on the stack

getIterator()

No description

offsetGet($offset)

No description

offsetExists($offset)

No description

offsetSet($offset, $val)

No description

offsetUnset($offset)

No description

length()

Return the number of objects in the stack. Can also be accessed as a property

int
count()

Alias for length, implementation for Countable interface

object
sort(string $by, bool $sortFlag = false)

Sort a collection by an item property

object
merge(object $collection, string $sort = false, bool $sortFlag = false)

Merges two collections together. If you pass a second argument it attempts to sort it via that property (both models must have that property).

array
splat(string $property, string $key = false)

Flattens the collection into a single property array This is useful for returning elements for an auto complete search system implemented via AJAX

object
grab(string $prop, mixed $val, bool $greedy = false)

Grab all the models whose property matches the passed value

metaIs($value, $label = false, $greedy = false)

No description

metaContains($value, $label = false, $greedy = false)

No description

Details

at line 12
__construct($itemStack = [])

Parameters

$itemStack

at line 28
push(object $obj)

Push a foundry\model object onto the stack

Parameters

object $obj a foundry\model

at line 39
mixed pop(int $count = 0)

Remove and return the last object in the stack

Parameters

int $count return number of models

Return Value

mixed if count is omitted a single object is returned. If count is set, a collection is returned

at line 66
mixed peekBack(int $count = 0)

Return the last model on the stack, but don't remove it

Parameters

int $count return number of models

Return Value

mixed if count is omitted a single object is returned. If count is set, a collection is returned

at line 96
object first()

Allows the collection to behave somewhat like a query operation.

Mostly allows you to call first() on a findby operation:

$section = M::init('section')->findBySlug('foo')->first()

Return Value

object

at line 106
unshift(object $obj)

Push a foundry\model object into the front of the stack

Parameters

object $obj foundry\model object

at line 119
mixed shift(int $count = 0)

Remove and return the first item from the stack

Parameters

int $count return a number of objects

Return Value

mixed if count is omitted a single object is returned. If count is set, a collection is returned

at line 146
mixed peekFront(int $count = 0)

Return, but don't remove, the first item on the stack

Parameters

int $count return number of objects

Return Value

mixed if count is omitted a single object is returned. If count is set, a collection is returned

at line 169
getIterator()

at line 173
offsetGet($offset)

Parameters

$offset

at line 180
offsetExists($offset)

Parameters

$offset

at line 191
offsetSet($offset, $val)

Parameters

$offset
$val

at line 195
offsetUnset($offset)

Parameters

$offset

at line 208
length()

Return the number of objects in the stack. Can also be accessed as a property

> echo $collection->length(); // 3
> echo $collection->length; // 3

at line 216
int count()

Alias for length, implementation for Countable interface

Return Value

int number of elements

at line 227
object sort(string $by, bool $sortFlag = false)

Sort a collection by an item property

Parameters

string $by sort value
bool $sortFlag if TRUE, will sort reverse

Return Value

object this

at line 259
object merge(object $collection, string $sort = false, bool $sortFlag = false)

Merges two collections together. If you pass a second argument it attempts to sort it via that property (both models must have that property).

    > $coll->merge($other, 'foo', \foundry\collection\SORT_REVERSE);

Parameters

object $collection the other collection
string $sort property to sort by
bool $sortFlag set to SORT_REVERSE to sort... in reverse

Return Value

object foundry\collection

at line 322
array splat(string $property, string $key = false)

Flattens the collection into a single property array This is useful for returning elements for an auto complete search system implemented via AJAX

$authors = _M( 'authors' )->find( ... );
return $authors->splat( 'name' );
// returns array( 'Author One', 'Author Two' );

return $authors->splat('name', 'uid');
// array( '1234' => 'Author One', '5678' => 'Author Two');

Parameters

string $property property to extract
string $key return array as k->v pair

Return Value

array

at line 349
object grab(string $prop, mixed $val, bool $greedy = false)

Grab all the models whose property matches the passed value

$authors = $allAuthors->grab('status', 1);
// grabs all the objects with a status of '1'

Parameters

string $prop property to check
mixed $val value to test against
bool $greedy if TRUE, matched objects are removed from the stack

Return Value

object foundry\model\collection

at line 421
metaIs($value, $label = false, $greedy = false)

Parameters

$value
$label
$greedy

at line 451
metaContains($value, $label = false, $greedy = false)

Parameters

$value
$label
$greedy