ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAccordionGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
12 {
13  protected $items = array();
14  protected static $accordion_cnt = 0;
15  const VERTICAL = "vertical";
16  const HORIZONTAL = "horizontal";
17  const FORCE_ALL_OPEN = "ForceAllOpen";
18  const FIRST_OPEN = "FirstOpen";
19  const ONE_OPEN_SESSION = "OneOpenSession";
20 
24  function __construct()
25  {
27  }
28 
34  function setId($a_val)
35  {
36  $this->id = $a_val;
37  }
38 
44  function getId()
45  {
46  return $this->id;
47  }
48 
54  function setOrientation($a_orientation)
55  {
56  if (in_array($a_orientation,
58  {
59  $this->orientation = $a_orientation;
60  }
61  }
62 
68  function getOrientation()
69  {
70  return $this->orientation;
71  }
72 
78  function setContainerClass($a_containerclass)
79  {
80  $this->containerclass = $a_containerclass;
81  }
82 
88  function getContainerClass()
89  {
90  return $this->containerclass;
91  }
92 
98  function setInnerContainerClass($a_containerclass)
99  {
100  $this->icontainerclass = $a_containerclass;
101  }
102 
109  {
110  return $this->icontainerclass;
111  }
112 
118  function setHeaderClass($a_headerclass)
119  {
120  $this->headerclass = $a_headerclass;
121  }
122 
128  function getHeaderClass()
129  {
130  return $this->headerclass;
131  }
132 
138  function setActiveHeaderClass($a_h_class)
139  {
140  $this->active_headerclass = $a_h_class;
141  }
142 
149  {
150  return $this->active_headerclass;
151  }
152 
158  function setContentClass($a_contentclass)
159  {
160  $this->contentclass = $a_contentclass;
161  }
162 
168  function getContentClass()
169  {
170  return $this->contentclass;
171  }
172 
178  function setContentWidth($a_contentwidth)
179  {
180  $this->contentwidth = $a_contentwidth;
181  }
182 
188  function getContentWidth()
189  {
190  return $this->contentwidth;
191  }
192 
198  function setContentHeight($a_contentheight)
199  {
200  $this->contentheight = $a_contentheight;
201  }
202 
208  function getContentHeight()
209  {
210  return $this->contentheight;
211  }
212 
218  function setBehaviour($a_val)
219  {
220  $this->behaviour = $a_val;
221  }
222 
228  function getBehaviour()
229  {
230  return $this->behaviour;
231  }
232 
236  static function addJavaScript()
237  {
238  global $tpl;
239 
240  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
245  $tpl->addJavaScript("./Services/Accordion/js/accordion.js", true, 3);
246  }
247 
251  static function addCss()
252  {
253  global $tpl;
254 
255  $tpl->addCss("./Services/Accordion/css/accordion.css");
256  }
257 
261  function addItem($a_header, $a_content)
262  {
263  $this->items[] = array("header" => $a_header,
264  "content" => $a_content);
265  }
266 
270  function getItems()
271  {
272  return $this->items;
273  }
274 
278  function getHTML()
279  {
280  global $ilUser;
281 
282  self::$accordion_cnt++;
283 
284  $or_short = ($this->getOrientation() == ilAccordionGUI::HORIZONTAL)
285  ? "H"
286  : "V";
287 
288  $width = (int) $this->getContentWidth();
289  $height = (int) $this->getContentHeight();
291  {
292  if ($width == 0)
293  {
294  $width = 200;
295  }
296  if ($height == 0)
297  {
298  $height = 100;
299  }
300  }
301 
302  $this->addJavascript();
303  $this->addCss();
304 
305  $tpl = new ilTemplate("tpl.accordion.html", true, true, "Services/Accordion");
306  foreach ($this->getItems() as $item)
307  {
308  $tpl->setCurrentBlock("item");
309  $tpl->setVariable("HEADER", $item["header"]);
310  $tpl->setVariable("CONTENT", $item["content"]);
311  $tpl->setVariable("HEADER_CLASS", $this->getHeaderClass()
312  ? $this->getHeaderClass() : "il_".$or_short."AccordionHead");
313  $tpl->setVariable("CONTENT_CLASS", $this->getContentClass()
314  ? $this->getContentClass() : "il_".$or_short."AccordionContent");
315  $tpl->setVariable("OR_SHORT", $or_short);
316 
317  $tpl->setVariable("INNER_CONTAINER_CLASS", $this->getInnerContainerClass()
318  ? $this->getInnerContainerClass() : "il_".$or_short."AccordionInnerContainer");
319 
320 
321  if ($height > 0)
322  {
323  $tpl->setVariable("HEIGHT", "height:".$height."px;");
324  }
325  if ($height > 0 && $this->getOrientation() == ilAccordionGUI::HORIZONTAL)
326  {
327  $tpl->setVariable("HHEIGHT", "height:".$height."px;");
328  }
329  $tpl->parseCurrentBlock();
330  }
331 
332  $tpl->setVariable("CNT", self::$accordion_cnt);
333  $tpl->setVariable("CONTAINER_CLASS", $this->getContainerClass()
334  ? $this->getContainerClass() : "il_".$or_short."AccordionContainer");
335  $tpl->setVariable("ORIENTATION", $this->getOrientation());
336  $tpl->setVariable("ID", $this->getId());
337  if ($this->getBehaviour() == "OneOpenSession" && $this->getId() != "")
338  {
339  include_once("./Services/Accordion/classes/class.ilAccordionPropertiesStorage.php");
340  $stor = new ilAccordionPropertiesStorage();
341  $ctab = $stor->getProperty($this->getId(), $ilUser->getId(),
342  "opened");
343  $tpl->setVariable("BEHAVIOUR", $ctab);
344  $tpl->setVariable("SAVE_URL", "./ilias.php?baseClass=ilaccordionpropertiesstorage&cmd=setOpenedTab".
345  "&accordion_id=".$this->getId()."&user_id=".$ilUser->getId());
346  }
347  else if ($this->getBehaviour() != "")
348  {
349  $tpl->setVariable("BEHAVIOUR", $this->getBehaviour());
350  }
351  $tpl->setVariable("OR2_SHORT", $or_short);
352  if ($width > 0)
353  {
354  $tpl->setVariable("WIDTH", $width);
355  }
356  else
357  {
358  $tpl->setVariable("WIDTH", "null");
359  }
360  if ($width > 0 && $this->getOrientation() == ilAccordionGUI::VERTICAL)
361  {
362  $tpl->setVariable("CWIDTH", 'style="width:'.$width.'px;"');
363  }
364 
365  if ($this->head_class_set)
366  {
367  $tpl->setVariable("ACTIVE_HEAD_CLASS", $this->getActiveHeaderClass());
368  }
369  else
370  {
372  {
373  $tpl->setVariable("ACTIVE_HEAD_CLASS", "il_HAccordionHeadActive");
374  }
375  else
376  {
377  $tpl->setVariable("ACTIVE_HEAD_CLASS", "il_VAccordionHeadActive");
378  }
379  }
380 
381  return $tpl->get();
382  }
383 
384 }
385 ?>