ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPCGrid.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24require_once("./Services/COPage/classes/class.ilPageContent.php");
25
34{
35 protected $grid_node;
36
40 public function init()
41 {
42 $this->setType("grid");
43 }
44
49 public function setNode($a_node)
50 {
51 parent::setNode($a_node); // this is the PageContent node
52 $this->grid_node = $a_node->first_child(); // this is the Tabs node
53 }
54
63 public static function getSizes()
64 {
65 return array("s" => "s", "m" => "m", "l" => "l", "xl" => "xl");
66 }
67
72 public static function getWidths()
73 {
74 return array(
75 "1" => "1/12", "2" => "2/12", "3" => "3/12",
76 "4" => "4/12", "5" => "5/12", "6" => "6/12",
77 "7" => "7/12", "8" => "8/12", "9" => "9/12",
78 "10" => "10/12", "11" => "11/12", "12" => "12/12"
79 );
80 }
81
85 public function create($a_pg_obj, $a_hier_id, $a_pc_id = "")
86 {
87 $this->node = $this->createPageContentNode();
88 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
89 $this->grid_node = $this->dom->create_element("Grid");
90 $this->grid_node = $this->node->append_child($this->grid_node);
91 }
92
101 public function applyTemplate(
102 int $post_layout_template,
103 int $number_of_cells,
104 $s,
105 $m,
106 $l,
107 $xl
108 ) {
109 switch ($post_layout_template) {
111 $this->addGridCell(12, 6, 6, 6);
112 $this->addGridCell(12, 6, 6, 6);
113 break;
114
116 $this->addGridCell(12, 4, 4, 4);
117 $this->addGridCell(12, 4, 4, 4);
118 $this->addGridCell(12, 4, 4, 4);
119 break;
120
122 $this->addGridCell(12, 6, 8, 9);
123 $this->addGridCell(12, 6, 4, 3);
124 break;
125
127 $this->addGridCell(12, 6, 6, 3);
128 $this->addGridCell(12, 6, 6, 3);
129 $this->addGridCell(12, 6, 6, 3);
130 $this->addGridCell(12, 6, 6, 3);
131 break;
132
133
135 for ($i = 0; $i < (int) $number_of_cells; $i++) {
136 $this->addGridCell($s, $m, $l, $xl);
137 }
138 break;
139 }
140 }
141
148 /*
149 protected function setTabsAttribute($a_attr, $a_value)
150 {
151 if (!empty($a_value))
152 {
153 $this->grid_node->set_attribute($a_attr, $a_value);
154 }
155 else
156 {
157 if ($this->grid_node->has_attribute($a_attr))
158 {
159 $this->grid_node->remove_attribute($a_attr);
160 }
161 }
162 }*/
163
164
170 public function savePositions($a_pos)
171 {
172 asort($a_pos);
173
174 $childs = $this->grid_node->child_nodes();
175 $nodes = array();
176 for ($i = 0; $i < count($childs); $i++) {
177 if ($childs[$i]->node_name() == "GridCell") {
178 $pc_id = $childs[$i]->get_attribute("PCID");
179 $hier_id = $childs[$i]->get_attribute("HierId");
180 $nodes[$hier_id . ":" . $pc_id] = $childs[$i];
181 $childs[$i]->unlink($childs[$i]);
182 }
183 }
184
185 foreach ($a_pos as $k => $v) {
186 if (is_object($nodes[$k])) {
187 $nodes[$k] = $this->grid_node->append_child($nodes[$k]);
188 }
189 }
190 }
191
195 public function saveWidths($a_width_s, $a_width_m, $a_width_l, $a_width_xl)
196 {
197 $cell_nodes = $this->grid_node->child_nodes();
198 for ($i = 0; $i < count($cell_nodes); $i++) {
199 if ($cell_nodes[$i]->node_name() == "GridCell") {
200 $pc_id = $cell_nodes[$i]->get_attribute("PCID");
201 $hier_id = $cell_nodes[$i]->get_attribute("HierId");
202 $k = $hier_id . ":" . $pc_id;
203 $cell_nodes[$i]->set_attribute("WIDTH_XS", "");
204 $cell_nodes[$i]->set_attribute("WIDTH_S", $a_width_s[$k]);
205 $cell_nodes[$i]->set_attribute("WIDTH_M", $a_width_m[$k]);
206 $cell_nodes[$i]->set_attribute("WIDTH_L", $a_width_l[$k]);
207 $cell_nodes[$i]->set_attribute("WIDTH_XL", $a_width_xl[$k]);
208 }
209 }
210 }
211
212
216 public function deleteGridCell($a_hier_id, $a_pc_id)
217 {
218 $childs = $this->grid_node->child_nodes();
219 for ($i = 0; $i < count($childs); $i++) {
220 if ($childs[$i]->node_name() == "GridCell") {
221 if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
222 $a_hier_id == $childs[$i]->get_attribute("HierId")) {
223 $childs[$i]->unlink($childs[$i]);
224 }
225 }
226 }
227 }
228
232 public function addGridCell($a_s, $a_m, $a_l, $a_xl)
233 {
234 $new_item = $this->dom->create_element("GridCell");
235 $new_item = $this->grid_node->append_child($new_item);
236 //$new_item->set_attribute("xs", $a_xs);
237 $new_item->set_attribute("WIDTH_XS", "");
238 $new_item->set_attribute("WIDTH_S", $a_s);
239 $new_item->set_attribute("WIDTH_M", $a_m);
240 $new_item->set_attribute("WIDTH_L", $a_l);
241 $new_item->set_attribute("WIDTH_XL", $a_xl);
242 }
243
247 public function addCell()
248 {
249 $new_item = $this->dom->create_element("GridCell");
250 $new_item->set_attribute("WIDTH_XS", "");
251 $new_item->set_attribute("WIDTH_S", "");
252 $new_item->set_attribute("WIDTH_M", "");
253 $new_item->set_attribute("WIDTH_L", "");
254 $new_item->set_attribute("WIDTH_XL", "");
255 $this->grid_node->append_child($new_item);
256 }
257
262 public static function getLangVars()
263 {
264 return array("pc_grid", "pc_grid_cell", "ed_delete_cell", "ed_cell_left", "ed_cell_right");
265 }
266
270 public function getJavascriptFiles($a_mode)
271 {
272 return parent::getJavascriptFiles($a_mode);
273 }
274
278 public function getCssFiles($a_mode)
279 {
280 return parent::getCssFiles($a_mode);
281 }
282
283 public function getCellData()
284 {
285 $cells = array();
286 $cell_nodes = $this->grid_node->child_nodes();
287 $k = 0;
288 for ($i = 0; $i < count($cell_nodes); $i++) {
289 if ($cell_nodes[$i]->node_name() == "GridCell") {
290 $pc_id = $cell_nodes[$i]->get_attribute("PCID");
291 $hier_id = $cell_nodes[$i]->get_attribute("HierId");
292 $cells[] = array("pos" => $k,
293 "xs" => $cell_nodes[$i]->get_attribute("WIDTH_XS"),
294 "s" => $cell_nodes[$i]->get_attribute("WIDTH_S"),
295 "m" => $cell_nodes[$i]->get_attribute("WIDTH_M"),
296 "l" => $cell_nodes[$i]->get_attribute("WIDTH_L"),
297 "xl" => $cell_nodes[$i]->get_attribute("WIDTH_XL"),
298 "pc_id" => $pc_id, "hier_id" => $hier_id);
299 $k++;
300 }
301 }
302
303 return $cells;
304 }
305}
An exception for terminatinating execution or to throw for unit testing.
const IL_INSERT_AFTER
const TEMPLATE_TWO_COLUMN
const TEMPLATE_TWO_BY_TWO
const TEMPLATE_THREE_COLUMN
const TEMPLATE_MAIN_SIDE
Grid element.
addGridCell($a_s, $a_m, $a_l, $a_xl)
Add grid cell.
init()
Init page content component.
getCssFiles($a_mode)
Get Javascript files.
applyTemplate(int $post_layout_template, int $number_of_cells, $s, $m, $l, $xl)
saveWidths($a_width_s, $a_width_m, $a_width_l, $a_width_xl)
Save widths of cells.
getJavascriptFiles($a_mode)
Get Javascript files.
create($a_pg_obj, $a_hier_id, $a_pc_id="")
Create new Grid node.
addCell()
Add a cell.
static getSizes()
Get sizes.
static getLangVars()
Get lang vars needed for editing.
savePositions($a_pos)
Set attribute of grid tag.
setNode($a_node)
Set content node.
deleteGridCell($a_hier_id, $a_pc_id)
Delete grid cell.
static getWidths()
Get widths.
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType($a_type)
Set Type.
$i
Definition: metadata.php:24