ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
InteractiveImageQueryActionHandler.php
Go to the documentation of this file.
1 <?php
2 
20 
23 
27 class 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  {
72  $ctrl = $this->ctrl;
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 
111 
115  protected function getIIMModel(): ?\stdClass
116  {
117  if ($this->pc_id !== "") {
118  $pc = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id);
119  return $pc->getIIMModel();
120  }
121  return null;
122  }
123 
124  protected function getPopupDummy(): string
125  {
126  if ($this->pc_id !== "") {
127  $pc = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id);
128  return $pc->getPopupDummy();
129  }
130  return "";
131  }
132 
133  protected function getLore(): string
134  {
135  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.";
136  }
137 
138  public function getMainHead(): string
139  {
140  $lng = $this->lng;
141  $tpl = new \ilTemplate("tpl.main_head.html", true, true, "components/ILIAS/COPage/PC/InteractiveImage");
142  $tpl->setVariable("TITLE", $lng->txt("cont_iim_edit"));
143  $tpl->setVariable("HEAD_TRIGGER", $lng->txt("cont_iim_trigger"));
144  $tpl->setVariable(
145  "CLOSE_BUTTON",
146  $this->section($this->ui_wrapper->getRenderedButton(
147  $lng->txt("cont_iim_finish_editing"),
148  "button",
149  "component.back",
150  null,
151  "InteractiveImage",
152  true
153  ))
154  );
155  return $tpl->get();
156  }
157 
158  protected function getSelectTriggerMessage(): string
159  {
160  $lng = $this->lng;
161  return $this->section($this->ui_wrapper->getRenderedInfoBox(
162  $lng->txt("cont_iim_select_trigger")
163  ));
164  }
165 
166  protected function getCommonSuccessMessage(): string
167  {
168  $lng = $this->lng;
169  return $this->section($this->ui_wrapper->getRenderedSuccessBox(
170  $lng->txt("msg_obj_modified")
171  ));
172  }
173 
174  protected function getLoader(): string
175  {
176  $lng = $this->lng;
177  return $this->section("<img src='" . \ilUtil::getImagePath("media/loader.svg") . "' />");
178  }
179 
180  protected function getAddTriggerMessage(): string
181  {
182  $lng = $this->lng;
183  return $this->section($this->ui_wrapper->getRenderedInfoBox(
184  $lng->txt("cont_iim_add_trigger_text")
185  ));
186  }
187 
188  public function getMainSlate(): string
189  {
190  $lng = $this->lng;
191 
192  $tpl = new \ilTemplate("tpl.main_slate.html", true, true, "components/ILIAS/COPage/PC/InteractiveImage");
193  $tpl->setVariable("HEAD_SETTINGS", $lng->txt("settings"));
194  $tpl->setVariable("HEAD_OVERVIEW", $lng->txt("cont_iim_overview"));
195 
196  $tpl->setVariable(
197  "ADD_BUTTON",
198  $this->section($this->ui_wrapper->getRenderedButton(
199  $this->lng->txt("cont_iim_add_trigger"),
200  "button",
201  "add.trigger",
202  null,
203  "InteractiveImage"
204  ))
205  );
206 
207  $tpl->setVariable(
208  "LINK_SETTINGS",
209  $this->section($this->ui_wrapper->getRenderedLink(
210  $lng->txt("cont_iim_background_image_and_caption"),
211  "InteractiveImage",
212  "link",
213  "switch.settings",
214  null
215  ))
216  );
217 
218  $tpl->setVariable(
219  "LINK_OVERLAY",
220  $this->section($this->ui_wrapper->getRenderedLink(
221  $lng->txt("cont_overlay_images"),
222  "InteractiveImage",
223  "link",
224  "switch.overlays",
225  null
226  ))
227  );
228 
229  $tpl->setVariable(
230  "LINK_POPUPS",
231  $this->section($this->ui_wrapper->getRenderedLink(
232  $lng->txt("cont_content_popups"),
233  "InteractiveImage",
234  "link",
235  "switch.popups",
236  null
237  ))
238  );
239 
240  return $tpl->get();
241  }
242 
243  public function getBackgroundImage(
244  ): string {
245 
246  if ($this->pc_id !== "") {
248  $pc = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id);
249  } else {
250  return "";
251  }
252 
253  return $pc->getBackgroundImage();
254  }
255 
256  protected function section(string $content): string
257  {
258  return "<div class='copg-edit-button-group'>" . $content . "</div>";
259  }
260 
261  protected function getTriggerBackButton(): string
262  {
263  return $this->section($this->ui_wrapper->getRenderedButton(
264  $this->lng->txt("back"),
265  "button",
266  "trigger.back",
267  null,
268  "InteractiveImage"
269  ));
270  }
271 
272  protected function getTriggerHeader(): string
273  {
274  return $this->getHeading($this->lng->txt("cont_iim_edit_trigger"));
275  }
276 
277  protected function getTriggerViewControls(): string
278  {
279  return $this->section($this->ui_wrapper->getRenderedViewControl(
280  [
281  ["InteractiveImage", "trigger.properties", $this->lng->txt("properties")],
282  ["InteractiveImage", "trigger.overlay", $this->lng->txt("cont_overlay_image")],
283  ["InteractiveImage", "trigger.popup", $this->lng->txt("cont_content_popup")]
284  ]
285  ));
286  }
287 
289  {
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  }
308 
309  protected function getMessageArea(): string
310  {
311  return "<div id='cont_iim_message'></div>";
312  }
313 
314  protected function getTriggerPropertiesInfo(): string
315  {
316  return $this->section($this->ui_wrapper->getRenderedInfoBox($this->lng->txt("cont_iim_tr_properties_info")));
317  }
318 
319  protected function getTriggerProperties(): string
320  {
321  $content = $this->getTriggerBackButton() .
322  $this->getTriggerHeader() .
323  $this->getTriggerViewControls();
324  $content .= $this->getMessageArea();
325  $content .= $this->ui_wrapper->getRenderedAdapterForm(
327  [["InteractiveImage", "trigger.properties.save", $this->lng->txt("save")]],
328  "copg-iim-trigger-prop-form"
329  );
330 
331  return $content;
332  }
333 
335  {
336  return $this->gui->form(null, "#")
337  ->select(
338  "overlay",
339  $this->lng->txt("cont_iim_select_overlay"),
340  [
341  ]
342  );
343  }
344 
345  protected function getTriggerOverlay(): string
346  {
347  $content = $this->getTriggerBackButton() .
348  $this->getTriggerHeader() .
349  $this->getTriggerViewControls();
350  $content .= $this->getMessageArea();
351  $content .= $this->section($this->ui_wrapper->getRenderedButton(
352  $this->lng->txt("cont_iim_add_overlay"),
353  "button",
354  "trigger.add.overlay",
355  null,
356  "InteractiveImage"
357  ));
358  $content .= $this->ui_wrapper->getRenderedAdapterForm(
360  [["InteractiveImage", "trigger.overlay.save", $this->lng->txt("save")]],
361  "copg-iim-trigger-overlay-form"
362  );
363 
364  return $content;
365  }
366 
368  {
369  return $this->gui->form(null, "#")
370  ->select(
371  "popup",
372  $this->lng->txt("cont_content_popup"),
373  [
374  ]
375  )->select(
376  "size",
377  $this->lng->txt("cont_iim_size"),
378  [
379  "sm" => $this->lng->txt("cont_iim_sm"),
380  "md" => $this->lng->txt("cont_iim_md"),
381  "lg" => $this->lng->txt("cont_iim_lg")
382  ],
383  "",
384  "md"
385  )->required();
386  }
387 
388  protected function getTriggerPopup(): string
389  {
390  $content = $this->getTriggerBackButton() .
391  $this->getTriggerHeader() .
392  $this->getTriggerViewControls();
393  $content .= $this->getMessageArea();
394  $content .= $this->section($this->ui_wrapper->getRenderedButton(
395  $this->lng->txt("cont_iim_tr_add_popup"),
396  "button",
397  "trigger.add.popup",
398  null,
399  "InteractiveImage"
400  ));
401  $content .= $this->ui_wrapper->getRenderedAdapterForm(
403  [["InteractiveImage", "trigger.save.popup", $this->lng->txt("save")]],
404  "copg-iim-trigger-popup-form"
405  );
406  return $content;
407  }
408 
409  protected function getHeading(string $text, $sub = false): string
410  {
411  // todo: classes need better naming
412  if ($sub) {
413  return "<div class='copg-edit-button-group'><h3>" . $text . "</h3></div>";
414  }
415  return "<div class='copg-edit-button-group'><h2>" . $text . "</h2></div>";
416  }
417 
418  protected function getPopupOverview(): string
419  {
420  $content = $this->getTriggerBackButton();
421  $content .= $this->getHeading($this->lng->txt("cont_content_popups"), true);
422  $content .= $this->getMessageArea();
423  $content .= $this->section($this->ui_wrapper->getRenderedButton(
424  $this->lng->txt("cont_iim_tr_add_popup"),
425  "button",
426  "trigger.add.popup",
427  null,
428  "InteractiveImage"
429  ));
430  $content .= $this->section($this->ui_wrapper->getRenderedListingPanelTemplate($this->lng->txt("cont_iim_overview")));
431  return $content;
432  }
433 
434  protected function getOverlayOverview(): string
435  {
436  $content = $this->getTriggerBackButton();
437  $content .= $this->getHeading($this->lng->txt("cont_overlay_images"), true);
438  $content .= $this->getMessageArea();
439  $content .= $this->section($this->ui_wrapper->getRenderedButton(
440  $this->lng->txt("cont_iim_add_overlay"),
441  "button",
442  "trigger.add.overlay",
443  null,
444  "InteractiveImage"
445  ));
446  $content .= $this->section($this->ui_wrapper->getRenderedListingPanelTemplate($this->lng->txt("cont_iim_overview"), true));
447 
448  return $content;
449  }
450 
451 
452  protected function getBackgroundProperties(): string
453  {
454  $this->ctrl->setParameterByClass(
455  \ilPCInteractiveImageGUI::class,
456  "mode",
457  "backgroundUpdate"
458  );
459 
460  $content = $this->getTriggerBackButton();
461  $content .= $this->getHeading($this->lng->txt("cont_iim_background_image"), true);
462  $content .= $this->getMessageArea();
463  $content .= $this->ui_wrapper->getRenderedAdapterForm(
464  $this->getPCInteractiveImageGUI()->getBackgroundPropertiesFormAdapter([get_class($this->page_gui), \ilPageEditorGUI::class, \ilPCInteractiveImageGUI::class]),
465  [["InteractiveImage", "component.save", $this->lng->txt("save")]]
466  );
467 
468  return $content;
469  }
470 
471  public function getModalTemplate(): array
472  {
473  $ui = $this->ui;
474  $modal = $ui->factory()->modal()->roundtrip('#title#', $ui->factory()->legacy()->content('#content#'))
475  ->withActionButtons([
476  $ui->factory()->button()->standard('#button_title#', '#'),
477  ]);
478  $modalt["signal"] = $modal->getShowSignal()->getId();
479  $modalt["closeSignal"] = $modal->getCloseSignal()->getId();
480  $modalt["template"] = $ui->renderer()->renderAsync($modal);
481 
482  return $modalt;
483  }
484 
486  {
487  $pg = $this->page_gui->getPageObject();
488  $iim = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id);
489  $iim_gui = new \ilPCInteractiveImageGUI($pg, $iim, "", $this->pc_id);
490  $iim_gui->setPageConfig($pg->getPageConfig());
491  return $iim_gui;
492  }
493 
495  {
496  return $this->getPCInteractiveImageGUI()
497  ->getOverlayUploadFormAdapter([get_class($this->page_gui), \ilPageEditorGUI::class, \ilPCInteractiveImageGUI::class]);
498  }
499 
500  protected function getOverlayUpload(): string
501  {
502  $this->ctrl->setParameterByClass(
503  \ilPCInteractiveImageGUI::class,
504  "mode",
505  "overlayUpload"
506  );
507  $content = $this->ui_wrapper->getRenderedAdapterForm(
509  [["InteractiveImage", "overlay.upload", $this->lng->txt("add")]],
510  "",
511  true
512  );
513  $this->ctrl->setParameterByClass(
514  \ilPCInteractiveImageGUI::class,
515  "mode",
516  null
517  );
518  return $content;
519  }
520 
521  protected function getPopupForm(): string
522  {
523  $iim_gui = $this->getPCInteractiveImageGUI();
524  $content = $this->ui_wrapper->getRenderedAdapterForm(
525  $iim_gui->getPopupFormAdapter(),
526  [["InteractiveImage", "popup.save", $this->lng->txt("save")]],
527  "",
528  true
529  );
530  return $content;
531  }
532 }
text(string $key, string $title, string $description="", ?string $value=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer Contains several chained tasks and infos about them.
select(string $key, string $title, array $options, string $description="", ?string $value=null)
Class ilPageObjectGUI.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Page editor json server.
global $DIC
Definition: shib_login.php:22
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
User interface class for interactive images.