ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
external.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
38function external()
39{
40 global $DIC;
41
45 $f = $DIC['ui.factory'];
46
50 $r = $DIC['ui.renderer'];
51
55 $refinery = $DIC['refinery'];
56
57 $df = new \ILIAS\Data\Factory();
58 $request = $DIC->http()->request();
59 $request_wrapper = $DIC->http()->wrapper()->query();
60
61 $columns = [
62 'id' => $f->table()->column()->number("ID"),
63 'letter' => $f->table()->column()->text("Letter")
64 ->withHighlight(true)
65 ];
66
67 $data_retrieval = new class ($f, $r) implements I\OrderingRetrieval {
68 protected array $records;
69
70 public function __construct(
71 protected \ILIAS\UI\Factory $ui_factory,
72 protected \ILIAS\UI\Renderer $ui_renderer
73 ) {
74 $this->records = $this->initRecords();
75 }
76
77 public function getRows(
78 I\OrderingRowBuilder $row_builder,
79 array $visible_column_ids
80 ): \Generator {
81 $records = array_values($this->records);
82 foreach ($this->records as $position_index => $record) {
83 yield $row_builder->buildOrderingRow((string) $record['id'], $record);
84 }
85 }
86
87 protected function initRecords(): array
88 {
89 $r = range(65, 68);
90 shuffle($r);
91
92 foreach ($r as $id) {
93 $records[(string) $id] = ['id' => $id, 'letter' => chr($id)];
94 }
95 return $records;
96 }
97
101 public function setOrder(array $ordered): void
102 {
103 $r = [];
104 foreach ($ordered as $id) {
105 $r[(string) $id] = $this->records[(string) $id];
106 }
107 $this->records = $r;
108 }
109 };
110
111 $out = [];
112
116 $target = (new URI((string) $request->getUri()))->withParameter('ordering_example', 3);
117 $table = $f->table()->ordering($data_retrieval, $target, 'sort the letters', $columns)
118 ->withRequest($request);
119
124 if ($request->getMethod() == "POST"
125 && $request_wrapper->has('ordering_example')
126 && $request_wrapper->retrieve('ordering_example', $refinery->kindlyTo()->int()) === 3
127 ) {
128 $data = $table->withRequest($request)->getData();
129 if ($data === range(65, 68)) {
130 $data_retrieval->setOrder($data);
131 $out[] = $f->messageBox()->success("ok. great ordering!");
132 } else {
133 $out[] = $f->messageBox()->failure("nah. try again.");
134 }
135 }
136 $out[] = $table;
137 return $r->render($out);
138}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$out
Definition: buildRTE.php:24
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26