ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
27  static $owl_path = "./Services/Accordion/lib/owl.carousel.2.0.0-beta.2.4";
28  static $owl_js_path = "/owl.carousel.js";
29  static $owl_css_path = "/assets/owl.carousel.css";
30 
34  function __construct()
35  {
37  }
38 
44  function setId($a_val)
45  {
46  $this->id = $a_val;
47  }
48 
54  function getId()
55  {
56  return $this->id;
57  }
58 
64  function setOrientation($a_orientation)
65  {
66  if (in_array($a_orientation,
68  {
69  $this->orientation = $a_orientation;
70  }
71  }
72 
78  function getOrientation()
79  {
80  return $this->orientation;
81  }
82 
88  function setContainerClass($a_containerclass)
89  {
90  $this->containerclass = $a_containerclass;
91  }
92 
98  function getContainerClass()
99  {
100  return $this->containerclass;
101  }
102 
108  function setInnerContainerClass($a_containerclass)
109  {
110  $this->icontainerclass = $a_containerclass;
111  }
112 
119  {
120  return $this->icontainerclass;
121  }
122 
128  function setHeaderClass($a_headerclass)
129  {
130  $this->headerclass = $a_headerclass;
131  }
132 
138  function getHeaderClass()
139  {
140  return $this->headerclass;
141  }
142 
148  function setActiveHeaderClass($a_h_class)
149  {
150  $this->active_headerclass = $a_h_class;
151  }
152 
159  {
160  return $this->active_headerclass;
161  }
162 
168  function setContentClass($a_contentclass)
169  {
170  $this->contentclass = $a_contentclass;
171  }
172 
178  function getContentClass()
179  {
180  return $this->contentclass;
181  }
182 
188  function setContentWidth($a_contentwidth)
189  {
190  $this->contentwidth = $a_contentwidth;
191  }
192 
198  function getContentWidth()
199  {
200  return $this->contentwidth;
201  }
202 
208  function setContentHeight($a_contentheight)
209  {
210  $this->contentheight = $a_contentheight;
211  }
212 
218  function getContentHeight()
219  {
220  return $this->contentheight;
221  }
222 
228  function setBehaviour($a_val)
229  {
230  $this->behaviour = $a_val;
231  }
232 
238  function getBehaviour()
239  {
240  return $this->behaviour;
241  }
242 
248  function setUseSessionStorage($a_val)
249  {
250  $this->use_session_storage = $a_val;
251  }
252 
259  {
261  }
262 
268  function setAllowMultiOpened($a_val)
269  {
270  $this->allow_multi_opened = $a_val;
271  }
272 
279  {
281  }
282 
288  function setShowAllElement($a_val)
289  {
290  $this->show_all_element = $a_val;
291  }
292 
298  function getShowAllElement()
299  {
301  }
302 
308  function setHideAllElement($a_val)
309  {
310  $this->hide_all_element = $a_val;
311  }
312 
318  function getHideAllElement()
319  {
321  }
322 
326  static function addJavaScript()
327  {
328  global $tpl;
329 
330 
331  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
333 
334  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
336 
337  foreach (self::getLocalJavascriptFiles() as $f)
338  {
339  $tpl->addJavaScript($f, true, 3);
340  }
341  }
342 
346  static function addCss()
347  {
348  global $tpl;
349 
350  foreach (self::getLocalCssFiles() as $f)
351  {
352  $tpl->addCss($f);
353  }
354  }
355 
359  static function getLocalJavascriptFiles()
360  {
361  return array(
362  "./Services/Accordion/js/accordion.js",
363  self::$owl_path.self::$owl_js_path
364  );
365  }
366 
370  static function getLocalCssFiles()
371  {
372  return array(
373  "./Services/Accordion/css/accordion.css",
374  self::$owl_path.self::$owl_css_path
375  );
376  }
377 
381  function addItem($a_header, $a_content, $a_force_open = false)
382  {
383  $this->items[] = array("header" => $a_header,
384  "content" => $a_content, "force_open" => $a_force_open);
385 
386  if($a_force_open)
387  {
388  $this->force_open[] = sizeof($this->items);
389  }
390  }
391 
395  function getItems()
396  {
397  return $this->items;
398  }
399 
403  function getHTML()
404  {
405  global $ilUser;
406 
407  self::$accordion_cnt++;
408 
409  $or_short = ($this->getOrientation() == ilAccordionGUI::HORIZONTAL)
410  ? "H"
411  : "V";
412 
413  $width = (int) $this->getContentWidth();
414  $height = (int) $this->getContentHeight();
416  {
417  if ($width == 0)
418  {
419  $width = 200;
420  }
421  if ($height == 0)
422  {
423  $height = 100;
424  }
425  }
426 
427  $this->addJavascript();
428  $this->addCss();
429 
430  $tpl = new ilTemplate("tpl.accordion.html", true, true, "Services/Accordion");
431  foreach ($this->getItems() as $item)
432  {
433  $tpl->setCurrentBlock("item");
434  $tpl->setVariable("HEADER", $item["header"]);
435  $tpl->setVariable("CONTENT", $item["content"]);
436  $tpl->setVariable("HEADER_CLASS", $this->getHeaderClass()
437  ? $this->getHeaderClass() : "il_".$or_short."AccordionHead");
438  $tpl->setVariable("CONTENT_CLASS", $this->getContentClass()
439  ? $this->getContentClass() : "il_".$or_short."AccordionContent");
440 
441  if ($this->getBehaviour() != self::FORCE_ALL_OPEN)
442  {
443  $tpl->setVariable("HIDE_CONTENT_CLASS", "ilAccHideContent");
444  }
445 
446  $tpl->setVariable("OR_SHORT", $or_short);
447 
448  $tpl->setVariable("INNER_CONTAINER_CLASS", $this->getInnerContainerClass()
449  ? $this->getInnerContainerClass() : "il_".$or_short."AccordionInnerContainer");
450 
451 
452  if ($height > 0)
453  {
454  $tpl->setVariable("HEIGHT", "height:".$height."px;");
455  }
456  if ($height > 0 && $this->getOrientation() == ilAccordionGUI::HORIZONTAL)
457  {
458  $tpl->setVariable("HHEIGHT", "height:".$height."px;");
459  }
460  $tpl->parseCurrentBlock();
461  }
462 
463  $tpl->setVariable("CONTAINER_CLASS", $this->getContainerClass()
464  ? $this->getContainerClass() : "il_".$or_short."AccordionContainer");
465 
466  $options["orientation"] = $this->getOrientation();
467  $options["int_id"] = $this->getId();
468 
469  if ($this->getUseSessionStorage() && $this->getId() != "")
470  {
471  include_once("./Services/Accordion/classes/class.ilAccordionPropertiesStorage.php");
472  $stor = new ilAccordionPropertiesStorage();
473 
474  $ctab = $stor->getProperty($this->getId(), $ilUser->getId(),
475  "opened");
476  $ctab_arr = explode(";", $ctab);
477 
478  foreach ($this->force_open as $fo)
479  {
480  if (!in_array($fo, $ctab_arr))
481  {
482  $ctab_arr[] = $fo;
483  }
484  }
485  $ctab = implode(";", $ctab_arr);
486 
487  if ($ctab == "0") {
488  $ctab = "";
489  }
490 
491  $options["initial_opened"] = $ctab;
492  $options["save_url"] = "./ilias.php?baseClass=ilaccordionpropertiesstorage&cmd=setOpenedTab".
493  "&accordion_id=".$this->getId()."&user_id=".$ilUser->getId();
494  }
495 
496  $options["behaviour"] = $this->getBehaviour();
498  {
499  $options["toggle_class"] = 'il_HAccordionToggleDef';
500  $options["toggle_act_class"] = 'il_HAccordionToggleActiveDef';
501  $options["content_class"] = 'il_HAccordionContentDef';
502  }
503  else
504  {
505  $options["toggle_class"] = 'il_VAccordionToggleDef';
506  $options["toggle_act_class"] = 'il_VAccordionToggleActiveDef';
507  $options["content_class"] = 'il_VAccordionContentDef';
508  }
509 
510 
511  if ($width > 0)
512  {
513  $options["width"] = $width;
514  }
515  else
516  {
517  $options["width"] = null;
518  }
519  if ($width > 0 && $this->getOrientation() == ilAccordionGUI::VERTICAL)
520  {
521  $tpl->setVariable("CWIDTH", 'style="width:'.$width.'px;"');
522  }
523 
524  if ($this->head_class_set)
525  {
526  $options["active_head_class"] = $this->getActiveHeaderClass();
527  }
528  else
529  {
531  {
532  $options["active_head_class"] = "il_HAccordionHeadActive";
533  }
534  else
535  {
536  $options["active_head_class"] = "il_VAccordionHeadActive";
537  }
538  }
539 
540  $options["height"] = null;
541  $options["id"] = 'accordion_'.$this->getId().'_'.self::$accordion_cnt;
542  $options["multi"] = (bool) $this->getAllowMultiOpened();
543  $options["show_all_element"] = $this->getShowAllElement();
544  $options["hide_all_element"] = $this->getHideAllElement();
545 
546  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
547  $tpl->setVariable("OPTIONS", $str = ilJsonUtil::encode($options));
548  $tpl->setVariable("ACC_ID", $options["id"]);
549 //echo "<br><br><br><br><br><br>".$str;
550  return $tpl->get();
551  }
552 
553 }
554 ?>
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.
static getLocalJavascriptFiles()
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
$a_content
Definition: workflow.php:94
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.
$ilUser
Definition: imgupload.php:18
getContentClass()
Get Content CSS Class.
Create styles array
The data for the language used.
setHeaderClass($a_headerclass)
Set Header CSS Class.
setId($a_val)
Set id.
getUseSessionStorage()
Get use session storage.
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.