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