ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules 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 $force_open = array();
15  protected static $accordion_cnt = 0;
16  protected $use_session_storage = false;
17  protected $allow_multi_opened = false;
18  protected $show_all_element = null;
19  protected $hide_all_element = null;
20 
21  const VERTICAL = "vertical";
22  const HORIZONTAL = "horizontal";
23  const FORCE_ALL_OPEN = "ForceAllOpen";
24  const FIRST_OPEN = "FirstOpen";
25  const ALL_CLOSED = "AllClosed";
26 
30  function __construct()
31  {
33  }
34 
40  function setId($a_val)
41  {
42  $this->id = $a_val;
43  }
44 
50  function getId()
51  {
52  return $this->id;
53  }
54 
60  function setOrientation($a_orientation)
61  {
62  if (in_array($a_orientation,
64  {
65  $this->orientation = $a_orientation;
66  }
67  }
68 
74  function getOrientation()
75  {
76  return $this->orientation;
77  }
78 
84  function setContainerClass($a_containerclass)
85  {
86  $this->containerclass = $a_containerclass;
87  }
88 
94  function getContainerClass()
95  {
96  return $this->containerclass;
97  }
98 
104  function setInnerContainerClass($a_containerclass)
105  {
106  $this->icontainerclass = $a_containerclass;
107  }
108 
115  {
116  return $this->icontainerclass;
117  }
118 
124  function setHeaderClass($a_headerclass)
125  {
126  $this->headerclass = $a_headerclass;
127  }
128 
134  function getHeaderClass()
135  {
136  return $this->headerclass;
137  }
138 
144  function setActiveHeaderClass($a_h_class)
145  {
146  $this->active_headerclass = $a_h_class;
147  }
148 
155  {
156  return $this->active_headerclass;
157  }
158 
164  function setContentClass($a_contentclass)
165  {
166  $this->contentclass = $a_contentclass;
167  }
168 
174  function getContentClass()
175  {
176  return $this->contentclass;
177  }
178 
184  function setContentWidth($a_contentwidth)
185  {
186  $this->contentwidth = $a_contentwidth;
187  }
188 
194  function getContentWidth()
195  {
196  return $this->contentwidth;
197  }
198 
204  function setContentHeight($a_contentheight)
205  {
206  $this->contentheight = $a_contentheight;
207  }
208 
214  function getContentHeight()
215  {
216  return $this->contentheight;
217  }
218 
224  function setBehaviour($a_val)
225  {
226  $this->behaviour = $a_val;
227  }
228 
234  function getBehaviour()
235  {
236  return $this->behaviour;
237  }
238 
244  function setUseSessionStorage($a_val)
245  {
246  $this->use_session_storage = $a_val;
247  }
248 
255  {
257  }
258 
264  function setAllowMultiOpened($a_val)
265  {
266  $this->allow_multi_opened = $a_val;
267  }
268 
275  {
277  }
278 
284  function setShowAllElement($a_val)
285  {
286  $this->show_all_element = $a_val;
287  }
288 
294  function getShowAllElement()
295  {
297  }
298 
304  function setHideAllElement($a_val)
305  {
306  $this->hide_all_element = $a_val;
307  }
308 
314  function getHideAllElement()
315  {
317  }
318 
322  static function addJavaScript()
323  {
324  global $tpl;
325 
326 
327  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
329 
330  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
332  $tpl->addJavaScript("./Services/Accordion/js/accordion.js", true, 3);
333  }
334 
338  static function addCss()
339  {
340  global $tpl;
341 
342  $tpl->addCss("./Services/Accordion/css/accordion.css");
343  }
344 
348  function addItem($a_header, $a_content, $a_force_open = false)
349  {
350  $this->items[] = array("header" => $a_header,
351  "content" => $a_content, "force_open" => $a_force_open);
352 
353  if($a_force_open)
354  {
355  $this->force_open[] = sizeof($this->items);
356  }
357  }
358 
362  function getItems()
363  {
364  return $this->items;
365  }
366 
370  function getHTML()
371  {
372  global $ilUser;
373 
374  self::$accordion_cnt++;
375 
376  $or_short = ($this->getOrientation() == ilAccordionGUI::HORIZONTAL)
377  ? "H"
378  : "V";
379 
380  $width = (int) $this->getContentWidth();
381  $height = (int) $this->getContentHeight();
383  {
384  if ($width == 0)
385  {
386  $width = 200;
387  }
388  if ($height == 0)
389  {
390  $height = 100;
391  }
392  }
393 
394  $this->addJavascript();
395  $this->addCss();
396 
397  $tpl = new ilTemplate("tpl.accordion.html", true, true, "Services/Accordion");
398  foreach ($this->getItems() as $item)
399  {
400  $tpl->setCurrentBlock("item");
401  $tpl->setVariable("HEADER", $item["header"]);
402  $tpl->setVariable("CONTENT", $item["content"]);
403  $tpl->setVariable("HEADER_CLASS", $this->getHeaderClass()
404  ? $this->getHeaderClass() : "il_".$or_short."AccordionHead");
405  $tpl->setVariable("CONTENT_CLASS", $this->getContentClass()
406  ? $this->getContentClass() : "il_".$or_short."AccordionContent");
407 
408  if ($this->getBehaviour() != self::FORCE_ALL_OPEN)
409  {
410  $tpl->setVariable("HIDE_CONTENT_CLASS", "ilAccHideContent");
411  }
412 
413  $tpl->setVariable("OR_SHORT", $or_short);
414 
415  $tpl->setVariable("INNER_CONTAINER_CLASS", $this->getInnerContainerClass()
416  ? $this->getInnerContainerClass() : "il_".$or_short."AccordionInnerContainer");
417 
418 
419  if ($height > 0)
420  {
421  $tpl->setVariable("HEIGHT", "height:".$height."px;");
422  }
423  if ($height > 0 && $this->getOrientation() == ilAccordionGUI::HORIZONTAL)
424  {
425  $tpl->setVariable("HHEIGHT", "height:".$height."px;");
426  }
427  $tpl->parseCurrentBlock();
428  }
429 
430  $tpl->setVariable("CONTAINER_CLASS", $this->getContainerClass()
431  ? $this->getContainerClass() : "il_".$or_short."AccordionContainer");
432 
433  $options["orientation"] = $this->getOrientation();
434  $options["int_id"] = $this->getId();
435 
436  if ($this->getUseSessionStorage() && $this->getId() != "")
437  {
438  include_once("./Services/Accordion/classes/class.ilAccordionPropertiesStorage.php");
439  $stor = new ilAccordionPropertiesStorage();
440 
441  $ctab = $stor->getProperty($this->getId(), $ilUser->getId(),
442  "opened");
443  $ctab_arr = explode(";", $ctab);
444 
445  foreach ($this->force_open as $fo)
446  {
447  if (!in_array($fo, $ctab_arr))
448  {
449  $ctab_arr[] = $fo;
450  }
451  }
452  $ctab = implode(";", $ctab_arr);
453 
454  if ($ctab == "0") {
455  $ctab = "";
456  }
457 
458  $options["initial_opened"] = $ctab;
459  $options["save_url"] = "./ilias.php?baseClass=ilaccordionpropertiesstorage&cmd=setOpenedTab".
460  "&accordion_id=".$this->getId()."&user_id=".$ilUser->getId();
461  }
462 
463  $options["behaviour"] = $this->getBehaviour();
465  {
466  $options["toggle_class"] = 'il_HAccordionToggleDef';
467  $options["toggle_act_class"] = 'il_HAccordionToggleActiveDef';
468  $options["content_class"] = 'il_HAccordionContentDef';
469  }
470  else
471  {
472  $options["toggle_class"] = 'il_VAccordionToggleDef';
473  $options["toggle_act_class"] = 'il_VAccordionToggleActiveDef';
474  $options["content_class"] = 'il_VAccordionContentDef';
475  }
476 
477 
478  if ($width > 0)
479  {
480  $options["width"] = $width;
481  }
482  else
483  {
484  $options["width"] = null;
485  }
486  if ($width > 0 && $this->getOrientation() == ilAccordionGUI::VERTICAL)
487  {
488  $tpl->setVariable("CWIDTH", 'style="width:'.$width.'px;"');
489  }
490 
491  if ($this->head_class_set)
492  {
493  $options["active_head_class"] = $this->getActiveHeaderClass();
494  }
495  else
496  {
498  {
499  $options["active_head_class"] = "il_HAccordionHeadActive";
500  }
501  else
502  {
503  $options["active_head_class"] = "il_VAccordionHeadActive";
504  }
505  }
506 
507  $options["height"] = null;
508  $options["id"] = 'accordion_'.$this->getId().'_'.self::$accordion_cnt;
509  $options["multi"] = (bool) $this->getAllowMultiOpened();
510  $options["show_all_element"] = $this->getShowAllElement();
511  $options["hide_all_element"] = $this->getHideAllElement();
512 
513  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
514  $tpl->setVariable("OPTIONS", $str = ilJsonUtil::encode($options));
515  $tpl->setVariable("ACC_ID", $options["id"]);
516 //echo "<br><br><br><br><br><br>".$str;
517  return $tpl->get();
518  }
519 
520 }
521 ?>
getContentWidth()
Get ContentWidth.
static initjQueryUI()
Init jQuery UI (see included_components.txt for included components)
getContentHeight()
Get ContentHeight.
setActiveHeaderClass($a_h_class)
Set active header class.
getContainerClass()
Get Container CSS Class.
getOrientation()
Get Orientation.
getActiveHeaderClass()
Get active Header CSS Class.
static initConnection()
Init YUI Connection module.
setAllowMultiOpened($a_val)
Set allow multi opened.
getHeaderClass()
Get Header CSS Class.
getAllowMultiOpened()
Get allow multi opened.
getHTML()
Get accordion html.
addItem($a_header, $a_content, $a_force_open=false)
Add item.
static addJavaScript()
Add javascript files that are necessary to run accordion.
setContentClass($a_contentclass)
Set Content CSS Class.
global $tpl
Definition: ilias.php:8
getShowAllElement()
Get show all element.
setContentHeight($a_contentheight)
Set ContentHeight.
setUseSessionStorage($a_val)
Set use session storage.
getHideAllElement()
Get hide all element.
getInnerContainerClass()
Get inner Container CSS Class.
static encode($mixed, $suppress_native=false)
static addCss()
Add required css.
if(!is_array($argv)) $options
setBehaviour($a_val)
Set behaviour "ForceAllOpen" | "FirstOpen" | "AllClosed".
setHideAllElement($a_val)
Set hide all element.
setShowAllElement($a_val)
Set show all element.
special template class to simplify handling of ITX/PEAR
setInnerContainerClass($a_containerclass)
Set inner Container CSS Class.
getContentClass()
Get Content CSS Class.
setHeaderClass($a_headerclass)
Set Header CSS Class.
setId($a_val)
Set id.
getUseSessionStorage()
Get use session storage.
global $ilUser
Definition: imgupload.php:15
setContentWidth($a_contentwidth)
Set ContentWidth.
setOrientation($a_orientation)
Set Orientation.
getItems()
Get all items.
Accordion user interface class.
Saves (mostly asynchronously) user properties of accordions.
setContainerClass($a_containerclass)
Set Container CSS Class.
getBehaviour()
Get behaviour.
__construct()
Constructor.