From 4a8111566d810f297123f629074517a937103789 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sat, 9 Jul 2016 22:34:45 +0200 Subject: [PATCH] Implemented pagination controller. --- src/engine/Api/V1/Processors/Paginate.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/engine/Api/V1/Processors/Paginate.php b/src/engine/Api/V1/Processors/Paginate.php index 14e725e8..83b400d9 100644 --- a/src/engine/Api/V1/Processors/Paginate.php +++ b/src/engine/Api/V1/Processors/Paginate.php @@ -15,6 +15,15 @@ namespace EA\Engine\Api\V1\Processors; class Paginate implements ProcessorsInterface { public static function process(array &$response) { - + if (!isset($_GET['page'])) { + return; + } + + $page = (int)$_GET['page']; + $length = isset($_GET['length']) ? (int)$_GET['length'] : 20; + + $chunks = array_chunk($response, $length); + + $response = isset($chunks[$page]) ? $chunks[$page] : []; } }