forked from projects/fipamo
92 lines
2.6 KiB
PHP
92 lines
2.6 KiB
PHP
<?php
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Slim\Views\Twig;
|
|
|
|
include "../brain/data/Book.inc.php";
|
|
|
|
class DashControl
|
|
{
|
|
public static function start(
|
|
ServerRequestInterface $request,
|
|
ResponseInterface $response,
|
|
array $args
|
|
): ResponseInterface {
|
|
$view = Twig::fromRequest($request);
|
|
$pageOptions = [];
|
|
$template = "";
|
|
switch (isset($args["second"]) ? $args["second"] : "index") {
|
|
case "pages":
|
|
$currentPage = isset($args["fourth"]) ? $args["fourth"] : 1;
|
|
$filter = isset($args["third"]) ? $args["third"] : "all";
|
|
$data = (new Book("../content/pages"))->getPages(
|
|
$currentPage,
|
|
4,
|
|
$filter
|
|
);
|
|
$template = "dash/book.twig";
|
|
$pageOptions = [
|
|
"entryCount" => $data["entryCount"],
|
|
"numOfPages" => $data["numOfPages"],
|
|
"currentPage" => $currentPage,
|
|
"filter" => $data["paginate"]["sort"],
|
|
"stats" => $data["stats"],
|
|
"pages" => $data["pages"],
|
|
"paginate" => $data["paginate"],
|
|
"status" => Session::active(),
|
|
];
|
|
break;
|
|
case "page":
|
|
if (Session::active()) {
|
|
$template = "dash/page-edit.twig";
|
|
$mode = $args["third"];
|
|
if ($mode == "edit") {
|
|
$uuid = $args["fourth"];
|
|
|
|
$pageOptions = [
|
|
"title" => "Fipamo | Edit Page",
|
|
"page" => (new Book("../content/pages"))->findPageById($uuid),
|
|
"mode" => $mode,
|
|
"status" => Session::active(),
|
|
];
|
|
} else {
|
|
$pageOptions = [
|
|
"title" => "Fipamo | Create Page",
|
|
"mode" => $mode,
|
|
"status" => Session::active(),
|
|
];
|
|
}
|
|
} else {
|
|
$template = "dash/start.twig";
|
|
$pageOptions = [
|
|
"title" => "Welcome to Fipamo",
|
|
"status" => Session::active(),
|
|
];
|
|
}
|
|
|
|
break;
|
|
case "logout":
|
|
Session::kill();
|
|
header("Location: /dashboard");
|
|
die();
|
|
break;
|
|
default:
|
|
$template = "dash/start.twig";
|
|
if (Session::active()) {
|
|
$pageOptions = [
|
|
"title" => "Welcome Back",
|
|
"status" => Session::active(),
|
|
"data" => (new Book("../content/pages"))->getPages(1, 4),
|
|
];
|
|
} else {
|
|
$pageOptions = [
|
|
"title" => "Welcome to Fipamo",
|
|
"status" => Session::active(),
|
|
];
|
|
}
|
|
break;
|
|
}
|
|
return $view->render($response, $template, $pageOptions);
|
|
}
|
|
}
|