ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPCGrid.php
Go to the documentation of this file.
1 <?php
2 
24 class ilPCGrid extends ilPageContent
25 {
27 
31  public function init(): void
32  {
33  $this->setType("grid");
34  }
35 
40  public function setNode(php4DOMElement $a_node): void
41  {
42  parent::setNode($a_node); // this is the PageContent node
43  $this->grid_node = $a_node->first_child(); // this is the Tabs node
44  }
45 
52  public static function getSizes(): array
53  {
54  return array("s" => "s", "m" => "m", "l" => "l", "xl" => "xl");
55  }
56 
60  public static function getWidths(): array
61  {
62  return array(
63  "1" => "1/12", "2" => "2/12", "3" => "3/12",
64  "4" => "4/12", "5" => "5/12", "6" => "6/12",
65  "7" => "7/12", "8" => "8/12", "9" => "9/12",
66  "10" => "10/12", "11" => "11/12", "12" => "12/12"
67  );
68  }
69 
70  public function create(
71  ilPageObject $a_pg_obj,
72  string $a_hier_id,
73  string $a_pc_id = ""
74  ): void {
75  $this->node = $this->createPageContentNode();
76  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
77  $this->grid_node = $this->dom->create_element("Grid");
78  $this->grid_node = $this->node->append_child($this->grid_node);
79  }
80 
81  public function applyTemplate(
82  int $post_layout_template,
83  int $number_of_cells,
84  int $s,
85  int $m,
86  int $l,
87  int $xl
88  ): void {
89  switch ($post_layout_template) {
91  $this->addGridCell(12, 6, 6, 6);
92  $this->addGridCell(12, 6, 6, 6);
93  break;
94 
96  $this->addGridCell(12, 4, 4, 4);
97  $this->addGridCell(12, 4, 4, 4);
98  $this->addGridCell(12, 4, 4, 4);
99  break;
100 
102  $this->addGridCell(12, 6, 8, 9);
103  $this->addGridCell(12, 6, 4, 3);
104  break;
105 
107  $this->addGridCell(12, 6, 6, 3);
108  $this->addGridCell(12, 6, 6, 3);
109  $this->addGridCell(12, 6, 6, 3);
110  $this->addGridCell(12, 6, 6, 3);
111  break;
112 
113 
115  for ($i = 0; $i < $number_of_cells; $i++) {
116  $this->addGridCell($s, $m, $l, $xl);
117  }
118  break;
119  }
120  }
121 
125  public function savePositions(array $a_pos): void
126  {
127  asort($a_pos);
128 
129  $childs = $this->grid_node->child_nodes();
130  $nodes = array();
131  for ($i = 0; $i < count($childs); $i++) {
132  if ($childs[$i]->node_name() == "GridCell") {
133  $pc_id = $childs[$i]->get_attribute("PCID");
134  $hier_id = $childs[$i]->get_attribute("HierId");
135  $nodes[$hier_id . ":" . $pc_id] = $childs[$i];
136  $childs[$i]->unlink($childs[$i]);
137  }
138  }
139 
140  foreach ($a_pos as $k => $v) {
141  if (is_object($nodes[$k])) {
142  $nodes[$k] = $this->grid_node->append_child($nodes[$k]);
143  }
144  }
145  }
146 
150  public function saveWidths(
151  array $a_width_s,
152  array $a_width_m,
153  array $a_width_l,
154  array $a_width_xl
155  ): void {
156  $cell_nodes = $this->grid_node->child_nodes();
157  for ($i = 0; $i < count($cell_nodes); $i++) {
158  if ($cell_nodes[$i]->node_name() == "GridCell") {
159  $pc_id = $cell_nodes[$i]->get_attribute("PCID");
160  $hier_id = $cell_nodes[$i]->get_attribute("HierId");
161  $k = $hier_id . ":" . $pc_id;
162  $cell_nodes[$i]->set_attribute("WIDTH_XS", "");
163  $cell_nodes[$i]->set_attribute("WIDTH_S", $a_width_s[$k]);
164  $cell_nodes[$i]->set_attribute("WIDTH_M", $a_width_m[$k]);
165  $cell_nodes[$i]->set_attribute("WIDTH_L", $a_width_l[$k]);
166  $cell_nodes[$i]->set_attribute("WIDTH_XL", $a_width_xl[$k]);
167  }
168  }
169  }
170 
171 
175  public function deleteGridCell(
176  string $a_hier_id,
177  string $a_pc_id
178  ): void {
179  $childs = $this->grid_node->child_nodes();
180  for ($i = 0; $i < count($childs); $i++) {
181  if ($childs[$i]->node_name() == "GridCell") {
182  if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
183  $a_hier_id == $childs[$i]->get_attribute("HierId")) {
184  $childs[$i]->unlink($childs[$i]);
185  }
186  }
187  }
188  }
189 
193  public function addGridCell(
194  int $a_s,
195  int $a_m,
196  int $a_l,
197  int $a_xl
198  ): void {
199  $new_item = $this->dom->create_element("GridCell");
200  $new_item = $this->grid_node->append_child($new_item);
201  //$new_item->set_attribute("xs", $a_xs);
202  $new_item->set_attribute("WIDTH_XS", "");
203  $new_item->set_attribute("WIDTH_S", $a_s);
204  $new_item->set_attribute("WIDTH_M", $a_m);
205  $new_item->set_attribute("WIDTH_L", $a_l);
206  $new_item->set_attribute("WIDTH_XL", $a_xl);
207  }
208 
212  public function addCell(): void
213  {
214  $new_item = $this->dom->create_element("GridCell");
215  $new_item->set_attribute("WIDTH_XS", "");
216  $new_item->set_attribute("WIDTH_S", "");
217  $new_item->set_attribute("WIDTH_M", "");
218  $new_item->set_attribute("WIDTH_L", "");
219  $new_item->set_attribute("WIDTH_XL", "");
220  $this->grid_node->append_child($new_item);
221  }
222 
227  public static function getLangVars(): array
228  {
229  return array("pc_grid", "pc_grid_cell", "ed_delete_cell", "ed_cell_left", "ed_cell_right");
230  }
231 
232  public function getJavascriptFiles(string $a_mode): array
233  {
234  return parent::getJavascriptFiles($a_mode);
235  }
236 
237  public function getCssFiles(string $a_mode): array
238  {
239  return parent::getCssFiles($a_mode);
240  }
241 
242  public function getCellData(): array
243  {
244  $cells = array();
245  $cell_nodes = $this->grid_node->child_nodes();
246  $k = 0;
247  for ($i = 0; $i < count($cell_nodes); $i++) {
248  if ($cell_nodes[$i]->node_name() == "GridCell") {
249  $pc_id = $cell_nodes[$i]->get_attribute("PCID");
250  $hier_id = $cell_nodes[$i]->get_attribute("HierId");
251  $cells[] = array("pos" => $k,
252  "xs" => $cell_nodes[$i]->get_attribute("WIDTH_XS"),
253  "s" => $cell_nodes[$i]->get_attribute("WIDTH_S"),
254  "m" => $cell_nodes[$i]->get_attribute("WIDTH_M"),
255  "l" => $cell_nodes[$i]->get_attribute("WIDTH_L"),
256  "xl" => $cell_nodes[$i]->get_attribute("WIDTH_XL"),
257  "pc_id" => $pc_id, "hier_id" => $hier_id);
258  $k++;
259  }
260  }
261 
262  return $cells;
263  }
264 }
addCell()
Add a cell.
static getWidths()
Get widths.
const TEMPLATE_TWO_BY_TWO
setType(string $a_type)
Set Type.
applyTemplate(int $post_layout_template, int $number_of_cells, int $s, int $m, int $l, int $xl)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
savePositions(array $a_pos)
Save positions of grid cells.
const TEMPLATE_TWO_COLUMN
getJavascriptFiles(string $a_mode)
saveWidths(array $a_width_s, array $a_width_m, array $a_width_l, array $a_width_xl)
Save widths of cells.
const TEMPLATE_MAIN_SIDE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCssFiles(string $a_mode)
deleteGridCell(string $a_hier_id, string $a_pc_id)
Delete grid cell.
php4DomElement
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
init()
Init page content component.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
const TEMPLATE_THREE_COLUMN
static getLangVars()
Get lang vars needed for editing.
const IL_INSERT_AFTER
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
php4DOMElement $grid_node
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
addGridCell(int $a_s, int $a_m, int $a_l, int $a_xl)
Add grid cell.
setNode(php4DOMElement $a_node)
Set content node.
$i
Definition: metadata.php:41
static getSizes()
Get sizes.