ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
24 require_once("./Services/COPage/classes/class.ilPageContent.php");
25 
33 class ilPCGrid extends ilPageContent
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 
99  /*
100  protected function setTabsAttribute($a_attr, $a_value)
101  {
102  if (!empty($a_value))
103  {
104  $this->grid_node->set_attribute($a_attr, $a_value);
105  }
106  else
107  {
108  if ($this->grid_node->has_attribute($a_attr))
109  {
110  $this->grid_node->remove_attribute($a_attr);
111  }
112  }
113  }*/
114 
115 
121  public function savePositions($a_pos)
122  {
123  asort($a_pos);
124 
125  $childs = $this->grid_node->child_nodes();
126  $nodes = array();
127  for ($i = 0; $i < count($childs); $i++) {
128  if ($childs[$i]->node_name() == "GridCell") {
129  $pc_id = $childs[$i]->get_attribute("PCID");
130  $hier_id = $childs[$i]->get_attribute("HierId");
131  $nodes[$hier_id . ":" . $pc_id] = $childs[$i];
132  $childs[$i]->unlink($childs[$i]);
133  }
134  }
135 
136  foreach ($a_pos as $k => $v) {
137  if (is_object($nodes[$k])) {
138  $nodes[$k] = $this->grid_node->append_child($nodes[$k]);
139  }
140  }
141  }
142 
146  public function saveWidths($a_width_s, $a_width_m, $a_width_l, $a_width_xl)
147  {
148  $cell_nodes = $this->grid_node->child_nodes();
149  for ($i = 0; $i < count($cell_nodes); $i++) {
150  if ($cell_nodes[$i]->node_name() == "GridCell") {
151  $pc_id = $cell_nodes[$i]->get_attribute("PCID");
152  $hier_id = $cell_nodes[$i]->get_attribute("HierId");
153  $k = $hier_id . ":" . $pc_id;
154  $cell_nodes[$i]->set_attribute("WIDTH_XS", "");
155  $cell_nodes[$i]->set_attribute("WIDTH_S", $a_width_s[$k]);
156  $cell_nodes[$i]->set_attribute("WIDTH_M", $a_width_m[$k]);
157  $cell_nodes[$i]->set_attribute("WIDTH_L", $a_width_l[$k]);
158  $cell_nodes[$i]->set_attribute("WIDTH_XL", $a_width_xl[$k]);
159  }
160  }
161  }
162 
163 
167  public function deleteGridCell($a_hier_id, $a_pc_id)
168  {
169  $childs = $this->grid_node->child_nodes();
170  for ($i = 0; $i < count($childs); $i++) {
171  if ($childs[$i]->node_name() == "GridCell") {
172  if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
173  $a_hier_id == $childs[$i]->get_attribute("HierId")) {
174  $childs[$i]->unlink($childs[$i]);
175  }
176  }
177  }
178  }
179 
183  public function addGridCell($a_s, $a_m, $a_l, $a_xl)
184  {
185  $new_item = $this->dom->create_element("GridCell");
186  $new_item = $this->grid_node->append_child($new_item);
187  //$new_item->set_attribute("xs", $a_xs);
188  $new_item->set_attribute("WIDTH_XS", "");
189  $new_item->set_attribute("WIDTH_S", $a_s);
190  $new_item->set_attribute("WIDTH_M", $a_m);
191  $new_item->set_attribute("WIDTH_L", $a_l);
192  $new_item->set_attribute("WIDTH_XL", $a_xl);
193  }
194 
198  public function addCell()
199  {
200  $new_item = $this->dom->create_element("GridCell");
201  $new_item->set_attribute("WIDTH_XS", "");
202  $new_item->set_attribute("WIDTH_S", "");
203  $new_item->set_attribute("WIDTH_M", "");
204  $new_item->set_attribute("WIDTH_L", "");
205  $new_item->set_attribute("WIDTH_XL", "");
206  $this->grid_node->append_child($new_item);
207  }
208 
213  public static function getLangVars()
214  {
215  return array("pc_grid", "pc_grid_cell", "ed_delete_cell", "ed_cell_left", "ed_cell_right");
216  }
217 
221  public function getJavascriptFiles($a_mode)
222  {
223  return parent::getJavascriptFiles($a_mode);
224  }
225 
229  public function getCssFiles($a_mode)
230  {
231  return parent::getCssFiles($a_mode);
232  }
233 
234  public function getCellData()
235  {
236  $cells = array();
237  $cell_nodes = $this->grid_node->child_nodes();
238  $k = 0;
239  for ($i = 0; $i < count($cell_nodes); $i++) {
240  if ($cell_nodes[$i]->node_name() == "GridCell") {
241  $pc_id = $cell_nodes[$i]->get_attribute("PCID");
242  $hier_id = $cell_nodes[$i]->get_attribute("HierId");
243  $cells[] = array("pos" => $k,
244  "xs" => $cell_nodes[$i]->get_attribute("WIDTH_XS"),
245  "s" => $cell_nodes[$i]->get_attribute("WIDTH_S"),
246  "m" => $cell_nodes[$i]->get_attribute("WIDTH_M"),
247  "l" => $cell_nodes[$i]->get_attribute("WIDTH_L"),
248  "xl" => $cell_nodes[$i]->get_attribute("WIDTH_XL"),
249  "pc_id" => $pc_id, "hier_id" => $hier_id);
250  $k++;
251  }
252  }
253 
254  return $cells;
255  }
256 }
addCell()
Add a cell.
static getWidths()
Get widths.
saveWidths($a_width_s, $a_width_m, $a_width_l, $a_width_xl)
Save widths of cells.
Grid element.
addGridCell($a_s, $a_m, $a_l, $a_xl)
Add grid cell.
setNode($a_node)
Set content node.
savePositions($a_pos)
Set attribute of grid tag.
deleteGridCell($a_hier_id, $a_pc_id)
Delete grid cell.
setType($a_type)
Set Type.
Class ilPageContent.
create($a_pg_obj, $a_hier_id, $a_pc_id="")
Create new Grid node.
init()
Init page content component.
static getLangVars()
Get lang vars needed for editing.
const IL_INSERT_AFTER
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
getJavascriptFiles($a_mode)
Get Javascript files.
$i
Definition: disco.tpl.php:19
getCssFiles($a_mode)
Get Javascript files.
static getSizes()
Get sizes.