ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
24 require_once("./Services/COPage/classes/class.ilPageContent.php");
25 
36 class ilPCTabs extends ilPageContent
37 {
39 
43  function init()
44  {
45  $this->setType("tabs");
46  }
47 
51  function setNode(&$a_node)
52  {
53  parent::setNode($a_node); // this is the PageContent node
54  $this->tabs_node =& $a_node->first_child(); // this is the Tabs node
55  }
56 
60  function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
61  {
62  $this->node = $this->createPageContentNode();
63  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
64  $this->tabs_node =& $this->dom->create_element("Tabs");
65  $this->tabs_node =& $this->node->append_child($this->tabs_node);
66  }
67 
71  function addItems($a_nr)
72  {
73  for ($i=1; $i<=$a_nr; $i++)
74  {
75  $new_item =& $this->dom->create_element("Tab");
76  $new_item =& $this->tabs_node->append_child($new_item);
77  }
78  }
79 
85  function setTabType($a_type = "HorizontalTabs")
86  {
87  switch ($a_type)
88  {
89  case "HorizontalTabs":
90  case "Accordion":
91  $this->tabs_node->set_attribute("Type", $a_type);
92  break;
93  }
94  }
95 
99  function getTabType()
100  {
101  return $this->tabs_node->get_attribute("Type");
102  }
103 
107  function setCaptions($a_captions)
108  {
109  // iterate all tab nodes
110  $j = 0;
111  $tab_nodes = $this->tabs_node->child_nodes();
112  for($i = 0; $i < count($tab_nodes); $i++)
113  {
114  if ($tab_nodes[$i]->node_name() == "Tab")
115  {
116  // if caption given, set it, otherwise delete caption subitem
117  if ($a_captions[$j] != "")
118  {
119  ilDOMUtil::setFirstOptionalElement($this->dom, $tab_nodes[$i], "TabCaption",
120  array("PageContent"), $a_captions[$j], array());
121  }
122  else
123  {
124  ilDOMUtil::deleteAllChildsByName($tab_nodes[$i], array("TabCaption"));
125  }
126  $j++;
127  }
128  }
129  }
130 
134  function getCaptions()
135  {
136  $captions = array();
137  $tab_nodes = $this->tabs_node->child_nodes();
138  for($i = 0; $i < count($tab_nodes); $i++)
139  {
140  if ($tab_nodes[$i]->node_name() == "Tab")
141  {
142  $tab_node_childs = $tab_nodes[$i]->child_nodes();
143  $current_caption = "";
144  for($j = 0; $j < count($tab_node_childs); $j++)
145  {
146  if ($tab_node_childs[$j]->node_name() == "TabCaption")
147  {
148  $current_caption = $tab_node_childs[$j]->get_content();
149  }
150  }
151  $captions[] = $current_caption;
152  }
153  }
154 
155  return $captions;
156  }
157 
158 }
159 ?>