Collection
class Collection extends Module implements ArrayAccess, IteratorAggregate, Countable
Properties
protected | $itemStack |
Methods
No description
Push a foundry\model object onto the stack
Remove and return the last object in the stack
Return the last model on the stack, but don't remove it
Allows the collection to behave somewhat like a query operation.
Push a foundry\model object into the front of the stack
Remove and return the first item from the stack
Return, but don't remove, the first item on the stack
No description
No description
No description
No description
No description
Return the number of objects in the stack. Can also be accessed as a property
Alias for length, implementation for Countable interface
Sort a collection by an item property
Merges two collections together. If you pass a second argument it attempts to sort it via that property (both models must have that property).
Flattens the collection into a single property array This is useful for returning elements for an auto complete search system implemented via AJAX
Grab all the models whose property matches the passed value
No description
No description
Details
at line 12
__construct($itemStack = [])
at line 28
push(object $obj)
Push a foundry\model object onto the stack
at line 39
mixed
pop(int $count = 0)
Remove and return the last object in the stack
at line 66
mixed
peekBack(int $count = 0)
Return the last model on the stack, but don't remove it
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()
at line 106
unshift(object $obj)
Push a foundry\model object into the front of the stack
at line 119
mixed
shift(int $count = 0)
Remove and return the first item from the stack
at line 146
mixed
peekFront(int $count = 0)
Return, but don't remove, the first item on the stack
at line 169
getIterator()
at line 173
offsetGet($offset)
at line 180
offsetExists($offset)
at line 191
offsetSet($offset, $val)
at line 195
offsetUnset($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
at line 227
object
sort(string $by, bool $sortFlag = false)
Sort a collection by an item property
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);
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');
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'