ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LSControlBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28
30{
31 public const CMD_START_OBJECT = 'start_legacy_obj';
32 public const CMD_CHECK_CURRENT_ITEM_LP = 'ccilp';
33
37 protected array $controls = [];
38
42 protected array $toggles = [];
43
47 protected array $mode_controls = [];
48
49 protected ?Component $exit_control = null;
50 protected ?Component $previous_control = null;
51 protected ?Component $next_control = null;
52 protected ?Component $done_control = null;
53 protected ?TOCBuilder $toc = null;
54 protected ?LocatorBuilder $loc = null;
55 protected ?JavaScriptBindable $start = null;
56 protected ?string $additional_js = null;
58 protected LSURLBuilder $url_builder;
59 protected ilLanguage $lng;
61 protected LSURLBuilder $lp_url_builder;
62
63 public function __construct(
65 LSURLBuilder $url_builder,
66 ilLanguage $language,
68 LSURLBuilder $lp_url_builder
69 ) {
70 $this->ui_factory = $ui_factory;
71 $this->url_builder = $url_builder;
72 $this->lng = $language;
73 $this->global_settings = $global_settings;
74 $this->lp_url_builder = $lp_url_builder;
75 }
76
80 public function getToggles(): array
81 {
82 return $this->toggles;
83 }
84
88 public function getModeControls(): array
89 {
91 }
92
96 public function getControls(): array
97 {
98 return $this->controls;
99 }
100
101 public function getExitControl(): ?Component
102 {
103 return $this->exit_control;
104 }
105
106 public function getPreviousControl(): ?Component
107 {
109 }
110
111 public function getNextControl(): ?Component
112 {
113 return $this->next_control;
114 }
115
116 public function getDoneControl(): ?Component
117 {
118 return $this->done_control;
119 }
120
121 public function getToc(): ?TOCBuilder
122 {
123 return $this->toc;
124 }
125
126 public function getLocator(): ?LocatorBuilder
127 {
128 return $this->loc;
129 }
130
131 public function exit(string $command): ControlBuilder
132 {
133 if ($this->exit_control) {
134 throw new \LogicException("Only one exit-control per view...", 1);
135 }
136 $cmd = $this->url_builder->getHref($command);
137
138 $label = 'lso_player_suspend';
139 if ($command === ilLSPlayer::LSO_CMD_FINISH) {
140 $label = 'lso_player_finish';
141 }
142
143 $exit_button = $this->ui_factory->button()->bulky(
144 $this->ui_factory->symbol()->glyph()->close(),
145 $this->lng->txt($label),
146 $cmd
147 );
148
149 $this->exit_control = $exit_button;
150 return $this;
151 }
152
153 public function next(string $command, ?int $parameter = null): ControlBuilder
154 {
155 if ($this->next_control) {
156 throw new \LogicException("Only one next-control per view...", 1);
157 }
158 $label = $this->lng->txt('lso_player_next');
159 $cmd = $this->url_builder->getHref($command, $parameter);
160 $btn = $this->ui_factory->button()->standard($label, $cmd);
161 if ($command === '') {
162 $btn = $btn->withUnavailableAction();
163 }
164 $this->next_control = $btn;
165 return $this;
166 }
167
168 public function previous(string $command, ?int $parameter = null): ControlBuilder
169 {
170 if ($this->previous_control) {
171 throw new \LogicException("Only one previous-control per view...", 1);
172 }
173 $label = $this->lng->txt('lso_player_previous');
174 $cmd = $this->url_builder->getHref($command, $parameter);
175 $btn = $this->ui_factory->button()->standard($label, $cmd);
176 if ($command === '') {
177 $btn = $btn->withUnavailableAction();
178 }
179 $this->previous_control = $btn;
180 return $this;
181 }
182
183 public function done(string $command, ?int $parameter = null): ControlBuilder
184 {
185 if ($this->done_control) {
186 throw new \LogicException("Only one done-control per view...", 1);
187 }
188 $label = $this->lng->txt('lso_player_done');
189 $cmd = $this->url_builder->getHref($command, $parameter);
190 $btn = $this->ui_factory->button()->primary($label, $cmd);
191 $this->done_control = $btn;
192 return $this;
193 }
194
195 public function generic(string $label, string $command, ?int $parameter = null): ControlBuilder
196 {
197 $cmd = $this->url_builder->getHref($command, $parameter);
198 $this->controls[] = $this->ui_factory->button()->standard($label, $cmd);
199 return $this;
200 }
201
202 public function genericWithSignal(string $label, Signal $signal): ControlBuilder
203 {
204 $this->controls[] = $this->ui_factory->button()->standard($label, '')
205 ->withOnClick($signal);
206 return $this;
207 }
208
209 public function toggle(string $label, string $on_command, string $off_command): ControlBuilder
210 {
211 throw new \Exception("NYI: Toggles", 1);
212 }
213
214 public function mode(string $command, array $labels): ControlBuilder
215 {
216 $actions = [];
217 foreach ($labels as $parameter => $label) {
218 $actions[$label] = $this->url_builder->getHref($command, $parameter);
219 }
220 $this->mode_controls[] = $this->ui_factory->viewControl()->mode($actions, '');
221 return $this;
222 }
223
224 public function locator(string $command): LocatorBuilder
225 {
226 if ($this->loc) {
227 throw new \LogicException("Only one locator per view...", 1);
228 }
229 $this->loc = new LSLocatorBuilder($command, $this);
230 return $this->loc;
231 }
232
233 public function tableOfContent(
234 string $label,
235 string $command,
236 ?int $parameter = null,
237 $state = null
238 ): TOCBuilder {
239 if ($this->toc) {
240 throw new \LogicException("Only one ToC per view...", 1);
241 }
242 $this->toc = new LSTOCBuilder($this, $command, $label, $parameter, $state);
243 return $this->toc;
244 }
245
253 public function start(string $label, string $url, int $obj_id): ControlBuilder
254 {
255 if ($this->start) {
256 throw new \LogicException("Only one start-control per view...", 1);
257 }
258
259 $this_cmd = $this->url_builder->getHref(self::CMD_START_OBJECT, 0);
260 $lp_cmd = $this->lp_url_builder->getHref(self::CMD_CHECK_CURRENT_ITEM_LP, $obj_id);
261
262 $this->setListenerJS($lp_cmd, $this_cmd);
263 $this->start = $this->ui_factory->button()
264 ->primary($label, '')
265 ->withOnLoadCode(function ($id) use ($url) {
266 $interval = $this->global_settings->getPollingIntervalMilliseconds();
267 return "$('#$id').on('click', function(ev) {
268 var _lso_win = window.open('$url');
269 });
270 window._lso_current_item_lp = -1;
271 window.setInterval(lso_checkLPOfObject, $interval);
272 ";
273 });
274
275 return $this;
276 }
277
279 {
280 return $this->start;
281 }
282
283 public function getAdditionalJS(): ?string
284 {
285 return $this->additional_js;
286 }
287
288 protected function setListenerJS(
289 string $check_lp_url,
290 string $on_lp_change_url
291 ): void {
292 $this->additional_js =
293<<<JS
294function lso_checkLPOfObject()
295{
296 if(! il.UICore.isPageVisible()) {
297 return;
298 }
299
300 $.ajax({
301 url: "$check_lp_url",
302 }).done(function(data) {
303 if(window._lso_current_item_lp === -1) {
304 window._lso_current_item_lp = data;
305 }
306 if (window._lso_current_item_lp !== data) {
307 location.replace('$on_lp_change_url');
308 }
309 });
310}
311JS;
312 }
313}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
JavaScriptBindable $start
done(string $command, ?int $parameter=null)
A done control allows the user to mark the object as done.
LocatorBuilder $loc
LSURLBuilder $lp_url_builder
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.
mode(string $command, array $labels)
A mode control can be used to switch between different modes in the view.
next(string $command, ?int $parameter=null)
A next control allows the user to progress to the next item in the object.
locator(string $command)
A locator allows the user to see the path leading to her current location and jump back to previous i...
Component $previous_control
LSURLBuilder $url_builder
setListenerJS(string $check_lp_url, string $on_lp_change_url)
genericWithSignal(string $label, Signal $signal)
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...
start(string $label, string $url, int $obj_id)
Add a "start"-button as primary.
toggle(string $label, string $on_command, string $off_command)
A toggle can be used to switch some behaviour in the view on or of.
LSGlobalSettings $global_settings
__construct(Factory $ui_factory, LSURLBuilder $url_builder, ilLanguage $language, LSGlobalSettings $global_settings, LSURLBuilder $lp_url_builder)
Global Settings of the Learning Sequence.
Class LSTOCBuilder.
const LSO_CMD_FINISH
language handling
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:29
A component is the most general form of an entity in the UI.
Definition: Component.php:28
Interface to be extended by components that have the possibility to bind to Javascript.
This is how the factory for UI elements looks.
Definition: Factory.php:38
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
if(!file_exists('../ilias.ini.php'))
$url
Definition: shib_logout.php:68