ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.MediaObjectCommandActionHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
29 class MediaObjectCommandActionHandler implements Server\CommandActionHandler
30 {
31  protected \ILIAS\DI\UIServices $ui;
32  protected \ilLanguage $lng;
33  protected \ilPageObjectGUI $page_gui;
34  protected \ilObjUser $user;
35  protected Server\UIWrapper $ui_wrapper;
36 
37  public function __construct(\ilPageObjectGUI $page_gui)
38  {
39  global $DIC;
40 
41  $this->ui = $DIC->ui();
42  $this->lng = $DIC->language();
43  $this->page_gui = $page_gui;
44  $this->user = $DIC->user();
45 
46  $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
47  }
48 
49  public function handle(array $query, array $body): Server\Response
50  {
51  switch ($body["action"]) {
52  case "insert":
53  return $this->insertCommand($body);
54 
55  case "update":
56  return $this->updateCommand($body);
57 
58  default:
59  throw new Exception("Unknown action " . $body["action"]);
60  }
61  }
62 
63  protected function insertCommand(array $body): Server\Response
64  {
65  $page = $this->page_gui->getPageObject();
66  $lng = $this->lng;
67 
68  $hier_id = "pg";
69  $pc_id = "";
70  if (!in_array($body["after_pcid"], ["", "pg"])) {
71  $hier_ids = $page->getHierIdsForPCIds([$body["after_pcid"]]);
72  $hier_id = $hier_ids[$body["after_pcid"]];
73  $pc_id = $body["after_pcid"];
74  }
75 
76 
77  // if (!$mob_gui->checkFormInput()) {
78  $pc_media = new \ilPCMediaObject($page);
79  $pc_media->createMediaObject();
80  $mob = $pc_media->getMediaObject();
81 
82  $mob_gui = new \ilObjMediaObjectGUI("");
83  $mob_gui->initForm("create");
84  if ($mob_gui->checkFormInput()) {
85  $mob_gui->setObjectPerCreationForm($mob);
86  $media_item = $mob->getMediaItem("Standard");
87  if (!is_null($media_item)) {
88  $pc_media->createAlias($page, $hier_id, $pc_id);
89  }
90  $updated = $page->update();
91  } else {
92  if ($mob_gui->getForm()->getInput("standard_type") === "File") {
93  $edit_gui = new \ilPCMediaObjectEditorGUI();
94  $form = $edit_gui->getUploadForm($lng);
95  $form->checkInput();
96  $form->setValuesByPost();
97  $rendered_form = $edit_gui->getRenderedUploadForm(
98  $this->ui_wrapper,
99  $lng,
100  $form
101  );
102  return $this->ui_wrapper->sendFormError($rendered_form);
103  } else {
104  $edit_gui = new \ilPCMediaObjectEditorGUI();
105  $form = $edit_gui->getUrlForm($lng);
106  $form->checkInput();
107  $form->setValuesByPost();
108  $rendered_form = $edit_gui->getRenderedUrlForm(
109  $this->ui_wrapper,
110  $lng,
111  $form
112  );
113  return $this->ui_wrapper->sendFormError($rendered_form);
114  }
115  }
116 
117 
118  return $this->ui_wrapper->sendPage($this->page_gui, $updated);
119  }
120 
121  protected function updateCommand(array $body): Server\Response
122  {
123  $page = $this->page_gui->getPageObject();
124 
126  $pc_media = $page->getContentObjectForPcId($body["pcid"]);
127  $quick_edit = new \ilPCMediaObjectQuickEdit($pc_media);
128 
129  $quick_edit->setTitle(\ilUtil::stripSlashes($body["standard_title"] ?? ""));
130  $quick_edit->setClass(\ilUtil::stripSlashes($body["characteristic"] ?? ""));
131  $quick_edit->setHorizontalAlign(\ilUtil::stripSlashes($body["horizontal_align"] ?? ""));
132 
133  $quick_edit->setUseFullscreen((bool) ($body["fullscreen"] ?? false));
134  $quick_edit->setCaption(\ilUtil::stripSlashes($body["standard_caption"] ?? ""));
135  $quick_edit->setTextRepresentation(\ilUtil::stripSlashes($body["text_representation"] ?? ""));
136 
137  $pc_media->getMediaObject()->update();
138  $updated = $page->update();
139 
140  return $this->ui_wrapper->sendPage($this->page_gui, $updated);
141  }
142 }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Class ilPageObjectGUI.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
Page editor json server.