Skip to content

Commit

Permalink
Add batch() function to Page Collection class
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Sep 16, 2016
1 parent 3047311 commit 7710cba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.1.6
## XX/XX/2016

1. [](#improved)
* Add `batch()` function to Page Collection class

# v1.1.5
## 09/09/2016

Expand Down
18 changes: 18 additions & 0 deletions system/src/Grav/Common/Page/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ public function offsetGet($offset)
return !empty($this->items[$offset]) ? $this->pages->get($offset) : null;
}

/**
* Split collection into array of smaller collections.
*
* @param $size
* @return array|Collection[]
*/
public function batch($size)
{
$chunks = array_chunk($this->items, $size, true);

$list = [];
foreach ($chunks as $chunk) {
$list[] = new static($chunk, $this->params, $this->pages);
}

return $list;
}

/**
* Remove item from the list.
*
Expand Down

0 comments on commit 7710cba

Please sign in to comment.