ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.PageCommandActionHandler.php
Go to the documentation of this file.
1 <?php
2 
20 
23 
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;
39 
40  public function __construct(\ilPageObjectGUI $page_gui)
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 
171  return $this->sendPage($updated);
172  }
173 
174  protected function dragDropCommand(array $body): Server\Response
175  {
176  $target = $body["data"]["target"];
177  $source = $body["data"]["source"];
178 
179  $page = $this->page_gui->getPageObject();
180 
181  $source = explode(":", $source);
182  $target = explode(":", $target);
183 
184  $updated = $page->moveContentAfter($source[0], $target[0], $source[1], $target[1]);
185 
186  return $this->sendPage($updated);
187  }
188 
193  protected function sendPage($updated): Server\Response
194  {
195  return $this->ui_wrapper->sendPage($this->page_gui, $updated);
196  }
197 
201  protected function getIdForPCId(string $pcid): string
202  {
203  $page = $this->page_gui->getPageObject();
204  $id = "pg:";
205  if (!in_array($pcid, ["", "pg"])) {
206  $hier_ids = $page->getHierIdsForPCIds([$pcid]);
207  $id = $hier_ids[$pcid] . ":" . $pcid;
208  }
209  return $id;
210  }
211 
215  protected function getHierIdForPCId(string $pcid): string
216  {
217  $page = $this->page_gui->getPageObject();
218  $id = "pg";
219  if (!in_array($pcid, ["", "pg"])) {
220  $hier_ids = $page->getHierIdsForPCIds([$pcid]);
221  $id = $hier_ids[$pcid];
222  }
223  return $id;
224  }
225 
226  protected function updateCommand(array $body): Server\Response
227  {
228  $page = $this->page_gui->getPageObject();
229 
230  $hier_ids = $page->getHierIdsForPCIds([$body["data"]["pcid"]]);
231  $pcid = $hier_ids[$body["data"]["pcid"]] . ":" . $body["data"]["pcid"];
232 
233  $content = "<div id='" .
234  $pcid . "' class='ilc_text_block_" .
235  $body["data"]["characteristic"] . "'>" . $body["data"]["content"] . "</div>";
236 
237  $this->content_obj = new \ilPCParagraph($page);
238 
239  $this->updated = $this->content_obj->saveJS(
240  $page,
241  $content,
242  \ilUtil::stripSlashes($body["data"]["characteristic"]),
243  \ilUtil::stripSlashes($pcid)
244  );
245 
246 
247  $data = new \stdClass();
248  $data->renderedContent = "Test the rendered content";
249  return new Server\Response($data);
250  }
251 
252  protected function activate(array $body): Server\Response
253  {
254  $pcids = $body["data"]["pcids"];
255  $page = $this->page_gui->getPageObject();
256 
257  $hids = array_map(
258  function ($pcid) {
259  return $this->getIdForPCId($pcid);
260  },
261  $pcids
262  );
263 
264  $updated = $page->switchEnableMultiple(
265  $hids,
266  true,
267  $this->page_gui->getPageConfig()->getEnableSelfAssessment()
268  );
269 
270 
271  return $this->sendPage($updated);
272  }
273 
279  protected function listEdit($body): Server\Response
280  {
281  $pcid = $body["data"]["pcid"];
282  $list_cmd = $body["data"]["list_cmd"];
283  $page = $this->page_gui->getPageObject();
284 
285  $pc = $page->getContentObjectForPcId($pcid);
286 
287  $updated = true;
288  switch ($list_cmd) {
289  case "newItemAfter":
290  $pc->newItemAfter();
291  break;
292  case "newItemBefore":
293  $pc->newItemBefore();
294  break;
295  case "deleteItem":
296  $pc->deleteItem();
297  break;
298  case "moveItemUp":
299  $pc->moveItemUp();
300  break;
301  case "moveItemDown":
302  $pc->moveItemDown();
303  break;
304  }
305  $updated = $page->update();
306 
307  return $this->sendPage($updated);
308  }
309 }
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...
Page editor json server.
$query
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$source
Definition: metadata.php:93