ILIAS  release_7 Revision v7.30-3-g800a261c036
class.TableCommandActionHandler.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 "insert":
61// return $this->insertCommand($body);
62 break;
63
64 case "update.data":
65 return $this->updateDataCommand($body);
66 break;
67
68 case "modify.table":
69 return $this->modifyTableCommand($body);
70 break;
71
72 default:
73 throw new Exception("Unknown action " . $body["action"]);
74 break;
75 }
76 }
77
83 /*
84 protected function insertCommand($body) : Server\Response
85 {
86 $page = $this->page_gui->getPageObject();
87
88 $hier_id = "pg";
89 $pc_id = "";
90 if (!in_array($body["after_pcid"], ["", "pg"])) {
91 $hier_ids = $page->getHierIdsForPCIds([$body["after_pcid"]]);
92 $hier_id = $hier_ids[$body["after_pcid"]];
93 $pc_id = $body["after_pcid"];
94 }
95
96
97 // if (!$mob_gui->checkFormInput()) {
98 $pc_media = new \ilPCMediaObject($page);
99 $pc_media->createMediaObject();
100 $mob = $pc_media->getMediaObject();
101 \ilObjMediaObjectGUI::setObjectPerCreationForm($mob);
102 $pc_media->createAlias($page, $hier_id, $pc_id);
103 $updated = $page->update();
104
105 return $this->ui_wrapper->sendPage($this->page_gui);
106 }*/
107
113 /*
114 protected function updateCommand($body) : Server\Response
115 {
116 $page = $this->page_gui->getPageObject();
117 $pc_media = $page->getContentObjectForPcId($body["pcid"]);
118
119 $quick_edit = new \ilPCMediaObjectQuickEdit($pc_media);
120
121 $quick_edit->setTitle(\ilUtil::stripSlashes($body["standard_title"]));
122 $quick_edit->setClass(\ilUtil::stripSlashes($body["characteristic"]));
123 $quick_edit->setHorizontalAlign(\ilUtil::stripSlashes($body["horizontal_align"]));
124
125 $quick_edit->setUseFullscreen((bool) ($body["fullscreen"]));
126 $quick_edit->setCaption(\ilUtil::stripSlashes($body["standard_caption"]));
127 $quick_edit->setTextRepresentation(\ilUtil::stripSlashes($body["text_representation"]));
128
129 $pc_media->getMediaObject()->update();
130 $page->update();
131
132 return $this->ui_wrapper->sendPage($this->page_gui);
133 }*/
134
140 protected function updateDataCommand($body) : Server\Response
141 {
142 $updated = $this->updateData($body["data"]["pcid"], $body["data"]["content"]);
143 if ($body["data"]["redirect"]) {
144 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
145 } else {
146 return $this->sendUpdateResponse($this->page_gui, $updated, $body["data"]["pcid"]);
147 }
148 }
149
157 public function sendUpdateResponse(\ilPageObjectGUI $page_gui, $updated, string $pcid) : Server\Response
158 {
159 $error = null;
160
161 $last_change = null;
162 if ($updated !== true) {
163 if (is_array($updated)) {
164 $error = implode("<br />", $updated);
165 } elseif (is_string($updated)) {
166 $error = $updated;
167 } else {
168 $error = print_r($updated, true);
169 }
170 } else {
171 $last_change = $page_gui->getPageObject()->getLastChange();
172 }
173
174 $data = new \stdClass();
175 $data->error = $error;
176 if ($last_change) {
177 $lu = new \ilDateTime($last_change, IL_CAL_DATETIME);
179 $data->last_update = \ilDatePresentation::formatDate($lu, true);
180 }
181
182 return new Server\Response($data);
183 }
184
185
191 protected function updateData($pcid, $content)
192 {
193 $page = $this->page_gui->getPageObject();
194 $table = $page->getContentObjectForPcId($pcid);
195
196 $data = [];
197 $updated = true;
198 if (is_array($content)) {
199 foreach ($content as $i => $row) {
200 if (is_array($row)) {
201 foreach ($row as $j => $cell) {
202 $text = "<div>" . $cell . "</div>";
203 if ($updated) {
204 // determine cell content
206 $data[$i][$j] = $text;
207 $updated = ($text !== false);
208 $text = $text["text"];
209 }
210
211 if ($updated) {
213 $text,
214 $table->getLanguage(),
215 true,
216 false
217 );
219
220 $data[$i][$j] = $text;
221 }
222 }
223 }
224 }
225 }
226
227 if ($updated) {
228 $table->setData($data);
229 $updated = $page->update();
230 }
231
232 return $updated;
233 }
234
235
241 protected function modifyTableCommand($body) : Server\Response
242 {
243 $page = $this->page_gui->getPageObject();
244 $page->addHierIDs();
245
247 $table = $page->getContentObjectForPcId($body["data"]["tablePcid"]);
248
249
250 if ($table->getType() == "dtab") {
251 $this->updateData($body["data"]["tablePcid"], $body["data"]["content"]);
252 }
253
254 $page->addHierIDs();
255
256
258 $td = $page->getContentObjectForPcId($body["data"]["cellPcid"]);
259
260 switch ($body["data"]["modification"]) {
261 case "col.before":
262 $td->newColBefore();
263 break;
264 case "col.after":
265 $td->newColAfter();
266 break;
267 case "col.left":
268 $td->moveColLeft();
269 break;
270 case "col.right":
271 $td->moveColRight();
272 break;
273 case "col.delete":
274 $td->deleteCol();
275 break;
276 case "row.before":
277 $td->newRowBefore();
278 break;
279 case "row.after":
280 $td->newRowAfter();
281 break;
282 case "row.up":
283 $td->moveRowUp();
284 break;
285 case "row.down":
286 $td->moveRowDown();
287 break;
288 case "row.delete":
289 $td->deleteRow();
290 break;
291 }
292
293 $page->update();
294
295 return $this->sendTable($this->page_gui, $body["data"]["tablePcid"]);
296 }
297
304 public function sendTable($page_gui, $pcid) : Server\Response
305 {
306 $page = $page_gui->getPageObject();
307 $page->addHierIds();
308 $table = $page->getContentObjectForPcId($pcid);
309 if ($table->getType() == "dtab") {
310 $table_gui = new \ilPCDataTableGUI(
311 $page_gui->getPageObject(),
312 $table,
313 $page->getHierIdForPCId($pcid),
314 $pcid
315 );
316 } else {
317 $table_gui = new \ilPCTableGUI(
318 $page_gui->getPageObject(),
319 $table,
320 $page->getHierIdForPCId($pcid),
321 $pcid
322 );
323 }
324
325 $data = new \stdClass();
326 $data->renderedContent = $table_gui->getEditDataTable();
327 $data->pcModel = $page_gui->getPageObject()->getPCModel();
328 return new Server\Response($data);
329 }
330}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
sendUpdateResponse(\ilPageObjectGUI $page_gui, $updated, string $pcid)
Get reponse data object.
Page editor json server.
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static _input2xml($a_text, $a_lang, $a_wysiwyg=0, $a_handle_lists=true)
converts user input to xml
static handleAjaxContent($a_content)
Handle ajax content.
static handleAjaxContentPost($text)
Post input2xml handling of ajax content.
Class ilPageObjectGUI.
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
$query
$data
Definition: storeScorm.php:23
ui()
Definition: ui.php:5