icingadb-web/application/controllers/ContactgroupsController.php

100 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2019-10-24 08:04:20 -04: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-10-24 08:04:20 -04:00
2020-11-02 08:33:08 -05:00
use GuzzleHttp\Psr7\ServerRequest;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Model\Usergroup;
2020-11-02 08:33:08 -05:00
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemList\ObjectList;
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
use ipl\Web\Control\LimitControl;
use ipl\Web\Control\SortControl;
use ipl\Web\Url;
2019-10-24 08:04:20 -04:00
2025-04-04 09:53:41 -04:00
class ContactgroupsController extends Controller
2019-10-24 08:04:20 -04:00
{
public function init()
{
parent::init();
$this->assertRouteAccess();
}
2019-10-24 08:04:20 -04:00
public function indexAction()
{
2025-04-04 09:53:41 -04:00
$this->addTitleTab(t('Contact Groups'));
2019-10-24 08:04:20 -04:00
$db = $this->getDb();
$usergroups = Usergroup::on($db);
2019-10-24 08:04:20 -04:00
$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($usergroups);
2019-12-11 08:00:26 -05:00
$sortControl = $this->createSortControl(
$usergroups,
[
'usergroup.display_name' => t('Name')
2019-12-11 08:00:26 -05:00
]
);
2020-11-02 08:33:08 -05:00
$searchBar = $this->createSearchBar($usergroups, [
$limitControl->getLimitParam(),
$sortControl->getSortParam()
]);
2019-10-24 08:04:20 -04:00
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
return;
}
} else {
$filter = $searchBar->getFilter();
}
$this->filter($usergroups, $filter);
2019-10-24 08:04:20 -04:00
yield $this->export($usergroups);
$this->addControl($paginationControl);
2019-12-11 08:00:26 -05:00
$this->addControl($sortControl);
2019-10-24 08:04:20 -04:00
$this->addControl($limitControl);
2020-11-02 08:33:08 -05:00
$this->addControl($searchBar);
2019-10-24 08:04:20 -04:00
$this->addContent(
(new ObjectList($usergroups))
->setEmptyStateMessage($paginationControl->getEmptyStateMessage())
);
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
2020-11-02 08:33:08 -05:00
$this->sendMultipartUpdate();
}
$this->setAutorefreshInterval(10);
2019-10-24 08:04:20 -04:00
}
2020-11-02 08:33:08 -05:00
public function completeAction()
{
$suggestions = new ObjectSuggestions();
$suggestions->setModel(Usergroup::class);
$suggestions->forRequest(ServerRequest::fromGlobals());
$this->getDocument()->add($suggestions);
}
public function searchEditorAction()
{
$editor = $this->createSearchEditor(Usergroup::on($this->getDb()), [
LimitControl::DEFAULT_LIMIT_PARAM,
SortControl::DEFAULT_SORT_PARAM,
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM
]);
$this->getDocument()->add($editor);
$this->setTitle(t('Adjust Filter'));
}
2019-10-24 08:04:20 -04:00
}