|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package midgard.admin.asgard |
|
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
|
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Component display |
|
11
|
|
|
* |
|
12
|
|
|
* @package midgard.admin.asgard |
|
13
|
|
|
*/ |
|
14
|
|
|
class midgard_admin_asgard_handler_components extends midcom_baseclasses_components_handler |
|
15
|
|
|
{ |
|
16
|
|
|
use midgard_admin_asgard_handler; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
private array $components = []; |
|
19
|
|
|
|
|
20
|
|
|
private array $libraries = []; |
|
21
|
|
|
|
|
22
|
2 |
|
public function _on_initialize() |
|
23
|
|
|
{ |
|
24
|
2 |
|
$this->add_stylesheet(MIDCOM_STATIC_URL . '/midgard.admin.asgard/components.css'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
2 |
|
private function _load_component_data(midcom_core_manifest $manifest) : array |
|
28
|
|
|
{ |
|
29
|
2 |
|
$data = [ |
|
30
|
2 |
|
'name' => $manifest->name, |
|
31
|
2 |
|
'title' => $manifest->get_name_translated(), |
|
32
|
2 |
|
'icon' => midcom::get()->componentloader->get_component_icon($manifest->name), |
|
33
|
2 |
|
'description' => $manifest->description, |
|
34
|
2 |
|
'toolbar' => new midcom_helper_toolbar() |
|
35
|
2 |
|
]; |
|
36
|
|
|
|
|
37
|
2 |
|
$data['toolbar']->add_item([ |
|
38
|
2 |
|
MIDCOM_TOOLBAR_URL => $this->router->generate('components_configuration', ['component' => $manifest->name]), |
|
39
|
2 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), |
|
40
|
2 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'wrench', |
|
41
|
2 |
|
]); |
|
42
|
2 |
|
$data['toolbar']->add_item([ |
|
43
|
2 |
|
MIDCOM_TOOLBAR_URL => '__ais/help/' . $manifest->name . '/', |
|
44
|
2 |
|
MIDCOM_TOOLBAR_LABEL => $this->_i18n->get_string('help', 'midcom.admin.help'), |
|
45
|
2 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'question', |
|
46
|
2 |
|
MIDCOM_TOOLBAR_OPTIONS => [ |
|
47
|
2 |
|
'target' => '_blank', |
|
48
|
2 |
|
] |
|
49
|
2 |
|
]); |
|
50
|
|
|
|
|
51
|
2 |
|
return $data; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
private function _list_components() |
|
55
|
|
|
{ |
|
56
|
1 |
|
foreach (midcom::get()->componentloader->get_manifests() as $manifest) { |
|
57
|
1 |
|
$type = ($manifest->purecode) ? 'libraries' : 'components'; |
|
58
|
1 |
|
$this->$type[$manifest->name] = $this->_load_component_data($manifest); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Component list view |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function _handler_list(array &$data) |
|
66
|
|
|
{ |
|
67
|
1 |
|
$data['view_title'] = $this->_l10n->get('components'); |
|
68
|
|
|
|
|
69
|
1 |
|
$this->_list_components(); |
|
70
|
|
|
|
|
71
|
|
|
// Set the breadcrumb data |
|
72
|
1 |
|
$this->add_breadcrumb($this->router->generate('welcome'), $this->_l10n->get($this->_component)); |
|
73
|
1 |
|
$this->add_breadcrumb($this->router->generate('components'), $this->_l10n->get('components')); |
|
74
|
1 |
|
return $this->get_response(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Shows the loaded components |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function _show_list(string $handler_id, array &$data) |
|
81
|
|
|
{ |
|
82
|
1 |
|
$this->_show_lists('components'); |
|
83
|
1 |
|
$this->_show_lists('libraries'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
private function _show_lists(string $type) |
|
87
|
|
|
{ |
|
88
|
1 |
|
$this->_request_data['list_type'] = $type; |
|
89
|
1 |
|
midcom_show_style('midgard_admin_asgard_components_header'); |
|
90
|
1 |
|
foreach ($this->$type as $component_data) { |
|
91
|
1 |
|
$this->_request_data['component_data'] = $component_data; |
|
92
|
1 |
|
midcom_show_style('midgard_admin_asgard_components_item'); |
|
93
|
|
|
} |
|
94
|
1 |
|
midcom_show_style('midgard_admin_asgard_components_footer'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Component display |
|
99
|
|
|
*/ |
|
100
|
1 |
|
public function _handler_component(string $component, array &$data) |
|
101
|
|
|
{ |
|
102
|
1 |
|
$data['component'] = $component; |
|
103
|
1 |
|
if (!midcom::get()->componentloader->is_installed($component)) { |
|
104
|
|
|
throw new midcom_error_notfound("Component {$component} is not installed."); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
1 |
|
$data['component_data'] = $this->_load_component_data(midcom::get()->componentloader->get_manifest($component)); |
|
|
|
|
|
|
108
|
|
|
|
|
109
|
1 |
|
$data['view_title'] = $data['component_data']['title']; |
|
110
|
|
|
|
|
111
|
1 |
|
$data['asgard_toolbar']->add_item([ |
|
112
|
1 |
|
MIDCOM_TOOLBAR_URL => $this->router->generate('components_configuration', ['component' => $component]), |
|
113
|
1 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), |
|
114
|
1 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'wrench', |
|
115
|
1 |
|
]); |
|
116
|
|
|
|
|
117
|
|
|
// Set the breadcrumb data |
|
118
|
1 |
|
$this->add_breadcrumb($this->router->generate('welcome'), $this->_l10n->get($this->_component)); |
|
119
|
1 |
|
$this->add_breadcrumb($this->router->generate('components'), $this->_l10n->get('components')); |
|
120
|
1 |
|
$this->add_breadcrumb('', $data['component_data']['title']); |
|
121
|
1 |
|
return $this->get_response('midgard_admin_asgard_components_component'); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|