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