ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
InteractiveImageQueryActionHandler.php
Go to the documentation of this file.
1<?php
2
20
23
27class InteractiveImageQueryActionHandler implements Server\QueryActionHandler
28{
29 protected \ILIAS\COPage\PC\InteractiveImage\IIMManager $iim_manager;
30 protected \ILIAS\COPage\InternalGUIService $gui;
31 protected string $pc_id = "";
32 protected \ILIAS\DI\UIServices $ui;
33 protected \ilLanguage $lng;
34 protected \ilPageObjectGUI $page_gui;
35 protected \ilObjUser $user;
36 protected Server\UIWrapper $ui_wrapper;
37 protected \ilCtrl $ctrl;
38 protected \ilComponentFactory $component_factory;
39
40 public function __construct(\ilPageObjectGUI $page_gui, string $pc_id = "")
41 {
42 global $DIC;
43
44 $this->ui = $DIC->ui();
45 $this->lng = $DIC->language();
46 $this->page_gui = $page_gui;
47 $this->user = $DIC->user();
48 $this->ctrl = $DIC->ctrl();
49 $this->component_factory = $DIC["component.factory"];
50 $this->pc_id = $pc_id;
51
52 $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
53 $this->gui = $DIC->copage()->internal()->gui();
54 $this->iim_manager = $DIC->copage()->internal()->domain()->pc()->interactiveImage();
55 }
56
60 public function handle(array $query): Server\Response
61 {
62 switch ($query["action"]) {
63 case "init":
64 return $this->init();
65
66 }
67 throw new Exception("Unknown action " . $query["action"]);
68 }
69
70 protected function init(): Server\Response
71 {
73 $o = new \stdClass();
74 $o->uiModel = new \stdClass();
75 $o->uiModel->mainHead = $this->getMainHead();
76 $o->uiModel->addTriggerMessage = $this->getAddTriggerMessage();
77 $o->uiModel->selectTriggerMessage = $this->getSelectTriggerMessage();
78 $o->uiModel->commonSuccessMessage = $this->getCommonSuccessMessage();
79 $o->uiModel->triggerPropertiesMesssage = $this->getTriggerPropertiesInfo();
80 $o->uiModel->mainSlate = $this->getMainSlate();
81 $o->uiModel->backgroundImage = $this->getBackgroundImage();
82 $o->uiModel->triggerProperties = $this->getTriggerProperties();
83 $o->uiModel->triggerOverlay = $this->getTriggerOverlay();
84 $o->uiModel->triggerPopup = $this->getTriggerPopup();
85 $o->uiModel->popupOverview = $this->getPopupOverview();
86 $o->uiModel->overlayOverview = $this->getOverlayOverview();
87 $o->uiModel->overlayUpload = $this->getOverlayUpload();
88 $o->uiModel->popupForm = $this->getPopupForm();
89 $o->uiModel->backgroundProperties = $this->getBackgroundProperties();
90 $o->uiModel->modal = $this->getModalTemplate();
91 $o->uiModel->loader = $this->getLoader();
92 $o->uiModel->popupDummy = $this->getPopupDummy();
93 $o->uiModel->lore = $this->getLore();
94 $o->uiModel->backUrl = $ctrl->getLinkTarget($this->page_gui, "edit") . "#pc" . $this->pc_id;
95
96 $o->iimModel = $this->getIIMModel();
97 /*
98 $o->errorMessage = $this->getErrorMessage();
99 $o->errorModalMessage = $this->getErrorModalMessage();
100 $o->pcModel = $this->getPCModel();
101 $o->pcDefinition = $this->getComponentsDefinitions();
102 $o->modal = $this->getModalTemplate();
103 $o->confirmation = $this->getConfirmationTemplate();
104 $o->autoSaveInterval = $this->getAutoSaveInterval();
105 $o->backUrl = $ctrl->getLinkTarget($this->page_gui, "edit");
106 $o->loaderUrl = \ilUtil::getImagePath("loader.svg");*/
107
108 return new Server\Response($o);
109 }
110
114 protected function getIIMModel(): ?\stdClass
115 {
116 if ($this->pc_id !== "") {
117 $pc = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id);
118 return $pc->getIIMModel();
119 }
120 return null;
121 }
122
123 protected function getPopupDummy(): string
124 {
125 if ($this->pc_id !== "") {
126 $pc = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id);
127 return $pc->getPopupDummy();
128 }
129 return "";
130 }
131
132 protected function getLore(): string
133 {
134 return "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
135 }
136
137 public function getMainHead(): string
138 {
140 $tpl = new \ilTemplate("tpl.main_head.html", true, true, "components/ILIAS/COPage/PC/InteractiveImage");
141 $tpl->setVariable("TITLE", $lng->txt("cont_iim_edit"));
142 $tpl->setVariable("HEAD_TRIGGER", $lng->txt("cont_iim_trigger"));
143 $tpl->setVariable(
144 "CLOSE_BUTTON",
145 $this->section($this->ui_wrapper->getRenderedButton(
146 $lng->txt("cont_iim_finish_editing"),
147 "button",
148 "component.back",
149 null,
150 "InteractiveImage",
151 true
152 ))
153 );
154 return $tpl->get();
155 }
156
157 protected function getSelectTriggerMessage(): string
158 {
160 return $this->section($this->ui_wrapper->getRenderedInfoBox(
161 $lng->txt("cont_iim_select_trigger")
162 ));
163 }
164
165 protected function getCommonSuccessMessage(): string
166 {
168 return $this->section($this->ui_wrapper->getRenderedSuccessBox(
169 $lng->txt("msg_obj_modified")
170 ));
171 }
172
173 protected function getLoader(): string
174 {
176 return $this->section("<img src='" . \ilUtil::getImagePath("media/loader.svg") . "' />");
177 }
178
179 protected function getAddTriggerMessage(): string
180 {
182 return $this->section($this->ui_wrapper->getRenderedInfoBox(
183 $lng->txt("cont_iim_add_trigger_text")
184 ));
185 }
186
187 public function getMainSlate(): string
188 {
190
191 $tpl = new \ilTemplate("tpl.main_slate.html", true, true, "components/ILIAS/COPage/PC/InteractiveImage");
192 $tpl->setVariable("HEAD_SETTINGS", $lng->txt("settings"));
193 $tpl->setVariable("HEAD_OVERVIEW", $lng->txt("cont_iim_overview"));
194
195 $tpl->setVariable(
196 "ADD_BUTTON",
197 $this->section($this->ui_wrapper->getRenderedButton(
198 $this->lng->txt("cont_iim_add_trigger"),
199 "button",
200 "add.trigger",
201 null,
202 "InteractiveImage"
203 ))
204 );
205
206 $tpl->setVariable(
207 "LINK_SETTINGS",
208 $this->section($this->ui_wrapper->getRenderedLink(
209 $lng->txt("cont_iim_background_image_and_caption"),
210 "InteractiveImage",
211 "link",
212 "switch.settings",
213 null
214 ))
215 );
216
217 $tpl->setVariable(
218 "LINK_OVERLAY",
219 $this->section($this->ui_wrapper->getRenderedLink(
220 $lng->txt("cont_overlay_images"),
221 "InteractiveImage",
222 "link",
223 "switch.overlays",
224 null
225 ))
226 );
227
228 $tpl->setVariable(
229 "LINK_POPUPS",
230 $this->section($this->ui_wrapper->getRenderedLink(
231 $lng->txt("cont_content_popups"),
232 "InteractiveImage",
233 "link",
234 "switch.popups",
235 null
236 ))
237 );
238
239 return $tpl->get();
240 }
241
242 public function getBackgroundImage(): string
243 {
244
245 if ($this->pc_id !== "") {
247 $pc = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id);
248 } else {
249 return "";
250 }
251
252 return $pc->getBackgroundImage();
253 }
254
255 protected function section(string $content): string
256 {
257 return "<div class='copg-edit-button-group'>" . $content . "</div>";
258 }
259
260 protected function getTriggerBackButton(): string
261 {
262 return $this->section($this->ui_wrapper->getRenderedButton(
263 $this->lng->txt("back"),
264 "button",
265 "trigger.back",
266 null,
267 "InteractiveImage"
268 ));
269 }
270
271 protected function getTriggerHeader(): string
272 {
273 return $this->getHeading($this->lng->txt("cont_iim_edit_trigger"));
274 }
275
276 protected function getTriggerViewControls(): string
277 {
278 return $this->section($this->ui_wrapper->getRenderedViewControl(
279 [
280 ["InteractiveImage", "trigger.properties", $this->lng->txt("properties")],
281 ["InteractiveImage", "trigger.overlay", $this->lng->txt("cont_overlay_image")],
282 ["InteractiveImage", "trigger.popup", $this->lng->txt("cont_content_popup")]
283 ]
284 ));
285 }
286
288 {
290 return $this->gui->form(null, "#")
291 ->text(
292 "title",
293 $this->lng->txt("title")
294 )
295 ->select(
296 "shape",
297 $this->lng->txt("cont_shape"),
298 [
299 "Rect" => $this->lng->txt("cont_Rect"),
300 "Circle" => $this->lng->txt("cont_Circle"),
301 "Poly" => $this->lng->txt("cont_Poly"),
302 "Marker" => $this->lng->txt("cont_marker")
303 ],
304 "",
305 "Rect"
306 )->required()
307 ->select(
308 "hl_mode",
309 $this->lng->txt("cont_highlight_mode"),
311 "",
312 ""
313 )->required()
314 ->select(
315 "hl_class",
316 $this->lng->txt("cont_highlight_class"),
318 "",
320 )->required();
321 }
322
323 protected function getMessageArea(): string
324 {
325 return "<div id='cont_iim_message'></div>";
326 }
327
328 protected function getTriggerPropertiesInfo(): string
329 {
330 return $this->section($this->ui_wrapper->getRenderedInfoBox($this->lng->txt("cont_iim_tr_properties_info")));
331 }
332
333 protected function getTriggerProperties(): string
334 {
335 $content = $this->getTriggerBackButton() .
336 $this->getTriggerHeader() .
337 $this->getTriggerViewControls();
338 $content .= $this->getMessageArea();
339 $content .= $this->ui_wrapper->getRenderedAdapterForm(
341 [
342 ["InteractiveImage", "trigger.properties.save", $this->lng->txt("save")],
343 ["InteractiveImage", "trigger.delete", $this->lng->txt("delete")],
344 ],
345 "copg-iim-trigger-prop-form"
346 );
347
348 return $content;
349 }
350
352 {
353 return $this->gui->form(null, "#")
354 ->select(
355 "overlay",
356 $this->lng->txt("cont_iim_select_overlay"),
357 [
358 ]
359 );
360 }
361
362 protected function getTriggerOverlay(): string
363 {
364 $content = $this->getTriggerBackButton() .
365 $this->getTriggerHeader() .
366 $this->getTriggerViewControls();
367 $content .= $this->getMessageArea();
368 $content .= $this->section($this->ui_wrapper->getRenderedButton(
369 $this->lng->txt("cont_iim_add_overlay"),
370 "button",
371 "trigger.add.overlay",
372 null,
373 "InteractiveImage"
374 ));
375 $content .= $this->ui_wrapper->getRenderedAdapterForm(
377 [["InteractiveImage", "trigger.overlay.save", $this->lng->txt("save")]],
378 "copg-iim-trigger-overlay-form"
379 );
380
381 return $content;
382 }
383
385 {
386 return $this->gui->form(null, "#")
387 ->select(
388 "popup",
389 $this->lng->txt("cont_content_popup"),
390 [
391 ]
392 )->select(
393 "size",
394 $this->lng->txt("cont_iim_size"),
395 [
396 "sm" => $this->lng->txt("cont_iim_sm"),
397 "md" => $this->lng->txt("cont_iim_md"),
398 "lg" => $this->lng->txt("cont_iim_lg")
399 ],
400 "",
401 "md"
402 )->required();
403 }
404
405 protected function getTriggerPopup(): string
406 {
407 $content = $this->getTriggerBackButton() .
408 $this->getTriggerHeader() .
409 $this->getTriggerViewControls();
410 $content .= $this->getMessageArea();
411 $content .= $this->section($this->ui_wrapper->getRenderedButton(
412 $this->lng->txt("cont_iim_tr_add_popup"),
413 "button",
414 "trigger.add.popup",
415 null,
416 "InteractiveImage"
417 ));
418 $content .= $this->ui_wrapper->getRenderedAdapterForm(
420 [["InteractiveImage", "trigger.save.popup", $this->lng->txt("save")]],
421 "copg-iim-trigger-popup-form"
422 );
423 return $content;
424 }
425
426 protected function getHeading(string $text, $sub = false): string
427 {
428 // todo: classes need better naming
429 if ($sub) {
430 return "<div class='copg-edit-button-group'><h3>" . $text . "</h3></div>";
431 }
432 return "<div class='copg-edit-button-group'><h2>" . $text . "</h2></div>";
433 }
434
435 protected function getPopupOverview(): string
436 {
437 $content = $this->getTriggerBackButton();
438 $content .= $this->getHeading($this->lng->txt("cont_content_popups"), true);
439 $content .= $this->getMessageArea();
440 $content .= $this->section($this->ui_wrapper->getRenderedButton(
441 $this->lng->txt("cont_iim_tr_add_popup"),
442 "button",
443 "trigger.add.popup",
444 null,
445 "InteractiveImage"
446 ));
447 $content .= $this->section($this->ui_wrapper->getRenderedListingPanelTemplate($this->lng->txt("cont_iim_overview")));
448 return $content;
449 }
450
451 protected function getOverlayOverview(): string
452 {
453 $content = $this->getTriggerBackButton();
454 $content .= $this->getHeading($this->lng->txt("cont_overlay_images"), true);
455 $content .= $this->getMessageArea();
456 $content .= $this->section($this->ui_wrapper->getRenderedButton(
457 $this->lng->txt("cont_iim_add_overlay"),
458 "button",
459 "trigger.add.overlay",
460 null,
461 "InteractiveImage"
462 ));
463 $content .= $this->section($this->ui_wrapper->getRenderedListingPanelTemplate(
464 $this->lng->txt("cont_iim_overview"),
465 true
466 ));
467
468 return $content;
469 }
470
471 protected function getBackgroundProperties(): string
472 {
473 $this->ctrl->setParameterByClass(
474 \ilPCInteractiveImageGUI::class,
475 "mode",
476 "backgroundUpdate"
477 );
478
479 $content = $this->getTriggerBackButton();
480 $content .= $this->getHeading($this->lng->txt("cont_iim_background_image"), true);
481 $content .= $this->getMessageArea();
482 $content .= $this->ui_wrapper->getRenderedAdapterForm(
483 $this->getPCInteractiveImageGUI()->getBackgroundPropertiesFormAdapter([get_class($this->page_gui),
484 \ilPageEditorGUI::class,
485 \ilPCInteractiveImageGUI::class
486 ]),
487 [["InteractiveImage", "component.save", $this->lng->txt("save")]]
488 );
489
490 return $content;
491 }
492
493 public function getModalTemplate(): array
494 {
495 $ui = $this->ui;
496 $modal = $ui->factory()->modal()->roundtrip('#title#', $ui->factory()->legacy()->content('#content#'))
497 ->withActionButtons([
498 $ui->factory()->button()->standard('#button_title#', '#'),
499 ]);
500 $modalt["signal"] = $modal->getShowSignal()->getId();
501 $modalt["closeSignal"] = $modal->getCloseSignal()->getId();
502 $modalt["template"] = $ui->renderer()->renderAsync($modal);
503
504 return $modalt;
505 }
506
508 {
509 $pg = $this->page_gui->getPageObject();
510 $iim = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id);
511 $iim_gui = new \ilPCInteractiveImageGUI($pg, $iim, "", $this->pc_id);
512 $iim_gui->setPageConfig($pg->getPageConfig());
513 return $iim_gui;
514 }
515
517 {
518 return $this->getPCInteractiveImageGUI()
519 ->getOverlayUploadFormAdapter([get_class($this->page_gui),
520 \ilPageEditorGUI::class,
521 \ilPCInteractiveImageGUI::class
522 ]);
523 }
524
525 protected function getOverlayUpload(): string
526 {
527 $this->ctrl->setParameterByClass(
528 \ilPCInteractiveImageGUI::class,
529 "mode",
530 "overlayUpload"
531 );
532 $content = $this->ui_wrapper->getRenderedAdapterForm(
534 [["InteractiveImage", "overlay.upload", $this->lng->txt("add")]],
535 "",
536 true
537 );
538 $this->ctrl->setParameterByClass(
539 \ilPCInteractiveImageGUI::class,
540 "mode",
541 null
542 );
543 return $content;
544 }
545
546 protected function getPopupForm(): string
547 {
548 $iim_gui = $this->getPCInteractiveImageGUI();
549 $content = $this->ui_wrapper->getRenderedAdapterForm(
550 $iim_gui->getPopupFormAdapter(),
551 [["InteractiveImage", "popup.save", $this->lng->txt("save")]],
552 "",
553 true
554 );
555 return $content;
556 }
557}
Page editor json server.
select(string $key, string $title, array $options, string $description="", ?string $value=null)
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getAllHighlightClasses()
const HLCL_ACCENTED
static getAllHighlightModes()
User interface class for interactive images.
Class ilPageObjectGUI.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
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...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26