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