summaryrefslogtreecommitdiffstats
path: root/library/Icingadb/Widget/ItemTable/HostRowItem.php
blob: cff70dd5e69c1dc313ae7ecc52f87156f04f36e3 (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
<?php

/* Icinga DB Web | (c) 2022 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Widget\ItemTable;

use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Model\Host;
use ipl\Html\BaseHtmlElement;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\Link;

class HostRowItem extends StateRowItem
{
    /** @var HostItemTable */
    protected $list;

    /** @var Host */
    protected $item;

    protected function init()
    {
        parent::init();

        $this->list->addDetailFilterAttribute($this, Filter::equal('name', $this->item->name))
            ->addMultiselectFilterAttribute($this, Filter::equal('host.name', $this->item->name));
    }

    protected function assembleCell(BaseHtmlElement $cell, string $path, $value)
    {
        switch ($path) {
            case 'name':
            case 'display_name':
                $cell->addHtml(new Link($this->item->$path, Links::host($this->item), [
                    'class' => 'subject',
                    'title' => $this->item->$path
                ]));
                break;
            case 'service.name':
            case 'service.display_name':
                $column = substr($path, 8);
                $cell->addHtml(new Link(
                    $this->item->service->$column,
                    Links::service($this->item->service, $this->item)
                ));
                break;
            default:
                parent::assembleCell($cell, $path, $value);
        }
    }
}