|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Configuration\View\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Magium\Configuration\Config\MergedStructure; |
|
6
|
|
|
use Magium\Configuration\File\Context\AbstractContextConfigurationFile; |
|
7
|
|
|
use Magium\Configuration\MagiumConfigurationFactoryInterface; |
|
8
|
|
|
use Magium\Configuration\View\Controllers\Helpers\ContextRepository; |
|
9
|
|
|
use Magium\Configuration\View\ViewConfiguration; |
|
10
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
11
|
|
|
use Zend\View\Model\ViewModel; |
|
12
|
|
|
|
|
13
|
|
|
class Layout implements ControllerInterface |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
protected $viewConfiguration; |
|
17
|
|
|
protected $contextFile; |
|
18
|
|
|
protected $jqueryScript; |
|
19
|
|
|
protected $factory; |
|
20
|
|
|
protected $mergedStructure; |
|
21
|
|
|
|
|
22
|
9 |
|
public function __construct( |
|
23
|
|
|
ViewConfiguration $viewConfiguration, |
|
24
|
|
|
AbstractContextConfigurationFile $contextFile, |
|
25
|
|
|
MagiumConfigurationFactoryInterface $factory, |
|
26
|
|
|
MergedStructure $mergedStructure |
|
27
|
|
|
) |
|
28
|
|
|
{ |
|
29
|
9 |
|
$this->viewConfiguration = $viewConfiguration; |
|
30
|
9 |
|
$this->contextFile = $contextFile; |
|
31
|
9 |
|
$this->factory = $factory; |
|
32
|
9 |
|
$this->mergedStructure = $mergedStructure; |
|
33
|
9 |
|
} |
|
34
|
|
|
|
|
35
|
9 |
|
public function execute(ServerRequestInterface $request) |
|
36
|
|
|
{ |
|
37
|
9 |
|
$viewModel = new ViewModel(); |
|
38
|
9 |
|
$viewModel->setVariable('sections', $this->provideSections()); |
|
39
|
9 |
|
$viewModel->setVariable('contexts', $this->provideContexts()); |
|
40
|
9 |
|
$viewModel->setVariable('provideHtmlWrapper', $this->viewConfiguration->getProvideWrapperHtml()); |
|
41
|
9 |
|
$viewModel->setVariable('jqueryUrl', $this->viewConfiguration->getJqueryUrl()); |
|
42
|
9 |
|
$viewModel->setVariable('bootstrapCssUrl', $this->viewConfiguration->getBootstrapCssUrl()); |
|
43
|
9 |
|
$viewModel->setVariable('bootstrapJsUrl', $this->viewConfiguration->getBootstrapJsUrl()); |
|
44
|
9 |
|
$viewModel->setTemplate($this->viewConfiguration->getLayoutFile()); |
|
45
|
9 |
|
return $viewModel; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getContextFile() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->contextFile; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
|
|
57
|
9 |
|
public function provideContexts() |
|
58
|
|
|
{ |
|
59
|
9 |
|
return (new ContextRepository($this->contextFile))->getContextHierarchy(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
9 |
|
public function getMergedStructure() |
|
63
|
|
|
{ |
|
64
|
9 |
|
return $this->mergedStructure; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return array A key=>value list of groups |
|
69
|
|
|
*/ |
|
70
|
|
|
|
|
71
|
9 |
|
protected function provideSections() |
|
72
|
|
|
{ |
|
73
|
9 |
|
$configuration = $this->getMergedStructure(); |
|
74
|
9 |
|
$returnSections = []; |
|
75
|
9 |
|
foreach ($configuration->section as $section) { |
|
76
|
6 |
|
if (isset($section['hidden']) && (string)$section['hidden'] == 'yes') { |
|
77
|
1 |
|
continue; |
|
78
|
|
|
} |
|
79
|
6 |
|
$sectionId = $sectionName = (string)$section['identifier']; |
|
80
|
6 |
|
if (isset($section['label'])) { |
|
81
|
4 |
|
$sectionName = (string)$section['label']; |
|
82
|
|
|
} |
|
83
|
6 |
|
$returnSections[$sectionId] = [ |
|
84
|
6 |
|
'label' => $sectionName |
|
85
|
|
|
]; |
|
86
|
6 |
|
if (isset($section['glyphicon'])) { |
|
87
|
1 |
|
$returnSections[$sectionId]['glyphicon'] = (string)$section['glyphicon']; |
|
88
|
5 |
|
} else if (isset($section['font-awesome'])) { |
|
89
|
6 |
|
$returnSections[$sectionId]['font-awesome'] = (string)$section['font-awesome']; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
9 |
|
return $returnSections; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|