summaryrefslogtreecommitdiffstats
path: root/application/controllers/PlugController.php.disabled
blob: a2c6453793b0a70ca305e0ae4cf1a4b56da926f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php

namespace Icinga\Module\Reporting\Controllers;

use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Module\Reporting\Hook\ReportHook;
use Icinga\Module\Reporting\Web\Forms\ReportForm;
use Icinga\Module\Reporting\Web\Controller;
use Icinga\Web\Hook;
use Icinga\Web\Url;
use ipl\Html\Html;

class PlugController extends Controller
{
    public function indexAction()
    {
        $moduleToShow = strtolower($this->params->get('module', 'reporting'));

        $reportsByModule = [];

        foreach (ReportHook::getReports() as $class => $report) {
            $moduleName = $report->getModuleName();

            if (! isset($reportsByModule[$moduleName])) {
                $reportsByModule[$moduleName] = [];
            }

            $reportsByModule[$moduleName][$class] = $report;
        }

        $editor = Html::tag('div', ['class' => 'editor']);

        $nav = [];

        $cards = [];

        foreach ($reportsByModule as $moduleName => $reports) {
            $link = Html::tag('a', ['href' => Url::fromRequest(['module' => $moduleName])], $moduleName);

            $nav[] = $link;

            if ($moduleName !== $moduleToShow) {
                continue;
            }

            $link->getAttributes()->add('class', 'active');

            foreach ($reports as $report) {
                $cards[] = Html::tag(
                    'div',
                    ['class' => 'card'],
                    [
                        Html::tag('div', ['class' => 'card-top'], $report->getPreview()),
                        Html::tag(
                            'div',
                            ['class' => 'card-content'],
                            Html::tag('h5', ['class' => 'card-title'], $report->getName()),
                            Html::tag('p', ['class' => 'card-text'], $report->getDescription())
                        )
                    ]
                );
            }
        }

        $editor->add(Html::tag('div', ['class' => 'editor-nav'], $nav));
        $editor->add(Html::tag('div', ['class' => 'editor-content'], $cards));

        $this->addContent($editor);

        $this->addContent(Html::tag('a', ['href' => 'plug', 'class' => 'modal-toggle', 'data-base-target' => 'modal-container'], 'Modal'));
    }
}