icingadb-web/application/controllers/ServicegroupController.php

95 lines
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;
use Icinga\Module\Icingadb\Redis\VolatileStateResults;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemList\ServiceList;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Widget\ItemList\ServicegroupList;
use ipl\Html\Html;
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->addTitleTab(t('Service Group'));
2019-11-04 17:30:56 -05:00
$name = $this->params->getRequired('name');
2019-11-04 17:30:56 -05:00
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;
$this->setTitle($servicegroup->display_name);
2019-11-04 17:30:56 -05:00
}
2019-11-04 17:30:56 -05:00
public function indexAction()
{
$db = $this->getDb();
$services = Service::on($db)->with([
'state',
'state.last_comment',
'icon_image',
2019-11-04 17:30:56 -05:00
'host',
'host.state'
])->utilize('servicegroup');
$services->setResultSetClass(VolatileStateResults::class);
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);
// ICINGAWEB_EXPORT_FORMAT is not set yet and $this->format is inaccessible, yeah...
if ($this->getRequest()->getParam('format') === 'pdf') {
$this->addContent((new ServicegroupList([$this->servicegroup]))
->setViewMode('minimal')
->setDetailActionsDisabled()
->setNoSubjectLink());
$this->addContent(Html::tag('h2', null, t('Services')));
} else {
$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
}
}