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