ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.MediaObjectCommandActionHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
29class 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
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();
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 if ($mob_gui->getForm()->getInput("standard_type") === "File") {
102 $edit_gui = new \ilPCMediaObjectEditorGUI();
103 $form = $edit_gui->getUploadForm($lng);
104 if ($error !== "") {
105 $input = $form->getItemByPostVar("standard_file");
106 $input->setAlert($error);
107 }
108 $form->checkInput();
109 $form->setValuesByPost();
110 $rendered_form = $edit_gui->getRenderedUploadForm(
111 $this->ui_wrapper,
112 $lng,
113 $form
114 );
115 return $this->ui_wrapper->sendFormError($rendered_form);
116 } else {
117 $edit_gui = new \ilPCMediaObjectEditorGUI();
118 $form = $edit_gui->getUrlForm($lng);
119 $form->checkInput();
120 $form->setValuesByPost();
121 $rendered_form = $edit_gui->getRenderedUrlForm(
122 $this->ui_wrapper,
123 $lng,
124 $form
125 );
126 return $this->ui_wrapper->sendFormError($rendered_form);
127 }
128 }
129
130
131 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
132 }
133
134 protected function updateCommand(array $body): Server\Response
135 {
136 $page = $this->page_gui->getPageObject();
137
139 $pc_media = $page->getContentObjectForPcId($body["pcid"]);
140 $quick_edit = new \ilPCMediaObjectQuickEdit($pc_media);
141
142 $quick_edit->setTitle(\ilUtil::stripSlashes($body["standard_title"] ?? ""));
143 $quick_edit->setClass(\ilUtil::stripSlashes($body["characteristic"] ?? ""));
144 $quick_edit->setHorizontalAlign(\ilUtil::stripSlashes($body["horizontal_align"] ?? ""));
145
146 $quick_edit->setUseFullscreen((bool) ($body["fullscreen"] ?? false));
147 $quick_edit->setCaption(\ilUtil::stripSlashes($body["standard_caption"] ?? ""));
148 $quick_edit->setTextRepresentation(\ilUtil::stripSlashes($body["text_representation"] ?? ""));
149
150 $pc_media->getMediaObject()->update();
151 $updated = $page->update();
152
153 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
154 }
155}
Page editor json server.
ilErrorHandling $error
Definition: class.ilias.php:69
Class ilPageObjectGUI.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26