ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
TableActions.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Refinery\Factory as Refinery;
30use ILIAS\UI\Factory as UIFactory;
31use ILIAS\UI\Renderer as UIRenderer;
34use ilLanguage;
35
37{
41 public function __construct(
42 protected readonly ilCtrlInterface $ctrl,
43 protected readonly ilLanguage $lng,
44 protected readonly ilGlobalTemplateInterface $tpl,
45 protected readonly UIFactory $ui_factory,
46 protected readonly UIRenderer $ui_renderer,
47 protected readonly Refinery $refinery,
48 protected readonly HttpService $http,
49 protected readonly array $actions
50 ) {
51 }
52
53 public function getEnabledActions(
54 URLBuilder $url_builder,
55 URLBuilderToken $row_id_token,
56 URLBuilderToken $action_token,
57 URLBuilderToken $action_type_token
58 ): array {
59 return array_filter(
60 array_map(
61 static fn(TableAction $action): ?Action => $action->isAvailable()
62 ? $action->getTableAction($url_builder, $row_id_token, $action_token, $action_type_token)
63 : null,
64 $this->actions
65 )
66 );
67 }
68
69 public function execute(
70 URLBuilder $url_builder,
71 URLBuilderToken $row_id_token,
72 URLBuilderToken $action_token,
73 URLBuilderToken $action_type_token
74 ): ?Modal {
75 if (!$this->http->has($action_token->getName())) {
76 return null;
77 }
78
79 $action_id = $this->http->resolveRowParameter($action_token->getName());
80 $action = $this->actions[$action_id] ?? null;
81 if ($action === null) {
82 return null;
83 }
84
85 $response = $action->onExecute($url_builder, $row_id_token, $action_token, $action_type_token);
86
87 return $response instanceof Modal ? $response : null;
88 }
89
90 public function onDataRow(DataRow $row, mixed $record): DataRow
91 {
92 foreach ($this->actions as $action_id => $action) {
93 if ($action->allowActionForRecord($record)) {
94 continue;
95 }
96
97 $row = $row->withDisabledAction($action_id);
98 }
99
100 return $row;
101 }
102}
onDataRow(DataRow $row, mixed $record)
execute(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
getEnabledActions(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
__construct(protected readonly ilCtrlInterface $ctrl, protected readonly ilLanguage $lng, protected readonly ilGlobalTemplateInterface $tpl, protected readonly UIFactory $ui_factory, protected readonly UIRenderer $ui_renderer, protected readonly Refinery $refinery, protected readonly HttpService $http, protected readonly array $actions)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
language handling
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes commonalities between the different modals.
Definition: Modal.php:35
withDisabledAction(string $action_id, bool $disable=true)
Refer to an Action by its id and disable it for this row/record only.
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
has(string $class_name)
global $lng
Definition: privfeed.php:26
if(!file_exists('../ilias.ini.php'))
$response
Definition: xapitoken.php:90