diff --git a/CHANGELOG.md b/CHANGELOG.md index 770f402853..c3a78cd82b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/system/src/Grav/Common/Page/Collection.php b/system/src/Grav/Common/Page/Collection.php index cdb52492ac..5a70ba99cc 100644 --- a/system/src/Grav/Common/Page/Collection.php +++ b/system/src/Grav/Common/Page/Collection.php @@ -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. *