ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLSPlayer.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
6
13{
14 const PARAM_LSO_COMMAND = 'lsocmd';
15 const PARAM_LSO_PARAMETER = 'lsov';
16
17 const LSO_CMD_NEXT = 'lsonext'; //with param directions
18 const LSO_CMD_GOTO = 'lsogoto'; //with param ref_id
19 const LSO_CMD_SUSPEND = 'lsosuspend';
20 const LSO_CMD_FINISH = 'lsofinish';
21
22
23 const GS_DATA_LS_KIOSK_MODE = 'ls_kiosk_mode';
24 const GS_DATA_LS_CONTENT = 'ls_content';
25 const GS_DATA_LS_MAINBARCONTROLS = 'ls_mainbar_controls';
26 const GS_DATA_LS_METABARCONTROLS = 'ls_metabar_controls';
27
28 public function __construct(
29 string $lso_title,
31 LSControlBuilder $control_builder,
32 LSUrlBuilder $url_builder,
33 ilLSCurriculumBuilder $curriculum_builder,
34 ilLSViewFactory $view_factory,
35 ilKioskPageRenderer $renderer,
36 ILIAS\UI\Factory $ui_factory,
37 ScreenContext $current_context
38 ) {
39 $this->lso_title = $lso_title;
40 $this->ls_items = $ls_items;
41 $this->control_builder = $control_builder;
42 $this->url_builder = $url_builder;
43 $this->curriculum_builder = $curriculum_builder;
44 $this->view_factory = $view_factory;
45 $this->page_renderer = $renderer;
46 $this->ui_factory = $ui_factory;
47 $this->current_context = $current_context;
48 }
49
50 public function play(array $get, array $post = null)
51 {
52 //init state and current item
53 $items = $this->ls_items->getItems();
54 $current_item = $this->getCurrentItem($items);
55 $current_item_ref_id = $current_item->getRefId();
56 $view = $this->view_factory->getViewFor($current_item);
57 $state = $this->ls_items->getStateFor($current_item, $view);
58 $state = $this->updateViewState($state, $view, $get, $post);
59 $items = $this->ls_items->getItems(); //reload items after update viewState
60
61 //now, digest parameter:
63 $param = (int) $_GET[self::PARAM_LSO_PARAMETER];
64
65 switch ($command) {
68 //store state and exit
69 $this->ls_items->storeState($state, $current_item_ref_id, $current_item_ref_id);
70 return 'EXIT::' . $command;
72 $next_item = $this->getNextItem($items, $current_item, $param);
73 break;
75 list($position, $next_item) = $this->findItemByRefId($items, $param);
76 break;
77 default: //view-internal / unknown command
78 $next_item = $current_item;
79 }
80 //write State to DB
81 $this->ls_items->storeState($state, $current_item_ref_id, $next_item->getRefId());
82
83 //get proper view
84 if ($next_item !== $current_item) {
85 $view = $this->view_factory->getViewFor($next_item);
86 $state = $this->ls_items->getStateFor($next_item, $view);
87 }
88
89 //get position
90 list($item_position, $item) = $this->findItemByRefId($items, $next_item->getRefId());
91
92 //have the view build controls
93 $control_builder = $this->control_builder;
94 $view->buildControls($state, $control_builder);
95
96 //amend controls not set by the view
97 $control_builder = $this->buildDefaultControls($control_builder, $item, $item_position, $items);
98
99 //content
100 $obj_title = $next_item->getTitle();
101 $icon = $this->ui_factory->symbol()->icon()
102 ->standard($next_item->getType(), $next_item->getType(), 'medium');
103
104 $content = $this->renderComponentView($state, $view);
105
106 $panel = $this->ui_factory->panel()->standard(
107 '', //panel_title
108 $content
109 );
110 $content = [$panel];
111
112
113 $rendered_body = $this->page_renderer->render(
114 $this->lso_title,
115 $control_builder,
116 $obj_title,
117 $icon,
118 $content
119 );
120
121 $metabar_controls = [
122 'exit' => $control_builder->getExitControl()
123 ];
124
125 //curriculum
126 $curriculum_slate = $this->page_renderer->buildCurriculumSlate(
127 $this->curriculum_builder
128 ->getLearnerCurriculum(true)
129 ->withActive($item_position)
130 );
131 $mainbar_controls = [
132 'curriculum' => $curriculum_slate
133 ];
134
135 //ToC
136 $toc = $control_builder->getToc();
137 if ($toc) {
138 $toc_slate = $this->page_renderer->buildToCSlate($toc, $icon);
139 $mainbar_controls['toc'] = $toc_slate;
140 }
141
142 $cc = $this->current_context;
143 $cc->addAdditionalData(self::GS_DATA_LS_KIOSK_MODE, true);
144 $cc->addAdditionalData(self::GS_DATA_LS_METABARCONTROLS, $metabar_controls);
145 $cc->addAdditionalData(self::GS_DATA_LS_MAINBARCONTROLS, $mainbar_controls);
146 $cc->addAdditionalData(self::GS_DATA_LS_CONTENT, $rendered_body);
147 return;
148 }
149
153 protected function getCurrentItem(array $items) : LSLearnerItem
154 {
155 $current_item = $items[0];
156 $current_item_ref_id = $this->ls_items->getCurrentItemRefId();
157 if ($current_item_ref_id !== 0) {
158 $valid_ref_ids = array_map(
159 function($item) {
160 return $item->getRefId();
161 },
162 array_values($this->ls_items->getItems())
163 );
164 if(in_array($current_item_ref_id, $valid_ref_ids)) {
165 list($position, $current_item) = $this->findItemByRefId($items, $current_item_ref_id);
166 }
167 }
168 return $current_item;
169 }
170
171 protected function updateViewState(
172 ILIAS\KioskMode\State $state,
173 ILIAS\KioskMode\View $view,
174 array $get,
175 array $post = null
176 ) : ILIAS\KioskMode\State {
177 //get view internal command
178 $command = $_GET[self::PARAM_LSO_COMMAND];
179 $param = (int) $_GET[self::PARAM_LSO_PARAMETER];
180 if (!is_null($command)) {
181 $state = $view->updateGet($state, $command, $param);
182 }
183 return $state;
184 }
185
189 protected function getNextItem(array $items, LSLearnerItem $current_item, int $direction) : LSLearnerItem
190 {
191 list($position, $item) = $this->findItemByRefId($items, $current_item->getRefId());
192 $next = $position + $direction;
193 if ($next >= 0 && $next < count($items)) {
194 return $items[$next];
195 }
196 return $current_item;
197 }
198
202 protected function findItemByRefId(array $items, int $ref_id) : array
203 {
204 foreach ($items as $index => $item) {
205 if ($item->getRefId() === $ref_id) {
206 return [$index, $item];
207 }
208 }
209 throw new \Exception("This is not a valid item.", 1);
210 }
211
212 protected function buildDefaultControls(
213 LSControlBuilder $control_builder,
214 LSLearnerItem $item,
215 int $item_position,
216 array $items
217 ) : ControlBuilder {
218 $is_first = $item_position === 0;
219 $is_last = $item_position === count($items) - 1;
220
221 if (!$control_builder->getExitControl()) {
222 $cmd = self::LSO_CMD_SUSPEND;
223 if ($is_last) {
224 $cmd = self::LSO_CMD_FINISH;
225 }
226 $control_builder = $control_builder->exit($cmd);
227 }
228
229 if (!$control_builder->getPreviousControl()) {
230 $direction_prev = -1;
231 $cmd = ''; //disables control
232
233 if (!$is_first) {
234 $available = $this->getNextItem($items, $item, $direction_prev)
235 ->getAvailability() === Step::AVAILABLE;
236
237 if ($available) {
238 $cmd = self::LSO_CMD_NEXT;
239 }
240 }
241
242 $control_builder = $control_builder
243 ->previous($cmd, $direction_prev);
244 }
245
246 if (!$control_builder->getNextControl()) {
247 $direction_next = 1;
248 $cmd = '';
249 if (!$is_last) {
250 $available = $this->getNextItem($items, $item, $direction_next)
251 ->getAvailability() === Step::AVAILABLE;
252
253 if ($available) {
254 $cmd = self::LSO_CMD_NEXT;
255 }
256 }
257
258 $control_builder = $control_builder
259 ->next($cmd, $direction_next);
260 }
261
262 return $control_builder;
263 }
264
265 protected function renderComponentView(
266 $state,
267 ILIAS\KioskMode\View $view
268 ) {
269 $component = $view->render(
270 $state,
271 $this->ui_factory,
272 $this->url_builder,
273 []
274 );
275 return $component;
276 }
277
278
280 {
281 $item = $this->getCurrentItem($this->ls_items->getItems());
282 return $item->getLearningProgressStatus();
283 }
284}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class LSControlBuilder.
previous(string $command, int $parameter=null)
A previous control allows the user to go back to the previous item in the object.The $parameter can b...
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.The $parameter can be used ...
getRefId()
Definition: LSItem.php:129
Add learning progress and availability information to the LSItem.
Class LSUrlBuilder.
Class ilKioskPageRenderer.
Builds the overview (curriculum) of a LearningSequence.
This combines calls to ProgressDB and StateDB to handle learner-items in the context of a specific LS...
Implementation of KioskMode Player.
findItemByRefId(array $items, int $ref_id)
const PARAM_LSO_COMMAND
const LSO_CMD_SUSPEND
updateViewState(ILIAS\KioskMode\State $state, ILIAS\KioskMode\View $view, array $get, array $post=null)
const GS_DATA_LS_KIOSK_MODE
getNextItem(array $items, LSLearnerItem $current_item, int $direction)
$direction is either -1 or 1;
__construct(string $lso_title, ilLSLearnerItemsQueries $ls_items, LSControlBuilder $control_builder, LSUrlBuilder $url_builder, ilLSCurriculumBuilder $curriculum_builder, ilLSViewFactory $view_factory, ilKioskPageRenderer $renderer, ILIAS\UI\Factory $ui_factory, ScreenContext $current_context)
const GS_DATA_LS_MAINBARCONTROLS
const LSO_CMD_FINISH
getCurrentItemLearningProgress()
const PARAM_LSO_PARAMETER
buildDefaultControls(LSControlBuilder $control_builder, LSLearnerItem $item, int $item_position, array $items)
play(array $get, array $post=null)
getCurrentItem(array $items)
const GS_DATA_LS_METABARCONTROLS
const GS_DATA_LS_CONTENT
renderComponentView( $state, ILIAS\KioskMode\View $view)
Build controls for the view.
This describes a Workflow Step.
Definition: Step.php:13
$index
Definition: metadata.php:128
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$param
Definition: xapitoken.php:31