ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.PageCommandActionHandler.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\COPage\Page;
20
23
27class PageCommandActionHandler implements Server\CommandActionHandler
28{
32 protected $updated;
33 protected \ilPCParagraph $content_obj;
34 protected \ILIAS\DI\UIServices $ui;
35 protected \ilLanguage $lng;
36 protected \ilPageObjectGUI $page_gui;
37 protected \ilObjUser $user;
38 protected Server\UIWrapper $ui_wrapper;
39
41 {
42 global $DIC;
43
44 $this->ui = $DIC->ui();
45 $this->lng = $DIC->language();
46 $this->page_gui = $page_gui;
47 $this->user = $DIC->user();
48
49 $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
50 }
51
55 public function handle(array $query, array $body): Server\Response
56 {
57 switch ($body["action"]) {
58 case "cut":
59 return $this->cutCommand($body);
60
61 case "paste":
62 return $this->pasteCommand($body);
63
64 case "copy":
65 return $this->copyCommand($body);
66
67 case "drag.drop":
68 return $this->dragDropCommand($body);
69
70 case "format":
71 return $this->format($body);
72
73 case "delete":
74 return $this->delete($body);
75
76 case "activate":
77 return $this->activate($body);
78
79 case "list.edit":
80 return $this->listEdit($body);
81 break;
82
83 default:
84 throw new Exception("Unknown action " . $body["action"]);
85 }
86 }
87
88 protected function cutCommand(array $body): Server\Response
89 {
90 $pcids = $body["data"]["pcids"];
91 $page = $this->page_gui->getPageObject();
92
93 $hids = array_map(
94 function ($pcid) {
95 return $this->getIdForPCId($pcid);
96 },
97 $pcids
98 );
99
100 $updated = $page->cutContents($hids);
101
102 return $this->sendPage($updated);
103 }
104
105 protected function pasteCommand(array $body): Server\Response
106 {
107 $target_pcid = $body["data"]["target_pcid"];
108 $page = $this->page_gui->getPageObject();
109 $updated = $page->pasteContents(
110 $this->getIdForPCId($target_pcid),
111 $page->getPageConfig()->getEnableSelfAssessment()
112 );
113
114 return $this->sendPage($updated);
115 }
116
117 protected function copyCommand(array $body): Server\Response
118 {
119 $pcids = $body["data"]["pcids"];
120 $page = $this->page_gui->getPageObject();
121
122 $hids = array_map(
123 function ($pcid) {
124 return $this->getIdForPCId($pcid);
125 },
126 $pcids
127 );
128
129 $page->copyContents($hids);
130
131 return $this->sendPage(true);
132 }
133
134 protected function format(array $body): Server\Response
135 {
136 $pcids = $body["data"]["pcids"];
137 $par = $body["data"]["paragraph_format"];
138 $sec = $body["data"]["section_format"];
139 $med = $body["data"]["media_format"];
140 $page = $this->page_gui->getPageObject();
141
142 $hids = array_map(
143 function ($pcid) {
144 return $this->getIdForPCId($pcid);
145 },
146 $pcids
147 );
148
149 $updated = $page->assignCharacteristic($hids, $par, $sec, $med);
150 return $this->sendPage($updated);
151 }
152
153 protected function delete(array $body): Server\Response
154 {
155 $pcids = $body["data"]["pcids"];
156 $page = $this->page_gui->getPageObject();
157
158 $hids = array_map(
159 function ($pcid) {
160 return $this->getIdForPCId($pcid);
161 },
162 $pcids
163 );
164
165 $updated = $page->deleteContents(
166 $hids,
167 true,
168 $this->page_gui->getPageConfig()->getEnableSelfAssessment()
169 );
170 if ($updated === true) {
171 $this->page_gui->afterDeleteContents();
172 }
173
174 return $this->sendPage($updated);
175 }
176
177 protected function dragDropCommand(array $body): Server\Response
178 {
179 $target = $body["data"]["target"];
180 $source = $body["data"]["source"];
181
182 $page = $this->page_gui->getPageObject();
183
184 $source = explode(":", $source);
185 $target = explode(":", $target);
186
187 $updated = $page->moveContentAfter($source[0], $target[0], $source[1], $target[1]);
188
189 return $this->sendPage($updated);
190 }
191
196 protected function sendPage($updated): Server\Response
197 {
198 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
199 }
200
204 protected function getIdForPCId(string $pcid): string
205 {
206 $page = $this->page_gui->getPageObject();
207 $id = "pg:";
208 if (!in_array($pcid, ["", "pg"])) {
209 $hier_ids = $page->getHierIdsForPCIds([$pcid]);
210 $id = $hier_ids[$pcid] . ":" . $pcid;
211 }
212 return $id;
213 }
214
218 protected function getHierIdForPCId(string $pcid): string
219 {
220 $page = $this->page_gui->getPageObject();
221 $id = "pg";
222 if (!in_array($pcid, ["", "pg"])) {
223 $hier_ids = $page->getHierIdsForPCIds([$pcid]);
224 $id = $hier_ids[$pcid];
225 }
226 return $id;
227 }
228
229 protected function updateCommand(array $body): Server\Response
230 {
231 $page = $this->page_gui->getPageObject();
232
233 $hier_ids = $page->getHierIdsForPCIds([$body["data"]["pcid"]]);
234 $pcid = $hier_ids[$body["data"]["pcid"]] . ":" . $body["data"]["pcid"];
235
236 $content = "<div id='" .
237 $pcid . "' class='ilc_text_block_" .
238 $body["data"]["characteristic"] . "'>" . $body["data"]["content"] . "</div>";
239
240 $this->content_obj = new \ilPCParagraph($page);
241
242 $this->updated = $this->content_obj->saveJS(
243 $page,
244 $content,
245 \ilUtil::stripSlashes($body["data"]["characteristic"]),
247 );
248
249
250 $data = new \stdClass();
251 $data->renderedContent = "Test the rendered content";
252 return new Server\Response($data);
253 }
254
255 protected function activate(array $body): Server\Response
256 {
257 $pcids = $body["data"]["pcids"];
258 $page = $this->page_gui->getPageObject();
259
260 $hids = array_map(
261 function ($pcid) {
262 return $this->getIdForPCId($pcid);
263 },
264 $pcids
265 );
266
267 $updated = $page->switchEnableMultiple(
268 $hids,
269 true,
270 $this->page_gui->getPageConfig()->getEnableSelfAssessment()
271 );
272
273
274 return $this->sendPage($updated);
275 }
276
282 protected function listEdit($body): Server\Response
283 {
284 $pcid = $body["data"]["pcid"];
285 $list_cmd = $body["data"]["list_cmd"];
286 $page = $this->page_gui->getPageObject();
287
288 $pc = $page->getContentObjectForPcId($pcid);
289
290 $updated = true;
291 switch ($list_cmd) {
292 case "newItemAfter":
293 $pc->newItemAfter();
294 break;
295 case "newItemBefore":
296 $pc->newItemBefore();
297 break;
298 case "deleteItem":
299 $pc->deleteItem();
300 break;
301 case "moveItemUp":
302 $pc->moveItemUp();
303 break;
304 case "moveItemDown":
305 $pc->moveItemDown();
306 break;
307 }
308 $updated = $page->update();
309
310 return $this->sendPage($updated);
311 }
312}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Page editor json server.
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...
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