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 %} +
+ {% 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 @@