ILIAS  release_8 Revision v8.24
class.ilPCDataTableGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected \ILIAS\HTTP\Services $http;
28
29 public function __construct(
30 ilPageObject $a_pg_obj,
31 ?ilPageContent $a_content_obj,
32 string $a_hier_id,
33 string $a_pc_id = ""
34 ) {
35 global $DIC;
36
37 $this->main_tpl = $DIC->ui()->mainTemplate();
38 $this->lng = $DIC->language();
39 $this->ctrl = $DIC->ctrl();
40 $this->tabs = $DIC->tabs();
41 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
42 $this->setCharacteristics(array("StandardTable" => $this->lng->txt("cont_StandardTable")));
43 $this->tool_context = $DIC->globalScreen()->tool()->context();
44 $this->http = $DIC->http();
45 }
46
47 protected function getFormTitle(string $a_mode = "edit"): string
48 {
49 if ($a_mode === "create") {
50 return $this->lng->txt("cont_ed_insert_dtab");
51 }
52 return $this->lng->txt("cont_table_properties");
53 }
54
59 public function executeCommand()
60 {
61 $this->getCharacteristicsOfCurrentStyle(["table"]); // scorm-2004
62
63 // get next class that processes or forwards current command
64 $next_class = $this->ctrl->getNextClass($this);
65
66 // get current command
67 $cmd = $this->ctrl->getCmd();
68
69 switch ($next_class) {
70 default:
71 $ret = $this->$cmd();
72 break;
73 }
74
75 return $ret;
76 }
77
78
82
86 public function update(bool $a_redirect = true): void
87 {
89
90 // handle input data
91 $data = array();
92 $cell = $this->request->getArrayArray("cell");
93 if (is_array($cell)) {
94 foreach ($cell as $i => $row) {
95 if (is_array($row)) {
96 foreach ($row as $j => $cell) {
97 $data[$i][$j] =
99 $cell,
100 $this->content_obj->getLanguage()
101 );
102 }
103 }
104 }
105 }
106
107 $this->updated = $this->content_obj->setData($data);
108
109 if ($this->updated !== true) {
110 $this->editData();
111 return;
112 }
113
114 $this->updated = $this->pg_obj->update();
115
116 if ($a_redirect) {
117 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
118 $this->ctrl->redirect($this, "editData");
119 }
120 }
121
125 public function updateJS(): void
126 {
128 $ilCtrl = $this->ctrl;
129
130 if ($this->request->getString("cancel_update") != "") {
131 // $this->ctrl->redirect($this, "editData");
132 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
133 }
134
135 // handle input data
136 $data = array();
137 $post = $this->http->request()->getParsedBody();
138 foreach ($post as $k => $content) {
139 if (substr($k, 0, 5) != "cell_") {
140 continue;
141 }
142
143 // determine cell content
144 $div = ilUtil::stripSlashes($content, false);
145 $p1 = strpos($div, '>');
146 $div = substr($div, $p1 + 1);
147 $div = "<div class='ilc_text_block_TableContent'>" . $div;
149 if ($text === false) {
150 $ilCtrl->returnToParent($this, "jump" . $this->hier_id);
151 }
152 $text = $text["text"];
153
155 $text,
156 $this->content_obj->getLanguage(),
157 true,
158 false
159 );
161
162 // set content in data array
163 $id = explode("_", $k);
164 $data[(int) $id[1]][(int) $id[2]] = $text;
165 }
166
167 // update data
168 $this->updated = $this->content_obj->setData($data);
169
170 if ($this->updated !== true) {
171 $this->editData();
172 return;
173 }
174
175 $this->updated = $this->pg_obj->update();
176
177 $tab_cmd_id = $this->request->getInt("tab_cmd_id");
178 $tab_cmd_type = $this->request->getString("tab_cmd_type");
179 $tab_cmd = $this->request->getString("tab_cmd");
180
181 // perform table action? (move...?)
182 //$this->update(false);
183 $this->pg_obj->addHierIDs();
184 $failed = false;
185 if ($tab_cmd != "") {
186 $cell_hier_id = ($tab_cmd_type == "col")
187 ? $this->hier_id . "_1_" . ($tab_cmd_id + 1)
188 : $this->hier_id . "_" . ($tab_cmd_id + 1) . "_1";
189 $cell_obj = $this->pg_obj->getContentObject($cell_hier_id);
190 if (is_object($cell_obj)) {
191 $cell_obj->$tab_cmd();
192 $ret = $this->pg_obj->update();
193 if ($ret !== true) {
194 $this->main_tpl->setOnScreenMessage('failure', $ret[0][1], true);
195 $failed = true;
196 }
197 }
198 }
199
200 if (!$failed) {
201 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
202 }
203 if ($this->request->getString("save_return") != "") {
204 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
205 } else {
206 $this->ctrl->redirect($this, "editData");
207 }
208 }
209
210
215 {
216 return new ilPCDataTable($this->getPage());
217 }
218
222 public function afterCreation(): void
223 {
224 $ilCtrl = $this->ctrl;
225
226 $this->pg_obj->stripHierIDs();
227 $this->pg_obj->addHierIDs();
228 $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
229 $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
230 $ilCtrl->redirect($this, "editData");
231 }
232
236 public function tableAction(): void
237 {
238 $ilCtrl = $this->ctrl;
239
240 $this->update(false);
241 $this->pg_obj->addHierIDs();
242
243 $type = $this->request->getString("type");
244 $action = $this->request->getString("action");
245 $id = $this->request->getInt("id");
246
247 $cell_hier_id = ($type == "col")
248 ? $this->hier_id . "_1_" . ($id + 1)
249 : $this->hier_id . "_" . ($id + 1) . "_1";
250 $cell_obj = $this->pg_obj->getContentObject($cell_hier_id);
251 if (is_object($cell_obj)) {
252 $cell_obj->$action();
253 $this->edit_repo->setPageError($this->pg_obj->update());
254 }
255 $ilCtrl->redirect($this, "editData");
256 }
257
261 public function setTabs(string $data_tab_txt_key = ""): void
262 {
263 parent::setTabs("cont_ed_edit_data");
264 }
265
266 protected function getCellContent(int $i, int $j): string
267 {
268 $cmd = $this->ctrl->getCmd();
269 if ($cmd == "update") {
270 $s_text = ilUtil::stripSlashes("cell_" . $i . "_" . $j, false);
271 } else {
273 $this->content_obj->getCellText($i, $j),
274 true,
275 false
276 );
277 include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
279 $s_text,
280 "TableContent",
281 $this->content_obj->readPCId() . "_" . $i . "_" . $j
282 );
283 }
284
285 // #20628
286 $s_text = str_replace("{", "&#123;", $s_text);
287 $s_text = str_replace("}", "&#125;", $s_text);
288 return $s_text;
289 }
290}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCellContent(int $i, int $j)
ILIAS HTTP Services $http
getNewTableObject()
Get new table object.
afterCreation()
After creation processing.
tableAction()
Perform operation on table (adding, moving, deleting rows/cols)
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
update(bool $a_redirect=true)
Update table data in dom and update page in db.
getFormTitle(string $a_mode="edit")
setTabs(string $data_tab_txt_key="")
Set tabs.
ilGlobalTemplateInterface $main_tpl
updateJS()
Update via JavaScript.
executeCommand()
execute command
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static xml2outputJS(string $s_text)
Prepare content for js output.
static xml2output(string $a_text, bool $a_wysiwyg=false, bool $a_replace_lists=true, bool $unmask=true)
Converts xml from DB to output in edit textarea.
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
editData()
Edit data of table.
getCharacteristicsOfCurrentStyle(array $a_type)
Get characteristics of current style and call setCharacteristics, if style is given.
setCharacteristics(array $a_chars)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$post
Definition: ltitoken.php:49
$i
Definition: metadata.php:41
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type