|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jidaikobo\Kontiki\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Jidaikobo\Kontiki\Services\RoutesService; |
|
6
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
|
7
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
|
8
|
|
|
use Slim\App; |
|
9
|
|
|
use Slim\Routing\RouteCollectorProxy; |
|
10
|
|
|
use Slim\Views\PhpRenderer; |
|
11
|
|
|
|
|
12
|
|
|
class DashboardController |
|
13
|
|
|
{ |
|
14
|
|
|
private PhpRenderer $view; |
|
15
|
|
|
private array $routes; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct( |
|
18
|
|
|
PhpRenderer $view, |
|
19
|
|
|
RoutesService $routesService |
|
20
|
|
|
) { |
|
21
|
|
|
$this->view = $view; |
|
22
|
|
|
$this->routes = $routesService->getRoutesByType('dashboard'); |
|
23
|
|
|
$this->setViewAttributes($routesService); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
protected function setViewAttributes($routesService): void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->view->setAttributes([ |
|
29
|
|
|
'lang' => env('APPLANG', 'en'), |
|
30
|
|
|
'sidebarItems' => $routesService->getRoutesByType('sidebar') |
|
31
|
|
|
]); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public static function registerRoutes(App $app): void |
|
35
|
|
|
{ |
|
36
|
|
|
$app->get('/dashboard', DashboardController::class . ':dashboard') |
|
37
|
|
|
->setName('dashboard'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function dashboard(Request $request, Response $response): Response |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$content = $this->view->fetch( |
|
43
|
|
|
'dashboard/dashboard.php', |
|
44
|
|
|
['dashboardItems' => $this->routes] |
|
45
|
|
|
); |
|
46
|
|
|
return $this->view->render( |
|
47
|
|
|
$response, |
|
48
|
|
|
'layout.php', |
|
49
|
|
|
[ |
|
50
|
|
|
'pageTitle' => __('management_portal', 'Management Portal'), |
|
51
|
|
|
'content' => $content, |
|
52
|
|
|
] |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.