From f78a7f12a934724da93c3f2dac55af663e3d90e7 Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandro@alejandrocelaya.com>
Date: Sun, 17 Jun 2018 18:29:40 +0200
Subject: [PATCH] Improved paginator properties

---
 docs/swagger/definitions/Pagination.json         | 16 ++++++++++++++--
 docs/swagger/paths/v1_short-codes.json           |  5 ++++-
 .../src/Paginator/Util/PaginatorUtilsTrait.php   |  7 +++++--
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/docs/swagger/definitions/Pagination.json b/docs/swagger/definitions/Pagination.json
index e9b731ef..18aab934 100644
--- a/docs/swagger/definitions/Pagination.json
+++ b/docs/swagger/definitions/Pagination.json
@@ -3,11 +3,23 @@
     "properties": {
         "currentPage": {
             "type": "integer",
-            "description": "The number of current page being displayed."
+            "description": "The number of current page."
         },
         "pagesCount": {
             "type": "integer",
-            "description": "The total number of pages that can be displayed."
+            "description": "The total number of pages that can be obtained."
+        },
+        "itemsPerPage": {
+            "type": "integer",
+            "description": "The number of items for every page."
+        },
+        "itemsInCurrentPage": {
+            "type": "integer",
+            "description": "The number of items in current page (could be smaller than itemsPerPage)."
+        },
+        "totalItems": {
+            "type": "integer",
+            "description": "The total number of items among all pages."
         }
     }
 }
diff --git a/docs/swagger/paths/v1_short-codes.json b/docs/swagger/paths/v1_short-codes.json
index b29bd182..9d52f798 100644
--- a/docs/swagger/paths/v1_short-codes.json
+++ b/docs/swagger/paths/v1_short-codes.json
@@ -116,7 +116,10 @@
                             ],
                             "pagination": {
                                 "currentPage": 5,
-                                "pagesCount": 12
+                                "pagesCount": 12,
+                                "itemsPerPage": 10,
+                                "itemsInCurrentPage": 10,
+                                "totalItems": 115
                             }
                         }
                     }
diff --git a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php
index 167de806..40f51d90 100644
--- a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php
+++ b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php
@@ -8,13 +8,16 @@ use Zend\Stdlib\ArrayUtils;
 
 trait PaginatorUtilsTrait
 {
-    protected function serializePaginator(Paginator $paginator)
+    protected function serializePaginator(Paginator $paginator): array
     {
         return [
             'data' => ArrayUtils::iteratorToArray($paginator->getCurrentItems()),
             'pagination' => [
                 'currentPage' => $paginator->getCurrentPageNumber(),
                 'pagesCount' => $paginator->count(),
+                'itemsPerPage' => $paginator->getItemCountPerPage(),
+                'itemsInCurrentPage' => $paginator->getCurrentItemCount(),
+                'totalItems' => $paginator->getTotalItemCount(),
             ],
         ];
     }
@@ -25,7 +28,7 @@ trait PaginatorUtilsTrait
      * @param Paginator $paginator
      * @return bool
      */
-    protected function isLastPage(Paginator $paginator)
+    protected function isLastPage(Paginator $paginator): bool
     {
         return $paginator->getCurrentPageNumber() >= $paginator->count();
     }