ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
LSControlBuilder.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
9
11
16{
17 const CMD_START_OBJECT = 'start_legacy_obj';
19
23 protected $exit_control;
24
29
33 protected $next_control;
34
38 protected $done_control;
39
43 protected $controls = [];
44
48 protected $toggles = [];
49
53 protected $mode_controls = [];
54
58 protected $toc;
59
63 protected $loc;
64
68 protected $ui_factory;
69
73 protected $url_builder;
74
78 protected $start;
79
83 protected $additional_js;
84
89
90 public function __construct(
92 LSURLBuilder $url_builder,
93 ilLanguage $language,
95 ) {
96 $this->ui_factory = $ui_factory;
97 $this->url_builder = $url_builder;
98 $this->lng = $language;
99 $this->global_settings = $global_settings;
100 }
101
102 public function getExitControl()
103 {
104 return $this->exit_control;
105 }
106
107 public function getPreviousControl()
108 {
110 }
111
112 public function getNextControl()
113 {
114 return $this->next_control;
115 }
116
117 public function getDoneControl()
118 {
119 return $this->done_control;
120 }
121
122 public function getToggles()
123 {
124 return $this->toggles;
125 }
126
127 public function getModeControls()
128 {
130 }
131
132 public function getControls() : array
133 {
134 return $this->controls;
135 }
136
137 public function getLocator()
138 {
139 return $this->loc;
140 }
141
142 public function getToc()
143 {
144 return $this->toc;
145 }
146
150 public function exit(string $command) : ControlBuilder
151 {
152 if ($this->exit_control) {
153 throw new \LogicException("Only one exit-control per view...", 1);
154 }
155 $cmd = $this->url_builder->getHref($command);
156
157 $label = 'lso_player_suspend';
158 if ($command === ilLSPlayer::LSO_CMD_FINISH) {
159 $label = 'lso_player_finish';
160 }
161
162 $exit_button = $this->ui_factory->button()->bulky(
163 $this->ui_factory->symbol()->glyph()->close(),
164 $this->lng->txt($label),
165 $cmd
166 );
167
168 $this->exit_control = $exit_button;
169 return $this;
170 }
171
175 public function next(string $command, int $parameter = null) : ControlBuilder
176 {
177 if ($this->next_control) {
178 throw new \LogicException("Only one next-control per view...", 1);
179 }
180 $label = $this->lng->txt('lso_player_next');
181 $cmd = $this->url_builder->getHref($command, $parameter);
182 $btn = $this->ui_factory->button()->standard($label, $cmd);
183 if ($command === '') {
184 $btn = $btn->withUnavailableAction();
185 }
186 $this->next_control = $btn;
187 return $this;
188 }
189
193 public function previous(string $command, int $parameter = null) : ControlBuilder
194 {
195 if ($this->previous_control) {
196 throw new \LogicException("Only one previous-control per view...", 1);
197 }
198 $label = $this->lng->txt('lso_player_previous');
199 $cmd = $this->url_builder->getHref($command, $parameter);
200 $btn = $this->ui_factory->button()->standard($label, $cmd);
201 if ($command === '') {
202 $btn = $btn->withUnavailableAction();
203 }
204 $this->previous_control = $btn;
205 return $this;
206 }
207
211 public function done(string $command, int $parameter = null) : ControlBuilder
212 {
213 if ($this->done_control) {
214 throw new \LogicException("Only one done-control per view...", 1);
215 }
216 $label = $this->lng->txt('lso_player_done');
217 $cmd = $this->url_builder->getHref($command, $parameter);
218 $btn = $this->ui_factory->button()->primary($label, $cmd);
219 $this->done_control = $btn;
220 return $this;
221 }
222
226 public function generic(string $label, string $command, int $parameter = null) : ControlBuilder
227 {
228 $cmd = $this->url_builder->getHref($command, $parameter);
229 $this->controls[] = $this->ui_factory->button()->standard($label, $cmd);
230 return $this;
231 }
232
236 public function toggle(string $label, string $on_command, string $off_command) : ControlBuilder
237 {
238 throw new \Exception("NYI: Toggles", 1);
239
240 $cmd_on = $this->url_builder->getHref($on_command, 0);
241 $cmd_off = $this->url_builder->getHref($off_command, 0);
242 //build toggle and add to $this->toggles
243 //return $this;
244 }
245
249 public function mode(string $command, array $labels) : ControlBuilder
250 {
251 $actions = [];
252 foreach ($labels as $parameter => $label) {
253 $actions[$label] = $this->url_builder->getHref($command, $parameter);
254 }
255 $this->mode_controls[] = $this->ui_factory->viewControl()->mode($actions, '');
256 return $this;
257 }
258
262 public function locator(string $command) : LocatorBuilder
263 {
264 if ($this->loc) {
265 throw new \LogicException("Only one locator per view...", 1);
266 }
267 $this->loc = new LSLocatorBuilder($command, $this);
268 return $this->loc;
269 }
270
274 public function tableOfContent(
275 string $label,
276 string $command,
277 int $parameter = null,
278 $state = null
279 ) : TOCBuilder {
280 if ($this->toc) {
281 throw new \LogicException("Only one ToC per view...", 1);
282 }
283 $this->toc = new LSTOCBuilder($this, $command, $label, $parameter, $state);
284 return $this->toc;
285 }
286
294 public function start(string $label, string $url, int $parameter = null) : ControlBuilder
295 {
296 if ($this->start) {
297 throw new \LogicException("Only one start-control per view...", 1);
298 }
299 $this_cmd = $this->url_builder->getHref(self::CMD_START_OBJECT, $parameter);
300 $lp_cmd = str_replace(
301 '&cmd=view&',
302 '&cmd=' . self::CMD_CHECK_CURRENT_ITEM_LP . '&',
303 $this_cmd
304 );
305
306 $this->setListenerJS($lp_cmd, $this_cmd);
307 $this->start = $this->ui_factory->button()
308 ->primary($label, '')
309 ->withOnLoadCode(function ($id) use ($url) {
310 $interval = $this->global_settings->getPollingIntervalMilliseconds();
311 return "$('#{$id}').on('click', function(ev) {
312 var il_ls_win = window.open('$url');
313 window._lso_current_item_lp = -1;
314 window.setInterval(lso_checkLPOfObject, $interval);
315 })";
316 });
317
318 return $this;
319 }
320
321 public function getStartControl()
322 {
323 return $this->start;
324 }
325
326 public function getAdditionalJS() : string
327 {
328 return $this->additional_js;
329 }
330
331 protected function setListenerJS(
332 string $check_lp_url,
333 string $on_lp_change_url
334 ) {
335 $this->additional_js =
336<<<JS
337function lso_checkLPOfObject()
338{
339 if(! il.UICore.isPageVisible()) {
340 return;
341 }
342
343 $.ajax({
344 url: "$check_lp_url",
345 }).done(function(data) {
346 if(window._lso_current_item_lp === -1) {
347 window._lso_current_item_lp = data;
348 }
349 if (window._lso_current_item_lp !== data) {
350 location.replace('$on_lp_change_url');
351 }
352 });
353}
354JS;
355 }
356}
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)
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