icingadb-web/application/controllers/HostgroupController.php

75 lines
2.1 KiB
PHP
Raw Normal View History

2019-11-04 17:30:38 -05:00
<?php
2020-03-13 03:38:01 -04:00
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
2019-11-04 19:07:30 -05:00
namespace Icinga\Module\Icingadb\Controllers;
2019-11-04 17:30:38 -05:00
use Icinga\Exception\NotFoundError;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\Hostgroupsummary;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemList\HostList;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Widget\ItemList\HostgroupList;
use ipl\Stdlib\Filter;
2019-11-04 17:30:38 -05:00
class HostgroupController extends Controller
{
/** @var Hostgroupsummary The host group object */
protected $hostgroup;
public function init()
{
$this->assertRouteAccess('hostgroups');
$this->setTitle(t('Host Group'));
2019-11-04 17:30:38 -05:00
$name = $this->params->shiftRequired('name');
$query = Hostgroupsummary::on($this->getDb());
foreach ($query->getUnions() as $unionPart) {
$unionPart->filter(Filter::equal('hostgroup.name', $name));
}
2019-11-04 17:30:38 -05:00
$this->applyRestrictions($query);
2019-11-04 17:30:38 -05:00
$hostgroup = $query->first();
if ($hostgroup === null) {
throw new NotFoundError(t('Host group not found'));
2019-11-04 17:30:38 -05:00
}
$this->hostgroup = $hostgroup;
}
2019-11-04 17:30:38 -05:00
public function indexAction()
{
$db = $this->getDb();
$hosts = Host::on($db)->with('state')->utilize('hostgroup');
2019-11-04 17:30:38 -05:00
$hosts->getSelectBase()->where(['host_hostgroup.id = ?' => $this->hostgroup->id]);
$this->applyRestrictions($hosts);
2019-11-04 17:30:38 -05:00
$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($hosts);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
2019-11-04 17:30:38 -05:00
$hostList = (new HostList($hosts))
->setViewMode($viewModeSwitcher->getViewMode());
yield $this->export($hosts);
$this->addControl((new HostgroupList([$this->hostgroup]))
->setViewMode('minimal')
->setDetailActionsDisabled()
->setNoSubjectLink());
2019-11-04 17:30:38 -05:00
$this->addControl($paginationControl);
$this->addControl($viewModeSwitcher);
$this->addControl($limitControl);
$this->addContent($hostList);
$this->setAutorefreshInterval(10);
2019-11-04 17:30:38 -05:00
}
}