ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
base.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
12 
13 function base()
14 {
15  global $DIC;
16  $f = $DIC['ui.factory'];
17  $r = $DIC['ui.renderer'];
18  $df = new \ILIAS\Data\Factory();
19  $refinery = $DIC['refinery'];
20 
21  //define multi actions for the table
22  $here_uri = $df->uri($DIC->http()->request()->getUri()->__toString());
23  $url_builder = new URLBuilder($here_uri);
24  $query_params_namespace = ['datatable', 'example'];
25  list($url_builder, $id_token, $action_token) = $url_builder->acquireParameters(
26  $query_params_namespace,
27  "relay_param",
28  "demo_table_action"
29  );
30 
31  $actions = [
32  'some_action' => $f->table()->action()->multi(
33  'do this',
34  $url_builder->withParameter($action_token, "do_something"),
35  $id_token
36  ),
37  'some_other_action' => $f->table()->action()->multi(
38  'do something else',
39  $url_builder->withParameter($action_token, "do_something_else"),
40  $id_token
41  )->withAsync(),
42  ];
43 
44  $table = getExampleTable($f)
45  ->withActions($actions)
46  ->withRequest($DIC->http()->request());
47 
48 
49  //render table and results
50  $result = [$table];
51 
52  $query = $DIC->http()->wrapper()->query();
53  if ($query->has($action_token->getName())) {
54  $action = $query->retrieve($action_token->getName(), $refinery->to()->string());
55  $ids = $query->retrieve($id_token->getName(), $refinery->custom()->transformation(fn ($v) => $v));
56 
57  if ($action === 'do_something_else') {
58  $items = [];
59  $ids = explode(',', $ids);
60  foreach ($ids as $id) {
61  $items[] = $f->modal()->interruptiveItem()->keyValue($id, $id_token->getName(), $id);
62  }
63  echo($r->renderAsync([
64  $f->modal()->interruptive(
65  'do something else',
66  'affected items',
67  '#'
68  )->withAffectedItems($items)
69  ]));
70  exit();
71  } else {
72  $items = $f->listing()->characteristicValue()->text(
73  [
74  'table_action' => $action,
75  'id' => print_r($ids, true),
76  ]
77  );
78  $result[] = $f->divider()->horizontal();
79  $result[] = $items;
80  }
81  }
82 
83  return $r->render($result);
84 }
85 
87 {
88  $columns = ['f1' => $f->table()->column()->text("Field 1")];
89 
90  $data_retrieval = new class () implements I\DataRetrieval {
91  public function getRows(
92  I\DataRowBuilder $row_builder,
93  array $visible_column_ids,
94  Range $range,
95  Order $order,
96  ?array $filter_data,
97  ?array $additional_parameters
98  ): \Generator {
99  foreach (range(0, 5) as $cnt) {
100  yield $row_builder->buildDataRow('row_id' . $cnt, ['f1' => $cnt]);
101  }
102  }
103 
104  public function getTotalRowCount(
105  ?array $filter_data,
106  ?array $additional_parameters
107  ): ?int {
108  return 6;
109  }
110  };
111  return $f->table()->data('a data table with actions', $columns, $data_retrieval);
112 }
exit
Definition: login.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:12
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query
uri(string $uri_string)
Object representing an uri valid according to RFC 3986 with restrictions imposed on valid characters ...
Definition: Factory.php:68
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
URLBuilder.
Definition: URLBuilder.php:39
A simple class to express a range of whole positive numbers.
Definition: Range.php:30
Refinery Factory $refinery