ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUserActionGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\UI\Factory as UIFactory;
24
30{
33
34 public function __construct(
35 private ilUserActionProviderFactory $user_action_provider_factory,
36 private ilUserActionContext $user_action_context,
37 private ilGlobalTemplateInterface $tpl,
38 private UIFactory $ui_factory,
39 private Renderer $ui_renderer,
40 private Language $lng,
41 ilDBInterface $db,
42 int $user_id
43 ) {
44 $this->lng->loadLanguageModule('usr');
45 $this->user_action_admin = new ilUserActionAdmin($db);
46 $this->user_action_collector = new ilUserActionCollector(
50 new ilUserActionAdmin($db)
51 );
52 }
53
54 public function init(): void
55 {
56 foreach ($this->user_action_provider_factory->getProviders() as $prov) {
57 foreach (array_keys($prov->getActionTypes()) as $act_type) {
58 if ($this->user_action_admin->isActionActive(
59 $this->user_action_context->getComponentId(),
60 $this->user_action_context->getContextId(),
61 $prov->getComponentId(),
62 $act_type
63 )) {
64 foreach ($prov->getJsScripts($act_type) as $script) {
65 $this->tpl->addJavaScript($script);
66 }
67 }
68 }
69 }
70 }
71
72 public function renderDropDown(int $target_user_id): string
73 {
74 $action_collection = $this->user_action_collector->getActionsForTargetUser($target_user_id);
75 $actions = [];
76 foreach ($action_collection->getActions() as $action) {
77 $action_link = $this->ui_factory->link()->standard($action->getText(), $action->getHref());
78 if ($action->getData() !== []) {
79 $data = $action->getData();
80 $action_link = $action_link->withAdditionalOnLoadCode(
81 static function ($id) use ($data): string {
82 $js = '';
83 foreach ($data as $key => $datum) {
84 $js .= "{$id}.setAttribute('data-{$key}', '{$datum}');";
85 }
86 return $js;
87 }
88 );
89 }
90
91 $actions[] = $action_link;
92 }
93 $action_list = $this->ui_factory->dropdown()->standard($actions)
94 ->withAriaLabel($this->lng->txt('user_actions'));
95 return $this->ui_renderer->render($action_list);
96 }
97}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User action administration.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A class that provides a collection of actions on users.
__construct(private ilUserActionProviderFactory $user_action_provider_factory, private ilUserActionContext $user_action_context, private ilGlobalTemplateInterface $tpl, private UIFactory $ui_factory, private Renderer $ui_renderer, private Language $lng, ilDBInterface $db, int $user_id)
renderDropDown(int $target_user_id)
ilUserActionCollector $user_action_collector
ilUserActionAdmin $user_action_admin
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilDBInterface.
global $lng
Definition: privfeed.php:31