ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_once("./Services/COPage/classes/class.ilPCGrid.php");
5 require_once("./Services/COPage/classes/class.ilPCGridCell.php");
6 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
7 
16 {
17  protected $toolbar;
18  protected $tabs;
19 
27  public function __construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id = "")
28  {
29  global $DIC;
30 
31  $this->ctrl = $DIC->ctrl();
32  $ilToolbar = $DIC->toolbar();
33  $ilTabs = $DIC->tabs();
34 
35  $this->toolbar = $ilToolbar;
36  $this->tabs = $ilTabs;
37  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
38  }
39 
43  public function executeCommand()
44  {
45  // get next class that processes or forwards current command
46  $next_class = $this->ctrl->getNextClass($this);
47 
48  // get current command
49  $cmd = $this->ctrl->getCmd();
50 
51  switch ($next_class) {
52  default:
53  $ret = $this->$cmd();
54  break;
55  }
56 
57  return $ret;
58  }
59 
63  public function insert()
64  {
65  $this->displayValidationError();
66  $form = $this->initCreationForm();
67  if ($this->ctrl->getCmd() == "create") {
68  $form->setValuesByPost();
69  }
70  $this->tpl->setContent($form->getHTML());
71  }
72 
76  public function editProperties()
77  {
78  $this->displayValidationError();
79  $this->setTabs();
80 
81  $form = $this->initForm();
82  $this->getFormValues($form);
83  $html = $form->getHTML();
84  $this->tpl->setContent($html);
85  }
86 
91  public function initCreationForm()
92  {
93  // edit form
94  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
95  $form = new ilPropertyFormGUI();
96  $form->setFormAction($this->ctrl->getFormAction($this));
97  $form->setTitle($this->lng->txt("cont_ed_insert_grid"));
98  $form->setDescription($this->lng->txt("cont_ed_insert_grid_info"));
99 
100  // number of cells
101  $ni = new ilNumberInputGUI($this->lng->txt("cont_grid_nr_cells"), "number_of_cells");
102  $ni->setMaxLength(2);
103  $ni->setSize(2);
104  $form->addItem($ni);
105 
106  $sh = new ilFormSectionHeaderGUI();
107  $sh->setTitle($this->lng->txt("cont_ed_grid_col_width"));
108  $sh->setInfo($this->lng->txt("cont_ed_grid_col_width_info"));
109  $form->addItem($sh);
110 
111  $options = array("" => "") + ilPCGrid::getWidths();
112 
113  // widths
114  foreach (ilPCGrid::getSizes() as $s) {
115  $si = new ilSelectInputGUI($this->lng->txt("cont_grid_width_" . $s), $s);
116  $si->setInfo($this->lng->txt("cont_grid_width_" . $s . "_info"));
117  $si->setOptions($options);
118  $form->addItem($si);
119  }
120 
121  // save/cancel buttons
122  $form->addCommandButton("create_grid", $this->lng->txt("save"));
123  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
124 
125  return $form;
126  }
127 
131  public function create()
132  {
133  $form = $this->initCreationForm();
134  if ($form->checkInput()) {
135  $this->content_obj = new ilPCGrid($this->getPage());
136  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
137 
138  for ($i = 0; $i < (int) $_POST["number_of_cells"]; $i++) {
139  $this->content_obj->addGridCell($_POST["s"], $_POST["m"], $_POST["l"], $_POST["xl"]);
140  }
141 
142  $this->updated = $this->pg_obj->update();
143 
144  if ($this->updated === true) {
145  $this->afterCreation();
146  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
147  } else {
148  $this->insert();
149  }
150  } else {
151  $form->setValuesByPost();
152  $this->tpl->setContent($form->getHTML());
153  }
154  }
155 
159  public function afterCreation()
160  {
161  $this->pg_obj->stripHierIDs();
162  $this->pg_obj->addHierIDs();
163  $this->ctrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
164  $this->ctrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
165  $this->content_obj->setHierId($this->content_obj->readHierId());
166  $this->setHierId($this->content_obj->readHierId());
167  $this->content_obj->setPCId($this->content_obj->readPCId());
168  $this->edit();
169  }
170 
171 
172  //
173  // Edit Grid cells
174  //
175 
179  public function edit()
180  {
181  $this->toolbar->addButton(
182  $this->lng->txt("cont_add_cell"),
183  $this->ctrl->getLinkTarget($this, "addCell")
184  );
185 
186  $this->setTabs();
187  $this->tabs->activateTab("settings");
188  include_once("./Services/COPage/classes/class.ilPCGridCellTableGUI.php");
189  $table_gui = new ilPCGridCellTableGUI($this, "edit", $this->content_obj);
190  $this->tpl->setContent($table_gui->getHTML());
191  }
192 
196  public function saveCells()
197  {
198  if (is_array($_POST["position"])) {
199  $positions = ilUtil::stripSlashesArray($_POST["position"]);
200  $this->content_obj->savePositions($positions);
201  }
202  $this->updated = $this->pg_obj->update();
203  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
204  $this->ctrl->redirect($this, "edit");
205  }
206 
210  public function addCell()
211  {
212  $this->content_obj->addCell("", "", "", "");
213  $this->updated = $this->pg_obj->update();
214 
215  ilUtil::sendSuccess($this->lng->txt("cont_added_cell"), true);
216  $this->ctrl->redirect($this, "edit");
217  }
218 
222  public function confirmCellDeletion()
223  {
224  $this->setTabs();
225 
226  if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0) {
227  ilUtil::sendInfo($this->lng->txt("no_checkbox"), true);
228  $this->ctrl->redirect($this, "edit");
229  } else {
230  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
231  $cgui = new ilConfirmationGUI();
232  $cgui->setFormAction($this->ctrl->getFormAction($this));
233  $cgui->setHeaderText($this->lng->txt("cont_grid_cell_confirm_deletion"));
234  $cgui->setCancel($this->lng->txt("cancel"), "cancelCellDeletion");
235  $cgui->setConfirm($this->lng->txt("delete"), "deleteCells");
236 
237  foreach ($_POST["tid"] as $k => $i) {
238  $id = explode(":", $k);
239  $id = explode("_", $id[0]);
240  $cgui->addItem("tid[]", $k, $this->lng->txt("cont_grid_cell") . " " . $id[count($id) - 1]);
241  }
242 
243  $this->tpl->setContent($cgui->getHTML());
244  }
245  }
246 
250  public function cancelCellDeletion()
251  {
252  $this->ctrl->redirect($this, "edit");
253  }
254 
258  public function deleteCells()
259  {
261 
262  if (is_array($_POST["tid"])) {
263  foreach ($_POST["tid"] as $tid) {
264  $ids = explode(":", $tid);
265  $this->content_obj->deleteGridCell($ids[0], $ids[1]);
266  }
267  }
268  $this->updated = $this->pg_obj->update();
269 
270  $ilCtrl->redirect($this, "edit");
271  }
272 
273 
277  public function setTabs()
278  {
279  $this->tabs->setBackTarget(
280  $this->lng->txt("pg"),
281  $this->ctrl->getParentReturn($this)
282  );
283 
284  $this->tabs->addTab(
285  "settings",
286  $this->lng->txt("settings"),
287  $this->ctrl->getLinkTarget($this, "edit")
288  );
289  }
290 
294  public function saveCellData()
295  {
296  $width_s = ilUtil::stripSlashesArray($_POST["width_s"]);
297  $width_m = ilUtil::stripSlashesArray($_POST["width_m"]);
298  $width_l = ilUtil::stripSlashesArray($_POST["width_l"]);
299  $width_xl = ilUtil::stripSlashesArray($_POST["width_xl"]);
300  $this->content_obj->saveWidths($width_s, $width_m, $width_l, $width_xl);
301 
302  if (is_array($_POST["position"])) {
303  $positions = ilUtil::stripSlashesArray($_POST["position"]);
304  $this->content_obj->savePositions($positions);
305  }
306  $this->updated = $this->pg_obj->update();
307  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
308  $this->ctrl->redirect($this, "edit");
309  }
310 }
static getWidths()
Get widths.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
afterCreation()
After creation processing.
This class represents a selection list property in a property form.
Grid element.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
create()
Create new grid element.
setTabs()
Set tabs.
This class represents a section header in a property form.
initCreationForm()
Init creation form.
if(!array_key_exists('StateId', $_REQUEST)) $id
$s
Definition: pwgen.php:45
saveCells()
Save cell properties.
confirmCellDeletion()
Confirm cell deletion.
cancelCellDeletion()
Cancel cell deletion.
addCell()
Add cell.
__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id="")
Constructor.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
Responsive Grid UI class.
if(isset($_POST['submit'])) $form
This class represents a number property in a property form.
saveCellData()
Save tabs properties in db and return to page edit screen.
displayValidationError()
display validation errors
deleteCells()
Delete Cells.
Create styles array
The data for the language used.
edit()
List all cells.
static stripSlashesArray($a_arr, $a_strip_html=true, $a_allow="")
Strip slashes from array.
executeCommand()
Execute command.
setMaxLength($a_maxlength)
Set Max Length.
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
editProperties()
Edit grid cells.
insert()
Insert new grid.
$_POST["username"]
$html
Definition: example_001.php:87
setHierId($a_hier_id)
get hierarchical id in dom object
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
static getSizes()
Get sizes.
Confirmation screen class.