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()->single(
55 'do this',
56 $url_builder->withParameter($action_token, "do_something"),
57 $id_token
58 ),
59 'some_other_action' => $f->table()->action()->single(
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 $query = $DIC->http()->wrapper()->query();
74 if ($query->has($action_token->getName())) {
75 $action = $query->retrieve($action_token->getName(), $refinery->to()->string());
76 $ids = $query->retrieve($id_token->getName(), $refinery->custom()->transformation(fn($v) => $v));
77
78 if ($action === 'do_something_else') {
79 $items = [];
80 foreach ($ids as $id) {
81 $items[] = $f->modal()->interruptiveItem()->keyValue($id, $id_token->getName(), $id);
82 }
83 echo($r->renderAsync([
84 $f->modal()->interruptive(
85 'do something else',
86 'affected items',
87 '#'
88 )->withAffectedItems($items)
89 ]));
90 exit();
91 } else {
92 $items = $f->listing()->characteristicValue()->text(
93 [
94 'table_action' => $action,
95 'id' => print_r($ids, true),
96 ]
97 );
98 $result[] = $f->divider()->horizontal();
99 $result[] = $items;
100 }
101 }
102 return $r->render($result);
103}
104
106{
107 $columns = ['f1' => $f->table()->column()->text("Field 1")];
108
109 $data_retrieval = new class () implements I\DataRetrieval {
110 public function getRows(
111 I\DataRowBuilder $row_builder,
112 array $visible_column_ids,
114 Order $order,
115 ?array $filter_data,
116 ?array $additional_parameters
117 ): \Generator {
118 foreach (range(0, 5) as $cnt) {
119 yield $row_builder->buildDataRow('row_id' . $cnt, ['f1' => $cnt]);
120 }
121 }
122
123 public function getTotalRowCount(
124 ?array $filter_data,
125 ?array $additional_parameters
126 ): ?int {
127 return 6;
128 }
129 };
130 return $f->table()->data($data_retrieval, 'a data table with actions', $columns);
131}
$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