Completed
Push — master ( 10885e...e41e62 )
by Andreas
13:56
created

midcom_helper_toolbar_host::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package midcom.helper
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
 * This class is a host toolbar class.
11
 *
12
 * @package midcom.helper
13
 */
14
class midcom_helper_toolbar_host extends midcom_helper_toolbar
15
{
16
    public function __construct()
17
    {
18
        $config = midcom::get()->config;
19
        parent::__construct($config->get('toolbars_host_style_class'), $config->get('toolbars_host_style_id'));
20
        $this->label = midcom::get()->i18n->get_string('host', 'midcom');
21
        $this->add_commands();
22
    }
23
24
    private function add_commands()
25
    {
26
        $buttons = [];
27
        if (midcom::get()->auth->user) {
28
            $buttons[] = [
29
                MIDCOM_TOOLBAR_URL => midcom_connection::get_url('self') . "midcom-logout-",
30
                MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('logout', 'midcom'),
31
                MIDCOM_TOOLBAR_GLYPHICON => 'sign-out',
32
                MIDCOM_TOOLBAR_ACCESSKEY => 'l',
33
            ];
34
        }
35
36
        $buttons[] = [
37
            MIDCOM_TOOLBAR_URL => midcom_connection::get_url('self') . "__mfa/asgard/",
38
            MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('midgard.admin.asgard', 'midgard.admin.asgard'),
39
            MIDCOM_TOOLBAR_GLYPHICON => 'server',
40
            MIDCOM_TOOLBAR_ACCESSKEY => 'a',
41
            MIDCOM_TOOLBAR_ENABLED => midcom::get()->auth->can_user_do('midgard.admin.asgard:access', null, 'midgard_admin_asgard_plugin'),
42
        ];
43
44
        if (midcom_connection::is_admin()) {
45
            $buttons[] = [
46
                MIDCOM_TOOLBAR_URL => midcom_connection::get_url('self') . "midcom-cache-invalidate",
47
                MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('invalidate cache', 'midcom'),
48
                MIDCOM_TOOLBAR_GLYPHICON => 'refresh',
49
            ];
50
            $workflow = new midcom\workflow\viewer;
51
            $buttons[] = $workflow->get_button(midcom_connection::get_url('self') . "midcom-config-test", [
52
                MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('test settings', 'midcom'),
53
                MIDCOM_TOOLBAR_GLYPHICON => 'wrench',
54
            ]);
55
        }
56
        $this->add_items($buttons);
57
    }
58
}
59