ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
external.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 
22 function external()
23 {
24  global $DIC;
25 
29  $f = $DIC['ui.factory'];
30 
34  $r = $DIC['ui.renderer'];
35 
39  $refinery = $DIC['refinery'];
40 
41  $df = new \ILIAS\Data\Factory();
42  $request = $DIC->http()->request();
43  $request_wrapper = $DIC->http()->wrapper()->query();
44 
45  $columns = [
46  'id' => $f->table()->column()->number("ID"),
47  'letter' => $f->table()->column()->text("Letter")
48  ->withHighlight(true)
49  ];
50 
51  $data_retrieval = new class ($f, $r) implements I\OrderingBinding {
52  protected array $records;
53 
54  public function __construct(
55  protected \ILIAS\UI\Factory $ui_factory,
56  protected \ILIAS\UI\Renderer $ui_renderer
57  ) {
58  $this->records = $this->initRecords();
59  }
60 
61  public function getRows(
62  I\OrderingRowBuilder $row_builder,
63  array $visible_column_ids
64  ): \Generator {
65  $records = array_values($this->records);
66  foreach ($this->records as $position_index => $record) {
67  yield $row_builder->buildOrderingRow((string) $record['id'], $record);
68  }
69  }
70 
71  protected function initRecords(): array
72  {
73  $r = range(65, 68);
74  shuffle($r);
75 
76  foreach ($r as $id) {
77  $records[(string) $id] = ['id' => $id, 'letter' => chr($id)];
78  }
79  return $records;
80  }
81 
85  public function setOrder(array $ordered): void
86  {
87  $r = [];
88  foreach ($ordered as $id) {
89  $r[(string) $id] = $this->records[(string) $id];
90  }
91  $this->records = $r;
92  }
93  };
94 
95  $out = [];
96 
100  $target = (new URI((string) $request->getUri()))->withParameter('ordering_example', 3);
101  $table = $f->table()->ordering('sort the letters', $columns, $data_retrieval, $target)
102  ->withRequest($request);
103 
108  if ($request->getMethod() == "POST"
109  && $request_wrapper->has('ordering_example')
110  && $request_wrapper->retrieve('ordering_example', $refinery->kindlyTo()->int()) === 3
111  ) {
112  $data = $table->withRequest($request)->getData();
113  if ($data === range(65, 68)) {
114  $data_retrieval->setOrder($data);
115  $out[] = $f->messageBox()->success("ok. great ordering!");
116  } else {
117  $out[] = $f->messageBox()->failure("nah. try again.");
118  }
119  }
120  $out[] = $table;
121  return $r->render($out);
122 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider .
global $DIC
Definition: feed.php:28
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
$out
Definition: buildRTE.php:24
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$r
Refinery Factory $refinery