ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 const CAROUSEL = "Carousel";
42
46 function init()
47 {
48 $this->setType("tabs");
49 }
50
54 function setNode(&$a_node)
55 {
56 parent::setNode($a_node); // this is the PageContent node
57 $this->tabs_node =& $a_node->first_child(); // this is the Tabs node
58 }
59
63 function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
64 {
65 $this->node = $this->createPageContentNode();
66 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
67 $this->tabs_node =& $this->dom->create_element("Tabs");
68 $this->tabs_node =& $this->node->append_child($this->tabs_node);
69 }
70
77 protected function setTabsAttribute($a_attr, $a_value)
78 {
79 if (!empty($a_value))
80 {
81 $this->tabs_node->set_attribute($a_attr, $a_value);
82 }
83 else
84 {
85 if ($this->tabs_node->has_attribute($a_attr))
86 {
87 $this->tabs_node->remove_attribute($a_attr);
88 }
89 }
90 }
91
97 function setTabType($a_type = "HorizontalTabs")
98 {
99 switch ($a_type)
100 {
104 $this->tabs_node->set_attribute("Type", $a_type);
105 break;
106 }
107 }
108
112 function getTabType()
113 {
114 return $this->tabs_node->get_attribute("Type");
115 }
116
122 function setContentWidth($a_val)
123 {
124 $this->setTabsAttribute("ContentWidth", $a_val);
125 }
126
133 {
134 return $this->tabs_node->get_attribute("ContentWidth");
135 }
136
142 function setContentHeight($a_val)
143 {
144 $this->setTabsAttribute("ContentHeight", $a_val);
145 }
146
153 {
154 return $this->tabs_node->get_attribute("ContentHeight");
155 }
156
162 function setHorizontalAlign($a_val)
163 {
164 $this->setTabsAttribute("HorizontalAlign", $a_val);
165 }
166
173 {
174 return $this->tabs_node->get_attribute("HorizontalAlign");
175 }
176
182 function setBehavior($a_val)
183 {
184 $this->setTabsAttribute("Behavior", $a_val);
185 }
186
192 function getBehavior()
193 {
194 return $this->tabs_node->get_attribute("Behavior");
195 }
196
200 function getCaptions()
201 {
202 $captions = array();
203 $tab_nodes = $this->tabs_node->child_nodes();
204 $k = 0;
205 for($i = 0; $i < count($tab_nodes); $i++)
206 {
207 if ($tab_nodes[$i]->node_name() == "Tab")
208 {
209 $pc_id = $tab_nodes[$i]->get_attribute("PCID");
210 $hier_id = $tab_nodes[$i]->get_attribute("HierId");
211
212 $tab_node_childs = $tab_nodes[$i]->child_nodes();
213 $current_caption = "";
214 for($j = 0; $j < count($tab_node_childs); $j++)
215 {
216 if ($tab_node_childs[$j]->node_name() == "TabCaption")
217 {
218 $current_caption = $tab_node_childs[$j]->get_content();
219 }
220 }
221 $captions[] = array("pos" => $k,
222 "caption" => $current_caption, "pc_id" => $pc_id, "hier_id" => $hier_id);
223 $k++;
224 }
225 }
226
227 return $captions;
228 }
229
233 function getCaption($a_hier_id, $a_pc_id)
234 {
235 $captions = array();
236 $tab_nodes = $this->tabs_node->child_nodes();
237 $k = 0;
238 for($i = 0; $i < count($tab_nodes); $i++)
239 {
240 if ($tab_nodes[$i]->node_name() == "Tab")
241 {
242 if ($a_pc_id == $tab_nodes[$i]->get_attribute("PCID") &&
243 ($a_hier_id == $tab_nodes[$i]->get_attribute("HierId")))
244 {
245 $tab_node_childs = $tab_nodes[$i]->child_nodes();
246 for($j = 0; $j < count($tab_node_childs); $j++)
247 {
248 if ($tab_node_childs[$j]->node_name() == "TabCaption")
249 {
250 return $tab_node_childs[$j]->get_content();
251 }
252 }
253 }
254 }
255 }
256
257 return "";
258 }
259
263 function savePositions($a_pos)
264 {
265 asort($a_pos);
266
267 // File Item
268 $childs = $this->tabs_node->child_nodes();
269 $nodes = array();
270 for ($i=0; $i<count($childs); $i++)
271 {
272 if ($childs[$i]->node_name() == "Tab")
273 {
274 $pc_id = $childs[$i]->get_attribute("PCID");
275 $hier_id = $childs[$i]->get_attribute("HierId");
276 $nodes[$hier_id.":".$pc_id] = $childs[$i];
277 $childs[$i]->unlink($childs[$i]);
278 }
279 }
280
281 foreach($a_pos as $k => $v)
282 {
283 if (is_object($nodes[$k]))
284 {
285 $nodes[$k] = $this->tabs_node->append_child($nodes[$k]);
286 }
287 }
288 }
289
293 function saveCaptions($a_captions)
294 {
295 // iterate all tab nodes
296 $tab_nodes = $this->tabs_node->child_nodes();
297 for($i = 0; $i < count($tab_nodes); $i++)
298 {
299 if ($tab_nodes[$i]->node_name() == "Tab")
300 {
301 $pc_id = $tab_nodes[$i]->get_attribute("PCID");
302 $hier_id = $tab_nodes[$i]->get_attribute("HierId");
303 $k = $hier_id.":".$pc_id;
304 // if caption given, set it, otherwise delete caption subitem
305 if ($a_captions[$k] != "")
306 {
307 ilDOMUtil::setFirstOptionalElement($this->dom, $tab_nodes[$i], "TabCaption",
308 array(), $a_captions[$k], array());
309 }
310 else
311 {
312 ilDOMUtil::deleteAllChildsByName($tab_nodes[$i], array("TabCaption"));
313 }
314 }
315 }
316 }
317
321 function deleteTab($a_hier_id, $a_pc_id)
322 {
323 // File Item
324 $childs = $this->tabs_node->child_nodes();
325 $nodes = array();
326 for ($i=0; $i<count($childs); $i++)
327 {
328 if ($childs[$i]->node_name() == "Tab")
329 {
330 if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
331 $a_hier_id == $childs[$i]->get_attribute("HierId"))
332 {
333 $childs[$i]->unlink($childs[$i]);
334 }
335 }
336 }
337 }
338
342 function addTab($a_caption)
343 {
344 $new_item = $this->dom->create_element("Tab");
345 $new_item = $this->tabs_node->append_child($new_item);
346 ilDOMUtil::setFirstOptionalElement($this->dom, $new_item, "TabCaption",
347 array(), $a_caption, array());
348 }
349
355 function setTemplate($a_template)
356 {
357 $this->setTabsAttribute("Template", $a_template);
358 }
359
365 function getTemplate()
366 {
367 return $this->tabs_node->get_attribute("Template");
368 }
369
374 static function getLangVars()
375 {
376 return array("pc_vacc", "pc_hacc", "pc_carousel");
377 }
378
379
385 function setAutoTime($a_val)
386 {
387 $this->setTabsAttribute("AutoAnimWait", $a_val);
388 }
389
395 function getAutoTime()
396 {
397 return $this->tabs_node->get_attribute("AutoAnimWait");
398 }
399
405 function setRandomStart($a_val)
406 {
407 $this->setTabsAttribute("RandomStart", $a_val);
408 }
409
415 function getRandomStart()
416 {
417 return $this->tabs_node->get_attribute("RandomStart");
418 }
419
423 function getJavascriptFiles($a_mode)
424 {
425 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
427 }
428
432 function getCssFiles($a_mode)
433 {
434 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
436 }
437
438}
439?>
const IL_INSERT_AFTER
static getLocalJavascriptFiles()
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.
const CAROUSEL
getTemplate()
Get template.
savePositions($a_pos)
Save positions of tabs.
const ACCORDION_HOR
getContentHeight()
Get content height.
saveCaptions($a_captions)
Add Tab items.
getAutoTime()
Get auto animation waiting time.
const ACCORDION_VER
getBehavior()
Get behavior.
getContentWidth()
Get content width.
static getLangVars()
Get lang vars needed for editing.
setAutoTime($a_val)
Set auto animation waiting time.
getTabType()
Get type of tabs.
getJavascriptFiles($a_mode)
Get Javascript files.
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.
getCssFiles($a_mode)
Get Javascript files.
getRandomStart()
Get random start.
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.
setRandomStart($a_val)
Set random start.
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.