ILIAS  release_8 Revision v8.24
class.TableCommandActionHandler.php
Go to the documentation of this file.
1<?php
2
20
23
28{
29 protected \ILIAS\DI\UIServices $ui;
30 protected \ilLanguage $lng;
31 protected \ilPageObjectGUI $page_gui;
32 protected \ilObjUser $user;
34
36 {
37 global $DIC;
38
39 $this->ui = $DIC->ui();
40 $this->lng = $DIC->language();
41 $this->page_gui = $page_gui;
42 $this->user = $DIC->user();
43
44 $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
45 }
46
47 public function handle(array $query, array $body): Server\Response
48 {
49 switch ($body["action"]) {
50 case "update.data":
51 return $this->updateDataCommand($body);
52
53 case "modify.table":
54 return $this->modifyTableCommand($body);
55
56 default:
57 throw new Exception("Unknown action " . $body["action"]);
58 }
59 }
60
61 protected function updateDataCommand(array $body): Server\Response
62 {
63 $updated = $this->updateData($body["data"]["pcid"], $body["data"]["content"]);
64 if ($body["data"]["redirect"]) {
65 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
66 } else {
67 return $this->sendUpdateResponse($this->page_gui, $updated, $body["data"]["pcid"]);
68 }
69 }
70
75 public function sendUpdateResponse(
78 string $pcid
79 ): Server\Response {
80 $error = null;
81
82 $last_change = null;
83 if ($updated !== true) {
84 if (is_array($updated)) {
85 $error = implode("<br />", $updated);
86 } elseif (is_string($updated)) {
88 } else {
89 $error = print_r($updated, true);
90 }
91 } else {
92 $last_change = $page_gui->getPageObject()->getLastChange();
93 }
94
95 $data = new \stdClass();
96 $data->error = $error;
97 if ($last_change) {
98 $lu = new \ilDateTime($last_change, IL_CAL_DATETIME);
100 $data->last_update = \ilDatePresentation::formatDate($lu, true);
101 }
102
103 return new Server\Response($data);
104 }
105
106
111 protected function updateData(
112 string $pcid,
113 array $content
114 ) {
115 $page = $this->page_gui->getPageObject();
116 $table = $page->getContentObjectForPcId($pcid);
117
118 $data = [];
119 $updated = true;
120 foreach ($content as $i => $row) {
121 if (is_array($row)) {
122 foreach ($row as $j => $cell) {
123 $text = "<div>" . $cell . "</div>";
124 if ($updated) {
125 // determine cell content
127 $data[$i][$j] = $text;
128 $updated = ($text !== false);
129 $text = $text["text"];
130 }
131
132 if ($updated) {
134 $text,
135 $table->getLanguage(),
136 true,
137 false
138 );
140
141 $data[$i][$j] = $text;
142 }
143 }
144 }
145 }
146
147 if ($updated) {
148 $table->setData($data);
149 $updated = $page->update();
150 }
151
152 return $updated;
153 }
154
155
156 protected function modifyTableCommand(array $body): Server\Response
157 {
158 $page = $this->page_gui->getPageObject();
159 $page->addHierIDs();
160
162 $table = $page->getContentObjectForPcId($body["data"]["tablePcid"]);
163
164
165 if ($table->getType() == "dtab") {
166 $this->updateData($body["data"]["tablePcid"], $body["data"]["content"]);
167 }
168
169 $page->addHierIDs();
170
171
173 $td = $page->getContentObjectForPcId($body["data"]["cellPcid"]);
174
175 switch ($body["data"]["modification"]) {
176 case "col.before":
177 $td->newColBefore();
178 break;
179 case "col.after":
180 $td->newColAfter();
181 break;
182 case "col.left":
183 $td->moveColLeft();
184 break;
185 case "col.right":
186 $td->moveColRight();
187 break;
188 case "col.delete":
189 $td->deleteCol();
190 break;
191 case "row.before":
192 $td->newRowBefore();
193 break;
194 case "row.after":
195 $td->newRowAfter();
196 break;
197 case "row.up":
198 $td->moveRowUp();
199 break;
200 case "row.down":
201 $td->moveRowDown();
202 break;
203 case "row.delete":
204 $td->deleteRow();
205 break;
206 }
207
208 $page->update();
209
210 return $this->sendTable($this->page_gui, $body["data"]["tablePcid"]);
211 }
212
216 public function sendTable(
217 \ilPageObjectGUI $page_gui,
218 string $pcid
219 ): Server\Response {
220 $page = $page_gui->getPageObject();
221 $page->addHierIDs();
222 $table = $page->getContentObjectForPcId($pcid);
223 if ($table->getType() == "dtab") {
224 $table_gui = new \ilPCDataTableGUI(
225 $page_gui->getPageObject(),
226 $table,
227 $page->getHierIdForPcId($pcid),
228 $pcid
229 );
230 } else {
231 $table_gui = new \ilPCTableGUI(
232 $page_gui->getPageObject(),
233 $table,
234 $page->getHierIdForPcId($pcid),
235 $pcid
236 );
237 }
238
239 $data = new \stdClass();
240 $data->renderedContent = $table_gui->getEditDataTable();
241 $data->pcModel = $page_gui->getPageObject()->getPCModel();
242 return new Server\Response($data);
243 }
244}
sendTable(\ilPageObjectGUI $page_gui, string $pcid)
Send whole table as response.
sendUpdateResponse(\ilPageObjectGUI $page_gui, $updated, string $pcid)
Page editor json server.
ilErrorHandling $error
Definition: class.ilias.php:55
const IL_CAL_DATETIME
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static handleAjaxContentPost(string $text)
Post input2xml handling of ajax content.
static _input2xml(string $a_text, string $a_lang, bool $a_wysiwyg=false, bool $a_handle_lists=true)
Converts user input to xml User input comes as bb code information, e.g.
static handleAjaxContent(string $a_content)
Handle ajax content.
Class ilPageObjectGUI.
global $DIC
Definition: feed.php:28
$i
Definition: metadata.php:41
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...
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
$query