ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $this->content_obj->applyTemplate(
163 $post_layout_template,
164 (int) $_POST["number_of_cells"],
165 $_POST["s"],
166 $_POST["m"],
167 $_POST["l"],
168 $_POST["xl"]
169 );
170 $this->updated = $this->pg_obj->update();
171
172 if ($this->updated === true) {
173 $this->afterCreation();
174 //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
175 } else {
176 $this->insert();
177 }
178 } else {
179 $form->setValuesByPost();
180 $this->tpl->setContent($form->getHTML());
181 }
182 }
183
187 public function afterCreation()
188 {
189 $this->pg_obj->stripHierIDs();
190 $this->pg_obj->addHierIDs();
191 $this->ctrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
192 $this->ctrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
193 $this->content_obj->setHierId($this->content_obj->readHierId());
194 $this->setHierId($this->content_obj->readHierId());
195 $this->content_obj->setPCId($this->content_obj->readPCId());
196 $this->edit();
197 }
198
199
200 //
201 // Edit Grid cells
202 //
203
207 public function edit()
208 {
209 $this->toolbar->addButton(
210 $this->lng->txt("cont_add_cell"),
211 $this->ctrl->getLinkTarget($this, "addCell")
212 );
213
214 $this->setTabs();
215 $this->tabs->activateTab("settings");
216 include_once("./Services/COPage/classes/class.ilPCGridCellTableGUI.php");
217 $table_gui = new ilPCGridCellTableGUI($this, "edit", $this->content_obj);
218 $this->tpl->setContent($table_gui->getHTML());
219 }
220
224 public function saveCells()
225 {
226 if (is_array($_POST["position"])) {
227 $positions = ilUtil::stripSlashesArray($_POST["position"]);
228 $this->content_obj->savePositions($positions);
229 }
230 $this->updated = $this->pg_obj->update();
231 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
232 $this->ctrl->redirect($this, "edit");
233 }
234
238 public function addCell()
239 {
240 $this->content_obj->addCell("", "", "", "");
241 $this->updated = $this->pg_obj->update();
242
243 ilUtil::sendSuccess($this->lng->txt("cont_added_cell"), true);
244 $this->ctrl->redirect($this, "edit");
245 }
246
250 public function confirmCellDeletion()
251 {
252 $this->setTabs();
253
254 if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0) {
255 ilUtil::sendInfo($this->lng->txt("no_checkbox"), true);
256 $this->ctrl->redirect($this, "edit");
257 } else {
258 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
259 $cgui = new ilConfirmationGUI();
260 $cgui->setFormAction($this->ctrl->getFormAction($this));
261 $cgui->setHeaderText($this->lng->txt("cont_grid_cell_confirm_deletion"));
262 $cgui->setCancel($this->lng->txt("cancel"), "cancelCellDeletion");
263 $cgui->setConfirm($this->lng->txt("delete"), "deleteCells");
264
265 foreach ($_POST["tid"] as $k => $i) {
266 $id = explode(":", $k);
267 $id = explode("_", $id[0]);
268 $cgui->addItem("tid[]", $k, $this->lng->txt("cont_grid_cell") . " " . $id[count($id) - 1]);
269 }
270
271 $this->tpl->setContent($cgui->getHTML());
272 }
273 }
274
278 public function cancelCellDeletion()
279 {
280 $this->ctrl->redirect($this, "edit");
281 }
282
286 public function deleteCells()
287 {
288 $ilCtrl = $this->ctrl;
289
290 if (is_array($_POST["tid"])) {
291 foreach ($_POST["tid"] as $tid) {
292 $ids = explode(":", $tid);
293 $this->content_obj->deleteGridCell($ids[0], $ids[1]);
294 }
295 }
296 $this->updated = $this->pg_obj->update();
297
298 $ilCtrl->redirect($this, "edit");
299 }
300
301
305 public function setTabs()
306 {
307 $this->tabs->setBackTarget(
308 $this->lng->txt("pg"),
309 $this->ctrl->getParentReturn($this)
310 );
311
312 $this->tabs->addTab(
313 "settings",
314 $this->lng->txt("settings"),
315 $this->ctrl->getLinkTarget($this, "edit")
316 );
317 }
318
322 public function saveCellData()
323 {
324 $width_s = ilUtil::stripSlashesArray($_POST["width_s"]);
325 $width_m = ilUtil::stripSlashesArray($_POST["width_m"]);
326 $width_l = ilUtil::stripSlashesArray($_POST["width_l"]);
327 $width_xl = ilUtil::stripSlashesArray($_POST["width_xl"]);
328 $this->content_obj->saveWidths($width_s, $width_m, $width_l, $width_xl);
329
330 if (is_array($_POST["position"])) {
331 $positions = ilUtil::stripSlashesArray($_POST["position"]);
332 $this->content_obj->savePositions($positions);
333 }
334 $this->updated = $this->pg_obj->update();
335 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
336 $this->ctrl->redirect($this, "edit");
337 }
338}
$_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 $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6