ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
class.ilPCGridGUI.php
Go to the documentation of this file.
1<?php
2
21
28{
29 public const TEMPLATE_MANUAL = 0;
30 public const TEMPLATE_TWO_COLUMN = 1;
31 public const TEMPLATE_THREE_COLUMN = 2;
32 public const TEMPLATE_MAIN_SIDE = 3;
33 public const TEMPLATE_TWO_BY_TWO = 4;
34 protected \ILIAS\COPage\InternalDomainService $domain;
35
37 protected ilTabsGUI $tabs;
38
39 public function __construct(
40 ilPageObject $a_pg_obj,
41 ?ilPageContent $a_content_obj,
42 string $a_hier_id,
43 string $a_pc_id = ""
44 ) {
45 global $DIC;
46
47 $this->ctrl = $DIC->ctrl();
48 $ilToolbar = $DIC->toolbar();
49 $ilTabs = $DIC->tabs();
50
51 $this->toolbar = $ilToolbar;
52 $this->tabs = $ilTabs;
53 $this->domain = $DIC->copage()->internal()->domain();
54 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
55 }
56
57 public function executeCommand(): void
58 {
59 // get next class that processes or forwards current command
60 $next_class = $this->ctrl->getNextClass($this);
61
62 // get current command
63 $cmd = $this->ctrl->getCmd();
64
65 switch ($next_class) {
66 default:
67 $this->$cmd();
68 break;
69 }
70 }
71
72 public function insert(): void
73 {
75 $form = $this->initCreationForm();
76 if ($this->ctrl->getCmd() == "create") {
77 $form->setValuesByPost();
78 }
79 $this->tpl->setContent($form->getHTML());
80 }
81
82 /*
83 public function editProperties() : void
84 {
85 $this->displayValidationError();
86 $this->setTabs();
87
88 $form = $this->initForm();
89 $this->getFormValues($form);
90 $html = $form->getHTML();
91 $this->tpl->setContent($html);
92 }*/
93
98 {
100
101 // edit form
102 $form = new ilPropertyFormGUI();
103 $form->setFormAction($this->ctrl->getFormAction($this));
104 $form->setTitle($this->lng->txt("cont_ed_insert_grid"));
105 $form->setDescription($this->lng->txt("cont_ed_insert_grid_info"));
106
107 //
108 $radg = new ilRadioGroupInputGUI($lng->txt("cont_pc_grid"), "layout_template");
109 $radg->setValue(self::TEMPLATE_TWO_COLUMN);
110 $op1 = new ilRadioOption($lng->txt("cont_grid_t_two_column"), self::TEMPLATE_TWO_COLUMN, $lng->txt("cont_grid_t_two_column_info"));
111 $radg->addOption($op1);
112 $op2 = new ilRadioOption($lng->txt("cont_grid_t_three_column"), self::TEMPLATE_THREE_COLUMN, $lng->txt("cont_grid_t_three_column_info"));
113 $radg->addOption($op2);
114 $op3 = new ilRadioOption($lng->txt("cont_grid_t_main_side"), self::TEMPLATE_MAIN_SIDE, $lng->txt("cont_grid_t_main_side_info"));
115 $radg->addOption($op3);
116 $op4 = new ilRadioOption($lng->txt("cont_grid_t_two_by_two"), self::TEMPLATE_TWO_BY_TWO, $lng->txt("cont_grid_t_two_by_two_info"));
117 $radg->addOption($op4);
118 $op5 = new ilRadioOption($lng->txt("cont_grid_t_manual"), self::TEMPLATE_MANUAL, $lng->txt("cont_grid_t_manual_info"));
119 $radg->addOption($op5);
120 $form->addItem($radg);
121
122
123 // number of cells
124 $ni = new ilNumberInputGUI($this->lng->txt("cont_grid_nr_cells"), "number_of_cells");
125 $ni->setMaxLength(2);
126 $ni->setSize(2);
127 $op5->addSubItem($ni);
128
129 /*$sh = new ilFormSectionHeaderGUI();
130 $sh->setTitle($this->lng->txt("cont_ed_grid_col_width"));
131 $sh->setInfo($this->lng->txt("cont_ed_grid_col_width_info"));
132 $form->addItem($sh);*/
133
134 $options = array("" => "") + ilPCGrid::getWidths();
135
136 // widths
137 foreach (ilPCGrid::getSizes() as $s) {
138 $si = new ilSelectInputGUI($this->lng->txt("cont_grid_width_" . $s), $s);
139 $si->setInfo($this->lng->txt("cont_grid_width_" . $s . "_info"));
140 $si->setOptions($options);
141 $op5->addSubItem($si);
142 }
143
144 // save/cancel buttons
145 $form->addCommandButton("create", $this->lng->txt("save"));
146 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
147
148 return $form;
149 }
150
154 public function create(): void
155 {
156 $form = $this->initCreationForm();
157 if ($form->checkInput()) {
158 $post_layout_template = (int) $form->getInput("layout_template");
159 $this->content_obj = new ilPCGrid($this->getPage());
160 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
161 $this->content_obj->applyTemplate(
162 $post_layout_template,
163 (int) $form->getInput("number_of_cells"),
164 (int) $form->getInput("s"),
165 (int) $form->getInput("m"),
166 (int) $form->getInput("l"),
167 (int) $form->getInput("xl")
168 );
169 $this->updated = $this->pg_obj->update();
170
171 if ($this->updated === true) {
172 $this->afterCreation();
173 //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
174 } else {
175 $this->insert();
176 }
177 } else {
178 $form->setValuesByPost();
179 $this->tpl->setContent($form->getHTML());
180 }
181 }
182
183 public function afterCreation(): void
184 {
185 $this->pg_obj->stripHierIDs();
186 $this->pg_obj->addHierIDs();
187 $this->ctrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
188 $this->ctrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
189 $this->content_obj->setHierId($this->content_obj->readHierId());
190 $this->setHierId($this->content_obj->readHierId());
191 $this->content_obj->setPcId($this->content_obj->readPCId());
192 $this->edit();
193 }
194
195
196 //
197 // Edit Grid cells
198 //
199
203 public function edit(): void
204 {
205 $this->toolbar->addButton(
206 $this->lng->txt("cont_add_cell"),
207 $this->ctrl->getLinkTarget($this, "addCell")
208 );
209
210 $this->setTabs();
211 $this->tabs->activateTab("settings");
212
213 $table = $this->gui->pc()->gridCellTableBuilder(
214 $this->content_obj,
215 $this,
216 "edit"
217 )->getTable();
218
219 if ($table->handleCommand()) {
220 return;
221 }
222
223 $this->tpl->setContent($table->render());
224 }
225
226 protected function getGridTable(): TableAdapterGUI
227 {
228 return $this->gui->pc()->gridCellTableBuilder(
229 $this->content_obj,
230 $this,
231 "edit"
232 )->getTable();
233 }
234
238 public function savePositions(): void
239 {
240 $table = $this->getGridTable();
241
242 $ordered_ids = $table->getData();
243
244 if (is_array($ordered_ids) && count($ordered_ids) > 0) {
245 $this->content_obj->savePositions($ordered_ids);
246 }
247 $this->updated = $this->pg_obj->update();
248 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
249 $this->ctrl->redirect($this, "edit");
250 }
251
252 public function editWidths(string $id): void
253 {
254 $form = $this->getEditWidthsForm($id);
255 $this->gui->modal($this->lng->txt("cont_ed_grid_col_widths"))
256 ->form($form)
257 ->send();
258 }
259
260 protected function getEditWidthsForm(string $id): FormAdapterGUI
261 {
262 $this->ctrl->setParameter($this, "tid", $id);
263 $options = ["" => ""] + ilPCGrid::getWidths();
264
265 $data = $this->content_obj->getCellData();
266 $row_data = [];
267 foreach ($data as $row) {
268 if ($row["hier_id"] . ":" . $row["pc_id"] === $id) {
269 $row_data = $row;
270 break;
271 }
272 }
273
274 $form = $this->gui->form([self::class], "saveWidths");
275 foreach (ilPCGrid::getSizes() as $s) {
276 $form->select(
277 "width_" . $s,
278 $this->lng->txt("cont_grid_width_" . $s),
279 $options,
280 "",
281 $row_data[$s] ?? ""
282 );
283 }
284
285 return $form;
286 }
287
288 protected function saveWidths(): void
289 {
290 $id = $this->request->getString("tid");
291 $form = $this->getEditWidthsForm($id);
292 if ($form->isValid()) {
293 $w_s = [$id => $form->getData("width_s")];
294 $w_m = [$id => $form->getData("width_m")];
295 $w_l = [$id => $form->getData("width_l")];
296 $w_xl = [$id => $form->getData("width_xl")];
297 $this->content_obj->saveWidths($w_s, $w_m, $w_l, $w_xl);
298 $this->updated = $this->pg_obj->update();
299 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
300 $this->ctrl->redirect($this, "edit");
301 }
302 }
303
304
308 public function addCell(): void
309 {
310 $this->content_obj->addCell();
311 $this->updated = $this->pg_obj->update();
312
313 $this->tpl->setOnScreenMessage('success', $this->lng->txt("cont_added_cell"), true);
314 $this->ctrl->redirect($this, "edit");
315 }
316
320 public function confirmCellDeletion(array $tids): void
321 {
322 $table = $this->getGridTable();
323 $ids = $table->getItemIds();
324
325 if (count($ids) === 0) {
326 $this->ctrl->redirect($this, "edit");
327 }
328
329 $retrieval = $this->domain->pc()->gridCellRetrieval($this->content_obj);
330 $data = $retrieval->getData([]);
331 $items = [];
332 $cnt = 1;
333 foreach ($data as $row) {
334 if (in_array($row["id"], $ids)) {
335 $items[$row["id"]] = $this->lng->txt("cont_grid_cell") . " " . $cnt;
336 }
337 $cnt++;
338 }
339
340 $table->renderDeletionConfirmation(
341 $this->lng->txt("delete"),
342 $this->lng->txt("cont_grid_cell_confirm_deletion"),
343 "deleteCells",
344 $items
345 );
346 }
347
351 public function cancelCellDeletion(): void
352 {
353 $this->ctrl->redirect($this, "edit");
354 }
355
359 public function deleteCells(): void
360 {
361 $ilCtrl = $this->ctrl;
362
363 $table = $this->getGridTable();
364 $ids = $table->getItemIds();
365
366 foreach ($ids as $tid) {
367 $ids = explode(":", $tid);
368 $this->content_obj->deleteGridCell($ids[0], $ids[1]);
369 }
370 $this->updated = $this->pg_obj->update();
371
372 $ilCtrl->redirect($this, "edit");
373 }
374
375 public function setTabs(): void
376 {
377 $this->tabs->setBackTarget(
378 $this->lng->txt("pg"),
379 $this->ctrl->getParentReturn($this)
380 );
381
382 $this->tabs->addTab(
383 "settings",
384 $this->lng->txt("settings"),
385 $this->ctrl->getLinkTarget($this, "edit")
386 );
387 }
388
392 public function saveCellData(): void
393 {
394 $width_s = $this->request->getStringArray("width_s");
395 $width_m = $this->request->getStringArray("width_m");
396 $width_l = $this->request->getStringArray("width_l");
397 $width_xl = $this->request->getStringArray("width_xl");
398 $this->content_obj->saveWidths($width_s, $width_m, $width_l, $width_xl);
399
400 $pos = $this->request->getStringArray("position");
401 if (count($pos) > 0) {
402 $this->content_obj->savePositions($pos);
403 }
404 $this->updated = $this->pg_obj->update();
405 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
406 $this->ctrl->redirect($this, "edit");
407 }
408}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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 class represents a number property in a property form.
Responsive Grid UI class.
getEditWidthsForm(string $id)
create()
Create new grid element.
const TEMPLATE_TWO_COLUMN
edit()
List all cells.
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
cancelCellDeletion()
Cancel cell deletion.
const TEMPLATE_TWO_BY_TWO
ILIAS COPage InternalDomainService $domain
confirmCellDeletion(array $tids)
Confirm cell deletion.
addCell()
Add cell.
initCreationForm()
Init creation form.
deleteCells()
Delete Cells.
saveCellData()
Save tabs properties in db and return to page edit screen.
const TEMPLATE_THREE_COLUMN
ilToolbarGUI $toolbar
savePositions()
Save positions.
const TEMPLATE_MAIN_SIDE
editWidths(string $id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getSizes()
Get sizes.
static getWidths()
Get widths.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
setHierId(string $a_hier_id)
set hierarchical id in dom object
Content object of ilPageObject (see ILIAS DTD).
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
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...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26