ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
base.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
35function base()
36{
37 global $DIC;
38 $f = $DIC['ui.factory'];
39 $r = $DIC['ui.renderer'];
40 $df = new \ILIAS\Data\Factory();
41 $refinery = $DIC['refinery'];
42
43 //define multi actions for the table
44 $here_uri = $df->uri($DIC->http()->request()->getUri()->__toString());
45 $url_builder = new URLBuilder($here_uri);
46 $query_params_namespace = ['datatable', 'example'];
47 list($url_builder, $id_token, $action_token) = $url_builder->acquireParameters(
48 $query_params_namespace,
49 "relay_param",
50 "demo_table_action"
51 );
52
53 $actions = [
54 'some_action' => $f->table()->action()->multi(
55 'do this',
56 $url_builder->withParameter($action_token, "do_something"),
57 $id_token
58 ),
59 'some_other_action' => $f->table()->action()->multi(
60 'do something else',
61 $url_builder->withParameter($action_token, "do_something_else"),
62 $id_token
63 )->withAsync(),
64 ];
65
66 $table = getExampleTable($f)
67 ->withActions($actions)
68 ->withRequest($DIC->http()->request());
69
70
71 //render table and results
72 $result = [$table];
73
74 $query = $DIC->http()->wrapper()->query();
75 if ($query->has($action_token->getName())) {
76 $action = $query->retrieve($action_token->getName(), $refinery->to()->string());
77 $ids = $query->retrieve($id_token->getName(), $refinery->custom()->transformation(fn($v) => $v));
78
79 if ($action === 'do_something_else') {
80 $items = [];
81 foreach ($ids as $id) {
82 $items[] = $f->modal()->interruptiveItem()->keyValue($id, $id_token->getName(), $id);
83 }
84 echo($r->renderAsync([
85 $f->modal()->interruptive(
86 'do something else',
87 'affected items',
88 '#'
89 )->withAffectedItems($items)
90 ]));
91 exit();
92 } else {
93 $items = $f->listing()->characteristicValue()->text(
94 [
95 'table_action' => $action,
96 'id' => print_r($ids, true),
97 ]
98 );
99 $result[] = $f->divider()->horizontal();
100 $result[] = $items;
101 }
102 }
103
104 return $r->render($result);
105}
106
108{
109 $columns = ['f1' => $f->table()->column()->text("Field 1")];
110
111 $data_retrieval = new class () implements I\DataRetrieval {
112 public function getRows(
113 I\DataRowBuilder $row_builder,
114 array $visible_column_ids,
116 Order $order,
117 ?array $filter_data,
118 ?array $additional_parameters
119 ): \Generator {
120 foreach (range(0, 5) as $cnt) {
121 yield $row_builder->buildDataRow('row_id' . $cnt, ['f1' => $cnt]);
122 }
123 }
124
125 public function getTotalRowCount(
126 ?array $filter_data,
127 ?array $additional_parameters
128 ): ?int {
129 return 6;
130 }
131 };
132 return $f->table()->data($data_retrieval, 'a data table with actions', $columns);
133}
$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:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
exit
global $DIC
Definition: shib_login.php:26