ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
class.ilPCTabs.php
Go to the documentation of this file.
1<?php
2
25{
26 public const ACCORDION_HOR = "HorizontalAccordion";
27 public const ACCORDION_VER = "VerticalAccordion";
28 public const CAROUSEL = "Carousel";
29
30 public function init(): void
31 {
32 $this->setType("tabs");
33 }
34
35 public function create(
36 ilPageObject $a_pg_obj,
37 string $a_hier_id,
38 string $a_pc_id = ""
39 ): void {
40 $this->createInitialChildNode($a_hier_id, $a_pc_id, "Tabs");
41 }
42
43 protected function setTabsAttribute(
44 string $a_attr,
45 string $a_value
46 ): void {
47 $this->dom_util->setAttribute($this->getChildNode(), $a_attr, $a_value);
48 }
49
53 public function setTabType(
54 string $a_type = "HorizontalTabs"
55 ): void {
56 switch ($a_type) {
60 $this->setTabsAttribute("Type", $a_type);
61 break;
62 }
63 }
64
65 public function getTabType(): string
66 {
67 return $this->getChildNode()->getAttribute("Type");
68 }
69
70 public function setContentWidth(string $a_val): void
71 {
72 $this->setTabsAttribute("ContentWidth", $a_val);
73 }
74
75 public function getContentWidth(): string
76 {
77 return $this->getChildNode()->getAttribute("ContentWidth");
78 }
79
80 public function setContentHeight(string $a_val): void
81 {
82 $this->setTabsAttribute("ContentHeight", $a_val);
83 }
84
85 public function getContentHeight(): string
86 {
87 return $this->getChildNode()->getAttribute("ContentHeight");
88 }
89
90 public function setHorizontalAlign(string $a_val): void
91 {
92 $this->setTabsAttribute("HorizontalAlign", $a_val);
93 }
94
95 public function getHorizontalAlign(): string
96 {
97 return $this->getChildNode()->getAttribute("HorizontalAlign");
98 }
99
100 public function setBehavior(string $a_val): void
101 {
102 $this->setTabsAttribute("Behavior", $a_val);
103 }
104
105 public function getBehavior(): string
106 {
107 return $this->getChildNode()->getAttribute("Behavior");
108 }
109
110 public function getCaptions(): array
111 {
112 $captions = array();
113 $k = 0;
114 foreach ($this->getChildNode()->childNodes as $child) {
115 if ($child->nodeName == "Tab") {
116 $pc_id = $child->getAttribute("PCID");
117 $hier_id = $child->getAttribute("HierId");
118 $current_caption = "";
119 foreach ($child->childNodes as $tab_child) {
120 if ($tab_child->nodeName == "TabCaption") {
121 $current_caption = $this->dom_util->getContent($tab_child);
122 }
123 }
124 $captions[] = array("pos" => $k,
125 "caption" => $current_caption,
126 "pc_id" => $pc_id,
127 "hier_id" => $hier_id
128 );
129 $k++;
130 }
131 }
132
133 return $captions;
134 }
135
136 public function getCaption(
137 string $a_hier_id,
138 string $a_pc_id
139 ): string {
140 foreach ($this->getCaptions() as $cap) {
141 if ($cap["pc_id"] === $a_pc_id && $cap["hier_id"] === $a_hier_id) {
142 return $cap["caption"];
143 }
144 }
145 return "";
146 }
147
151 public function savePositions(
152 array $a_pos
153 ): void {
154 asort($a_pos);
155
156 // File Item
157 $nodes = array();
158 foreach ($this->getChildNode()->childNodes as $child) {
159 if ($child->nodeName == "Tab") {
160 $pc_id = $child->getAttribute("PCID");
161 $hier_id = $child->getAttribute("HierId");
162 $nodes[$hier_id . ":" . $pc_id] = $child;
163 }
164 }
165 $this->dom_util->deleteAllChildsByName($this->getChildNode(), ["Tab"]);
166
167 foreach ($a_pos as $k => $v) {
168 if (is_object($nodes[$k])) {
169 $nodes[$k] = $this->getChildNode()->appendChild($nodes[$k]);
170 }
171 }
172 }
173
174 public function saveCaptions(array $a_captions): void
175 {
176 // iterate all tab nodes
177 foreach ($this->getChildNode()->childNodes as $child) {
178 if ($child->nodeName == "Tab") {
179 $pc_id = $child->getAttribute("PCID");
180 $hier_id = $child->getAttribute("HierId");
181 $k = $hier_id . ":" . $pc_id;
182 // if caption given, set it, otherwise delete caption subitem
183 if ($a_captions[$k] != "") {
184 $this->dom_util->setFirstOptionalElement(
185 $child,
186 "TabCaption",
187 array(),
188 $a_captions[$k],
189 array()
190 );
191 } else {
192 $this->dom_util->deleteAllChildsByName($child, array("TabCaption"));
193 }
194 }
195 }
196 }
197
198 public function deleteTab(
199 string $a_hier_id,
200 string $a_pc_id
201 ): void {
202 // File Item
203 foreach ($this->getChildNode()->childNodes as $child) {
204 if ($child->nodeName == "Tab") {
205 if ($a_pc_id == $child->getAttribute("PCID") &&
206 $a_hier_id == $child->getAttribute("HierId")) {
207 $child->parentNode->removeChild($child);
208 }
209 }
210 }
211 }
212
213 public function addTab(string $a_caption): void
214 {
215 $new_item = $this->dom_doc->createElement("Tab");
216 $new_item = $this->getChildNode()->appendChild($new_item);
217 $this->dom_util->setFirstOptionalElement(
218 $new_item,
219 "TabCaption",
220 array(),
221 $a_caption,
222 array()
223 );
224 }
225
226 public function setTemplate(string $a_template): void
227 {
228 $this->setTabsAttribute("Template", $a_template);
229 }
230
231 public function getTemplate(): string
232 {
233 return $this->getChildNode()->getAttribute("Template");
234 }
235
236 public static function getLangVars(): array
237 {
238 return array("pc_vacc", "pc_hacc", "pc_carousel");
239 }
240
241 public function setAutoTime(?int $a_val): void
242 {
243 $this->setTabsAttribute("AutoAnimWait", (string) $a_val);
244 }
245
246 public function getAutoTime(): ?int
247 {
248 $val = $this->getChildNode()->getAttribute("AutoAnimWait");
249 if ($val) {
250 return (int) $val;
251 }
252 return null;
253 }
254
255 public function setRandomStart(bool $a_val): void
256 {
257 $this->setTabsAttribute("RandomStart", $a_val);
258 }
259
260 public function getRandomStart(): bool
261 {
262 return (bool) $this->getChildNode()->getAttribute("RandomStart");
263 }
264
265 public function getJavascriptFiles(string $a_mode): array
266 {
268 if ($a_mode !== "edit") {
269 $files[] = "./components/ILIAS/COPage/PC/Tabs/js/presentation.js";
270 }
271 return $files;
272 }
273
274 public function getCssFiles(string $a_mode): array
275 {
277 }
278
279 public function saveCaption(string $pc_id, string $caption): void
280 {
281 $tab_nodes = $this->getChildNode()->childNodes;
282 foreach ($tab_nodes as $tab_node) {
283 if ($tab_node->nodeName === "Tab") {
284 $current_pc_id = $tab_node->getAttribute("PCID");
285 if ($current_pc_id === $pc_id) {
286 if ($caption !== "") {
287 $this->dom_util->setFirstOptionalElement(
288 $tab_node,
289 "TabCaption",
290 [],
291 $caption,
292 []
293 );
294 } else {
295 $this->dom_util->deleteAllChildsByName($tab_node, ["TabCaption"]);
296 }
297 }
298 }
299 }
300 }
301
302 public function addAbove(string $pc_id, string $caption = ""): void
303 {
304 $dom = $this->getPage()->getDomDoc();
305 $new_tab = $dom->createElement("Tab");
306 $tab = $this->getPage()->getDomNodeForPCId($pc_id);
307 if (!is_null($tab)) {
308 $new_tab = $tab->parentNode->insertBefore($new_tab, $tab);
309 if ($caption !== "") {
310 $dom_util = $this->domain->domUtil();
311 $dom_util->setFirstOptionalElement(
312 $new_tab,
313 "TabCaption",
314 array(),
315 $caption,
316 array()
317 );
318 }
319 }
320 }
321
322 public function addBelow(string $pc_id, string $caption = ""): void
323 {
324 $dom = $this->getPage()->getDomDoc();
325 $new_tab = $dom->createElement("Tab");
326 $tab = $this->getPage()->getDomNodeForPCId($pc_id);
327 if (!is_null($tab)) {
328 if ($next = $tab->nextSibling) {
329 $new_tab = $next->parentNode->insertBefore($new_tab, $next);
330 } else {
331 $new_tab = $tab->parentNode->appendChild($new_tab);
332 }
333
334 if ($caption !== "") {
335 $dom_util = $this->domain->domUtil();
336 $dom_util->setFirstOptionalElement(
337 $new_tab,
338 "TabCaption",
339 array(),
340 $caption,
341 array()
342 );
343 }
344 }
345 }
346
347 public function moveUp(string $pc_id): void
348 {
349 $dom = $this->getPage()->getDomDoc();
350 $new_tab = $dom->createElement("Tab");
351 $tab = $this->getPage()->getDomNodeForPCId($pc_id);
352 if (!is_null($tab)) {
353 $prev = $tab->previousSibling;
354 if ($prev) {
355 $tab->parentNode->removeChild($tab);
356 $tab = $prev->parentNode->insertBefore($tab, $prev);
357 }
358 }
359 }
360
361 public function moveDown(string $pc_id): void
362 {
363 $dom = $this->getPage()->getDomDoc();
364 $new_tab = $dom->createElement("Tab");
365 $tab = $this->getPage()->getDomNodeForPCId($pc_id);
366 if (!is_null($tab)) {
367 $next = $tab->nextSibling;
368 if ($next) {
369 $next2 = $next->nextSibling;
370 $tab->parentNode->removeChild($tab);
371 if ($next2) {
372 $tab = $next2->parentNode->insertBefore($tab, $next2);
373 } else {
374 $tab = $next->parentNode->appendChild($tab);
375 }
376 }
377 }
378 }
379
380 public function moveTop(string $pc_id): void
381 {
382 $dom = $this->getPage()->getDomDoc();
383 $new_tab = $dom->createElement("Tab");
384 $tab = $this->getPage()->getDomNodeForPCId($pc_id);
385 if (!is_null($tab)) {
386 $prev = $tab->previousSibling;
387 if ($prev) {
388 $tab->parentNode->removeChild($tab);
389 $first = $prev->parentNode->childNodes->item(0);
390 $tab = $prev->parentNode->insertBefore($tab, $first);
391 }
392 }
393 }
394
395 public function moveBottom(string $pc_id): void
396 {
397 $dom = $this->getPage()->getDomDoc();
398 $new_tab = $dom->createElement("Tab");
399 $tab = $this->getPage()->getDomNodeForPCId($pc_id);
400 if (!is_null($tab)) {
401 $next = $tab->nextSibling;
402 if ($next) {
403 $tab->parentNode->removeChild($tab);
404 $tab = $next->parentNode->appendChild($tab);
405 }
406 }
407 }
408
409 public function deletePanel(string $pc_id): void
410 {
411 $dom = $this->getPage()->getDomDoc();
412 $new_tab = $dom->createElement("Tab");
413 $tab = $this->getPage()->getDomNodeForPCId($pc_id);
414 if (!is_null($tab)) {
415 $tab->parentNode->removeChild($tab);
416 }
417 }
418
419 public function getNodeXml(string $pc_id): string
420 {
421 $tab = $this->getPage()->getDomNodeForPCId($pc_id);
422 if (!is_null($tab)) {
423 $xml = "";
424 foreach ($tab->childNodes as $node) {
425 if ($node->nodeName === "PageContent") {
426 $xml .= $node->ownerDocument->saveXml($node);
427 }
428 }
429 return $xml;
430 }
431 return "";
432 }
433}
static getLocalJavascriptFiles()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CAROUSEL
getJavascriptFiles(string $a_mode)
moveBottom(string $pc_id)
const ACCORDION_HOR
setBehavior(string $a_val)
setTabType(string $a_type="HorizontalTabs")
getNodeXml(string $pc_id)
saveCaption(string $pc_id, string $caption)
addBelow(string $pc_id, string $caption="")
deleteTab(string $a_hier_id, string $a_pc_id)
getCssFiles(string $a_mode)
moveDown(string $pc_id)
addAbove(string $pc_id, string $caption="")
setTabsAttribute(string $a_attr, string $a_value)
const ACCORDION_VER
addTab(string $a_caption)
static getLangVars()
Get lang vars needed for editing.
init()
Init object.
setRandomStart(bool $a_val)
setContentWidth(string $a_val)
saveCaptions(array $a_captions)
getHorizontalAlign()
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
setHorizontalAlign(string $a_val)
moveTop(string $pc_id)
getCaption(string $a_hier_id, string $a_pc_id)
deletePanel(string $pc_id)
moveUp(string $pc_id)
setAutoTime(?int $a_val)
savePositions(array $a_pos)
Save positions of tabs.
setContentHeight(string $a_val)
setTemplate(string $a_template)
Content object of ilPageObject (see ILIAS DTD).
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)