ILIAS  release_8 Revision v8.24
base.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
12
13function base()
14{
15 global $DIC;
16 $f = $DIC['ui.factory'];
17 $r = $DIC['ui.renderer'];
18 $df = new \ILIAS\Data\Factory();
19 $refinery = $DIC['refinery'];
20
21 //define multi actions for the table
22 $here_uri = $df->uri($DIC->http()->request()->getUri()->__toString());
23 $url_builder = new URLBuilder($here_uri);
24 $query_params_namespace = ['datatable', 'example'];
25 list($url_builder, $id_token, $action_token) = $url_builder->acquireParameters(
26 $query_params_namespace,
27 "relay_param",
28 "demo_table_action"
29 );
30
31 $actions = [
32 'some_action' => $f->table()->action()->single(
33 'do this',
34 $url_builder->withParameter($action_token, "do_something"),
35 $id_token
36 ),
37 'some_other_action' => $f->table()->action()->single(
38 'do something else',
39 $url_builder->withParameter($action_token, "do_something_else"),
40 $id_token
41 )->withAsync(),
42 ];
43
44 $table = getExampleTable($f)
45 ->withActions($actions)
46 ->withRequest($DIC->http()->request());
47
48
49 //render table and results
50 $result = [$table];
51 $query = $DIC->http()->wrapper()->query();
52 if ($query->has($action_token->getName())) {
53 $action = $query->retrieve($action_token->getName(), $refinery->to()->string());
54 $ids = $query->retrieve($id_token->getName(), $refinery->custom()->transformation(fn ($v) => $v));
55
56 if ($action === 'do_something_else') {
57 $items = [];
58 $ids = explode(',', $ids);
59 foreach ($ids as $id) {
60 $items[] = $f->modal()->interruptiveItem()->keyValue($id, $id_token->getName(), $id);
61 }
62 echo($r->renderAsync([
63 $f->modal()->interruptive(
64 'do something else',
65 'affected items',
66 '#'
67 )->withAffectedItems($items)
68 ]));
69 exit();
70 } else {
71 $items = $f->listing()->characteristicValue()->text(
72 [
73 'table_action' => $action,
74 'id' => print_r($ids, true),
75 ]
76 );
77 $result[] = $f->divider()->horizontal();
78 $result[] = $items;
79 }
80 }
81 return $r->render($result);
82}
83
85{
86 $columns = ['f1' => $f->table()->column()->text("Field 1")];
87
88 $data_retrieval = new class () implements I\DataRetrieval {
89 public function getRows(
90 I\DataRowBuilder $row_builder,
91 array $visible_column_ids,
92 Range $range,
93 Order $order,
94 ?array $filter_data,
95 ?array $additional_parameters
96 ): \Generator {
97 foreach (range(0, 5) as $cnt) {
98 yield $row_builder->buildDataRow('row_id' . $cnt, ['f1' => $cnt]);
99 }
100 }
101
102 public function getTotalRowCount(
103 ?array $filter_data,
104 ?array $additional_parameters
105 ): ?int {
106 return 6;
107 }
108 };
109 return $f->table()->data('a data table with actions', $columns, $data_retrieval);
110}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:13
A simple class to express a range of whole positive numbers.
Definition: Range.php:31
global $DIC
Definition: feed.php:28
exit
Definition: login.php:28
Refinery Factory $refinery
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...
$query