68 public function all() {
76 return count($this->items);
93 public function get(
$id) {
101 return array_key_exists(
$id, $this->items);
107 public function remove(
$id) {
108 unset($this->items[
$id]);
137 public function filter(callable $callback = null) {
139 $items = array_filter($this->items, $callback);
141 $items = array_values($this->items);
150 public function sort(callable $callback = null) {
154 $p2 = $f2->getPriority() ? : 500;
159 return $p1 < $p2 ? -1 : 1;
163 uasort($this->items, $callback);
181 public function walk(callable $callback) {
182 foreach ($this->items as
$id =>
$item) {
183 call_user_func($callback,
$item,
$id);
192 public function map(callable $callback) {
252 return key($this->items);
259 return key($this->items) !== null;
273 $keys = array_keys($this->items);
276 throw new \OutOfBoundsException();
281 return $this->items[
$key];
offsetSet($offset, $value)
{}
A collection of unique items.
getPriority()
Get priority (weight) of the item within a collection.
has($id)
{Check if collection has an item with a given ID.IDbool}
Collection item interface.
assertValidItem($item)
Validate if item is a valid collection item.
map(callable $callback)
{Walk through all items in the collection and apply a callback.Mappermixed}
walk(callable $callback)
Walk through members of the collection and apply a callback.
__construct($items=[], $item_class=null)
Constructor.
$id
River item delete action.
count()
{Count collection items.int}
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
An interface for organizing items into collections.
add($item)
{Add a new item to collection.Itemstatic}
fill($items)
{Replace collection items.$items Itemsstatic}
all()
{Returns all collection items by reference.CollectionItemInterface[]}
filter(callable $callback=null)
{Filter collection items using a custom filter Returns a new collection instance.Filterstatic} ...
sort(callable $callback=null)
{Sort fields using custom callable If not provided, will sort items by priority.Sorterstatic} ...
merge($items)
{Add new items to collection, replacing items with matching IDs.$items Itemsstatic} ...