19declare(strict_types=1);
43 protected \ILIAS\Data\Factory
$df;
45 protected \ilLanguage
$lng;
48 protected \ilCtrlInterface
$ctrl;
49 protected \ILIAS\DI\UIServices
$ui;
57 protected string $title,
59 protected object $parent_gui,
60 protected string $parent_cmd =
"tableCommand",
62 protected string $ordering_cmd =
"",
63 protected ?\Closure $active_action_closure =
null,
64 protected ?\Closure $row_transformer =
null,
65 protected bool $numeric_ids =
true
68 $this->
ui = $DIC->ui();
69 $this->
ctrl = $DIC->ctrl();
70 $this->
http = $DIC->http();
71 $this->
lng = $DIC->language();
73 $this->
user = $DIC->user();
74 $this->df = new \ILIAS\Data\Factory();
77 $this->
namespace = $id;
79 $this->order_cmd = $ordering_cmd;
81 $form_action = $this->df->uri(
82 ILIAS_HTTP_PATH .
'/' .
83 $this->
ctrl->getLinkTarget($this->parent_gui, $this->parent_cmd)
85 $this->url_builder =
new URLBuilder($form_action);
87 $this->url_builder->acquireParameters(
98 bool $sortable =
false
100 $column = $this->
ui->
factory()->table()->column()->text($title)->withIsSortable($sortable);
108 bool $sortable =
false
110 $column = $this->
ui->
factory()->table()->column()->statusIcon($title)->withIsSortable($sortable);
111 $this->addColumn($key, $column);
118 bool $sortable =
false
120 $column = $this->
ui->
factory()->table()->column()->date($title, $this->
user->getDateTimeFormat())->withIsSortable($sortable);
121 $this->addColumn($key, $column);
128 bool $sortable =
false
130 $column = $this->
ui->
factory()->table()->column()->
link($title)->withIsSortable($sortable);
131 $this->addColumn($key, $column);
138 bool $sortable =
false
140 $column = $this->
ui->
factory()->table()->column()->linkListing($title)->withIsSortable($sortable);
141 $this->addColumn($key, $column);
150 $this->addAction(self::SINGLE, $action, $title, $async);
159 string $id_param =
""
161 $this->addAction(self::SINGLE, $action, $title);
162 $act = $this->actions[$this->last_action_key] ??
false;
163 if ($act && $act[
"type"] === self::SINGLE) {
164 $act[
"redirect_class_path"] = $class_path;
165 $act[
"redirect_cmd"] = $cmd;
166 $act[
"redirect_id_param"] = $id_param;
167 $this->actions[$this->last_action_key] = $act;
176 $this->addAction(self::STANDARD, $action, $title);
184 $this->addAction(self::MULTI, $action, $title);
193 $this->filter_data = $filter_data;
197 protected function addAction(
int $type,
string $action,
string $title,
bool $async =
false): void
199 $this->actions[$action] = [
205 $this->last_action_key = $action;
211 throw new \ilException(
"Missing Input Key: " . $key);
213 if (isset($this->columns[$key])) {
214 throw new \ilException(
"Duplicate Input Key: " . $key);
216 $this->columns[$key] = $column;
217 $this->last_key = $key;
222 if (!isset($this->columns[$key])) {
223 throw new \ilException(
"Unknown Key: " . $key);
225 return $this->columns[$key];
230 return $this->columns[$this->last_key] ??
null;
235 if ($this->last_key !==
"") {
236 $this->columns[$this->last_key] = $column;
242 if ($this->numeric_ids) {
243 $ids = $this->
intArray($this->row_id_token->getName());
245 $ids = $this->
strArray($this->row_id_token->getName());
247 if (count($ids) > 0) {
250 if ($this->numeric_ids) {
251 $ids = $this->
intArray(
"interruptive_items");
253 $ids = $this->
strArray(
"interruptive_items");
255 if (count($ids) > 0) {
263 $action = $this->
str($this->action_parameter_token->getName());
264 if ($action !==
"") {
265 if ($this->actions[$action][
"type"] === self::SINGLE) {
266 $id = $this->getItemIds()[0];
267 if ($this->actions[$action][
"redirect_class_path"] ??
false) {
268 $path = $this->actions[$action][
"redirect_class_path"];
269 if ($this->actions[$action][
"redirect_id_param"] ??
false) {
270 $this->
ctrl->setParameterByClass(
272 $this->actions[$action][
"redirect_id_param"],
276 $cmd = $this->actions[$action][
"redirect_cmd"] ?? $action;
277 $this->
ctrl->redirectByClass($this->actions[$action][
"redirect_class_path"], $cmd);
279 $this->parent_gui->$action(
$id);
282 $this->parent_gui->$action($this->getItemIds());
291 $a = $this->
ui->factory()->table()->action();
293 if (is_null($this->table)) {
295 foreach ($this->columns as $key => $column) {
296 $columns[$key] = $column;
299 foreach ($this->actions as $act) {
300 switch ($act[
"type"]) {
302 $actions[$act[
"action"]] =
$a->single(
304 $this->url_builder->withParameter($this->action_parameter_token, $act[
"action"]),
309 $actions[$act[
"action"]] =
$a->standard(
311 $this->url_builder->withParameter($this->action_parameter_token, $act[
"action"]),
316 $actions[$act[
"action"]] =
$a->multi(
318 $this->url_builder->withParameter($this->action_parameter_token, $act[
"action"]),
324 $actions[$act[
"action"]] = $actions[$act[
"action"]]->withAsync(
true);
327 if ($this->order_cmd !==
"") {
328 $uri = $this->df->uri(
329 ILIAS_HTTP_PATH .
'/' .
330 $this->
ctrl->getLinkTarget($this->parent_gui, $this->order_cmd)
334 array_keys($actions),
335 $this->active_action_closure,
336 $this->row_transformer
342 ->ordering($table_retrieval, $uri, $this->title, $columns)
344 ->withActions($actions)
345 ->withRequest($this->
http->request());
349 array_keys($actions),
350 $this->active_action_closure,
351 $this->row_transformer
357 ->data($table_retrieval, $this->title, $columns)
359 ->withActions($actions)
360 ->withRequest($this->
http->request())
361 ->withFilter($this->filter_data);
369 return $this->getTable()->getData();
374 $html = $this->
ui->renderer()->render($this->getTable());
380 string $modal_message,
385 $r = $this->
ui->renderer();
387 foreach ($items as
$id => $title) {
388 if (is_array($title)) {
389 $key = $title[0] ??
"";
390 $val = $title[1] ??
"";
395 $del_items[] =
$f->modal()->interruptiveItem()->keyValue((
string)
$id, $key, $val);
397 $action = $this->
ctrl->getLinkTarget($this->parent_gui, $delete_cmd);
399 echo($r->renderAsync([
400 $f->modal()->interruptive(
404 )->withAffectedItems($del_items)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
URLBuilderToken $action_parameter_token
textColumn(string $key, string $title, bool $sortable=false)
singleAction(string $action, string $title, bool $async=false)
filterData(array $filter_data)
Not applied if the table supports ordering.
renderDeletionConfirmation(string $modal_title, string $modal_message, string $delete_cmd, array $items)
dateColumn(string $key, string $title, bool $sortable=false)
addAction(int $type, string $action, string $title, bool $async=false)
standardAction(string $action, string $title)
__construct(protected string $id, protected string $title, protected RetrievalInterface $retrieval, protected object $parent_gui, protected string $parent_cmd="tableCommand", protected string $namespace="", protected string $ordering_cmd="", protected ?\Closure $active_action_closure=null, protected ?\Closure $row_transformer=null, protected bool $numeric_ids=true)
getColumnForKey(string $key)
singleRedirectAction(string $action, string $title, array $class_path, string $cmd="", string $id_param="")
replaceLastColumn(Column $column)
multiAction(string $action, string $title)
URLBuilderToken $row_id_token
linkListingColumn(string $key, string $title, bool $sortable=false)
addColumn(string $key, Column $column)
linkColumn(string $key, string $title, bool $sortable=false)
iconColumn(string $key, string $title, bool $sortable=false)
trait BaseGUIRequest
Base gui request wrapper.
if($err=$client->getError()) $namespace
A Column describes the form of presentation for a certain aspect of data, i.e.
static http()
Fetches the global http state from ILIAS.
initRequest(HTTP\Services $http, Refinery\Factory $refinery, ?array $passed_query_params=null, ?array $passed_post_data=null)
Query params and post data parameters are used for testing.
link(string $caption, string $href, bool $new_viewport=false)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples