ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPCGridGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once("./Services/COPage/classes/class.ilPCGrid.php");
5require_once("./Services/COPage/classes/class.ilPCGridCell.php");
6require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
7
16{
17 const TEMPLATE_MANUAL = 0;
22
23 protected $toolbar;
24 protected $tabs;
25
33 public function __construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id = "")
34 {
35 global $DIC;
36
37 $this->ctrl = $DIC->ctrl();
38 $ilToolbar = $DIC->toolbar();
39 $ilTabs = $DIC->tabs();
40
41 $this->toolbar = $ilToolbar;
42 $this->tabs = $ilTabs;
43 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
44 }
45
49 public function executeCommand()
50 {
51 // get next class that processes or forwards current command
52 $next_class = $this->ctrl->getNextClass($this);
53
54 // get current command
55 $cmd = $this->ctrl->getCmd();
56
57 switch ($next_class) {
58 default:
59 $ret = $this->$cmd();
60 break;
61 }
62
63 return $ret;
64 }
65
69 public function insert()
70 {
72 $form = $this->initCreationForm();
73 if ($this->ctrl->getCmd() == "create") {
74 $form->setValuesByPost();
75 }
76 $this->tpl->setContent($form->getHTML());
77 }
78
82 public function editProperties()
83 {
85 $this->setTabs();
86
87 $form = $this->initForm();
88 $this->getFormValues($form);
89 $html = $form->getHTML();
90 $this->tpl->setContent($html);
91 }
92
97 public function initCreationForm()
98 {
100
101 // edit form
102 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
103 $form = new ilPropertyFormGUI();
104 $form->setFormAction($this->ctrl->getFormAction($this));
105 $form->setTitle($this->lng->txt("cont_ed_insert_grid"));
106 $form->setDescription($this->lng->txt("cont_ed_insert_grid_info"));
107
108 //
109 $radg = new ilRadioGroupInputGUI($lng->txt("cont_pc_grid"), "layout_template");
110 $radg->setValue(self::TEMPLATE_TWO_COLUMN);
111 $op1 = new ilRadioOption($lng->txt("cont_grid_t_two_column"), self::TEMPLATE_TWO_COLUMN, $lng->txt("cont_grid_t_two_column_info"));
112 $radg->addOption($op1);
113 $op2 = new ilRadioOption($lng->txt("cont_grid_t_three_column"), self::TEMPLATE_THREE_COLUMN, $lng->txt("cont_grid_t_three_column_info"));
114 $radg->addOption($op2);
115 $op3 = new ilRadioOption($lng->txt("cont_grid_t_main_side"), self::TEMPLATE_MAIN_SIDE, $lng->txt("cont_grid_t_main_side_info"));
116 $radg->addOption($op3);
117 $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"));
118 $radg->addOption($op4);
119 $op5 = new ilRadioOption($lng->txt("cont_grid_t_manual"), self::TEMPLATE_MANUAL, $lng->txt("cont_grid_t_manual_info"));
120 $radg->addOption($op5);
121 $form->addItem($radg);
122
123
124 // number of cells
125 $ni = new ilNumberInputGUI($this->lng->txt("cont_grid_nr_cells"), "number_of_cells");
126 $ni->setMaxLength(2);
127 $ni->setSize(2);
128 $op5->addSubItem($ni);
129
130 /*$sh = new ilFormSectionHeaderGUI();
131 $sh->setTitle($this->lng->txt("cont_ed_grid_col_width"));
132 $sh->setInfo($this->lng->txt("cont_ed_grid_col_width_info"));
133 $form->addItem($sh);*/
134
135 $options = array("" => "") + ilPCGrid::getWidths();
136
137 // widths
138 foreach (ilPCGrid::getSizes() as $s) {
139 $si = new ilSelectInputGUI($this->lng->txt("cont_grid_width_" . $s), $s);
140 $si->setInfo($this->lng->txt("cont_grid_width_" . $s . "_info"));
141 $si->setOptions($options);
142 $op5->addSubItem($si);
143 }
144
145 // save/cancel buttons
146 $form->addCommandButton("create_grid", $this->lng->txt("save"));
147 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
148
149 return $form;
150 }
151
155 public function create()
156 {
157 $form = $this->initCreationForm();
158 if ($form->checkInput()) {
159 $post_layout_template = (int) $_POST["layout_template"];
160 $this->content_obj = new ilPCGrid($this->getPage());
161 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
162
163 switch ($post_layout_template) {
165 $this->content_obj->addGridCell(12, 6, 6, 6);
166 $this->content_obj->addGridCell(12, 6, 6, 6);
167 break;
168
170 $this->content_obj->addGridCell(12, 4, 4, 4);
171 $this->content_obj->addGridCell(12, 4, 4, 4);
172 $this->content_obj->addGridCell(12, 4, 4, 4);
173 break;
174
176 $this->content_obj->addGridCell(12, 6, 8, 9);
177 $this->content_obj->addGridCell(12, 6, 4, 3);
178 break;
179
181 $this->content_obj->addGridCell(12, 6, 6, 3);
182 $this->content_obj->addGridCell(12, 6, 6, 3);
183 $this->content_obj->addGridCell(12, 6, 6, 3);
184 $this->content_obj->addGridCell(12, 6, 6, 3);
185 break;
186
187
189 for ($i = 0; $i < (int) $_POST["number_of_cells"]; $i++) {
190 $this->content_obj->addGridCell($_POST["s"], $_POST["m"], $_POST["l"], $_POST["xl"]);
191 }
192 break;
193 }
194
195 $this->updated = $this->pg_obj->update();
196
197 if ($this->updated === true) {
198 $this->afterCreation();
199 //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
200 } else {
201 $this->insert();
202 }
203 } else {
204 $form->setValuesByPost();
205 $this->tpl->setContent($form->getHTML());
206 }
207 }
208
212 public function afterCreation()
213 {
214 $this->pg_obj->stripHierIDs();
215 $this->pg_obj->addHierIDs();
216 $this->ctrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
217 $this->ctrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
218 $this->content_obj->setHierId($this->content_obj->readHierId());
219 $this->setHierId($this->content_obj->readHierId());
220 $this->content_obj->setPCId($this->content_obj->readPCId());
221 $this->edit();
222 }
223
224
225 //
226 // Edit Grid cells
227 //
228
232 public function edit()
233 {
234 $this->toolbar->addButton(
235 $this->lng->txt("cont_add_cell"),
236 $this->ctrl->getLinkTarget($this, "addCell")
237 );
238
239 $this->setTabs();
240 $this->tabs->activateTab("settings");
241 include_once("./Services/COPage/classes/class.ilPCGridCellTableGUI.php");
242 $table_gui = new ilPCGridCellTableGUI($this, "edit", $this->content_obj);
243 $this->tpl->setContent($table_gui->getHTML());
244 }
245
249 public function saveCells()
250 {
251 if (is_array($_POST["position"])) {
252 $positions = ilUtil::stripSlashesArray($_POST["position"]);
253 $this->content_obj->savePositions($positions);
254 }
255 $this->updated = $this->pg_obj->update();
256 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
257 $this->ctrl->redirect($this, "edit");
258 }
259
263 public function addCell()
264 {
265 $this->content_obj->addCell("", "", "", "");
266 $this->updated = $this->pg_obj->update();
267
268 ilUtil::sendSuccess($this->lng->txt("cont_added_cell"), true);
269 $this->ctrl->redirect($this, "edit");
270 }
271
275 public function confirmCellDeletion()
276 {
277 $this->setTabs();
278
279 if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0) {
280 ilUtil::sendInfo($this->lng->txt("no_checkbox"), true);
281 $this->ctrl->redirect($this, "edit");
282 } else {
283 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
284 $cgui = new ilConfirmationGUI();
285 $cgui->setFormAction($this->ctrl->getFormAction($this));
286 $cgui->setHeaderText($this->lng->txt("cont_grid_cell_confirm_deletion"));
287 $cgui->setCancel($this->lng->txt("cancel"), "cancelCellDeletion");
288 $cgui->setConfirm($this->lng->txt("delete"), "deleteCells");
289
290 foreach ($_POST["tid"] as $k => $i) {
291 $id = explode(":", $k);
292 $id = explode("_", $id[0]);
293 $cgui->addItem("tid[]", $k, $this->lng->txt("cont_grid_cell") . " " . $id[count($id) - 1]);
294 }
295
296 $this->tpl->setContent($cgui->getHTML());
297 }
298 }
299
303 public function cancelCellDeletion()
304 {
305 $this->ctrl->redirect($this, "edit");
306 }
307
311 public function deleteCells()
312 {
314
315 if (is_array($_POST["tid"])) {
316 foreach ($_POST["tid"] as $tid) {
317 $ids = explode(":", $tid);
318 $this->content_obj->deleteGridCell($ids[0], $ids[1]);
319 }
320 }
321 $this->updated = $this->pg_obj->update();
322
323 $ilCtrl->redirect($this, "edit");
324 }
325
326
330 public function setTabs()
331 {
332 $this->tabs->setBackTarget(
333 $this->lng->txt("pg"),
334 $this->ctrl->getParentReturn($this)
335 );
336
337 $this->tabs->addTab(
338 "settings",
339 $this->lng->txt("settings"),
340 $this->ctrl->getLinkTarget($this, "edit")
341 );
342 }
343
347 public function saveCellData()
348 {
349 $width_s = ilUtil::stripSlashesArray($_POST["width_s"]);
350 $width_m = ilUtil::stripSlashesArray($_POST["width_m"]);
351 $width_l = ilUtil::stripSlashesArray($_POST["width_l"]);
352 $width_xl = ilUtil::stripSlashesArray($_POST["width_xl"]);
353 $this->content_obj->saveWidths($width_s, $width_m, $width_l, $width_xl);
354
355 if (is_array($_POST["position"])) {
356 $positions = ilUtil::stripSlashesArray($_POST["position"]);
357 $this->content_obj->savePositions($positions);
358 }
359 $this->updated = $this->pg_obj->update();
360 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
361 $this->ctrl->redirect($this, "edit");
362 }
363}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
This class represents a number property in a property form.
Responsive Grid UI class.
confirmCellDeletion()
Confirm cell deletion.
create()
Create new grid element.
editProperties()
Edit grid cells.
const TEMPLATE_TWO_COLUMN
edit()
List all cells.
cancelCellDeletion()
Cancel cell deletion.
const TEMPLATE_TWO_BY_TWO
insert()
Insert new grid.
addCell()
Add cell.
executeCommand()
Execute command.
initCreationForm()
Init creation form.
saveCells()
Save cell properties.
deleteCells()
Delete Cells.
saveCellData()
Save tabs properties in db and return to page edit screen.
__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id="")
Constructor.
afterCreation()
After creation processing.
const TEMPLATE_THREE_COLUMN
setTabs()
Set tabs.
const TEMPLATE_MAIN_SIDE
Grid element.
static getSizes()
Get sizes.
static getWidths()
Get widths.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
displayValidationError()
display validation errors
setHierId($a_hier_id)
get hierarchical id in dom object
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.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static stripSlashesArray($a_arr, $a_strip_html=true, $a_allow="")
Strip slashes from array.
global $ilCtrl
Definition: ilias.php:18
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
$DIC
Definition: xapitoken.php:46