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