ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilPCTabs.php
Go to the documentation of this file.
1 <?php
2 
24 class ilPCTabs extends ilPageContent
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) {
59  case ilPCTabs::CAROUSEL:
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  }
269 
270  public function getCssFiles(string $a_mode): array
271  {
273  }
274 
275  public function saveCaption(string $pc_id, string $caption): void
276  {
277  $tab_nodes = $this->getChildNode()->childNodes;
278  foreach ($tab_nodes as $tab_node) {
279  if ($tab_node->nodeName === "Tab") {
280  $current_pc_id = $tab_node->getAttribute("PCID");
281  if ($current_pc_id === $pc_id) {
282  if ($caption !== "") {
283  $this->dom_util->setFirstOptionalElement(
284  $tab_node,
285  "TabCaption",
286  [],
287  $caption,
288  []
289  );
290  } else {
291  $this->dom_util->deleteAllChildsByName($tab_node, ["TabCaption"]);
292  }
293  }
294  }
295  }
296  }
297 
298  public function addAbove(string $pc_id, string $caption = ""): void
299  {
300  $dom = $this->getPage()->getDomDoc();
301  $new_tab = $dom->createElement("Tab");
302  $tab = $this->getPage()->getDomNodeForPCId($pc_id);
303  if (!is_null($tab)) {
304  $new_tab = $tab->parentNode->insertBefore($new_tab, $tab);
305  if ($caption !== "") {
306  $dom_util = $this->domain->domUtil();
307  $dom_util->setFirstOptionalElement(
308  $new_tab,
309  "TabCaption",
310  array(),
311  $caption,
312  array()
313  );
314  }
315  }
316  }
317 
318  public function addBelow(string $pc_id, string $caption = ""): void
319  {
320  $dom = $this->getPage()->getDomDoc();
321  $new_tab = $dom->createElement("Tab");
322  $tab = $this->getPage()->getDomNodeForPCId($pc_id);
323  if (!is_null($tab)) {
324  if ($next = $tab->nextSibling) {
325  $new_tab = $next->parentNode->insertBefore($new_tab, $next);
326  } else {
327  $new_tab = $tab->parentNode->appendChild($new_tab);
328  }
329 
330  if ($caption !== "") {
331  $dom_util = $this->domain->domUtil();
332  $dom_util->setFirstOptionalElement(
333  $new_tab,
334  "TabCaption",
335  array(),
336  $caption,
337  array()
338  );
339  }
340  }
341  }
342 
343  public function moveUp(string $pc_id): void
344  {
345  $dom = $this->getPage()->getDomDoc();
346  $new_tab = $dom->createElement("Tab");
347  $tab = $this->getPage()->getDomNodeForPCId($pc_id);
348  if (!is_null($tab)) {
349  $prev = $tab->previousSibling;
350  if ($prev) {
351  $tab->parentNode->removeChild($tab);
352  $tab = $prev->parentNode->insertBefore($tab, $prev);
353  }
354  }
355  }
356 
357  public function moveDown(string $pc_id): void
358  {
359  $dom = $this->getPage()->getDomDoc();
360  $new_tab = $dom->createElement("Tab");
361  $tab = $this->getPage()->getDomNodeForPCId($pc_id);
362  if (!is_null($tab)) {
363  $next = $tab->nextSibling;
364  if ($next) {
365  $next2 = $next->nextSibling;
366  $tab->parentNode->removeChild($tab);
367  if ($next2) {
368  $tab = $next2->parentNode->insertBefore($tab, $next2);
369  } else {
370  $tab = $next->parentNode->appendChild($tab);
371  }
372  }
373  }
374  }
375 
376  public function moveTop(string $pc_id): void
377  {
378  $dom = $this->getPage()->getDomDoc();
379  $new_tab = $dom->createElement("Tab");
380  $tab = $this->getPage()->getDomNodeForPCId($pc_id);
381  if (!is_null($tab)) {
382  $prev = $tab->previousSibling;
383  if ($prev) {
384  $tab->parentNode->removeChild($tab);
385  $first = $prev->parentNode->childNodes->item(0);
386  $tab = $prev->parentNode->insertBefore($tab, $first);
387  }
388  }
389  }
390 
391  public function moveBottom(string $pc_id): void
392  {
393  $dom = $this->getPage()->getDomDoc();
394  $new_tab = $dom->createElement("Tab");
395  $tab = $this->getPage()->getDomNodeForPCId($pc_id);
396  if (!is_null($tab)) {
397  $next = $tab->nextSibling;
398  if ($next) {
399  $tab->parentNode->removeChild($tab);
400  $tab = $next->parentNode->appendChild($tab);
401  }
402  }
403  }
404 
405  public function deletePanel(string $pc_id): void
406  {
407  $dom = $this->getPage()->getDomDoc();
408  $new_tab = $dom->createElement("Tab");
409  $tab = $this->getPage()->getDomNodeForPCId($pc_id);
410  if (!is_null($tab)) {
411  $tab->parentNode->removeChild($tab);
412  }
413  }
414 
415  public function getNodeXml(string $pc_id): string
416  {
417  $tab = $this->getPage()->getDomNodeForPCId($pc_id);
418  if (!is_null($tab)) {
419  $xml = "";
420  foreach ($tab->childNodes as $node) {
421  if ($node->nodeName === "PageContent") {
422  $xml .= $node->ownerDocument->saveXml($node);
423  }
424  }
425  return $xml;
426  }
427  return "";
428  }
429 
430  public function modifyPageContentPostXsl(
431  string $a_output,
432  string $a_mode,
433  bool $a_abstract_only = false
434  ): string {
435  $debug = "";
436  //$debug = ".";
437  if ($a_mode !== "edit") {
438  $a_output .= '<script type="module" src="' . $debug . './components/ILIAS/COPage/PC/Tabs/js/presentation.js"></script>';
439  }
440  return $a_output;
441  }
442 
443 }
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
setTabType(string $a_type="HorizontalTabs")
savePositions(array $a_pos)
Save positions of tabs.
saveCaption(string $pc_id, string $caption)
setType(string $a_type)
Set Type.
addAbove(string $pc_id, string $caption="")
getJavascriptFiles(string $a_mode)
static getLangVars()
getCssFiles(string $a_mode)
setContentHeight(string $a_val)
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
setRandomStart(bool $a_val)
setTemplate(string $a_template)
setBehavior(string $a_val)
setContentWidth(string $a_val)
deleteTab(string $a_hier_id, string $a_pc_id)
Content object of ilPageObject (see ILIAS DTD).
moveBottom(string $pc_id)
moveUp(string $pc_id)
static getLocalJavascriptFiles()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const ACCORDION_HOR
getCaption(string $a_hier_id, string $a_pc_id)
moveTop(string $pc_id)
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
setTabsAttribute(string $a_attr, string $a_value)
addBelow(string $pc_id, string $caption="")
const ACCORDION_VER
addTab(string $a_caption)
moveDown(string $pc_id)
setAutoTime(?int $a_val)
saveCaptions(array $a_captions)
getHorizontalAlign()
deletePanel(string $pc_id)
const CAROUSEL
ILIAS COPage Dom DomUtil $dom_util
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setHorizontalAlign(string $a_val)
getNodeXml(string $pc_id)
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])