ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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  $ok = false;
85  $error = "";
86  if ($mob_gui->checkFormInput()) {
87  $ok = true;
88  try {
89  $mob_gui->setObjectPerCreationForm($mob);
90  } catch (\Exception $e) {
91  $ok = false;
92  $error = $e->getMessage();
93  }
94  $media_item = $mob->getMediaItem("Standard");
95  if (!is_null($media_item)) {
96  $pc_media->createAlias($page, $hier_id, $pc_id);
97  }
98  $updated = $page->update();
99  }
100  if (!$ok)
101  {
102  if ($mob_gui->getForm()->getInput("standard_type") === "File") {
103  $edit_gui = new \ilPCMediaObjectEditorGUI();
104  $form = $edit_gui->getUploadForm($lng);
105  if ($error !== "") {
106  $input = $form->getItemByPostVar("standard_file");
107  $input->setAlert($error);
108  }
109  $form->checkInput();
110  $form->setValuesByPost();
111  $rendered_form = $edit_gui->getRenderedUploadForm(
112  $this->ui_wrapper,
113  $lng,
114  $form
115  );
116  return $this->ui_wrapper->sendFormError($rendered_form);
117  } else {
118  $edit_gui = new \ilPCMediaObjectEditorGUI();
119  $form = $edit_gui->getUrlForm($lng);
120  $form->checkInput();
121  $form->setValuesByPost();
122  $rendered_form = $edit_gui->getRenderedUrlForm(
123  $this->ui_wrapper,
124  $lng,
125  $form
126  );
127  return $this->ui_wrapper->sendFormError($rendered_form);
128  }
129  }
130 
131 
132  return $this->ui_wrapper->sendPage($this->page_gui, $updated);
133  }
134 
135  protected function updateCommand(array $body): Server\Response
136  {
137  $page = $this->page_gui->getPageObject();
138 
140  $pc_media = $page->getContentObjectForPcId($body["pcid"]);
141  $quick_edit = new \ilPCMediaObjectQuickEdit($pc_media);
142 
143  $quick_edit->setTitle(\ilUtil::stripSlashes($body["standard_title"] ?? ""));
144  $quick_edit->setClass(\ilUtil::stripSlashes($body["characteristic"] ?? ""));
145  $quick_edit->setHorizontalAlign(\ilUtil::stripSlashes($body["horizontal_align"] ?? ""));
146 
147  $quick_edit->setUseFullscreen((bool) ($body["fullscreen"] ?? false));
148  $quick_edit->setCaption(\ilUtil::stripSlashes($body["standard_caption"] ?? ""));
149  $quick_edit->setTextRepresentation(\ilUtil::stripSlashes($body["text_representation"] ?? ""));
150 
151  $pc_media->getMediaObject()->update();
152  $updated = $page->update();
153 
154  return $this->ui_wrapper->sendPage($this->page_gui, $updated);
155  }
156 }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Class ilPageObjectGUI.
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:25
ilErrorHandling $error
Definition: class.ilias.php:69