ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
base.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use Psr\Http\Message\ServerRequestInterface;
28
41function base()
42{
43 global $DIC;
44
48 $f = $DIC['ui.factory'];
49
53 $r = $DIC['ui.renderer'];
54
58 $refinery = $DIC['refinery'];
59 $df = new \ILIAS\Data\Factory();
60 $request = $DIC->http()->request();
61 $request_wrapper = $DIC->http()->wrapper()->query();
62
66 $columns = [
67 'word' => $f->table()->column()->text("Word")
68 ->withHighlight(true),
69 'phrase' => $f->table()->column()->text("Phrase")
70 ->withIsOptional(true, false)
71 ];
72
78 $url_builder = new URLBuilder($df->uri($request->getUri()->__toString()));
79 $query_params_namespace = ['orderingtable', 'example'];
80 list($url_builder, $action_parameter_token, $row_id_token) = $url_builder->acquireParameters(
81 $query_params_namespace,
82 "table_action",
83 "ids"
84 );
85 $actions = [
86 $f->table()->action()->standard(
87 'Properties',
88 $url_builder->withParameter($action_parameter_token, "edit"),
89 $row_id_token
90 )
91 ];
92
93
97 $data_retrieval = new class ($f, $r) implements I\OrderingRetrieval {
98 protected array $records;
99
100 public function __construct(
101 protected \ILIAS\UI\Factory $ui_factory,
102 protected \ILIAS\UI\Renderer $ui_renderer
103 ) {
104 $this->records = $this->initRecords();
105 }
106
107 public function getRows(
108 I\OrderingRowBuilder $row_builder,
109 array $visible_column_ids
110 ): \Generator {
111 $records = array_values($this->records);
112 foreach ($this->records as $position_index => $record) {
113 $row_id = (string) $record['id'];
114 yield $row_builder->buildOrderingRow($row_id, $record);
115 }
116 }
117
118 protected function initRecords(): array
119 {
120 $r = [
121 ['A is for apple', 'it’s red and its green'],
122 ['B is for ball', 'and it bounces between'],
123 ['C is for cat', 'it’s licking its paws'],
124 ['D is for dog', 'it loves playing with balls'],
125 ['E is for elephant', 'bigger than me'],
126 ['F is for fish', 'he’s missing the sea'],
127 ['G for gorilla', 'he’s big and he’s strong'],
128 ['H is for home', 'and that’s where I belong'],
129 ['I is for insect', 'flying around'],
130 ['J is for jumping', 'jump up and down'],
131 ];
132 shuffle($r);
133
134 foreach ($r as $record) {
135 list($word, $phrase) = $record;
136 $id = substr($word, 0, 1);
137 $records[$id] = [
138 'id' => $id,
139 'word' => $word,
140 'phrase' => $phrase,
141 ];
142 }
143 return $records;
144 }
145
149 public function setOrder(array $ordered): void
150 {
151 $r = [];
152 foreach ($ordered as $id) {
153 $r[(string) $id] = $this->records[(string) $id];
154 }
155 $this->records = $r;
156 }
157
158 };
159
160 $target = (new URI((string) $request->getUri()))->withParameter('ordering_example', 1);
161 $table = $f->table()->ordering($data_retrieval, $target, 'ordering table', $columns)
162 ->withActions($actions)
163 ->withRequest($request);
164
165 $out = [];
166 if ($request->getMethod() == "POST"
167 && $request_wrapper->has('ordering_example')
168 && $request_wrapper->retrieve('ordering_example', $refinery->kindlyTo()->int()) === 1
169 ) {
170 if ($data = $table->getData()) {
171 $out[] = $f->legacy()->content('<pre>' . print_r($data, true) . '</pre>');
172 }
173 $data_retrieval->setOrder($data);
174 }
175
176 $out[] = $table;
177 return $r->render($out);
178}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$out
Definition: buildRTE.php:24
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Definition: UI.php:24
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26