From 8e9b6ac42266f77a8b80ab630eae42af3d07cf86 Mon Sep 17 00:00:00 2001 From: Ro Date: Thu, 8 Apr 2021 15:27:05 -0700 Subject: [PATCH] plugged in filtered pagination for entry pages --- brain/controller/DashControl.inc.php | 10 ++++++---- brain/data/Book.inc.php | 23 ++++++++++++++++++----- brain/views/dash/book.twig | 17 ++++++++++++++++- brain/views/dash/partials/index.twig | 2 +- src/styles/main/_posts.sass | 2 +- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/brain/controller/DashControl.inc.php b/brain/controller/DashControl.inc.php index 1a64f81..5455535 100644 --- a/brain/controller/DashControl.inc.php +++ b/brain/controller/DashControl.inc.php @@ -17,18 +17,20 @@ class DashControl $template = ""; switch (isset($args["second"]) ? $args["second"] : "index") { case "pages": - $data = (new Book("../content/pages"))->getPages(1, 4); + $currentPage = isset($args["fourth"]) ? $args["fourth"] : 1; + $data = (new Book("../content/pages"))->getPages($currentPage, 4); $template = "dash/book.twig"; $pageOptions = [ "entryCount" => $data["entryCount"], - "filter" => $data["sort"], + "numOfPages" => $data["numOfPages"], + "currentPage" => $currentPage, + "filter" => $data["paginate"]["sort"], "stats" => $data["stats"], "pages" => $data["pages"], + "paginate" => $data["paginate"], ]; break; default: - //$_SESSION["TEST"] = "TESTERZ"; - //session_unset(); $template = "dash/start.twig"; if (Session::active()) { $pageOptions = [ diff --git a/brain/data/Book.inc.php b/brain/data/Book.inc.php index 1a1aca1..45a6c1a 100644 --- a/brain/data/Book.inc.php +++ b/brain/data/Book.inc.php @@ -33,7 +33,6 @@ class Book return $item["published"] == "true"; }); $deleted = filter($content, function ($item) { - //echo $item["deleted"]; return $item["deleted"]; }); @@ -65,19 +64,33 @@ class Book } $range = $page * $limit - $limit; for ($i = 0; $i <= $limit; $i++) { - try { + if (isset($filtered[$i + $range])) { array_push($folder, $filtered[$i + $range]); - } catch (Exception $error) { - //echo $error; + } else { + //chill out } } } + $prev = $page - 1; + if ($prev <= 0) { + $prev = $numOfPages; + } + + $next = $page + 1; + if ($next > $numOfPages) { + $next = 1; + } + return [ "pages" => $folder, "numOfPages" => $numOfPages, "entryCount" => count($filtered), - "sort" => $filter, + "paginate" => [ + "sort" => $filter, + "nextPage" => $next, + "prevPage" => $prev, + ], "stats" => [ "all" => count($all), "published" => count($published), diff --git a/brain/views/dash/book.twig b/brain/views/dash/book.twig index 63b886e..09eb558 100644 --- a/brain/views/dash/book.twig +++ b/brain/views/dash/book.twig @@ -5,7 +5,7 @@ {% endblock %} {% block stylesheets %} - + {% endblock %} {% block mainContent %} @@ -56,6 +56,21 @@ {% endfor %} + {% if numOfPages > 1 %} +
+ + + + + {{ currentPage }} + of + {{ numOfPages }} + + + + +
+ {% endif %} diff --git a/brain/views/dash/partials/index.twig b/brain/views/dash/partials/index.twig index da43421..20a4056 100644 --- a/brain/views/dash/partials/index.twig +++ b/brain/views/dash/partials/index.twig @@ -9,7 +9,7 @@
- {% if data["total"] != 0 %} + {% if data["entryCount"] != 0 %} {% for page in data['pages'] %}
diff --git a/src/styles/main/_posts.sass b/src/styles/main/_posts.sass index 38526e8..93c0292 100644 --- a/src/styles/main/_posts.sass +++ b/src/styles/main/_posts.sass @@ -122,7 +122,7 @@ padding: 5px margin-top: -2px display: inline-block - width: 200px + width: 190px font-size: 1.5em color: $tertiary