|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** ActionController of Core */ |
|
11
|
|
|
namespace Core\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Core\Listener\DefaultListener; |
|
14
|
|
|
use Interop\Container\ContainerInterface; |
|
15
|
|
|
use Zend\ModuleManager\ModuleManager; |
|
16
|
|
|
use Zend\ModuleManager\ModuleManagerInterface; |
|
17
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
18
|
|
|
use Zend\View\Model\ViewModel; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Main Action Controller for the application. |
|
22
|
|
|
* Responsible for displaying the home site. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Anthonius Munthi <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class IndexController extends AbstractActionController |
|
27
|
|
|
{ |
|
28
|
|
|
/** @var DefaultListener */ |
|
29
|
|
|
private $defaultListener; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
private $config; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ModuleManager |
|
35
|
|
|
*/ |
|
36
|
|
|
private $moduleManager; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct( |
|
39
|
|
|
ModuleManagerInterface $moduleManager, |
|
40
|
|
|
$config |
|
41
|
|
|
) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->config = $config; |
|
44
|
|
|
$this->moduleManager = $moduleManager; |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Home site |
|
49
|
|
|
* |
|
50
|
|
|
*/ |
|
51
|
|
|
public function indexAction() |
|
52
|
|
|
{ |
|
53
|
|
|
$auth = $this->Auth(); |
|
|
|
|
|
|
54
|
|
|
$config = $this->config; |
|
55
|
|
|
if (array_key_exists('startpage', $config['view_manager']['template_map'])) { |
|
56
|
|
|
$this->layout()->setTerminal(true)->setTemplate('startpage'); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
return ['auth' => $auth]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function dashboardAction() |
|
62
|
|
|
{ |
|
63
|
|
|
$model = new ViewModel(); |
|
64
|
|
|
$model->setTemplate('core/index/dashboard'); |
|
65
|
|
|
$modules = $this->moduleManager->getLoadedModules(); |
|
66
|
|
|
foreach ($this->config('dashboard', array_keys($modules)) as $module => $cfg) { |
|
|
|
|
|
|
67
|
|
|
if (!isset($cfg['enabled']) || true !== $cfg['enabled']) { |
|
68
|
|
|
continue; |
|
69
|
|
|
} |
|
70
|
|
|
foreach ($cfg['widgets'] as $captureTo => $spec) { |
|
71
|
|
|
if (isset($spec['controller'])) { |
|
72
|
|
|
$params = array('action' => 'dashboard'); |
|
73
|
|
|
if (isset($spec['params'])) { |
|
74
|
|
|
$params = array_merge($params, $spec['params']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$viewModel = $this->forward()->dispatch($spec['controller'], $params); |
|
78
|
|
|
// we ignore all errors and simply continue with the error template as widget content |
|
79
|
|
|
$response = $this->getResponse(); |
|
80
|
|
|
if (200 != $response->getStatusCode()) { |
|
81
|
|
|
$response->setStatusCode(200); |
|
82
|
|
|
$viewModel = array( |
|
83
|
|
|
'content' => 'Error loading widget.', |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
if (!$viewModel instanceof ViewModel) { |
|
87
|
|
|
$viewModel = new ViewModel($viewModel); |
|
88
|
|
|
} |
|
89
|
|
|
if ($template = $viewModel->getTemplate()) { |
|
90
|
|
|
$viewModel->setVariable('script', $template); |
|
91
|
|
|
} |
|
92
|
|
|
} elseif (isset($spec['script'])) { |
|
93
|
|
|
$viewModel = new ViewModel(array('script' => $spec['script'])); |
|
94
|
|
|
} elseif (isset($spec['content'])) { |
|
95
|
|
|
$viewModel = new ViewModel(array('content' => $spec['content'])); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$viewModel->setTemplate('core/index/dashboard-widget.phtml'); |
|
|
|
|
|
|
99
|
|
|
$model->addChild($viewModel, "dashboard_{$module}_{$captureTo}"); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
return $model; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function errorAction() |
|
106
|
|
|
{ |
|
107
|
|
|
$viewModel = new ViewModel(); |
|
108
|
|
|
$viewModel->setTemplate('error/index') |
|
109
|
|
|
->setVariable('message', 'An unexpected error had occured. Please try again later.'); |
|
110
|
|
|
return $viewModel; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.