ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilPCGridGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  public const TEMPLATE_MANUAL = 0;
27  public const TEMPLATE_TWO_COLUMN = 1;
28  public const TEMPLATE_THREE_COLUMN = 2;
29  public const TEMPLATE_MAIN_SIDE = 3;
30  public const TEMPLATE_TWO_BY_TWO = 4;
31 
33  protected ilTabsGUI $tabs;
34 
35  public function __construct(
36  ilPageObject $a_pg_obj,
37  ?ilPageContent $a_content_obj,
38  string $a_hier_id,
39  string $a_pc_id = ""
40  ) {
41  global $DIC;
42 
43  $this->ctrl = $DIC->ctrl();
44  $ilToolbar = $DIC->toolbar();
45  $ilTabs = $DIC->tabs();
46 
47  $this->toolbar = $ilToolbar;
48  $this->tabs = $ilTabs;
49  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
50  }
51 
52  public function executeCommand(): void
53  {
54  // get next class that processes or forwards current command
55  $next_class = $this->ctrl->getNextClass($this);
56 
57  // get current command
58  $cmd = $this->ctrl->getCmd();
59 
60  switch ($next_class) {
61  default:
62  $this->$cmd();
63  break;
64  }
65  }
66 
67  public function insert(): void
68  {
69  $this->displayValidationError();
70  $form = $this->initCreationForm();
71  if ($this->ctrl->getCmd() == "create") {
72  $form->setValuesByPost();
73  }
74  $this->tpl->setContent($form->getHTML());
75  }
76 
77  /*
78  public function editProperties() : void
79  {
80  $this->displayValidationError();
81  $this->setTabs();
82 
83  $form = $this->initForm();
84  $this->getFormValues($form);
85  $html = $form->getHTML();
86  $this->tpl->setContent($html);
87  }*/
88 
93  {
94  $lng = $this->lng;
95 
96  // edit form
97  $form = new ilPropertyFormGUI();
98  $form->setFormAction($this->ctrl->getFormAction($this));
99  $form->setTitle($this->lng->txt("cont_ed_insert_grid"));
100  $form->setDescription($this->lng->txt("cont_ed_insert_grid_info"));
101 
102  //
103  $radg = new ilRadioGroupInputGUI($lng->txt("cont_pc_grid"), "layout_template");
104  $radg->setValue(self::TEMPLATE_TWO_COLUMN);
105  $op1 = new ilRadioOption($lng->txt("cont_grid_t_two_column"), self::TEMPLATE_TWO_COLUMN, $lng->txt("cont_grid_t_two_column_info"));
106  $radg->addOption($op1);
107  $op2 = new ilRadioOption($lng->txt("cont_grid_t_three_column"), self::TEMPLATE_THREE_COLUMN, $lng->txt("cont_grid_t_three_column_info"));
108  $radg->addOption($op2);
109  $op3 = new ilRadioOption($lng->txt("cont_grid_t_main_side"), self::TEMPLATE_MAIN_SIDE, $lng->txt("cont_grid_t_main_side_info"));
110  $radg->addOption($op3);
111  $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"));
112  $radg->addOption($op4);
113  $op5 = new ilRadioOption($lng->txt("cont_grid_t_manual"), self::TEMPLATE_MANUAL, $lng->txt("cont_grid_t_manual_info"));
114  $radg->addOption($op5);
115  $form->addItem($radg);
116 
117 
118  // number of cells
119  $ni = new ilNumberInputGUI($this->lng->txt("cont_grid_nr_cells"), "number_of_cells");
120  $ni->setMaxLength(2);
121  $ni->setSize(2);
122  $op5->addSubItem($ni);
123 
124  /*$sh = new ilFormSectionHeaderGUI();
125  $sh->setTitle($this->lng->txt("cont_ed_grid_col_width"));
126  $sh->setInfo($this->lng->txt("cont_ed_grid_col_width_info"));
127  $form->addItem($sh);*/
128 
129  $options = array("" => "") + ilPCGrid::getWidths();
130 
131  // widths
132  foreach (ilPCGrid::getSizes() as $s) {
133  $si = new ilSelectInputGUI($this->lng->txt("cont_grid_width_" . $s), $s);
134  $si->setInfo($this->lng->txt("cont_grid_width_" . $s . "_info"));
135  $si->setOptions($options);
136  $op5->addSubItem($si);
137  }
138 
139  // save/cancel buttons
140  $form->addCommandButton("create", $this->lng->txt("save"));
141  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
142 
143  return $form;
144  }
145 
149  public function create(): void
150  {
151  $form = $this->initCreationForm();
152  if ($form->checkInput()) {
153  $post_layout_template = (int) $form->getInput("layout_template");
154  $this->content_obj = new ilPCGrid($this->getPage());
155  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
156  $this->content_obj->applyTemplate(
157  $post_layout_template,
158  (int) $form->getInput("number_of_cells"),
159  (int) $form->getInput("s"),
160  (int) $form->getInput("m"),
161  (int) $form->getInput("l"),
162  (int) $form->getInput("xl")
163  );
164  $this->updated = $this->pg_obj->update();
165 
166  if ($this->updated === true) {
167  $this->afterCreation();
168  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
169  } else {
170  $this->insert();
171  }
172  } else {
173  $form->setValuesByPost();
174  $this->tpl->setContent($form->getHTML());
175  }
176  }
177 
178  public function afterCreation(): void
179  {
180  $this->pg_obj->stripHierIDs();
181  $this->pg_obj->addHierIDs();
182  $this->ctrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
183  $this->ctrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
184  $this->content_obj->setHierId($this->content_obj->readHierId());
185  $this->setHierId($this->content_obj->readHierId());
186  $this->content_obj->setPcId($this->content_obj->readPCId());
187  $this->edit();
188  }
189 
190 
191  //
192  // Edit Grid cells
193  //
194 
198  public function edit(): void
199  {
200  $this->toolbar->addButton(
201  $this->lng->txt("cont_add_cell"),
202  $this->ctrl->getLinkTarget($this, "addCell")
203  );
204 
205  $this->setTabs();
206  $this->tabs->activateTab("settings");
208  $grid = $this->content_obj;
209  $table_gui = new ilPCGridCellTableGUI($this, "edit", $grid);
210  $this->tpl->setContent($table_gui->getHTML());
211  }
212 
216  public function saveCells(): void
217  {
218  $pos = $this->request->getStringArray("position");
219  if (count($pos) > 0) {
220  $this->content_obj->savePositions($pos);
221  }
222  $this->updated = $this->pg_obj->update();
223  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
224  $this->ctrl->redirect($this, "edit");
225  }
226 
230  public function addCell(): void
231  {
232  $this->content_obj->addCell();
233  $this->updated = $this->pg_obj->update();
234 
235  $this->tpl->setOnScreenMessage('success', $this->lng->txt("cont_added_cell"), true);
236  $this->ctrl->redirect($this, "edit");
237  }
238 
242  public function confirmCellDeletion(): void
243  {
244  $this->setTabs();
245 
246  $tid = $this->request->getStringArray("tid");
247  if (count($tid) == 0) {
248  $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_checkbox"), true);
249  $this->ctrl->redirect($this, "edit");
250  } else {
251  $cgui = new ilConfirmationGUI();
252  $cgui->setFormAction($this->ctrl->getFormAction($this));
253  $cgui->setHeaderText($this->lng->txt("cont_grid_cell_confirm_deletion"));
254  $cgui->setCancel($this->lng->txt("cancel"), "cancelCellDeletion");
255  $cgui->setConfirm($this->lng->txt("delete"), "deleteCells");
256 
257  foreach ($tid as $k => $i) {
258  $id = explode(":", $k);
259  $id = explode("_", $id[0]);
260  $cgui->addItem("tid[]", $k, $this->lng->txt("cont_grid_cell") . " " . $id[count($id) - 1]);
261  }
262 
263  $this->tpl->setContent($cgui->getHTML());
264  }
265  }
266 
270  public function cancelCellDeletion(): void
271  {
272  $this->ctrl->redirect($this, "edit");
273  }
274 
278  public function deleteCells(): void
279  {
280  $ilCtrl = $this->ctrl;
281 
282  $tids = $this->request->getStringArray("tid");
283  foreach ($tids as $tid) {
284  $ids = explode(":", $tid);
285  $this->content_obj->deleteGridCell($ids[0], $ids[1]);
286  }
287  $this->updated = $this->pg_obj->update();
288 
289  $ilCtrl->redirect($this, "edit");
290  }
291 
292  public function setTabs(): void
293  {
294  $this->tabs->setBackTarget(
295  $this->lng->txt("pg"),
296  $this->ctrl->getParentReturn($this)
297  );
298 
299  $this->tabs->addTab(
300  "settings",
301  $this->lng->txt("settings"),
302  $this->ctrl->getLinkTarget($this, "edit")
303  );
304  }
305 
309  public function saveCellData(): void
310  {
311  $width_s = $this->request->getStringArray("width_s");
312  $width_m = $this->request->getStringArray("width_m");
313  $width_l = $this->request->getStringArray("width_l");
314  $width_xl = $this->request->getStringArray("width_xl");
315  $this->content_obj->saveWidths($width_s, $width_m, $width_l, $width_xl);
316 
317  $pos = $this->request->getStringArray("position");
318  if (count($pos) > 0) {
319  $this->content_obj->savePositions($pos);
320  }
321  $this->updated = $this->pg_obj->update();
322  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
323  $this->ctrl->redirect($this, "edit");
324  }
325 }
static getWidths()
Get widths.
const TEMPLATE_TWO_BY_TWO
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...
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...
create()
Create new grid element.
initCreationForm()
Init creation form.
setMaxLength(int $a_maxlength)
const TEMPLATE_TWO_COLUMN
setHierId(string $a_hier_id)
set hierarchical id in dom object
const TEMPLATE_MAIN_SIDE
saveCells()
Save cell properties.
ilToolbarGUI $toolbar
confirmCellDeletion()
Confirm cell deletion.
Content object of ilPageObject (see ILIAS DTD).
cancelCellDeletion()
Cancel cell deletion.
addCell()
Add cell.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
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...
This class represents a property in a property form.
This class represents a number property in a property form.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
saveCellData()
Save tabs properties in db and return to page edit screen.
global $DIC
Definition: shib_login.php:22
const TEMPLATE_THREE_COLUMN
deleteCells()
Delete Cells.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
static getSizes()
Get sizes.