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 
11 use ILIAS\Data\URI;
12 
25 function base()
26 {
27  global $DIC;
28 
32  $f = $DIC['ui.factory'];
33 
37  $r = $DIC['ui.renderer'];
38 
42  $refinery = $DIC['refinery'];
43  $df = new \ILIAS\Data\Factory();
44  $request = $DIC->http()->request();
45  $request_wrapper = $DIC->http()->wrapper()->query();
46 
50  $columns = [
51  'word' => $f->table()->column()->text("Word")
52  ->withHighlight(true),
53  'phrase' => $f->table()->column()->text("Phrase")
54  ->withIsOptional(true, false)
55  ];
56 
62  $url_builder = new URLBuilder($df->uri($request->getUri()->__toString()));
63  $query_params_namespace = ['orderingtable', 'example'];
64  list($url_builder, $action_parameter_token, $row_id_token) = $url_builder->acquireParameters(
65  $query_params_namespace,
66  "table_action",
67  "ids"
68  );
69  $actions = [
70  $f->table()->action()->standard(
71  'Properties',
72  $url_builder->withParameter($action_parameter_token, "edit"),
73  $row_id_token
74  )
75  ];
76 
77 
81  $data_retrieval = new class ($f, $r) implements I\OrderingBinding {
82  protected array $records;
83 
84  public function __construct(
85  protected \ILIAS\UI\Factory $ui_factory,
86  protected \ILIAS\UI\Renderer $ui_renderer
87  ) {
88  $this->records = $this->initRecords();
89  }
90 
91  public function getRows(
92  I\OrderingRowBuilder $row_builder,
93  array $visible_column_ids
94  ): \Generator {
95  $records = array_values($this->records);
96  foreach ($this->records as $position_index => $record) {
97  $row_id = (string) $record['id'];
98  yield $row_builder->buildOrderingRow($row_id, $record);
99  }
100  }
101 
102  protected function initRecords(): array
103  {
104  $r = [
105  ['A is for apple', 'it’s red and its green'],
106  ['B is for ball', 'and it bounces between'],
107  ['C is for cat', 'it’s licking its paws'],
108  ['D is for dog', 'it loves playing with balls'],
109  ['E is for elephant', 'bigger than me'],
110  ['F is for fish', 'he’s missing the sea'],
111  ['G for gorilla', 'he’s big and he’s strong'],
112  ['H is for home', 'and that’s where I belong'],
113  ['I is for insect', 'flying around'],
114  ['J is for jumping', 'jump up and down'],
115  ];
116  shuffle($r);
117 
118  foreach ($r as $record) {
119  list($word, $phrase) = $record;
120  $id = substr($word, 0, 1);
121  $records[$id] = [
122  'id' => $id,
123  'word' => $word,
124  'phrase' => $phrase,
125  ];
126  }
127  return $records;
128  }
129 
133  public function setOrder(array $ordered): void
134  {
135  $r = [];
136  foreach ($ordered as $id) {
137  $r[(string) $id] = $this->records[(string) $id];
138  }
139  $this->records = $r;
140  }
141 
142  };
143 
144  $target = (new URI((string) $request->getUri()))->withParameter('ordering_example', 1);
145  $table = $f->table()->ordering('ordering table', $columns, $data_retrieval, $target)
146  ->withActions($actions)
147  ->withRequest($request);
148 
149  $out = [];
150  if ($request->getMethod() == "POST"
151  && $request_wrapper->has('ordering_example')
152  && $request_wrapper->retrieve('ordering_example', $refinery->kindlyTo()->int()) === 1
153  ) {
154  if ($data = $table->getData()) {
155  $out[] = $f->legacy('<pre>' . print_r($data, true) . '</pre>');
156  }
157  $data_retrieval->setOrder($data);
158  }
159 
160  $out[] = $table;
161  return $r->render($out);
162 }
Interface Observer Contains several chained tasks and infos about them.
This is how the factory for UI elements looks.
Definition: Factory.php:37
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
$out
Definition: buildRTE.php:24
global $DIC
Definition: shib_login.php:25
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
base()
description: > Example performing a page reload if switching between sections of some data...
Definition: base.php:20
URLBuilder.
Definition: URLBuilder.php:39
$r