summaryrefslogtreecommitdiffstats
path: root/library/Businessprocess/Web/Component/BpDashboardTile.php
blob: 17d3a0c1a4d23cb8b20f7687d756c64daa716e9f (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
<?php

namespace Icinga\Module\Businessprocess\Web\Component;

use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Web\Url;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\Text;

class BpDashboardTile extends BaseHtmlElement
{
    protected $tag = 'div';

    protected $defaultAttributes = ['class' => 'dashboard-tile'];

    public function __construct(BpConfig $bp, $title, $description, $icon, $url, $urlParams = null, $attributes = null)
    {
        if (! isset($attributes['href'])) {
            $attributes['href'] = Url::fromPath($url, $urlParams ?: []);
        }

        $this->add(Html::tag(
            'div',
            ['class' => 'bp-link', 'data-base-target' => '_main'],
            Html::tag('a', $attributes, Html::tag('i', ['class' => 'icon icon-' . $icon]))
                ->add(Html::tag('span', ['class' => 'header'], $title))
                ->add($description)
        ));

        $tiles = Html::tag('div', ['class' => 'bp-root-tiles']);

        foreach ($bp->getChildren() as $node) {
            $state = strtolower($node->getStateName());

            $tiles->add(Html::tag(
                'a',
                [
                    'href'  => Url::fromPath($url, $urlParams ?: [])->with(['node' => $node->getName()]),
                    'class' => "badge state-{$state}",
                    'title' => $node->getAlias()
                ],
                Text::create('&nbsp;')->setEscaped()
            ));
        }

        $this->add($tiles);
    }
}