\Ceo\CompatCollection

Summary

Methods
Properties
Constants
__construct()
push()
pop()
peekBack()
first()
unshift()
shift()
peekFront()
getIterator()
offsetGet()
offsetExists()
offsetSet()
offsetUnset()
length()
count()
sort()
merge()
splat()
grab()
metaIs()
metaContains()
No public properties found
No constants found
No protected methods found
$itemStack
N/A
No private methods found
No private properties found
N/A

Properties

$itemStack

$itemStack : 

Type

Methods

__construct()

__construct(  $itemStack = array()) 

Parameters

$itemStack

push()

push(object  $obj) 

Push a foundry\model object onto the stack

Parameters

object $obj

a foundry\model

pop()

pop(integer  $count) : mixed

Remove and return the last object in the stack

Parameters

integer $count

return number of models

Returns

mixed —

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

peekBack()

peekBack(integer  $count) : mixed

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

Parameters

integer $count

return number of models

Returns

mixed —

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

first()

first() : object

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()

Returns

object

unshift()

unshift(object  $obj) 

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

Parameters

object $obj

foundry\model object

shift()

shift(integer  $count) : mixed

Remove and return the first item from the stack

Parameters

integer $count

return a number of objects

Returns

mixed —

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

peekFront()

peekFront(integer  $count) : mixed

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

Parameters

integer $count

return number of objects

Returns

mixed —

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

getIterator()

getIterator() 

offsetGet()

offsetGet(  $offset) 

Parameters

$offset

offsetExists()

offsetExists(  $offset) 

Parameters

$offset

offsetSet()

offsetSet(  $offset,   $val) 

Parameters

$offset
$val

offsetUnset()

offsetUnset(  $offset) 

Parameters

$offset

length()

length() 

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

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

count()

count() : integer

Alias for length, implementation for Countable interface

Returns

integer —

number of elements

sort()

sort(string  $by, boolean  $sortFlag = false) : object

Sort a collection by an item property

Parameters

string $by

sort value

boolean $sortFlag

if TRUE, will sort reverse

Returns

object —

this

merge()

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

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

boolean $sortFlag

set to SORT_REVERSE to sort... in reverse

Returns

object —

foundry\collection

splat()

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

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

Returns

array

grab()

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

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

boolean $greedy

if TRUE, matched objects are removed from the stack

Returns

object —

foundry\model\collection

metaIs()

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

Parameters

$value
$label
$greedy

metaContains()

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

Parameters

$value
$label
$greedy