ILIAS  release_8 Revision v8.24
class.ilLSPlayer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
28
33{
34 public const PARAM_LSO_COMMAND = 'lsocmd';
35 public const PARAM_LSO_PARAMETER = 'lsov';
36
37 public const LSO_CMD_NEXT = 'lsonext'; //with param directions
38 public const LSO_CMD_GOTO = 'lsogoto'; //with param ref_id
39 public const LSO_CMD_SUSPEND = 'lsosuspend';
40 public const LSO_CMD_FINISH = 'lsofinish';
41
42 public const GS_DATA_LS_KIOSK_MODE = 'ls_kiosk_mode';
43 public const GS_DATA_LS_CONTENT = 'ls_content';
44 public const GS_DATA_LS_MAINBARCONTROLS = 'ls_mainbar_controls';
45 public const GS_DATA_LS_METABARCONTROLS = 'ls_metabar_controls';
46
55 protected Refinery\Factory $refinery;
56
57 public function __construct(
63 ilKioskPageRenderer $renderer,
66 Refinery\Factory $refinery
67 ) {
68 $this->ls_items = $ls_items;
69 $this->control_builder = $control_builder;
70 $this->url_builder = $url_builder;
71 $this->curriculum_builder = $curriculum_builder;
72 $this->view_factory = $view_factory;
73 $this->page_renderer = $renderer;
74 $this->ui_factory = $ui_factory;
75 $this->current_context = $current_context;
76 $this->refinery = $refinery;
77 }
78
79 public function play(RequestWrapper $get): ?string
80 {
81 //init state and current item
82 $items = $this->ls_items->getItems();
83
84 if (count($items) === 0) {
85 return null;
86 }
87
88 $current_item = $this->getCurrentItem($items);
89
90 while ($current_item->getAvailability() !== Step::AVAILABLE) {
91 $prev_item = $this->getNextItem($items, $current_item, -1);
92 if ($prev_item === $current_item) {
93 throw new \Exception("Cannot view first LSO-item", 1);
94 }
95 $current_item = $prev_item;
96 }
97
98 $view = $this->view_factory->getViewFor($current_item);
99 $state = $this->ls_items->getStateFor($current_item, $view);
100 $state = $this->updateViewState($state, $view, $get);
101 //reload items after update viewState
102 $items = $this->ls_items->getItems();
103
104 $current_item_ref_id = $current_item->getRefId();
105 //now, digest parameter:
106 $command = null;
107 if ($get->has(self::PARAM_LSO_COMMAND)) {
108 $command = $get->retrieve(self::PARAM_LSO_COMMAND, $this->refinery->kindlyTo()->string());
109 }
110 $param = null;
111 if ($get->has(self::PARAM_LSO_PARAMETER)) {
112 $param = $get->retrieve(self::PARAM_LSO_PARAMETER, $this->refinery->kindlyTo()->int());
113 }
114
115 switch ($command) {
118 $this->ls_items->storeState($state, $current_item_ref_id, $current_item_ref_id);
119 return 'EXIT::' . $command;
121 $next_item = $this->getNextItem($items, $current_item, $param);
122 if ($next_item->getAvailability() !== Step::AVAILABLE) {
123 $next_item = $current_item;
124 }
125 break;
127 list(, $next_item) = $this->findItemByRefId($items, $param);
128 break;
129 default: //view-internal / unknown command
130 $next_item = $current_item;
131 }
132 //write State to DB
133 $this->ls_items->storeState($state, $current_item_ref_id, $next_item->getRefId());
134
135 //get proper view
136 if ($next_item != $current_item) {
137 $view = $this->view_factory->getViewFor($next_item);
138 $state = $this->ls_items->getStateFor($next_item, $view);
139 }
140
141 //content
142 $obj_title = $next_item->getTitle();
143 $icon = $this->ui_factory->symbol()->icon()->standard(
144 $next_item->getType(),
145 $next_item->getType(),
146 'medium'
147 );
148
149 $content = $this->renderComponentView($state, $view);
150
151 $panel = $this->ui_factory->panel()->standard(
152 '',
153 $content
154 );
155 $content = [$panel];
156
157 $items = $this->ls_items->getItems(); //reload items after renderComponentView content
158
159 //get position
160 list($item_position, $item) = $this->findItemByRefId($items, $next_item->getRefId());
161
162 //have the view build controls
164 $view->buildControls($state, $control_builder);
165
166 //amend controls not set by the view
167 $control_builder = $this->buildDefaultControls($control_builder, $item, $item_position, $items);
168
169 $rendered_body = $this->page_renderer->render(
171 $obj_title,
172 $icon,
173 $content
174 );
175
176 $metabar_controls = [
178 ];
179
180 $curriculum_slate = $this->page_renderer->buildCurriculumSlate(
181 $this->curriculum_builder
182 ->getLearnerCurriculum(true)
183 ->withActive($item_position)
184 );
185 $mainbar_controls = [
186 'curriculum' => $curriculum_slate
187 ];
188
189 $toc = $control_builder->getToc();
190 if ($toc) {
191 $toc_slate = $this->page_renderer->buildToCSlate($toc, $icon);
192 $mainbar_controls['toc'] = $toc_slate;
193 }
194
196 $cc->addAdditionalData(self::GS_DATA_LS_KIOSK_MODE, true);
197 $cc->addAdditionalData(self::GS_DATA_LS_METABARCONTROLS, $metabar_controls);
198 $cc->addAdditionalData(self::GS_DATA_LS_MAINBARCONTROLS, $mainbar_controls);
199 $cc->addAdditionalData(self::GS_DATA_LS_CONTENT, $rendered_body);
200
201 return null;
202 }
203
207 protected function getCurrentItem(array $items): LSLearnerItem
208 {
209 $current_item = $items[0];
210 $current_item_ref_id = $this->ls_items->getCurrentItemRefId();
211 if ($current_item_ref_id !== 0) {
212 $valid_ref_ids = array_map(
213 fn ($item) => $item->getRefId(),
214 array_values($this->ls_items->getItems())
215 );
216 if (in_array($current_item_ref_id, $valid_ref_ids)) {
217 list(, $current_item) = $this->findItemByRefId($items, $current_item_ref_id);
218 }
219 }
220 return $current_item;
221 }
222
223 protected function updateViewState(
224 ILIAS\KioskMode\State $state,
225 ILIAS\KioskMode\View $view,
226 RequestWrapper $get
227 ): ILIAS\KioskMode\State {
228 if ($get->has(self::PARAM_LSO_COMMAND) && $get->has(self::PARAM_LSO_PARAMETER)) {
229 $command = $get->retrieve(self::PARAM_LSO_COMMAND, $this->refinery->kindlyTo()->string());
230 $param = $get->retrieve(self::PARAM_LSO_PARAMETER, $this->refinery->kindlyTo()->int());
231 $state = $view->updateGet($state, $command, $param);
232 }
233 return $state;
234 }
235
239 protected function getNextItem(array $items, LSLearnerItem $current_item, int $direction): LSLearnerItem
240 {
241 list($position) = $this->findItemByRefId($items, $current_item->getRefId());
242 $next = $position + $direction;
243 if ($next >= 0 && $next < count($items)) {
244 return $items[$next];
245 }
246 return $current_item;
247 }
248
252 protected function findItemByRefId(array $items, int $ref_id): array
253 {
254 foreach ($items as $index => $item) {
255 if ($item->getRefId() === $ref_id) {
256 return [$index, $item];
257 }
258 }
259 throw new \Exception("This is not a valid item.", 1);
260 }
261
262 protected function buildDefaultControls(
263 LSControlBuilder $control_builder,
264 LSLearnerItem $item,
265 int $item_position,
266 array $items
267 ): ControlBuilder {
268 $is_first = $item_position === 0;
269 $is_last = $item_position === count($items) - 1;
270
271 if (!$control_builder->getExitControl()) {
272 $cmd = self::LSO_CMD_SUSPEND;
273 if ($is_last) {
274 $cmd = self::LSO_CMD_FINISH;
275 }
276 $control_builder = $control_builder->exit($cmd);
277 }
278
279 if (!$control_builder->getPreviousControl()) {
280 $direction_prev = -1;
281 $cmd = ''; //disables control
282
283 if (!$is_first) {
284 $available = $this->getNextItem($items, $item, $direction_prev)
285 ->getAvailability() === Step::AVAILABLE;
286
287 if ($available) {
288 $cmd = self::LSO_CMD_NEXT;
289 }
290 }
291
292 $control_builder = $control_builder
293 ->previous($cmd, $direction_prev);
294 }
295
296 if (!$control_builder->getNextControl()) {
297 $direction_next = 1;
298 $cmd = '';
299 if (!$is_last) {
300 $available = $this->getNextItem($items, $item, $direction_next)
301 ->getAvailability() === Step::AVAILABLE;
302
303 if ($available) {
304 $cmd = self::LSO_CMD_NEXT;
305 }
306 }
307
308 $control_builder = $control_builder
309 ->next($cmd, $direction_next);
310 }
311
312 return $control_builder;
313 }
314
315 protected function renderComponentView($state, ILIAS\KioskMode\View $view): Component
316 {
317 return $view->render(
318 $state,
319 $this->ui_factory,
320 $this->url_builder,
321 []
322 );
323 }
324
325
327 {
328 $item = $this->getCurrentItem($this->ls_items->getItems());
329 return $item->getLearningProgressStatus();
330 }
331}
Builds data types.
Definition: Factory.php:21
previous(string $command, int $parameter=null)
A previous control allows the user to go back to the previous item in the object.
exit(string $command)
An exit control allows the user to gracefully leave the object providing the kiosk mode.
next(string $command, int $parameter=null)
A next control allows the user to progress to the next item in the object.
getRefId()
Definition: LSItem.php:90
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This combines calls to ProgressDB and StateDB to handle learner-items in the context of a specific LS...
Implementation of KioskMode Player.
ilLSViewFactory $view_factory
findItemByRefId(array $items, int $ref_id)
const PARAM_LSO_COMMAND
ilLSLearnerItemsQueries $ls_items
renderComponentView($state, ILIAS\KioskMode\View $view)
ilLSCurriculumBuilder $curriculum_builder
Refinery Factory $refinery
const LSO_CMD_SUSPEND
play(RequestWrapper $get)
LSUrlBuilder $url_builder
const GS_DATA_LS_KIOSK_MODE
getNextItem(array $items, LSLearnerItem $current_item, int $direction)
$direction is either -1 or 1;
const GS_DATA_LS_MAINBARCONTROLS
Factory $ui_factory
__construct(ilLSLearnerItemsQueries $ls_items, LSControlBuilder $control_builder, LSUrlBuilder $url_builder, ilLSCurriculumBuilder $curriculum_builder, ilLSViewFactory $view_factory, ilKioskPageRenderer $renderer, Factory $ui_factory, ScreenContext $current_context, Refinery\Factory $refinery)
const LSO_CMD_FINISH
getCurrentItemLearningProgress()
ScreenContext $current_context
const PARAM_LSO_PARAMETER
updateViewState(ILIAS\KioskMode\State $state, ILIAS\KioskMode\View $view, RequestWrapper $get)
LSControlBuilder $control_builder
ilKioskPageRenderer $page_renderer
buildDefaultControls(LSControlBuilder $control_builder, LSLearnerItem $item, int $item_position, array $items)
getCurrentItem(array $items)
const GS_DATA_LS_METABARCONTROLS
const GS_DATA_LS_CONTENT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
if(isset($_FILES['img_file']) &&is_array($_FILES['img_file'])) $panel
Definition: imgupload.php:198
Interface RequestWrapper.
retrieve(string $key, Transformation $transformation)
Build controls for the view.
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This describes a Workflow Step.
Definition: Step.php:30
This is how the factory for UI elements looks.
Definition: Factory.php:38
$ref_id
Definition: ltiauth.php:67
$index
Definition: metadata.php:145
has(string $class_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ByTrying.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
$param
Definition: xapitoken.php:46