45 protected string $id =
"";
47 public static string $owl_path =
"./node_modules/owl.carousel/dist";
58 $this->main_tpl =
$DIC->ui()->mainTemplate();
60 $this->
user = $DIC->user();
64 public function setId(
string $a_val): void
80 $this->orientation = $a_orientation;
91 $this->containerclass = $a_containerclass;
101 $this->icontainerclass = $a_containerclass;
111 $this->headerclass = $a_headerclass;
121 $this->active_headerclass = $a_h_class;
131 $this->contentclass = $a_contentclass;
141 $this->contentwidth = $a_contentwidth;
151 $this->contentheight = $a_contentheight;
164 $this->behaviour = $a_val;
174 $this->use_session_storage = $a_val;
184 $this->allow_multi_opened = $a_val;
197 $this->show_all_element = $a_val;
210 $this->hide_all_element = $a_val;
231 foreach (self::getLocalJavascriptFiles() as
$f) {
232 $tpl->addJavaScript(
$f,
true, 3);
245 foreach (self::getLocalCssFiles() as
$f) {
255 "../components/ILIAS/Accordion/resources/accordion.js"
259 "assets/js/accordion.js",
260 "assets/js" . self::$owl_js_path
267 "./components/ILIAS/Accordion/css/accordion.css",
268 self::$owl_path . self::$owl_css_path
275 bool $a_force_open =
false
277 $this->items[] = array(
"header" => $a_header,
278 "content" => $a_content,
"force_open" => $a_force_open);
290 public function getHTML(
bool $async =
false): string
292 $ilUser = $this->user;
294 self::$accordion_cnt++;
300 $width = (
int) $this->getContentWidth();
301 $height = (
int) $this->getContentHeight();
311 $this->addJavascript();
314 $tpl =
new ilTemplate(
"tpl.accordion.html",
true,
true,
"components/ILIAS/Accordion");
315 foreach ($this->getItems() as $item) {
316 $tpl->setCurrentBlock(
"item");
317 $tpl->setVariable(
"HEADER", $item[
"header"]);
318 $tpl->setVariable(
"CONTENT", $item[
"content"]);
319 $tpl->setVariable(
"HEADER_CLASS", $this->getHeaderClass()
320 ? $this->getHeaderClass() :
"il_" . $or_short .
"AccordionHead");
321 $tpl->setVariable(
"CONTENT_CLASS", $this->getContentClass()
322 ? $this->getContentClass() :
"il_" . $or_short .
"AccordionContent");
324 if ($this->getBehaviour() != self::FORCE_ALL_OPEN) {
325 $tpl->setVariable(
"HIDE_CONTENT_CLASS",
"ilAccHideContent");
328 $tpl->setVariable(
"OR_SHORT", $or_short);
330 $tpl->setVariable(
"INNER_CONTAINER_CLASS", $this->getInnerContainerClass()
331 ? $this->getInnerContainerClass() :
"il_" . $or_short .
"AccordionInnerContainer");
335 $tpl->setVariable(
"HEIGHT",
"height:" . $height .
"px;");
338 $tpl->setVariable(
"HHEIGHT",
"height:" . $height .
"px;");
340 $tpl->parseCurrentBlock();
343 $tpl->setVariable(
"CONTAINER_CLASS", $this->getContainerClass()
344 ? $this->getContainerClass() :
"il_" . $or_short .
"AccordionContainer");
346 $options[
"orientation"] = $this->getOrientation();
349 if ($this->getUseSessionStorage() && $this->
getId() !=
"") {
352 $ctab = $stor->getProperty(
357 $ctab_arr = explode(
";", $ctab);
359 foreach ($this->force_open as $fo) {
360 if (!in_array($fo, $ctab_arr)) {
364 $ctab = implode(
";", $ctab_arr);
371 $options[
"save_url"] =
"./ilias.php?baseClass=ilaccordionpropertiesstoragegui&cmd=setOpenedTab" .
372 "&accordion_id=" . $this->
getId() .
"&user_id=" . $ilUser->getId();
375 $options[
"behaviour"] = $this->getBehaviour();
377 $options[
"toggle_class"] =
'il_HAccordionToggleDef';
378 $options[
"toggle_act_class"] =
'il_HAccordionToggleActiveDef';
379 $options[
"content_class"] =
'il_HAccordionContentDef';
381 $options[
"toggle_class"] =
'il_VAccordionToggleDef';
382 $options[
"toggle_act_class"] =
'il_VAccordionToggleActiveDef';
383 $options[
"content_class"] =
'il_VAccordionContentDef';
393 $tpl->setVariable(
"CWIDTH",
'style="width:' . $width .
'px;"');
396 if ($this->head_class_set) {
397 $options[
"active_head_class"] = $this->getActiveHeaderClass();
400 $options[
"active_head_class"] =
"il_HAccordionHeadActive";
402 $options[
"active_head_class"] =
"il_VAccordionHeadActive";
407 $options[
"id"] =
'accordion_' . $this->
getId() .
'_' . self::$accordion_cnt;
408 $options[
"multi"] = (bool) $this->getAllowMultiOpened();
409 $options[
"show_all_element"] = $this->getShowAllElement();
410 $options[
"hide_all_element"] = $this->getHideAllElement();
412 $tpl->setVariable(
"ACC_ID",
$options[
"id"]);
415 $code = $this->getOnloadCode(
$options);
417 $this->main_tpl->addOnLoadCode($code);
419 $html .=
"<script>$code</script>";
426 return 'il.Accordion.add(' . json_encode(
$options, JSON_THROW_ON_ERROR) .
');';
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContentClass(string $a_contentclass)
setContentWidth(?int $a_contentwidth)
setShowAllElement(string $a_val)
setContentHeight(?int $a_contentheight)
setContainerClass(string $a_containerclass)
setActiveHeaderClass(string $a_h_class)
getOnloadCode(array $options)
setUseSessionStorage(bool $a_val)
setOrientation(string $a_orientation)
string $active_headerclass
static string $owl_css_path
addItem(string $a_header, string $a_content, bool $a_force_open=false)
getHTML(bool $async=false)
setInnerContainerClass(string $a_containerclass)
static string $owl_js_path
static int $accordion_cnt
bool $use_session_storage
setAllowMultiOpened(bool $a_val)
setHideAllElement(string $a_val)
setBehaviour(string $a_val)
Set behaviour "ForceAllOpen" | "FirstOpen" | "AllClosed".
static addCss()
Add required css.
setHeaderClass(string $a_headerclass)
static getLocalJavascriptFiles()
static getLocalCssFiles()
static addJavaScript(?ilGlobalTemplate $main_tpl=null)
Add javascript files that are necessary to run accordion.
ilGlobalTemplateInterface $main_tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
special template class to simplify handling of ITX/PEAR