mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
Introduce class UserDetail
This commit is contained in:
parent
2f8bb8bb6c
commit
39d0448ff5
1 changed files with 85 additions and 0 deletions
85
library/Icingadb/Widget/Detail/UserDetail.php
Normal file
85
library/Icingadb/Widget/Detail/UserDetail.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?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\User;
|
||||
use Icinga\Module\Icingadb\Widget\EmptyState;
|
||||
use Icinga\Module\Icingadb\Widget\HorizontalKeyValue;
|
||||
use Icinga\Module\Icingadb\Widget\ItemList\UsergroupList;
|
||||
use Icinga\Module\Icingadb\Widget\ShowMore;
|
||||
use ipl\Html\BaseHtmlElement;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Html\Text;
|
||||
|
||||
class UserDetail extends BaseHtmlElement
|
||||
{
|
||||
use Auth;
|
||||
|
||||
/** @var User The given user */
|
||||
protected $user;
|
||||
|
||||
protected $defaultAttributes = ['class' => 'user-detail'];
|
||||
|
||||
protected $tag = 'div';
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
protected function createCustomVars()
|
||||
{
|
||||
$content = [new HtmlElement('h2', null, Text::create(t('Custom Variables')))];
|
||||
$flattenedVars = $this->user->customvar_flat;
|
||||
$this->applyRestrictions($flattenedVars);
|
||||
|
||||
$vars = $this->user->customvar_flat->getModel()->unflattenVars($flattenedVars);
|
||||
if (! empty($vars)) {
|
||||
$customvarTable = new CustomVarTable($vars);
|
||||
$customvarTable->setAttribute('id', 'user-customvars');
|
||||
$content[] = $customvarTable;
|
||||
} else {
|
||||
$content[] = new EmptyState(t('No custom variables configured.'));
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function createUserDetail()
|
||||
{
|
||||
return [
|
||||
new HtmlElement('h2', null, Text::create(t('Details'))),
|
||||
new HorizontalKeyValue(t('E-Mail'), $this->user->email),
|
||||
new HorizontalKeyValue(t('Pager'), $this->user->pager)
|
||||
];
|
||||
}
|
||||
|
||||
protected function createUsergroupList()
|
||||
{
|
||||
$userGroups = $this->user->usergroup->limit(6)->peekAhead()->execute();
|
||||
|
||||
$showMoreLink = new ShowMore(
|
||||
$userGroups,
|
||||
Links::usergroups()->addParams(['user.name' => $this->user->name])
|
||||
);
|
||||
|
||||
return [
|
||||
new HtmlElement('h2', null, Text::create(t('Groups'))),
|
||||
new UsergroupList($userGroups),
|
||||
$showMoreLink
|
||||
];
|
||||
}
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
$this->add([
|
||||
$this->createUserDetail(),
|
||||
$this->createUsergroupList(),
|
||||
$this->createCustomVars()
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue