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

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

namespace Icinga\Module\Icingadb\Widget\ItemTable;

use Icinga\Module\Icingadb\Model\Hostgroup;
use Icinga\Module\Icingadb\Widget\Detail\HostStatistics;
use Icinga\Module\Icingadb\Widget\Detail\ServiceStatistics;
use ipl\Html\BaseHtmlElement;
use ipl\Stdlib\Filter;

/**
 * Hostgroup table row of a hostgroup table. Represents one database row.
 *
 * @property Hostgroup $item
 * @property HostgroupTable $table
 */
class HostgroupTableRow extends BaseHostGroupItem
{
    use TableRowLayout;

    protected $defaultAttributes = ['class' => 'hostgroup-table-row'];

    /**
     * Create Host and service statistics columns
     *
     * @return BaseHtmlElement[]
     */
    protected function createStatistics(): array
    {
        $hostStats = new HostStatistics($this->item);

        $hostStats->setBaseFilter(Filter::equal('hostgroup.name', $this->item->name));
        if (isset($this->table) && $this->table->hasBaseFilter()) {
            $hostStats->setBaseFilter(
                Filter::all($hostStats->getBaseFilter(), $this->table->getBaseFilter())
            );
        }

        $serviceStats = new ServiceStatistics($this->item);

        $serviceStats->setBaseFilter(Filter::equal('hostgroup.name', $this->item->name));
        if (isset($this->table) && $this->table->hasBaseFilter()) {
            $serviceStats->setBaseFilter(
                Filter::all($serviceStats->getBaseFilter(), $this->table->getBaseFilter())
            );
        }

        return [
            $this->createColumn($hostStats),
            $this->createColumn($serviceStats)
        ];
    }
}