diff --git a/brain/controller/DashControl.inc.php b/brain/controller/DashControl.inc.php index e109cc8..1a64f81 100644 --- a/brain/controller/DashControl.inc.php +++ b/brain/controller/DashControl.inc.php @@ -14,13 +14,22 @@ class DashControl ): ResponseInterface { $view = Twig::fromRequest($request); $pageOptions = []; + $template = ""; switch (isset($args["second"]) ? $args["second"] : "index") { case "pages": - $content = []; + $data = (new Book("../content/pages"))->getPages(1, 4); + $template = "dash/book.twig"; + $pageOptions = [ + "entryCount" => $data["entryCount"], + "filter" => $data["sort"], + "stats" => $data["stats"], + "pages" => $data["pages"], + ]; break; default: //$_SESSION["TEST"] = "TESTERZ"; //session_unset(); + $template = "dash/start.twig"; if (Session::active()) { $pageOptions = [ "title" => "Welcome to Fipamo", @@ -33,9 +42,8 @@ class DashControl "status" => Session::active(), ]; } - break; } - return $view->render($response, "dash/start.twig", $pageOptions); + return $view->render($response, $template, $pageOptions); } } diff --git a/brain/data/Book.inc.php b/brain/data/Book.inc.php index c32011b..1a1aca1 100644 --- a/brain/data/Book.inc.php +++ b/brain/data/Book.inc.php @@ -2,6 +2,7 @@ use Mni\FrontYAML\Parser; use function _\orderBy; +use function _\filter; class Book { @@ -24,24 +25,64 @@ class Book } } - public function getPages(int $page, int $limit) + public function getPages(int $page, int $limit, string $sort = null) { $content = $this->getContents(); - $count = ceil(count($content) / $limit); + + $published = filter($content, function ($item) { + return $item["published"] == "true"; + }); + $deleted = filter($content, function ($item) { + //echo $item["deleted"]; + return $item["deleted"]; + }); + + $all = $content; + + $filter = isset($sort) ? $sort : "all"; + + //echo $filter; + $filtered = []; + switch ($filter) { + case "published": + $filtered = $published; + break; + case "deleted": + $filtered = $deleted; + break; + default: + $filtered = $content; + break; + } + + $numOfPages = ceil(count($filtered) / $limit); $folder = []; - $range = $page * $limit - $limit; - for ($i = 0; $i <= $limit; $i++) { - try { - array_push($folder, $content[$i + $range]); - } catch (Exception $error) { - //echo $error; + + if (count($filtered) != 0) { + if (count($filtered) < $limit) { + $limit = count($filtered) - 1; + } + $range = $page * $limit - $limit; + for ($i = 0; $i <= $limit; $i++) { + try { + array_push($folder, $filtered[$i + $range]); + } catch (Exception $error) { + //echo $error; + } } } return [ "pages" => $folder, - "total" => $count, + "numOfPages" => $numOfPages, + "entryCount" => count($filtered), + "sort" => $filter, + "stats" => [ + "all" => count($all), + "published" => count($published), + "deleted" => count($deleted), + ], ]; } public function getContents() diff --git a/brain/views/dash/book.twig b/brain/views/dash/book.twig new file mode 100644 index 0000000..63b886e --- /dev/null +++ b/brain/views/dash/book.twig @@ -0,0 +1,67 @@ +{% extends "dash/_frame.twig" %} + +{% block title %} + {{ title }} +{% endblock %} + +{% block stylesheets %} + + {% endblock %} + + {% block mainContent %} +
+
+
+ All Pages ({{ stats['all'] }}) + . + Published ({{ stats['published'] }}) + . + Deleted ({{ stats['deleted'] }}) +
+ +
+
+ {% endblock %} + + {% block javascripts %} + + {% endblock %} \ No newline at end of file diff --git a/brain/views/dash/partials/index.twig b/brain/views/dash/partials/index.twig index b7af1d2..da43421 100644 --- a/brain/views/dash/partials/index.twig +++ b/brain/views/dash/partials/index.twig @@ -3,7 +3,7 @@

Recent

- View Pages + View Pages . Create Page