|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// namespace Anax\Page; |
|
4
|
|
|
namespace Marcusgsta\Page; |
|
5
|
|
|
|
|
6
|
|
|
use \Anax\DI\InjectionAwareInterface; |
|
7
|
|
|
use \Anax\DI\InjectionAwareTrait; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* A default page rendering class. |
|
11
|
|
|
*/ |
|
12
|
|
|
class PageRender implements PageRenderInterface, InjectionAwareInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use InjectionAwareTrait; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Render a standard web page using a specific layout. |
|
20
|
|
|
* |
|
21
|
|
|
* @param array $data variables to expose to layout view. |
|
22
|
|
|
* @param integer $status code to use when delivering the result. |
|
23
|
|
|
* @SuppressWarnings(PHPMD.ExitExpression) |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
|
|
public function renderPage($data, $status = 200) |
|
27
|
|
|
{ |
|
28
|
|
|
$data["stylesheets"] = ["css/bootstrap.min.css", "css/style.css", "css/remserver.css"]; |
|
29
|
|
|
$data["javascripts"] = [ |
|
30
|
|
|
"js/jquery-3.2.1.slim.min.js", |
|
31
|
|
|
"js/tether.min.js", |
|
32
|
|
|
"js/popper.min.js", |
|
33
|
|
|
"js/bootstrap.min.js" |
|
34
|
|
|
]; |
|
35
|
|
|
$data["commentableRoutes"] = ["index", "about", "report", "remserver", "book"]; |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
// create navbar from class |
|
39
|
|
|
$navbar = new \Marcusgsta\Navbar\Navbar(); |
|
40
|
|
|
$navbar->configure(); |
|
41
|
|
|
$navbarconfig = $navbar->config; |
|
42
|
|
|
|
|
43
|
|
|
// check if a user is logged in |
|
44
|
|
|
// $acronym = $this->di->session->get("user"); |
|
45
|
|
|
$acronym = $this->di->get("loginController")->isLoggedIn(); |
|
46
|
|
|
|
|
47
|
|
|
$role = $this->di->get("commentController")->getRole($acronym); |
|
48
|
|
|
|
|
49
|
|
|
// Add common header, navbar and footer |
|
50
|
|
|
// Add layout, render it, add to response and send. |
|
51
|
|
|
$view = $this->di->get("view"); |
|
52
|
|
|
$view->add("take1/header", [], "header"); |
|
53
|
|
|
$view->add("take1/navbar", $navbarconfig, "navbar"); |
|
54
|
|
|
|
|
55
|
|
|
$comments = $this->di->get("commentController")->getComments(); |
|
56
|
|
|
$comments = $comments['items']; |
|
57
|
|
|
|
|
58
|
|
|
$commentableRoutes = $data['commentableRoutes']; |
|
59
|
|
|
// $view->add("take1/comment", ["user" => $acronym], "commentsection"); |
|
60
|
|
|
$view->add( |
|
61
|
|
|
"take1/comment", |
|
62
|
|
|
[ |
|
63
|
|
|
"comments" => $comments, |
|
64
|
|
|
"user" => $acronym, |
|
65
|
|
|
"role" => $role, |
|
66
|
|
|
"commentableRoutes" => $commentableRoutes |
|
67
|
|
|
], |
|
68
|
|
|
"commentsection" |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$view->add("take1/footer", ["user" => $acronym], "footer"); |
|
72
|
|
|
$view->add("default1/layout", $data, "layout"); |
|
73
|
|
|
$body = $view->renderBuffered("layout"); |
|
74
|
|
|
$this->di->get("response")->setBody($body) |
|
75
|
|
|
->send($status); |
|
76
|
|
|
exit; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|