ILIAS  release_7 Revision v7.30-3-g800a261c036
LSControlBuilder.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
9
12
17{
18 const CMD_START_OBJECT = 'start_legacy_obj';
20
24 protected $exit_control;
25
30
34 protected $next_control;
35
39 protected $done_control;
40
44 protected $controls = [];
45
49 protected $toggles = [];
50
54 protected $mode_controls = [];
55
59 protected $toc;
60
64 protected $loc;
65
69 protected $ui_factory;
70
74 protected $url_builder;
75
79 protected $start;
80
84 protected $additional_js;
85
90
91 public function __construct(
93 LSURLBuilder $url_builder,
94 ilLanguage $language,
96 ) {
97 $this->ui_factory = $ui_factory;
98 $this->url_builder = $url_builder;
99 $this->lng = $language;
100 $this->global_settings = $global_settings;
101 }
102
103 public function getExitControl()
104 {
105 return $this->exit_control;
106 }
107
108 public function getPreviousControl()
109 {
111 }
112
113 public function getNextControl()
114 {
115 return $this->next_control;
116 }
117
118 public function getDoneControl()
119 {
120 return $this->done_control;
121 }
122
123 public function getToggles()
124 {
125 return $this->toggles;
126 }
127
128 public function getModeControls()
129 {
131 }
132
133 public function getControls() : array
134 {
135 return $this->controls;
136 }
137
138 public function getLocator()
139 {
140 return $this->loc;
141 }
142
143 public function getToc()
144 {
145 return $this->toc;
146 }
147
151 public function exit(string $command) : ControlBuilder
152 {
153 if ($this->exit_control) {
154 throw new \LogicException("Only one exit-control per view...", 1);
155 }
156 $cmd = $this->url_builder->getHref($command);
157
158 $label = 'lso_player_suspend';
159 if ($command === ilLSPlayer::LSO_CMD_FINISH) {
160 $label = 'lso_player_finish';
161 }
162
163 $exit_button = $this->ui_factory->button()->bulky(
164 $this->ui_factory->symbol()->glyph()->close(),
165 $this->lng->txt($label),
166 $cmd
167 );
168
169 $this->exit_control = $exit_button;
170 return $this;
171 }
172
176 public function next(string $command, int $parameter = null) : ControlBuilder
177 {
178 if ($this->next_control) {
179 throw new \LogicException("Only one next-control per view...", 1);
180 }
181 $label = $this->lng->txt('lso_player_next');
182 $cmd = $this->url_builder->getHref($command, $parameter);
183 $btn = $this->ui_factory->button()->standard($label, $cmd);
184 if ($command === '') {
185 $btn = $btn->withUnavailableAction();
186 }
187 $this->next_control = $btn;
188 return $this;
189 }
190
194 public function previous(string $command, int $parameter = null) : ControlBuilder
195 {
196 if ($this->previous_control) {
197 throw new \LogicException("Only one previous-control per view...", 1);
198 }
199 $label = $this->lng->txt('lso_player_previous');
200 $cmd = $this->url_builder->getHref($command, $parameter);
201 $btn = $this->ui_factory->button()->standard($label, $cmd);
202 if ($command === '') {
203 $btn = $btn->withUnavailableAction();
204 }
205 $this->previous_control = $btn;
206 return $this;
207 }
208
212 public function done(string $command, int $parameter = null) : ControlBuilder
213 {
214 if ($this->done_control) {
215 throw new \LogicException("Only one done-control per view...", 1);
216 }
217 $label = $this->lng->txt('lso_player_done');
218 $cmd = $this->url_builder->getHref($command, $parameter);
219 $btn = $this->ui_factory->button()->primary($label, $cmd);
220 $this->done_control = $btn;
221 return $this;
222 }
223
227 public function generic(string $label, string $command, int $parameter = null) : ControlBuilder
228 {
229 $cmd = $this->url_builder->getHref($command, $parameter);
230 $this->controls[] = $this->ui_factory->button()->standard($label, $cmd);
231 return $this;
232 }
233
234 public function genericWithSignal(string $label, Signal $signal) : ControlBuilder
235 {
236 $this->controls[] = $this->ui_factory->button()->standard($label, '')
237 ->withOnClick($signal);
238 return $this;
239 }
240
244 public function toggle(string $label, string $on_command, string $off_command) : ControlBuilder
245 {
246 throw new \Exception("NYI: Toggles", 1);
247
248 $cmd_on = $this->url_builder->getHref($on_command, 0);
249 $cmd_off = $this->url_builder->getHref($off_command, 0);
250 //build toggle and add to $this->toggles
251 //return $this;
252 }
253
257 public function mode(string $command, array $labels) : ControlBuilder
258 {
259 $actions = [];
260 foreach ($labels as $parameter => $label) {
261 $actions[$label] = $this->url_builder->getHref($command, $parameter);
262 }
263 $this->mode_controls[] = $this->ui_factory->viewControl()->mode($actions, '');
264 return $this;
265 }
266
270 public function locator(string $command) : LocatorBuilder
271 {
272 if ($this->loc) {
273 throw new \LogicException("Only one locator per view...", 1);
274 }
275 $this->loc = new LSLocatorBuilder($command, $this);
276 return $this->loc;
277 }
278
282 public function tableOfContent(
283 string $label,
284 string $command,
285 int $parameter = null,
286 $state = null
287 ) : TOCBuilder {
288 if ($this->toc) {
289 throw new \LogicException("Only one ToC per view...", 1);
290 }
291 $this->toc = new LSTOCBuilder($this, $command, $label, $parameter, $state);
292 return $this->toc;
293 }
294
302 public function start(string $label, string $url, int $parameter = null) : ControlBuilder
303 {
304 if ($this->start) {
305 throw new \LogicException("Only one start-control per view...", 1);
306 }
307 $this_cmd = $this->url_builder->getHref(self::CMD_START_OBJECT, $parameter);
308 $lp_cmd = str_replace(
309 '&cmd=view&',
310 '&cmd=' . self::CMD_CHECK_CURRENT_ITEM_LP . '&',
311 $this_cmd
312 );
313
314 $this->setListenerJS($lp_cmd, $this_cmd);
315 $this->start = $this->ui_factory->button()
316 ->primary($label, '')
317 ->withOnLoadCode(function ($id) use ($url) {
318 $interval = $this->global_settings->getPollingIntervalMilliseconds();
319 return "$('#{$id}').on('click', function(ev) {
320 var il_ls_win = window.open('$url');
321 window._lso_current_item_lp = -1;
322 window.setInterval(lso_checkLPOfObject, $interval);
323 })";
324 });
325
326 return $this;
327 }
328
329 public function getStartControl()
330 {
331 return $this->start;
332 }
333
334 public function getAdditionalJS() : string
335 {
336 return $this->additional_js;
337 }
338
339 protected function setListenerJS(
340 string $check_lp_url,
341 string $on_lp_change_url
342 ) {
343 $this->additional_js =
344<<<JS
345function lso_checkLPOfObject()
346{
347 if(! il.UICore.isPageVisible()) {
348 return;
349 }
350
351 $.ajax({
352 url: "$check_lp_url",
353 }).done(function(data) {
354 if(window._lso_current_item_lp === -1) {
355 window._lso_current_item_lp = data;
356 }
357 if (window._lso_current_item_lp !== data) {
358 location.replace('$on_lp_change_url');
359 }
360 });
361}
362JS;
363 }
364}
An exception for terminatinating execution or to throw for unit testing.
Class LSControlBuilder.
__construct(Factory $ui_factory, LSURLBuilder $url_builder, ilLanguage $language, LSGlobalSettings $global_settings)
tableOfContent(string $label, string $command, int $parameter=null, $state=null)
A table of content allows the user to get an overview over the generally available content in the obj...
done(string $command, int $parameter=null)
A done control allows the user to mark the object as done.The $parameter can be used to pass addition...
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....
mode(string $command, array $labels)
A mode control can be used to switch between different modes in the view.Uses the indizes of the labe...
locator(string $command)
A locator allows the user to see the path leading to her current location and jump back to previous i...
start(string $label, string $url, int $parameter=null)
Add a "start"-button as primary.
setListenerJS(string $check_lp_url, string $on_lp_change_url)
genericWithSignal(string $label, Signal $signal)
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 ...
toggle(string $label, string $on_command, string $off_command)
A toggle can be used to switch some behaviour in the view on or of.
Global Settings of the Learning Sequence.
Class LSTOCBuilder.
Class LSTOCBuilder.
const LSO_CMD_FINISH
language handling
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
Build controls for the view.
mode(string $command, array $labels)
A mode control can be used to switch between different modes in the view.
Build a locator for the view.
Build a nested table of contents for the view.
Definition: TOCBuilder.php:12
The URLBuilder allows views to get links that are used somewhere inline in the content.
Definition: URLBuilder.php:13
This is how the factory for UI elements looks.
Definition: Factory.php:18
$url