ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCheckboxListOverlayGUI.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  protected ilLanguage $lng;
28  private array $items = array();
29  protected string $id;
30  protected string $link_title;
31  protected string $selectionheaderclass;
32  protected string $form_cmd;
33  protected string $field_var;
34  protected string $hidden_var;
35  protected \ilGlobalTemplateInterface $main_tpl;
36 
37  public function __construct(
38  string $a_id = ""
39  ) {
40  global $DIC;
41 
42  $this->lng = $DIC->language();
43  $this->setId($a_id);
44  $this->main_tpl = $DIC->ui()->mainTemplate();
45  }
46 
47  public function setId(string $a_val): void
48  {
49  $this->id = $a_val;
50  }
51 
52  public function getId(): string
53  {
54  return $this->id;
55  }
56 
57  public function setLinkTitle(string $a_val): void
58  {
59  $this->link_title = $a_val;
60  }
61 
62  public function getLinkTitle(): string
63  {
64  return $this->link_title;
65  }
66 
67  public function setItems(array $a_val): void
68  {
69  $this->items = $a_val;
70  }
71 
72  public function getItems(): array
73  {
74  return $this->items;
75  }
76 
77  public function setSelectionHeaderClass(
78  string $a_selectionheaderclass
79  ): void {
80  $this->selectionheaderclass = $a_selectionheaderclass;
81  }
82 
83  public function getSelectionHeaderClass(): string
84  {
86  }
87 
88  public function setFormCmd(string $a_val): void
89  {
90  $this->form_cmd = $a_val;
91  }
92 
93  public function getFormCmd(): string
94  {
95  return $this->form_cmd;
96  }
97 
98  public function setFieldVar(string $a_val): void
99  {
100  $this->field_var = $a_val;
101  }
102 
103  public function getFieldVar(): string
104  {
105  return $this->field_var;
106  }
107 
108  public function setHiddenVar(string $a_val): void
109  {
110  $this->hidden_var = $a_val;
111  }
112 
113  public function getHiddenVar(): string
114  {
115  return $this->hidden_var;
116  }
117 
118  public function getHTML(bool $pull_right = true): string
119  {
120  $lng = $this->lng;
121 
122  $items = $this->getItems();
123 
124  $tpl = new ilTemplate(
125  "tpl.checkbox_list_overlay.html",
126  true,
127  true,
128  "components/ILIAS/UIComponent/CheckboxListOverlay",
129  "DEFAULT",
130  false,
131  true
132  );
133 
134  $this->main_tpl->addOnLoadCode("
135  const o = document.getElementById('chkbxlstovl_{$this->getId()}');
136  o.addEventListener('click', (e) => {
137  e.stopPropagation();
138  });
139  let b;
140  const close = () => {
141  b.parentNode.classList.remove('open');
142  b.area_expanded = 'false';
143  document.removeEventListener('click', close);
144  }
145  const closeOnEscape = (e) => {
146  if (e.key === 'Escape') {
147  close();
148  document.removeEventListener('keydown', closeOnEscape);
149  }
150  }
151  o.previousElementSibling.addEventListener('click', (e) => {
152  e.stopPropagation();
153  b = e.target.closest('button');
154  if (b.parentNode.classList.contains('open')) {
155  close();
156  return;
157  }
158  b.parentNode.classList.add('open');
159  b.area_expanded = 'true';
160  document.body.click();
161  document.addEventListener('click', close);
162  document.addEventListener('keydown', closeOnEscape);
163  });
164  ");
165 
166  $tpl->touchBlock("top_img");
167 
168  // do not repeat title (accessibility) -> empty alt
169  $tpl->setVariable("TXT_SEL_TOP", $this->getLinkTitle());
170 
171  $tpl->parseCurrentBlock();
172 
173  reset($items);
174  $cnt = 0;
175  foreach ($items as $k => $v) {
176  $tpl->setCurrentBlock("list_entry");
177  $tpl->setVariable("VAR", $this->getFieldVar());
178  $tpl->setVariable("VAL_ENTRY", $k);
179  $tpl->setVariable("TXT_ENTRY", $v["txt"]);
180  $tpl->setVariable("IDX_ENTRY", ++$cnt);
181  if ($v["selected"]) {
182  $tpl->setVariable("CHECKED", "checked='checked'");
183  }
184  $tpl->parseCurrentBlock();
185  }
186 
187  if ($pull_right) {
188  $tpl->touchBlock("pr");
189  }
190 
191  $tpl->setVariable("ID", $this->getId());
192  $tpl->setVariable("HIDDEN_VAR", $this->getHiddenVar());
193  $tpl->setVariable("CMD_SUBMIT", $this->getFormCmd());
194  $tpl->setVariable("VAL_SUBMIT", $lng->txt("refresh"));
195  return $tpl->get();
196  }
197 }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setSelectionHeaderClass(string $a_selectionheaderclass)
global $DIC
Definition: shib_login.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...