ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCGrid.php
Go to the documentation of this file.
1<?php
2
25{
29 public function init(): void
30 {
31 $this->setType("grid");
32 }
33
40 public static function getSizes(): array
41 {
42 return array("s" => "s", "m" => "m", "l" => "l", "xl" => "xl");
43 }
44
48 public static function getWidths(): array
49 {
50 return array(
51 "1" => "1/12", "2" => "2/12", "3" => "3/12",
52 "4" => "4/12", "5" => "5/12", "6" => "6/12",
53 "7" => "7/12", "8" => "8/12", "9" => "9/12",
54 "10" => "10/12", "11" => "11/12", "12" => "12/12"
55 );
56 }
57
58 public function create(
59 ilPageObject $a_pg_obj,
60 string $a_hier_id,
61 string $a_pc_id = ""
62 ): void {
63 $this->createInitialChildNode($a_hier_id, $a_pc_id, "Grid");
64 }
65
66 public function applyTemplate(
67 int $post_layout_template,
68 int $number_of_cells,
69 int $s,
70 int $m,
71 int $l,
72 int $xl
73 ): void {
74 switch ($post_layout_template) {
76 $this->addGridCell(12, 6, 6, 6);
77 $this->addGridCell(12, 6, 6, 6);
78 break;
79
81 $this->addGridCell(12, 4, 4, 4);
82 $this->addGridCell(12, 4, 4, 4);
83 $this->addGridCell(12, 4, 4, 4);
84 break;
85
87 $this->addGridCell(12, 6, 8, 9);
88 $this->addGridCell(12, 6, 4, 3);
89 break;
90
92 $this->addGridCell(12, 6, 6, 3);
93 $this->addGridCell(12, 6, 6, 3);
94 $this->addGridCell(12, 6, 6, 3);
95 $this->addGridCell(12, 6, 6, 3);
96 break;
97
98
100 for ($i = 0; $i < $number_of_cells; $i++) {
101 $this->addGridCell($s, $m, $l, $xl);
102 }
103 break;
104 }
105 }
106
110 public function savePositions(array $a_pos): void
111 {
112 asort($a_pos);
113
114 $nodes = array();
115 foreach ($this->getChildNode()->childNodes as $c) {
116 if ($c->nodeName === "GridCell") {
117 $pc_id = $c->getAttribute("PCID");
118 $hier_id = $c->getAttribute("HierId");
119 $nodes[$hier_id . ":" . $pc_id] = $c;
120 }
121 }
122 $this->dom_util->deleteAllChildsByName($this->getChildNode(), ["GridCell"]);
123
124 foreach ($a_pos as $k => $v) {
125 if (is_object($nodes[$k])) {
126 $nodes[$k] = $this->getChildNode()->appendChild($nodes[$k]);
127 }
128 }
129 }
130
134 public function saveWidths(
135 array $a_width_s,
136 array $a_width_m,
137 array $a_width_l,
138 array $a_width_xl
139 ): void {
140 foreach ($this->getChildNode()->childNodes as $c) {
141 if ($c->nodeName === "GridCell") {
142 $pc_id = $c->getAttribute("PCID");
143 $hier_id = $c->getAttribute("HierId");
144 $k = $hier_id . ":" . $pc_id;
145 $c->setAttribute("WIDTH_XS", "");
146 $c->setAttribute("WIDTH_S", $a_width_s[$k]);
147 $c->setAttribute("WIDTH_M", $a_width_m[$k]);
148 $c->setAttribute("WIDTH_L", $a_width_l[$k]);
149 $c->setAttribute("WIDTH_XL", $a_width_xl[$k]);
150 }
151 }
152 }
153
154
158 public function deleteGridCell(
159 string $a_hier_id,
160 string $a_pc_id
161 ): void {
162 foreach ($this->getChildNode()->childNodes as $c) {
163 if ($c->nodeName === "GridCell") {
164 if ($a_pc_id === $c->getAttribute("PCID") &&
165 $a_hier_id === $c->getAttribute("HierId")) {
166 $c->parentNode->removeChild($c);
167 }
168 }
169 }
170 }
171
175 public function addGridCell(
176 int $a_s,
177 int $a_m,
178 int $a_l,
179 int $a_xl
180 ): void {
181 $new_item = $this->dom_doc->createElement("GridCell");
182 $new_item = $this->getChildNode()->appendChild($new_item);
183 $new_item->setAttribute("WIDTH_XS", "");
184 $new_item->setAttribute("WIDTH_S", $a_s);
185 $new_item->setAttribute("WIDTH_M", $a_m);
186 $new_item->setAttribute("WIDTH_L", $a_l);
187 $new_item->setAttribute("WIDTH_XL", $a_xl);
188 }
189
193 public function addCell(): void
194 {
195 $new_item = $this->dom_doc->createElement("GridCell");
196 $new_item->setAttribute("WIDTH_XS", "");
197 $new_item->setAttribute("WIDTH_S", "");
198 $new_item->setAttribute("WIDTH_M", "");
199 $new_item->setAttribute("WIDTH_L", "");
200 $new_item->setAttribute("WIDTH_XL", "");
201 $this->getChildNode()->appendChild($new_item);
202 }
203
208 public static function getLangVars(): array
209 {
210 return array("pc_grid", "pc_grid_cell", "ed_delete_cell", "ed_cell_left", "ed_cell_right");
211 }
212
213 public function getJavascriptFiles(string $a_mode): array
214 {
215 return parent::getJavascriptFiles($a_mode);
216 }
217
218 public function getCssFiles(string $a_mode): array
219 {
220 return parent::getCssFiles($a_mode);
221 }
222
223 public function getCellData(): array
224 {
225 $cells = array();
226 $k = 0;
227 foreach ($this->getChildNode()->childNodes as $c) {
228 if ($c->nodeName === "GridCell") {
229 $pc_id = $c->getAttribute("PCID");
230 $hier_id = $c->getAttribute("HierId");
231 $cells[] = array("pos" => $k,
232 "xs" => $c->getAttribute("WIDTH_XS"),
233 "s" => $c->getAttribute("WIDTH_S"),
234 "m" => $c->getAttribute("WIDTH_M"),
235 "l" => $c->getAttribute("WIDTH_L"),
236 "xl" => $c->getAttribute("WIDTH_XL"),
237 "pc_id" => $pc_id, "hier_id" => $hier_id);
238 $k++;
239 }
240 }
241
242 return $cells;
243 }
244}
const TEMPLATE_TWO_COLUMN
const TEMPLATE_TWO_BY_TWO
const TEMPLATE_THREE_COLUMN
const TEMPLATE_MAIN_SIDE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveWidths(array $a_width_s, array $a_width_m, array $a_width_l, array $a_width_xl)
Save widths of cells.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
init()
Init page content component.
savePositions(array $a_pos)
Save positions of grid cells.
getJavascriptFiles(string $a_mode)
applyTemplate(int $post_layout_template, int $number_of_cells, int $s, int $m, int $l, int $xl)
deleteGridCell(string $a_hier_id, string $a_pc_id)
Delete grid cell.
addCell()
Add a cell.
static getSizes()
Get sizes.
static getLangVars()
Get lang vars needed for editing.
addGridCell(int $a_s, int $a_m, int $a_l, int $a_xl)
Add grid cell.
getCssFiles(string $a_mode)
static getWidths()
Get widths.
Content object of ilPageObject (see ILIAS DTD).
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
$c
Definition: deliver.php:25