icingadb-web/application/controllers/ServicegroupController.php

79 lines
2.3 KiB
PHP
Raw Normal View History

2019-11-04 17:30:56 -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:56 -05:00
use Icinga\Exception\NotFoundError;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Model\Service;
2019-11-05 03:22:58 -05:00
use Icinga\Module\Icingadb\Model\ServicegroupSummary;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ServiceList;
use Icinga\Module\Icingadb\Widget\ItemList\ServicegroupList;
use ipl\Stdlib\Filter;
2019-11-04 17:30:56 -05:00
class ServicegroupController extends Controller
{
2019-11-05 03:22:58 -05:00
/** @var ServicegroupSummary The service group object */
2019-11-04 17:30:56 -05:00
protected $servicegroup;
public function init()
{
$this->assertRouteAccess('servicegroups');
$this->setTitle(t('Service Group'));
2019-11-04 17:30:56 -05:00
$name = $this->params->shiftRequired('name');
2019-11-05 03:22:58 -05:00
$query = ServicegroupSummary::on($this->getDb());
2019-11-04 17:30:56 -05:00
foreach ($query->getUnions() as $unionPart) {
$unionPart->filter(Filter::equal('servicegroup.name', $name));
}
2019-11-04 17:30:56 -05:00
$this->applyRestrictions($query);
2019-11-04 17:30:56 -05:00
$servicegroup = $query->first();
if ($servicegroup === null) {
throw new NotFoundError(t('Service group not found'));
2019-11-04 17:30:56 -05:00
}
$this->servicegroup = $servicegroup;
}
2019-11-04 17:30:56 -05:00
public function indexAction()
{
$db = $this->getDb();
$services = Service::on($db)->with([
'state',
'host',
'host.state'
])->utilize('servicegroup');
2019-11-04 17:30:56 -05:00
$services->getSelectBase()->where(['service_servicegroup.id = ?' => $this->servicegroup->id]);
$this->applyRestrictions($services);
2019-11-04 17:30:56 -05:00
$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($services);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
2019-11-04 17:30:56 -05:00
$serviceList = (new ServiceList($services))
->setViewMode($viewModeSwitcher->getViewMode());
yield $this->export($services);
$this->addControl((new ServicegroupList([$this->servicegroup]))
->setViewMode('minimal')
->setDetailActionsDisabled()
->setNoSubjectLink());
2019-11-04 17:30:56 -05:00
$this->addControl($paginationControl);
$this->addControl($viewModeSwitcher);
$this->addControl($limitControl);
$this->addContent($serviceList);
$this->setAutorefreshInterval(10);
2019-11-04 17:30:56 -05:00
}
}