ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
external.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 use ILIAS\Data\URI;
26 
38 function 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 }
Interface Observer Contains several chained tasks and infos about them.
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
$out
Definition: buildRTE.php:24
global $DIC
Definition: shib_login.php:22
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$r