ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
38  public $tabs_node;
39  const ACCORDION_HOR = "HorizontalAccordion";
40  const ACCORDION_VER = "VerticalAccordion";
41  const CAROUSEL = "Carousel";
42 
46  public function init()
47  {
48  $this->setType("tabs");
49  }
50 
54  public 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  public 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  $this->tabs_node->set_attribute($a_attr, $a_value);
81  } else {
82  if ($this->tabs_node->has_attribute($a_attr)) {
83  $this->tabs_node->remove_attribute($a_attr);
84  }
85  }
86  }
87 
93  public function setTabType($a_type = "HorizontalTabs")
94  {
95  switch ($a_type) {
98  case ilPCTabs::CAROUSEL:
99  $this->tabs_node->set_attribute("Type", $a_type);
100  break;
101  }
102  }
103 
107  public function getTabType()
108  {
109  return $this->tabs_node->get_attribute("Type");
110  }
111 
117  public function setContentWidth($a_val)
118  {
119  $this->setTabsAttribute("ContentWidth", $a_val);
120  }
121 
127  public function getContentWidth()
128  {
129  return $this->tabs_node->get_attribute("ContentWidth");
130  }
131 
137  public function setContentHeight($a_val)
138  {
139  $this->setTabsAttribute("ContentHeight", $a_val);
140  }
141 
147  public function getContentHeight()
148  {
149  return $this->tabs_node->get_attribute("ContentHeight");
150  }
151 
157  public function setHorizontalAlign($a_val)
158  {
159  $this->setTabsAttribute("HorizontalAlign", $a_val);
160  }
161 
167  public function getHorizontalAlign()
168  {
169  return $this->tabs_node->get_attribute("HorizontalAlign");
170  }
171 
177  public function setBehavior($a_val)
178  {
179  $this->setTabsAttribute("Behavior", $a_val);
180  }
181 
187  public function getBehavior()
188  {
189  return $this->tabs_node->get_attribute("Behavior");
190  }
191 
195  public function getCaptions()
196  {
197  $captions = array();
198  $tab_nodes = $this->tabs_node->child_nodes();
199  $k = 0;
200  for ($i = 0; $i < count($tab_nodes); $i++) {
201  if ($tab_nodes[$i]->node_name() == "Tab") {
202  $pc_id = $tab_nodes[$i]->get_attribute("PCID");
203  $hier_id = $tab_nodes[$i]->get_attribute("HierId");
204 
205  $tab_node_childs = $tab_nodes[$i]->child_nodes();
206  $current_caption = "";
207  for ($j = 0; $j < count($tab_node_childs); $j++) {
208  if ($tab_node_childs[$j]->node_name() == "TabCaption") {
209  $current_caption = $tab_node_childs[$j]->get_content();
210  }
211  }
212  $captions[] = array("pos" => $k,
213  "caption" => $current_caption, "pc_id" => $pc_id, "hier_id" => $hier_id);
214  $k++;
215  }
216  }
217 
218  return $captions;
219  }
220 
224  public function getCaption($a_hier_id, $a_pc_id)
225  {
226  $captions = array();
227  $tab_nodes = $this->tabs_node->child_nodes();
228  $k = 0;
229  for ($i = 0; $i < count($tab_nodes); $i++) {
230  if ($tab_nodes[$i]->node_name() == "Tab") {
231  if ($a_pc_id == $tab_nodes[$i]->get_attribute("PCID") &&
232  ($a_hier_id == $tab_nodes[$i]->get_attribute("HierId"))) {
233  $tab_node_childs = $tab_nodes[$i]->child_nodes();
234  for ($j = 0; $j < count($tab_node_childs); $j++) {
235  if ($tab_node_childs[$j]->node_name() == "TabCaption") {
236  return $tab_node_childs[$j]->get_content();
237  }
238  }
239  }
240  }
241  }
242 
243  return "";
244  }
245 
249  public function savePositions($a_pos)
250  {
251  asort($a_pos);
252 
253  // File Item
254  $childs = $this->tabs_node->child_nodes();
255  $nodes = array();
256  for ($i = 0; $i < count($childs); $i++) {
257  if ($childs[$i]->node_name() == "Tab") {
258  $pc_id = $childs[$i]->get_attribute("PCID");
259  $hier_id = $childs[$i]->get_attribute("HierId");
260  $nodes[$hier_id . ":" . $pc_id] = $childs[$i];
261  $childs[$i]->unlink($childs[$i]);
262  }
263  }
264 
265  foreach ($a_pos as $k => $v) {
266  if (is_object($nodes[$k])) {
267  $nodes[$k] = $this->tabs_node->append_child($nodes[$k]);
268  }
269  }
270  }
271 
275  public function saveCaptions($a_captions)
276  {
277  // iterate all tab nodes
278  $tab_nodes = $this->tabs_node->child_nodes();
279  for ($i = 0; $i < count($tab_nodes); $i++) {
280  if ($tab_nodes[$i]->node_name() == "Tab") {
281  $pc_id = $tab_nodes[$i]->get_attribute("PCID");
282  $hier_id = $tab_nodes[$i]->get_attribute("HierId");
283  $k = $hier_id . ":" . $pc_id;
284  // if caption given, set it, otherwise delete caption subitem
285  if ($a_captions[$k] != "") {
287  $this->dom,
288  $tab_nodes[$i],
289  "TabCaption",
290  array(),
291  $a_captions[$k],
292  array()
293  );
294  } else {
295  ilDOMUtil::deleteAllChildsByName($tab_nodes[$i], array("TabCaption"));
296  }
297  }
298  }
299  }
300 
304  public function deleteTab($a_hier_id, $a_pc_id)
305  {
306  // File Item
307  $childs = $this->tabs_node->child_nodes();
308  $nodes = array();
309  for ($i = 0; $i < count($childs); $i++) {
310  if ($childs[$i]->node_name() == "Tab") {
311  if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
312  $a_hier_id == $childs[$i]->get_attribute("HierId")) {
313  $childs[$i]->unlink($childs[$i]);
314  }
315  }
316  }
317  }
318 
322  public function addTab($a_caption)
323  {
324  $new_item = $this->dom->create_element("Tab");
325  $new_item = $this->tabs_node->append_child($new_item);
327  $this->dom,
328  $new_item,
329  "TabCaption",
330  array(),
331  $a_caption,
332  array()
333  );
334  }
335 
341  public function setTemplate($a_template)
342  {
343  $this->setTabsAttribute("Template", $a_template);
344  }
345 
351  public function getTemplate()
352  {
353  return $this->tabs_node->get_attribute("Template");
354  }
355 
360  public static function getLangVars()
361  {
362  return array("pc_vacc", "pc_hacc", "pc_carousel");
363  }
364 
365 
371  public function setAutoTime($a_val)
372  {
373  $this->setTabsAttribute("AutoAnimWait", $a_val);
374  }
375 
381  public function getAutoTime()
382  {
383  return $this->tabs_node->get_attribute("AutoAnimWait");
384  }
385 
391  public function setRandomStart($a_val)
392  {
393  $this->setTabsAttribute("RandomStart", $a_val);
394  }
395 
401  public function getRandomStart()
402  {
403  return $this->tabs_node->get_attribute("RandomStart");
404  }
405 
409  public function getJavascriptFiles($a_mode)
410  {
411  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
413  }
414 
418  public function getCssFiles($a_mode)
419  {
420  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
422  }
423 }
getBehavior()
Get behavior.
setContentWidth($a_val)
Set content width.
getCaptions()
Get captions.
getContentWidth()
Get content width.
getContentHeight()
Get content height.
static getLangVars()
Get lang vars needed for editing.
setRandomStart($a_val)
Set random start.
init()
Init page content component.
setBehavior($a_val)
Set behavior.
static deleteAllChildsByName($a_parent, $a_node_names)
delete all childs of a node by names in $a_node_names
setType($a_type)
Set Type.
getTemplate()
Get template.
setTemplate($a_template)
Set template.
getCaption($a_hier_id, $a_pc_id)
Get caption.
Class ilPageContent.
static getLocalJavascriptFiles()
const ACCORDION_HOR
$a_type
Definition: workflow.php:92
getCssFiles($a_mode)
Get Javascript files.
savePositions($a_pos)
Save positions of tabs.
setHorizontalAlign($a_val)
Set horizontal align.
setContentHeight($a_val)
Set content height.
addTab($a_caption)
Add a tab.
getTabType()
Get type of tabs.
setTabsAttribute($a_attr, $a_value)
Set attribute of tabs tag.
const ACCORDION_VER
setAutoTime($a_val)
Set auto animation waiting time.
setNode($a_node)
Set content node.
const IL_INSERT_AFTER
getAutoTime()
Get auto animation waiting time.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
getHorizontalAlign()
Get horizontal align.
const CAROUSEL
$i
Definition: disco.tpl.php:19
saveCaptions($a_captions)
Add Tab items.
getJavascriptFiles($a_mode)
Get Javascript files.
static 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.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create new Tabs node.
deleteTab($a_hier_id, $a_pc_id)
Save positions of tabs.
setTabType($a_type="HorizontalTabs")
Set type of tabs.
getRandomStart()
Get random start.