ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
16  protected $user;
17 
18  protected $items = array();
19  protected $force_open = array();
20  protected static $accordion_cnt = 0;
21  protected $use_session_storage = false;
22  protected $allow_multi_opened = false;
23  protected $show_all_element = null;
24  protected $hide_all_element = null;
25 
26  const VERTICAL = "vertical";
27  const HORIZONTAL = "horizontal";
28  const FORCE_ALL_OPEN = "ForceAllOpen";
29  const FIRST_OPEN = "FirstOpen";
30  const ALL_CLOSED = "AllClosed";
31 
32  public static $owl_path = "./libs/bower/bower_components/owl.carousel/dist";
33  public static $owl_js_path = "/owl.carousel.js";
34  public static $owl_css_path = "/assets/owl.carousel.css";
35 
39  public function __construct()
40  {
41  global $DIC;
42 
43  $this->user = $DIC->user();
45  }
46 
52  public function setId($a_val)
53  {
54  $this->id = $a_val;
55  }
56 
62  public function getId()
63  {
64  return $this->id;
65  }
66 
72  public function setOrientation($a_orientation)
73  {
74  if (in_array(
75  $a_orientation,
77  )) {
78  $this->orientation = $a_orientation;
79  }
80  }
81 
87  public function getOrientation()
88  {
89  return $this->orientation;
90  }
91 
97  public function setContainerClass($a_containerclass)
98  {
99  $this->containerclass = $a_containerclass;
100  }
101 
107  public function getContainerClass()
108  {
109  return $this->containerclass;
110  }
111 
117  public function setInnerContainerClass($a_containerclass)
118  {
119  $this->icontainerclass = $a_containerclass;
120  }
121 
127  public function getInnerContainerClass()
128  {
129  return $this->icontainerclass;
130  }
131 
137  public function setHeaderClass($a_headerclass)
138  {
139  $this->headerclass = $a_headerclass;
140  }
141 
147  public function getHeaderClass()
148  {
149  return $this->headerclass;
150  }
151 
157  public function setActiveHeaderClass($a_h_class)
158  {
159  $this->active_headerclass = $a_h_class;
160  }
161 
167  public function getActiveHeaderClass()
168  {
169  return $this->active_headerclass;
170  }
171 
177  public function setContentClass($a_contentclass)
178  {
179  $this->contentclass = $a_contentclass;
180  }
181 
187  public function getContentClass()
188  {
189  return $this->contentclass;
190  }
191 
197  public function setContentWidth($a_contentwidth)
198  {
199  $this->contentwidth = $a_contentwidth;
200  }
201 
207  public function getContentWidth()
208  {
209  return $this->contentwidth;
210  }
211 
217  public function setContentHeight($a_contentheight)
218  {
219  $this->contentheight = $a_contentheight;
220  }
221 
227  public function getContentHeight()
228  {
229  return $this->contentheight;
230  }
231 
237  public function setBehaviour($a_val)
238  {
239  $this->behaviour = $a_val;
240  }
241 
247  public function getBehaviour()
248  {
249  return $this->behaviour;
250  }
251 
257  public function setUseSessionStorage($a_val)
258  {
259  $this->use_session_storage = $a_val;
260  }
261 
267  public function getUseSessionStorage()
268  {
270  }
271 
277  public function setAllowMultiOpened($a_val)
278  {
279  $this->allow_multi_opened = $a_val;
280  }
281 
287  public function getAllowMultiOpened()
288  {
290  }
291 
297  public function setShowAllElement($a_val)
298  {
299  $this->show_all_element = $a_val;
300  }
301 
307  public function getShowAllElement()
308  {
310  }
311 
317  public function setHideAllElement($a_val)
318  {
319  $this->hide_all_element = $a_val;
320  }
321 
327  public function getHideAllElement()
328  {
330  }
331 
335  public static function addJavaScript(ilTemplate $main_tpl = null)
336  {
337  global $DIC;
338 
339  if ($main_tpl != null) {
340  $tpl = $main_tpl;
341  } else {
342  $tpl = $DIC["tpl"];
343  }
344 
345  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
347 
348  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
350 
351  foreach (self::getLocalJavascriptFiles() as $f) {
352  $tpl->addJavaScript($f, true, 3);
353  }
354  }
355 
359  public static function addCss()
360  {
361  global $DIC;
362 
363  $tpl = $DIC["tpl"];
364 
365  foreach (self::getLocalCssFiles() as $f) {
366  $tpl->addCss($f);
367  }
368  }
369 
373  public static function getLocalJavascriptFiles()
374  {
375  return array(
376  "./Services/Accordion/js/accordion.js",
377  self::$owl_path . self::$owl_js_path
378  );
379  }
380 
384  public static function getLocalCssFiles()
385  {
386  return array(
387  "./Services/Accordion/css/accordion.css",
388  self::$owl_path . self::$owl_css_path
389  );
390  }
391 
395  public function addItem($a_header, $a_content, $a_force_open = false)
396  {
397  $this->items[] = array("header" => $a_header,
398  "content" => $a_content, "force_open" => $a_force_open);
399 
400  if ($a_force_open) {
401  $this->force_open[] = sizeof($this->items);
402  }
403  }
404 
408  public function getItems()
409  {
410  return $this->items;
411  }
412 
416  public function getHTML()
417  {
419 
420  self::$accordion_cnt++;
421 
422  $or_short = ($this->getOrientation() == ilAccordionGUI::HORIZONTAL)
423  ? "H"
424  : "V";
425 
426  $width = (int) $this->getContentWidth();
427  $height = (int) $this->getContentHeight();
428  if ($this->getOrientation() == ilAccordionGUI::HORIZONTAL) {
429  if ($width == 0) {
430  $width = 200;
431  }
432  if ($height == 0) {
433  $height = 100;
434  }
435  }
436 
437  $this->addJavascript();
438  $this->addCss();
439 
440  $tpl = new ilTemplate("tpl.accordion.html", true, true, "Services/Accordion");
441  foreach ($this->getItems() as $item) {
442  $tpl->setCurrentBlock("item");
443  $tpl->setVariable("HEADER", $item["header"]);
444  $tpl->setVariable("CONTENT", $item["content"]);
445  $tpl->setVariable("HEADER_CLASS", $this->getHeaderClass()
446  ? $this->getHeaderClass() : "il_" . $or_short . "AccordionHead");
447  $tpl->setVariable("CONTENT_CLASS", $this->getContentClass()
448  ? $this->getContentClass() : "il_" . $or_short . "AccordionContent");
449 
450  if ($this->getBehaviour() != self::FORCE_ALL_OPEN) {
451  $tpl->setVariable("HIDE_CONTENT_CLASS", "ilAccHideContent");
452  }
453 
454  $tpl->setVariable("OR_SHORT", $or_short);
455 
456  $tpl->setVariable("INNER_CONTAINER_CLASS", $this->getInnerContainerClass()
457  ? $this->getInnerContainerClass() : "il_" . $or_short . "AccordionInnerContainer");
458 
459 
460  if ($height > 0) {
461  $tpl->setVariable("HEIGHT", "height:" . $height . "px;");
462  }
463  if ($height > 0 && $this->getOrientation() == ilAccordionGUI::HORIZONTAL) {
464  $tpl->setVariable("HHEIGHT", "height:" . $height . "px;");
465  }
466  $tpl->parseCurrentBlock();
467  }
468 
469  $tpl->setVariable("CONTAINER_CLASS", $this->getContainerClass()
470  ? $this->getContainerClass() : "il_" . $or_short . "AccordionContainer");
471 
472  $options["orientation"] = $this->getOrientation();
473  $options["int_id"] = $this->getId();
474 
475  if ($this->getUseSessionStorage() && $this->getId() != "") {
476  include_once("./Services/Accordion/classes/class.ilAccordionPropertiesStorage.php");
477  $stor = new ilAccordionPropertiesStorage();
478 
479  $ctab = $stor->getProperty(
480  $this->getId(),
481  $ilUser->getId(),
482  "opened"
483  );
484  $ctab_arr = explode(";", $ctab);
485 
486  foreach ($this->force_open as $fo) {
487  if (!in_array($fo, $ctab_arr)) {
488  $ctab_arr[] = $fo;
489  }
490  }
491  $ctab = implode(";", $ctab_arr);
492 
493  if ($ctab == "0") {
494  $ctab = "";
495  }
496 
497  $options["initial_opened"] = $ctab;
498  $options["save_url"] = "./ilias.php?baseClass=ilaccordionpropertiesstorage&cmd=setOpenedTab" .
499  "&accordion_id=" . $this->getId() . "&user_id=" . $ilUser->getId();
500  }
501 
502  $options["behaviour"] = $this->getBehaviour();
503  if ($this->getOrientation() == ilAccordionGUI::HORIZONTAL) {
504  $options["toggle_class"] = 'il_HAccordionToggleDef';
505  $options["toggle_act_class"] = 'il_HAccordionToggleActiveDef';
506  $options["content_class"] = 'il_HAccordionContentDef';
507  } else {
508  $options["toggle_class"] = 'il_VAccordionToggleDef';
509  $options["toggle_act_class"] = 'il_VAccordionToggleActiveDef';
510  $options["content_class"] = 'il_VAccordionContentDef';
511  }
512 
513 
514  if ($width > 0) {
515  $options["width"] = $width;
516  } else {
517  $options["width"] = null;
518  }
519  if ($width > 0 && $this->getOrientation() == ilAccordionGUI::VERTICAL) {
520  $tpl->setVariable("CWIDTH", 'style="width:' . $width . 'px;"');
521  }
522 
523  if ($this->head_class_set) {
524  $options["active_head_class"] = $this->getActiveHeaderClass();
525  } else {
526  if ($this->getOrientation() == ilAccordionGUI::VERTICAL) {
527  $options["active_head_class"] = "il_HAccordionHeadActive";
528  } else {
529  $options["active_head_class"] = "il_VAccordionHeadActive";
530  }
531  }
532 
533  $options["height"] = null;
534  $options["id"] = 'accordion_' . $this->getId() . '_' . self::$accordion_cnt;
535  $options["multi"] = (bool) $this->getAllowMultiOpened();
536  $options["show_all_element"] = $this->getShowAllElement();
537  $options["hide_all_element"] = $this->getHideAllElement();
538 
539  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
540  $tpl->setVariable("OPTIONS", $str = ilJsonUtil::encode($options));
541  $tpl->setVariable("ACC_ID", $options["id"]);
542  //echo "<br><br><br><br><br><br>".$str;
543  return $tpl->get();
544  }
545 }
getContentWidth()
Get ContentWidth.
getContentHeight()
Get ContentHeight.
setActiveHeaderClass($a_h_class)
Set active header class.
getContainerClass()
Get Container CSS Class.
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
static initConnection(ilTemplate $a_main_tpl=null)
Init YUI Connection module.
getOrientation()
Get Orientation.
getActiveHeaderClass()
Get active Header CSS Class.
setAllowMultiOpened($a_val)
Set allow multi opened.
if(!array_key_exists('StateId', $_REQUEST)) $id
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.
user()
Definition: user.php:4
static getLocalJavascriptFiles()
static addJavaScript(ilTemplate $main_tpl=null)
Add javascript files that are necessary to run accordion.
setContentClass($a_contentclass)
Set Content CSS Class.
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.
$a_content
Definition: workflow.php:93
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.
static initjQueryUI($a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components.txt for included components)
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.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
__construct()
Constructor.