ILIAS  eassessment Revision 61809
 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 setContentClass($a_contentclass)
139  {
140  $this->contentclass = $a_contentclass;
141  }
142 
148  function getContentClass()
149  {
150  return $this->contentclass;
151  }
152 
158  function setContentWidth($a_contentwidth)
159  {
160  $this->contentwidth = $a_contentwidth;
161  }
162 
168  function getContentWidth()
169  {
170  return $this->contentwidth;
171  }
172 
178  function setContentHeight($a_contentheight)
179  {
180  $this->contentheight = $a_contentheight;
181  }
182 
188  function getContentHeight()
189  {
190  return $this->contentheight;
191  }
192 
198  function setBehaviour($a_val)
199  {
200  $this->behaviour = $a_val;
201  }
202 
208  function getBehaviour()
209  {
210  return $this->behaviour;
211  }
212 
216  static function addJavaScript()
217  {
218  global $tpl;
219 
220  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
225  $tpl->addJavaScript("./Services/Accordion/js/accordion.js", true, 3);
226  }
227 
231  static function addCss()
232  {
233  global $tpl;
234 
235  $tpl->addCss("./Services/Accordion/css/accordion.css");
236  }
237 
241  function addItem($a_header, $a_content)
242  {
243  $this->items[] = array("header" => $a_header,
244  "content" => $a_content);
245  }
246 
250  function getItems()
251  {
252  return $this->items;
253  }
254 
258  function getHTML()
259  {
260  global $ilUser;
261 
262  self::$accordion_cnt++;
263 
264  $or_short = ($this->getOrientation() == ilAccordionGUI::HORIZONTAL)
265  ? "H"
266  : "V";
267 
268  $width = (int) $this->getContentWidth();
269  $height = (int) $this->getContentHeight();
271  {
272  if ($width == 0)
273  {
274  $width = 200;
275  }
276  if ($height == 0)
277  {
278  $height = 100;
279  }
280  }
281 
282  $this->addJavascript();
283  $this->addCss();
284 
285  $tpl = new ilTemplate("tpl.accordion.html", true, true, "Services/Accordion");
286  foreach ($this->getItems() as $item)
287  {
288  $tpl->setCurrentBlock("item");
289  $tpl->setVariable("HEADER", $item["header"]);
290  $tpl->setVariable("CONTENT", $item["content"]);
291  $tpl->setVariable("HEADER_CLASS", $this->getHeaderClass()
292  ? $this->getHeaderClass() : "il_".$or_short."AccordionHead");
293  $tpl->setVariable("CONTENT_CLASS", $this->getContentClass()
294  ? $this->getContentClass() : "il_".$or_short."AccordionContent");
295  $tpl->setVariable("OR_SHORT", $or_short);
296 
297  $tpl->setVariable("INNER_CONTAINER_CLASS", $this->getInnerContainerClass()
298  ? $this->getInnerContainerClass() : "il_".$or_short."AccordionInnerContainer");
299 
300 
301  if ($height > 0)
302  {
303  $tpl->setVariable("HEIGHT", "height:".$height."px;");
304  }
305  if ($height > 0 && $this->getOrientation() == ilAccordionGUI::HORIZONTAL)
306  {
307  $tpl->setVariable("HHEIGHT", "height:".$height."px;");
308  }
309  $tpl->parseCurrentBlock();
310  }
311 
312  $tpl->setVariable("CNT", self::$accordion_cnt);
313  $tpl->setVariable("CONTAINER_CLASS", $this->getContainerClass()
314  ? $this->getContainerClass() : "il_".$or_short."AccordionContainer");
315  $tpl->setVariable("ORIENTATION", $this->getOrientation());
316  if ($this->getBehaviour() == "OneOpenSession" && $this->getId() != "")
317  {
318  include_once("./Services/Accordion/classes/class.ilAccordionPropertiesStorage.php");
319  $stor = new ilAccordionPropertiesStorage();
320  $ctab = $stor->getProperty($this->getId(), $ilUser->getId(),
321  "opened");
322  $tpl->setVariable("BEHAVIOUR", $ctab);
323  $tpl->setVariable("SAVE_URL", "./ilias.php?baseClass=ilaccordionpropertiesstorage&cmd=setOpenedTab".
324  "&accordion_id=".$this->getId()."&user_id=".$ilUser->getId());
325  }
326  else if ($this->getBehaviour() != "")
327  {
328  $tpl->setVariable("BEHAVIOUR", $this->getBehaviour());
329  }
330  $tpl->setVariable("OR2_SHORT", $or_short);
331  if ($width > 0)
332  {
333  $tpl->setVariable("WIDTH", $width);
334  }
335  else
336  {
337  $tpl->setVariable("WIDTH", "null");
338  }
339  if ($width > 0 && $this->getOrientation() == ilAccordionGUI::VERTICAL)
340  {
341  $tpl->setVariable("CWIDTH", 'style="width:'.$width.'px;"');
342  }
343 
344  return $tpl->get();
345  }
346 
347 }
348 ?>