1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alvo\Page; |
4
|
|
|
|
5
|
|
|
use \Anax\DI\InjectionAwareInterface; |
6
|
|
|
use \Anax\DI\InjectionAwareTrait; |
7
|
|
|
use \Anax\Page\PageRenderInterface; |
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
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
* |
26
|
|
|
* @SuppressWarnings("exit") |
27
|
|
|
*/ |
28
|
|
|
public function renderPage($data = [], $status = 200) |
29
|
|
|
{ |
30
|
|
|
$data["stylesheets"] = [ |
31
|
|
|
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css", |
32
|
|
|
"lib/css/font-awesome.min.css", |
33
|
|
|
"https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css", |
34
|
|
|
"css/style.css", |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
$data["title"] = isset($data["title"]) ? "Anax | " . $data["title"] : "Anax"; |
|
|
|
|
38
|
|
|
|
39
|
|
|
$data["scripts"] = [ |
40
|
|
|
"https://code.jquery.com/jquery-3.2.1.slim.min.js", |
41
|
|
|
"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js", |
42
|
|
|
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js", |
43
|
|
|
"https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js", |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
// Add common header, navbar and footer |
47
|
|
|
// $this->view->add("common/header", [], "header"); |
48
|
|
|
$view = $this->di->get("view"); |
49
|
|
|
// $user = $this->di->get("session")->get('user', null); |
50
|
|
|
$user = $this->di->get("user")->getUser(); |
51
|
|
|
$userId = $this->di->get("session")->get('userId', null); |
52
|
|
|
|
53
|
|
|
$view->add("common/navbar", ["user" => $user, "userId" => $userId], "navbar"); |
54
|
|
|
$view->add("common/footer", [], "footer"); |
55
|
|
|
|
56
|
|
|
// Add layout, render it, add to response and send. |
57
|
|
|
$view->add("layout/layout", $data, "layout"); |
58
|
|
|
$body = $view->renderBuffered("layout"); |
59
|
|
|
$this->di->get("response")->setBody($body) |
60
|
|
|
->send($status); |
61
|
|
|
exit; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|