ILIAS  release_4-4 Revision
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;
15  protected static $accordion_cnt = 0;
16 
17  const VERTICAL = "vertical";
18  const HORIZONTAL = "horizontal";
19  const FORCE_ALL_OPEN = "ForceAllOpen";
20  const FIRST_OPEN = "FirstOpen";
21  const ONE_OPEN_SESSION = "OneOpenSession";
22 
26  function __construct()
27  {
29  }
30 
36  function setId($a_val)
37  {
38  $this->id = $a_val;
39  }
40 
46  function getId()
47  {
48  return $this->id;
49  }
50 
56  function setOrientation($a_orientation)
57  {
58  if (in_array($a_orientation,
60  {
61  $this->orientation = $a_orientation;
62  }
63  }
64 
70  function getOrientation()
71  {
72  return $this->orientation;
73  }
74 
80  function setContainerClass($a_containerclass)
81  {
82  $this->containerclass = $a_containerclass;
83  }
84 
90  function getContainerClass()
91  {
92  return $this->containerclass;
93  }
94 
100  function setInnerContainerClass($a_containerclass)
101  {
102  $this->icontainerclass = $a_containerclass;
103  }
104 
111  {
112  return $this->icontainerclass;
113  }
114 
120  function setHeaderClass($a_headerclass)
121  {
122  $this->headerclass = $a_headerclass;
123  }
124 
130  function getHeaderClass()
131  {
132  return $this->headerclass;
133  }
134 
140  function setActiveHeaderClass($a_h_class)
141  {
142  $this->active_headerclass = $a_h_class;
143  }
144 
151  {
152  return $this->active_headerclass;
153  }
154 
160  function setContentClass($a_contentclass)
161  {
162  $this->contentclass = $a_contentclass;
163  }
164 
170  function getContentClass()
171  {
172  return $this->contentclass;
173  }
174 
180  function setContentWidth($a_contentwidth)
181  {
182  $this->contentwidth = $a_contentwidth;
183  }
184 
190  function getContentWidth()
191  {
192  return $this->contentwidth;
193  }
194 
200  function setContentHeight($a_contentheight)
201  {
202  $this->contentheight = $a_contentheight;
203  }
204 
210  function getContentHeight()
211  {
212  return $this->contentheight;
213  }
214 
220  function setBehaviour($a_val)
221  {
222  $this->behaviour = $a_val;
223  }
224 
230  function getBehaviour()
231  {
232  return $this->behaviour;
233  }
234 
238  static function addJavaScript()
239  {
240  global $tpl;
241 
242  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
247  $tpl->addJavaScript("./Services/Accordion/js/accordion.js", true, 3);
248  }
249 
253  static function addCss()
254  {
255  global $tpl;
256 
257  $tpl->addCss("./Services/Accordion/css/accordion.css");
258  }
259 
263  function addItem($a_header, $a_content, $a_force_open = false)
264  {
265  $this->items[] = array("header" => $a_header,
266  "content" => $a_content);
267 
268  if($a_force_open)
269  {
270  $this->force_open = sizeof($this->items);
271  }
272  }
273 
277  function getItems()
278  {
279  return $this->items;
280  }
281 
285  function getHTML()
286  {
287  global $ilUser;
288 
289  self::$accordion_cnt++;
290 
291  $or_short = ($this->getOrientation() == ilAccordionGUI::HORIZONTAL)
292  ? "H"
293  : "V";
294 
295  $width = (int) $this->getContentWidth();
296  $height = (int) $this->getContentHeight();
298  {
299  if ($width == 0)
300  {
301  $width = 200;
302  }
303  if ($height == 0)
304  {
305  $height = 100;
306  }
307  }
308 
309  $this->addJavascript();
310  $this->addCss();
311 
312  $tpl = new ilTemplate("tpl.accordion.html", true, true, "Services/Accordion");
313  foreach ($this->getItems() as $item)
314  {
315  $tpl->setCurrentBlock("item");
316  $tpl->setVariable("HEADER", $item["header"]);
317  $tpl->setVariable("CONTENT", $item["content"]);
318  $tpl->setVariable("HEADER_CLASS", $this->getHeaderClass()
319  ? $this->getHeaderClass() : "il_".$or_short."AccordionHead");
320  $tpl->setVariable("CONTENT_CLASS", $this->getContentClass()
321  ? $this->getContentClass() : "il_".$or_short."AccordionContent");
322  $tpl->setVariable("OR_SHORT", $or_short);
323 
324  $tpl->setVariable("INNER_CONTAINER_CLASS", $this->getInnerContainerClass()
325  ? $this->getInnerContainerClass() : "il_".$or_short."AccordionInnerContainer");
326 
327 
328  if ($height > 0)
329  {
330  $tpl->setVariable("HEIGHT", "height:".$height."px;");
331  }
332  if ($height > 0 && $this->getOrientation() == ilAccordionGUI::HORIZONTAL)
333  {
334  $tpl->setVariable("HHEIGHT", "height:".$height."px;");
335  }
336  $tpl->parseCurrentBlock();
337  }
338 
339  $tpl->setVariable("CNT", self::$accordion_cnt);
340  $tpl->setVariable("CONTAINER_CLASS", $this->getContainerClass()
341  ? $this->getContainerClass() : "il_".$or_short."AccordionContainer");
342  $tpl->setVariable("ORIENTATION", $this->getOrientation());
343  $tpl->setVariable("ID", $this->getId());
344  if ($this->getBehaviour() == "OneOpenSession" && $this->getId() != "")
345  {
346  include_once("./Services/Accordion/classes/class.ilAccordionPropertiesStorage.php");
347  $stor = new ilAccordionPropertiesStorage();
348 
349  if($this->force_open)
350  {
351  $stor->storeProperty($this->getId(), $ilUser->getId(),
352  "opened", $this->force_open);
353 
354  $ctab = $this->force_open;
355  }
356  else
357  {
358  $ctab = $stor->getProperty($this->getId(), $ilUser->getId(),
359  "opened");
360  }
361 
362  $tpl->setVariable("BEHAVIOUR", $ctab);
363  $tpl->setVariable("SAVE_URL", "./ilias.php?baseClass=ilaccordionpropertiesstorage&cmd=setOpenedTab".
364  "&accordion_id=".$this->getId()."&user_id=".$ilUser->getId());
365  }
366  else if ($this->getBehaviour() != "")
367  {
368  $tpl->setVariable("BEHAVIOUR", $this->getBehaviour());
369  }
370  $tpl->setVariable("OR2_SHORT", $or_short);
371  if ($width > 0)
372  {
373  $tpl->setVariable("WIDTH", $width);
374  }
375  else
376  {
377  $tpl->setVariable("WIDTH", "null");
378  }
379  if ($width > 0 && $this->getOrientation() == ilAccordionGUI::VERTICAL)
380  {
381  $tpl->setVariable("CWIDTH", 'style="width:'.$width.'px;"');
382  }
383 
384  if ($this->head_class_set)
385  {
386  $tpl->setVariable("ACTIVE_HEAD_CLASS", $this->getActiveHeaderClass());
387  }
388  else
389  {
391  {
392  $tpl->setVariable("ACTIVE_HEAD_CLASS", "il_HAccordionHeadActive");
393  }
394  else
395  {
396  $tpl->setVariable("ACTIVE_HEAD_CLASS", "il_VAccordionHeadActive");
397  }
398  }
399 
400  return $tpl->get();
401  }
402 
403 }
404 ?>
getContentWidth()
Get ContentWidth.
getContentHeight()
Get ContentHeight.
setActiveHeaderClass($a_h_class)
Set active header class.
static initAnimation()
Init YUI Animation.
getContainerClass()
Get Container CSS Class.
getOrientation()
Get Orientation.
getActiveHeaderClass()
Get active Header CSS Class.
static initConnection()
Init YUI Connection module.
getHeaderClass()
Get Header CSS Class.
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.
static initDom()
Init YUI Dom.
setContentHeight($a_contentheight)
Set ContentHeight.
getInnerContainerClass()
Get inner Container CSS Class.
static addCss()
Add required css.
setBehaviour($a_val)
Set behaviour "ForceAllOpen" | "FirstOpen" | "OneOpenSession".
special template class to simplify handling of ITX/PEAR
setInnerContainerClass($a_containerclass)
Set inner Container CSS Class.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
static initEvent()
Init YUI Event.
getContentClass()
Get Content CSS Class.
setHeaderClass($a_headerclass)
Set Header CSS Class.
setId($a_val)
Set id.
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.