ILIAS  release_7 Revision v7.30-3-g800a261c036
class.PageCommandActionHandler.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
9
14{
18 protected $ui;
19
23 protected $lng;
24
28 protected $page_gui;
29
33 protected $user;
34
38 protected $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
57 public function handle($query, $body) : Server\Response
58 {
59 switch ($body["action"]) {
60 case "cut":
61 return $this->cutCommand($body);
62 break;
63
64 case "paste":
65 return $this->pasteCommand($body);
66 break;
67
68 case "copy":
69 return $this->copyCommand($body);
70 break;
71
72 case "drag.drop":
73 return $this->dragDropCommand($body);
74 break;
75
76 case "format":
77 return $this->format($body);
78 break;
79
80 case "delete":
81 return $this->delete($body);
82 break;
83
84 case "activate":
85 return $this->activate($body);
86 break;
87
88 case "list.edit":
89 return $this->listEdit($body);
90 break;
91
92 default:
93 throw new Exception("Unknown action " . $body["action"]);
94 break;
95 }
96 }
97
103 protected function cutCommand($body) : Server\Response
104 {
105 $pcids = $body["data"]["pcids"];
106 $page = $this->page_gui->getPageObject();
107
108 $hids = array_map(
109 function ($pcid) {
110 return $this->getIdForPCId($pcid);
111 },
112 $pcids
113 );
114
115 $updated = $page->cutContents($hids);
116
117 return $this->sendPage($updated);
118 }
119
125 protected function pasteCommand($body) : Server\Response
126 {
127 $target_pcid = $body["data"]["target_pcid"];
128 $page = $this->page_gui->getPageObject();
129 $updated = $page->pasteContents($this->getIdForPCId($target_pcid),
130 $page->getPageConfig()->getEnableSelfAssessment());
131
132 return $this->sendPage($updated);
133 }
134
140 protected function copyCommand($body) : Server\Response
141 {
142 $pcids = $body["data"]["pcids"];
143 $page = $this->page_gui->getPageObject();
144
145 $hids = array_map(
146 function ($pcid) {
147 return $this->getIdForPCId($pcid);
148 },
149 $pcids
150 );
151
152 $page->copyContents($hids);
153
154 return $this->sendPage(true);
155 }
156
162 protected function format($body) : Server\Response
163 {
164 $pcids = $body["data"]["pcids"];
165 $par = $body["data"]["paragraph_format"];
166 $sec = $body["data"]["section_format"];
167 $med = $body["data"]["media_format"];
168 $page = $this->page_gui->getPageObject();
169
170 $hids = array_map(
171 function ($pcid) {
172 return $this->getIdForPCId($pcid);
173 },
174 $pcids
175 );
176
177 $updated = $page->assignCharacteristic($hids, $par, $sec, $med);
178 return $this->sendPage($updated);
179 }
180
186 protected function delete($body) : Server\Response
187 {
188 $pcids = $body["data"]["pcids"];
189 $page = $this->page_gui->getPageObject();
190
191 $hids = array_map(
192 function ($pcid) {
193 return $this->getIdForPCId($pcid);
194 },
195 $pcids
196 );
197
198 $updated = $page->deleteContents(
199 $hids,
200 true,
201 $this->page_gui->getPageConfig()->getEnableSelfAssessment()
202 );
203
204 return $this->sendPage($updated);
205 }
206
212 protected function dragDropCommand($body) : Server\Response
213 {
214 $target = $body["data"]["target"];
215 $source = $body["data"]["source"];
216
217 $page = $this->page_gui->getPageObject();
218
219 /*
220 $hids = array_map(
221 function ($pcid) {
222 return $this->getIdForPCId($pcid);
223 },
224 $pcids
225 );*/
226
227 $source = explode(":", $source);
228 $target = explode(":", $target);
229
230 $updated = $page->moveContentAfter($source[0], $target[0], $source[1], $target[1]);
231
232 return $this->sendPage($updated);
233 }
234
239 protected function sendPage($updated) : Server\Response
240 {
241 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
242 }
243
249 protected function getIdForPCId($pcid)
250 {
251 $page = $this->page_gui->getPageObject();
252 $id = "pg:";
253 if (!in_array($pcid, ["", "pg"])) {
254 $hier_ids = $page->getHierIdsForPCIds([$pcid]);
255 $id = $hier_ids[$pcid] . ":" . $pcid;
256 }
257 return $id;
258 }
259
265 protected function getHierIdForPCId($pcid)
266 {
267 $page = $this->page_gui->getPageObject();
268 $id = "pg";
269 if (!in_array($pcid, ["", "pg"])) {
270 $hier_ids = $page->getHierIdsForPCIds([$pcid]);
271 $id = $hier_ids[$pcid];
272 }
273 return $id;
274 }
275
276
282 protected function updateCommand($body) : Server\Response
283 {
284 $page = $this->page_gui->getPageObject();
285
286 $hier_ids = $page->getHierIdsForPCIds([$body["data"]["pcid"]]);
287 $pcid = $hier_ids[$body["data"]["pcid"]] . ":" . $body["data"]["pcid"];
288
289 $content = "<div id='" .
290 $pcid . "' class='ilc_text_block_" .
291 $body["data"]["characteristic"] . "'>" . $body["data"]["content"] . "</div>";
292
293 $this->content_obj = new \ilPCParagraph($page);
294
295 $this->updated = $this->content_obj->saveJS(
296 $page,
297 $content,
298 \ilUtil::stripSlashes($body["data"]["characteristic"]),
300 );
301
302
303 $data = new \stdClass();
304 $data->renderedContent = "Test the rendered content";
305 return new Server\Response($data);
306 }
307
313 protected function activate($body) : Server\Response
314 {
315 $pcids = $body["data"]["pcids"];
316 $page = $this->page_gui->getPageObject();
317
318 $hids = array_map(
319 function ($pcid) {
320 return $this->getIdForPCId($pcid);
321 },
322 $pcids
323 );
324
325 $updated = $page->switchEnableMultiple(
326 $hids,
327 true,
328 $this->page_gui->getPageConfig()->getEnableSelfAssessment()
329 );
330
331
332 return $this->sendPage($updated);
333 }
334
340 protected function listEdit($body) : Server\Response
341 {
342 $pcid = $body["data"]["pcid"];
343 $list_cmd = $body["data"]["list_cmd"];
344 $page = $this->page_gui->getPageObject();
345
346 $pc = $page->getContentObjectForPcId($pcid);
347
348 $updated = true;
349 switch ($list_cmd) {
350 case "newItemAfter":
351 $pc->newItemAfter();
352 break;
353 case "newItemBefore":
354 $pc->newItemBefore();
355 break;
356 case "deleteItem":
357 $pc->deleteItem();
358 break;
359 case "moveItemUp":
360 $pc->moveItemUp();
361 break;
362 case "moveItemDown":
363 $pc->moveItemDown();
364 break;
365 }
366 $updated = $page->update();
367
368 return $this->sendPage($updated);
369 }
370
371}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Page editor json server.
Class ilPageObjectGUI.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $DIC
Definition: goto.php:24
$source
Definition: metadata.php:76
$query
$data
Definition: storeScorm.php:23
ui()
Definition: ui.php:5