ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilPCInteractiveImageGUI.php
Go to the documentation of this file.
1 <?php
2 
24 
32 {
33  protected \ILIAS\COPage\PC\InteractiveImage\IIMManager $iim_manager;
34  protected \ILIAS\COPage\PC\InteractiveImage\GUIService $iim_gui;
35  protected ilTabsGUI $tabs;
37 
38  public function __construct(
39  ilPageObject $a_pg_obj,
40  ?ilPageContent $a_content_obj,
41  string $a_hier_id,
42  string $a_pc_id = ""
43  ) {
44  global $DIC;
45 
46  $this->tpl = $DIC["tpl"];
47  $this->lng = $DIC->language();
48  $this->tabs = $DIC->tabs();
49  $this->ctrl = $DIC->ctrl();
50  $this->toolbar = $DIC->toolbar();
51  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
52  $this->iim_gui = $DIC->copage()->internal()->gui()->pc()->interactiveImage();
53  $this->iim_manager = $DIC->copage()->internal()->domain()->pc()->interactiveImage();
54  }
55 
56  public function executeCommand(): void
57  {
58  $tpl = $this->tpl;
59  $ilTabs = $this->tabs;
60 
61  // get next class that processes or forwards current command
62  $next_class = $this->ctrl->getNextClass($this);
63 
64  // get current command
65  $cmd = $this->ctrl->getCmd();
66 
67  if (is_object($this->content_obj)) {
68  $tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_mob.svg"));
69  $this->getTabs();
70  }
71 
72  switch ($next_class) {
73  case strtolower(ilRepoStandardUploadHandlerGUI::class):
75  break;
76 
77  default:
78  $this->$cmd();
79  break;
80  }
81  }
82 
83  protected function forwardFormToUploadHandler(): void
84  {
85  switch ($this->request->getString("mode")) {
86  case "overlayUpload":
87  $form = $this->getOverlayUploadFormAdapter();
88  $gui = $form->getRepoStandardUploadHandlerGUI("overlay_file");
89  break;
90 
91  case "backgroundUpdate":
92  $form = $this->getBackgroundPropertiesFormAdapter();
93  $gui = $form->getRepoStandardUploadHandlerGUI("input_file");
94  break;
95 
96  default:
97  $form = $this->getImportFormAdapter();
98  $gui = $form->getRepoStandardUploadHandlerGUI("input_file");
99  break;
100  }
101  $this->ctrl->forwardCommand($gui);
102  }
103 
107  public function getTabs(
108  bool $a_create = false,
109  bool $a_change_obj_ref = false
110  ): void {
111  $ilCtrl = $this->ctrl;
112  $ilTabs = $this->tabs;
113  $lng = $this->lng;
114 
115  if (!$a_create) {
116  $ilTabs->setBackTarget(
117  $lng->txt("pg"),
118  (string) $ilCtrl->getParentReturn($this)
119  );
120  }
121  }
122 
126  public function insert(
127  string $a_post_cmd = "edpost",
128  string $a_submit_cmd = "",
129  bool $a_input_error = false
130  ): void {
131  $tpl = $this->tpl;
132  $ilCtrl = $this->ctrl;
133  $lng = $this->lng;
134 
135  $this->tpl->setOnScreenMessage('info', $lng->txt("cont_iim_create_info"));
136 
137  $form = $this->initForm("create");
138  $form->setFormAction($ilCtrl->getFormAction($this));
139 
140  $this->displayValidationError();
141 
142  $tpl->setContent($form->getHTML());
143  }
144 
145  public function edit(): void
146  {
147  $ilCtrl = $this->ctrl;
148  $ilCtrl->redirect($this, "editor");
149  }
150 
151  public function editBaseImage(): void
152  {
153  $tpl = $this->tpl;
154  $ilTabs = $this->tabs;
155  $ilTabs->activateTab("edit_base_image");
156  $form = $this->initForm();
157  $tpl->setContent($form->getHTML());
158  }
159 
160 
161  public function initForm(string $a_mode = "edit"): ilPropertyFormGUI
162  {
163  $lng = $this->lng;
164  $ilCtrl = $this->ctrl;
165  $ti = null;
166 
167  $form = new ilPropertyFormGUI();
168 
169  // image file
170  $fi = new ilImageFileInputGUI($lng->txt("cont_file"), "image_file");
171  $fi->setAllowDeletion(false);
172  if ($a_mode == "edit") {
173  $fi->setImage($this->content_obj->getBaseThumbnailTarget());
174  } else {
175  $fi->setRequired(true);
176  }
177  $form->addItem($fi);
178 
179  if ($a_mode == "edit") {
180  // caption
181  $ti = new ilTextInputGUI($this->lng->txt("cont_caption"), "caption");
182  $ti->setMaxLength(200);
183  $ti->setSize(50);
184  $form->addItem($ti);
185  }
186 
187  // save and cancel commands
188  if ($a_mode == "create") {
189  $form->setTitle($lng->txt("cont_ed_insert_iim"));
190  $form->addCommandButton("create_iim", $lng->txt("save"));
191  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
192  } else {
193  // get caption
194  $std_alias_item = new ilMediaAliasItem(
195  $this->content_obj->getDomDoc(),
196  $this->getHierId(),
197  "Standard",
198  $this->content_obj->getPCId(),
199  "InteractiveImage"
200  );
201  $ti->setValue($std_alias_item->getCaption());
202 
203  $form->setTitle($lng->txt("cont_edit_base_image"));
204  $form->addCommandButton("update", $lng->txt("save"));
205  }
206 
207  $form->setFormAction($ilCtrl->getFormAction($this));
208 
209  return $form;
210  }
211 
212 
216  public function update(): void
217  {
218  $ilCtrl = $this->ctrl;
219  $lng = $this->lng;
220 
221  $form = $this->initForm("edit");
222  if ($form->checkInput()) {
223  $mob = $this->content_obj->getMediaObject();
224  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
225  $std_item = $mob->getMediaItem("Standard");
226  $location = $_FILES['image_file']['name'];
227 
228  if ($location != "" && is_file($_FILES['image_file']['tmp_name'])) {
229  $file = $mob_dir . "/" . $_FILES['image_file']['name'];
231  $_FILES['image_file']['tmp_name'],
232  $_FILES['image_file']['name'],
233  $file
234  );
235 
236  // get mime type
237  $format = ilObjMediaObject::getMimeType($file);
238  $location = $_FILES['image_file']['name'];
239  $std_item->setFormat($format);
240  $std_item->setLocation($location);
241  $std_item->setLocationType("LocalFile");
242  $mob->setDescription($format);
243  $mob->update();
244  }
245 
246  // set caption
247  $std_alias_item = new ilMediaAliasItem(
248  $this->content_obj->getDomDoc(),
249  $this->getHierId(),
250  "Standard",
251  $this->content_obj->getPCId(),
252  "InteractiveImage"
253  );
254  $std_alias_item->setCaption(
255  $form->getInput("caption")
256  );
257  $this->edit_repo->setPageError($this->pg_obj->update());
258  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
259  }
260 
261  $ilCtrl->redirectByClass("ilpcinteractiveimagegui", "editBaseImage");
262  }
263 
264 
268  public function centerAlign(): void
269  {
270  $std_alias_item = new ilMediaAliasItem(
271  $this->content_obj->getDomDoc(),
272  $this->getHierId(),
273  "Standard",
274  $this->content_obj->getPCId(),
275  "InteractiveImage"
276  );
277  $std_alias_item->setHorizontalAlign("Center");
278  $this->updateAndReturn();
279  }
280 
284  public function leftAlign(): void
285  {
286  $std_alias_item = new ilMediaAliasItem(
287  $this->dom,
288  $this->getHierId(),
289  "Standard",
290  $this->content_obj->getPCId(),
291  "InteractiveImage"
292  );
293  $std_alias_item->setHorizontalAlign("Left");
294  $this->updateAndReturn();
295  }
296 
300  public function rightAlign(): void
301  {
302  $std_alias_item = new ilMediaAliasItem(
303  $this->content_obj->getDomDoc(),
304  $this->getHierId(),
305  "Standard",
306  $this->content_obj->getPCId(),
307  "InteractiveImage"
308  );
309  $std_alias_item->setHorizontalAlign("Right");
310  $this->updateAndReturn();
311  }
312 
316  public function leftFloatAlign(): void
317  {
318  $std_alias_item = new ilMediaAliasItem(
319  $this->content_obj->getDomDoc(),
320  $this->getHierId(),
321  "Standard",
322  $this->content_obj->getPCId(),
323  "InteractiveImage"
324  );
325  $std_alias_item->setHorizontalAlign("LeftFloat");
326  $this->updateAndReturn();
327  }
328 
332  public function rightFloatAlign(): void
333  {
334  $std_alias_item = new ilMediaAliasItem(
335  $this->content_obj->getDomDoc(),
336  $this->getHierId(),
337  "Standard",
338  $this->content_obj->getPCId(),
339  "InteractiveImage"
340  );
341  $std_alias_item->setHorizontalAlign("RightFloat");
342  $this->updateAndReturn();
343  }
344 
345  public function getImportFormAdapter(): \ILIAS\Repository\Form\FormAdapterGUI
346  {
347  $this->ctrl->setParameter($this, "cname", "InteractiveImage");
348  $form = $this->gui->form([self::class], "#")
349  ->async()
350  ->section("f", $this->lng->txt("cont_ed_insert_iim"))
351  ->file(
352  "input_file",
353  $this->lng->txt("file"),
354  \Closure::fromCallable([$this, 'handleUploadResult']),
355  "mob_id",
356  "",
357  1,
358  [],
359  [self::class],
360  "copg"
361  )->required();
362  return $form;
363  }
364 
365  public function handleUploadResult(
366  FileUpload $upload,
367  UploadResult $result
368  ): BasicHandlerResult {
369  return $this->iim_manager->handleUploadResult($upload, $result);
370  }
371 
372  public function editor(): void
373  {
374  $ilTabs = $this->tabs;
375  $ilTabs->activateTab("editor");
376  $this->tpl->addCss(ilObjStyleSheet::getBaseContentStylePath());
377  $this->tpl->setContent($this->iim_gui->editorInit()->getInitHtml());
379  }
380 
381  protected function initInteractiveImageEditor(): void
382  {
383  $this->setEditorToolContext();
384  $this->iim_gui->editorInit()->initUI($this->tpl);
385  }
386 
387  public function getOverlayUploadFormAdapter(?array $path = null): \ILIAS\Repository\Form\FormAdapterGUI
388  {
389  if (is_null($path)) {
390  $path = [self::class];
391  }
392 
393  $f = $this->gui->form($path, "#")
394  ->async()
395  ->file(
396  "overlay_file",
397  $this->lng->txt("file"),
398  \Closure::fromCallable([$this, 'handleOverlayUpload']),
399  "mob_id",
400  "",
401  1,
402  ["image/png", "image/jpeg", "image/gif"],
403  $path,
404  "copg"
405  );
406  return $f;
407  }
408 
409 
410  public function handleOverlayUpload(
411  FileUpload $upload,
412  UploadResult $result
413  ): BasicHandlerResult {
414  return $this->iim_manager->handleOverlayUpload(
415  $this->content_obj->getMediaObject(),
416  $upload,
417  $result
418  );
419  }
420 
421  public function getPopupFormAdapter(): \ILIAS\Repository\Form\FormAdapterGUI
422  {
423  $f = $this->gui->form(null, "#")
424  ->text(
425  "title",
426  $this->lng->txt("title")
427  );
428  return $f;
429  }
430 
431  public function getBackgroundPropertiesFormAdapter(?array $path = null): \ILIAS\Repository\Form\FormAdapterGUI
432  {
433  if (is_null($path)) {
434  $path = [self::class];
435  }
436 
437  $f = $this->gui->form($path, "#")
438  ->async()
439  ->file(
440  "input_file",
441  $this->lng->txt("file"),
442  \Closure::fromCallable([$this, 'handleBackgroundUpload']),
443  "mob_id",
444  "",
445  1,
446  ["image/png", "image/jpeg", "image/gif"],
447  $path,
448  "copg"
449  )->text(
450  "caption",
451  $this->lng->txt("cont_caption")
452  );
453  return $f;
454  }
455 
456 
457  public function handleBackgroundUpload(
458  FileUpload $upload,
459  UploadResult $result
460  ): BasicHandlerResult {
461  $this->log->debug(">>>");
462  $this->log->debug("Start upload");
463  $this->log->debug($this->content_obj->getMediaObject()->getId());
464  return $this->iim_manager->handleUploadResult(
465  $upload,
466  $result,
467  $this->content_obj->getMediaObject()
468  );
469  }
470 
471 }
centerAlign()
Align media object to center.
insert(string $a_post_cmd="edpost", string $a_submit_cmd="", bool $a_input_error=false)
Insert new media object form.
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
setCaption(string $a_caption)
handleUploadResult(FileUpload $upload, UploadResult $result)
$location
Definition: buildRTE.php:22
Interface Observer Contains several chained tasks and infos about them.
getTabs(bool $a_create=false, bool $a_change_obj_ref=false)
Add tabs to ilTabsGUI object.
setContent(string $a_html)
Sets content for standard template.
handleOverlayUpload(FileUpload $upload, UploadResult $result)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Content object of ilPageObject (see ILIAS DTD).
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
static _getDirectory(int $a_mob_id)
Get absolute directory.
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
global $DIC
Definition: shib_login.php:26
handleBackgroundUpload(FileUpload $upload, UploadResult $result)
ilGlobalTemplateInterface $tpl
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
rightFloatAlign()
align media object to right, floating text
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
Class FileUpload.
Definition: FileUpload.php:37
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
This class represents an image file property in a property form.
activateTab(string $a_id)
leftFloatAlign()
align media object to left, floating text
leftAlign()
align media object to left
__construct(Container $dic, ilPlugin $plugin)
ILIAS COPage PC InteractiveImage GUIService $iim_gui
getBackgroundPropertiesFormAdapter(?array $path=null)
rightAlign()
align media object to right
User interface class for interactive images.
setHorizontalAlign(string $a_halign)
ILIAS COPage InternalGUIService $gui
ILIAS COPage PC InteractiveImage IIMManager $iim_manager