ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilPCTabs.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
37{
39 const ACCORDION_HOR = "HorizontalAccordion";
40 const ACCORDION_VER = "VerticalAccordion";
41
45 function init()
46 {
47 $this->setType("tabs");
48 }
49
53 function setNode(&$a_node)
54 {
55 parent::setNode($a_node); // this is the PageContent node
56 $this->tabs_node =& $a_node->first_child(); // this is the Tabs node
57 }
58
62 function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
63 {
64 $this->node = $this->createPageContentNode();
65 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
66 $this->tabs_node =& $this->dom->create_element("Tabs");
67 $this->tabs_node =& $this->node->append_child($this->tabs_node);
68 }
69
76 protected function setTabsAttribute($a_attr, $a_value)
77 {
78 if (!empty($a_value))
79 {
80 $this->tabs_node->set_attribute($a_attr, $a_value);
81 }
82 else
83 {
84 if ($this->tabs_node->has_attribute($a_attr))
85 {
86 $this->tabs_node->remove_attribute($a_attr);
87 }
88 }
89 }
90
96 function setTabType($a_type = "HorizontalTabs")
97 {
98 switch ($a_type)
99 {
102 $this->tabs_node->set_attribute("Type", $a_type);
103 break;
104 }
105 }
106
110 function getTabType()
111 {
112 return $this->tabs_node->get_attribute("Type");
113 }
114
120 function setContentWidth($a_val)
121 {
122 $this->setTabsAttribute("ContentWidth", $a_val);
123 }
124
131 {
132 return $this->tabs_node->get_attribute("ContentWidth");
133 }
134
140 function setContentHeight($a_val)
141 {
142 $this->setTabsAttribute("ContentHeight", $a_val);
143 }
144
151 {
152 return $this->tabs_node->get_attribute("ContentHeight");
153 }
154
160 function setHorizontalAlign($a_val)
161 {
162 $this->setTabsAttribute("HorizontalAlign", $a_val);
163 }
164
171 {
172 return $this->tabs_node->get_attribute("HorizontalAlign");
173 }
174
180 function setBehavior($a_val)
181 {
182 $this->setTabsAttribute("Behavior", $a_val);
183 }
184
190 function getBehavior()
191 {
192 return $this->tabs_node->get_attribute("Behavior");
193 }
194
198 function getCaptions()
199 {
200 $captions = array();
201 $tab_nodes = $this->tabs_node->child_nodes();
202 $k = 0;
203 for($i = 0; $i < count($tab_nodes); $i++)
204 {
205 if ($tab_nodes[$i]->node_name() == "Tab")
206 {
207 $pc_id = $tab_nodes[$i]->get_attribute("PCID");
208 $hier_id = $tab_nodes[$i]->get_attribute("HierId");
209
210 $tab_node_childs = $tab_nodes[$i]->child_nodes();
211 $current_caption = "";
212 for($j = 0; $j < count($tab_node_childs); $j++)
213 {
214 if ($tab_node_childs[$j]->node_name() == "TabCaption")
215 {
216 $current_caption = $tab_node_childs[$j]->get_content();
217 }
218 }
219 $captions[] = array("pos" => $k,
220 "caption" => $current_caption, "pc_id" => $pc_id, "hier_id" => $hier_id);
221 $k++;
222 }
223 }
224
225 return $captions;
226 }
227
231 function getCaption($a_hier_id, $a_pc_id)
232 {
233 $captions = array();
234 $tab_nodes = $this->tabs_node->child_nodes();
235 $k = 0;
236 for($i = 0; $i < count($tab_nodes); $i++)
237 {
238 if ($tab_nodes[$i]->node_name() == "Tab")
239 {
240 if ($a_pc_id == $tab_nodes[$i]->get_attribute("PCID") &&
241 ($a_hier_id == $tab_nodes[$i]->get_attribute("HierId")))
242 {
243 $tab_node_childs = $tab_nodes[$i]->child_nodes();
244 for($j = 0; $j < count($tab_node_childs); $j++)
245 {
246 if ($tab_node_childs[$j]->node_name() == "TabCaption")
247 {
248 return $tab_node_childs[$j]->get_content();
249 }
250 }
251 }
252 }
253 }
254
255 return "";
256 }
257
261 function savePositions($a_pos)
262 {
263 asort($a_pos);
264
265 // File Item
266 $childs = $this->tabs_node->child_nodes();
267 $nodes = array();
268 for ($i=0; $i<count($childs); $i++)
269 {
270 if ($childs[$i]->node_name() == "Tab")
271 {
272 $pc_id = $childs[$i]->get_attribute("PCID");
273 $hier_id = $childs[$i]->get_attribute("HierId");
274 $nodes[$hier_id.":".$pc_id] = $childs[$i];
275 $childs[$i]->unlink($childs[$i]);
276 }
277 }
278
279 foreach($a_pos as $k => $v)
280 {
281 if (is_object($nodes[$k]))
282 {
283 $nodes[$k] = $this->tabs_node->append_child($nodes[$k]);
284 }
285 }
286 }
287
291 function saveCaptions($a_captions)
292 {
293 // iterate all tab nodes
294 $tab_nodes = $this->tabs_node->child_nodes();
295 for($i = 0; $i < count($tab_nodes); $i++)
296 {
297 if ($tab_nodes[$i]->node_name() == "Tab")
298 {
299 $pc_id = $tab_nodes[$i]->get_attribute("PCID");
300 $hier_id = $tab_nodes[$i]->get_attribute("HierId");
301 $k = $hier_id.":".$pc_id;
302 // if caption given, set it, otherwise delete caption subitem
303 if ($a_captions[$k] != "")
304 {
305 ilDOMUtil::setFirstOptionalElement($this->dom, $tab_nodes[$i], "TabCaption",
306 array(), $a_captions[$k], array());
307 }
308 else
309 {
310 ilDOMUtil::deleteAllChildsByName($tab_nodes[$i], array("TabCaption"));
311 }
312 }
313 }
314 }
315
319 function deleteTab($a_hier_id, $a_pc_id)
320 {
321 // File Item
322 $childs = $this->tabs_node->child_nodes();
323 $nodes = array();
324 for ($i=0; $i<count($childs); $i++)
325 {
326 if ($childs[$i]->node_name() == "Tab")
327 {
328 if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
329 $a_hier_id == $childs[$i]->get_attribute("HierId"))
330 {
331 $childs[$i]->unlink($childs[$i]);
332 }
333 }
334 }
335 }
336
340 function addTab($a_caption)
341 {
342 $new_item = $this->dom->create_element("Tab");
343 $new_item = $this->tabs_node->append_child($new_item);
344 ilDOMUtil::setFirstOptionalElement($this->dom, $new_item, "TabCaption",
345 array(), $a_caption, array());
346 }
347
353 function setTemplate($a_template)
354 {
355 $this->setTabsAttribute("Template", $a_template);
356 }
357
363 function getTemplate()
364 {
365 return $this->tabs_node->get_attribute("Template");
366 }
367
372 static function getLangVars()
373 {
374 return array("pc_vacc", "pc_hacc");
375 }
376
377}
378?>
const IL_INSERT_AFTER
deleteAllChildsByName(&$a_parent, $a_node_names)
delete all childs of a node by names in $a_node_names
setFirstOptionalElement(&$doc, &$parent_node, $a_node_name, $a_successors, $a_content, $a_attributes, $a_remove_childs=true)
searches for an element $a_node_name within the childs of $parent_node if no node is found,...
Class ilPCTabs.
deleteTab($a_hier_id, $a_pc_id)
Save positions of tabs.
getTemplate()
Get template.
savePositions($a_pos)
Save positions of tabs.
const ACCORDION_HOR
getContentHeight()
Get content height.
saveCaptions($a_captions)
Add Tab items.
const ACCORDION_VER
getBehavior()
Get behavior.
getContentWidth()
Get content width.
static getLangVars()
Get lang vars needed for editing.
getTabType()
Get type of tabs.
setBehavior($a_val)
Set behavior.
init()
Init page content component.
setTabType($a_type="HorizontalTabs")
Set type of tabs.
getHorizontalAlign()
Get horizontal align.
getCaptions()
Get captions.
setTemplate($a_template)
Set template.
setContentWidth($a_val)
Set content width.
getCaption($a_hier_id, $a_pc_id)
Get caption.
setHorizontalAlign($a_val)
Set horizontal align.
setNode(&$a_node)
Set content node.
setContentHeight($a_val)
Set content height.
setTabsAttribute($a_attr, $a_value)
Set attribute of tabs tag.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create new Tabs node.
addTab($a_caption)
Add a tab.
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.