mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
Introduce class UsergroupDetail
This commit is contained in:
parent
39d0448ff5
commit
784f3481e5
1 changed files with 74 additions and 0 deletions
74
library/Icingadb/Widget/Detail/UsergroupDetail.php
Normal file
74
library/Icingadb/Widget/Detail/UsergroupDetail.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */
|
||||
|
||||
namespace Icinga\Module\Icingadb\Widget\Detail;
|
||||
|
||||
use Icinga\Module\Icingadb\Common\Auth;
|
||||
use Icinga\Module\Icingadb\Common\Links;
|
||||
use Icinga\Module\Icingadb\Model\Usergroup;
|
||||
use Icinga\Module\Icingadb\Widget\EmptyState;
|
||||
use Icinga\Module\Icingadb\Widget\ItemList\UserList;
|
||||
use Icinga\Module\Icingadb\Widget\ShowMore;
|
||||
use ipl\Html\BaseHtmlElement;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Html\Text;
|
||||
|
||||
class UsergroupDetail extends BaseHtmlElement
|
||||
{
|
||||
use Auth;
|
||||
|
||||
/** @var Usergroup The given user group */
|
||||
protected $usergroup;
|
||||
|
||||
protected $defaultAttributes = ['class' => 'usergroup-detail'];
|
||||
|
||||
protected $tag = 'div';
|
||||
|
||||
public function __construct(Usergroup $usergroup)
|
||||
{
|
||||
$this->usergroup = $usergroup;
|
||||
}
|
||||
|
||||
protected function createCustomVars()
|
||||
{
|
||||
$content = [new HtmlElement('h2', null, Text::create(t('Custom Variables')))];
|
||||
$flattenedVars = $this->usergroup->customvar_flat;
|
||||
$this->applyRestrictions($flattenedVars);
|
||||
|
||||
$vars = $this->usergroup->customvar_flat->getModel()->unflattenVars($flattenedVars);
|
||||
if (! empty($vars)) {
|
||||
$customvarTable = new CustomVarTable($vars);
|
||||
$customvarTable->setAttribute('id', 'usergroup-customvars');
|
||||
$content[] = $customvarTable;
|
||||
} else {
|
||||
$content[] = new EmptyState(t('No custom variables configured.'));
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function createUserList()
|
||||
{
|
||||
$users = $this->usergroup->user->limit(6)->peekAhead()->execute();
|
||||
|
||||
$showMoreLink = new ShowMore(
|
||||
$users,
|
||||
Links::users()->addParams(['usergroup.name' => $this->usergroup->name])
|
||||
);
|
||||
|
||||
return [
|
||||
new HtmlElement('h2', null, Text::create(t('Users'))),
|
||||
new UserList($users),
|
||||
$showMoreLink
|
||||
];
|
||||
}
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
$this->add([
|
||||
$this->createUserList(),
|
||||
$this->createCustomVars()
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue