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