ILIAS  release_8 Revision v8.24
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
31
32 public function init(): void
33 {
34 $this->setType("tabs");
35 }
36
37 public function setNode(php4DOMElement $a_node): void
38 {
39 parent::setNode($a_node); // this is the PageContent node
40 $this->tabs_node = $a_node->first_child(); // this is the Tabs node
41 }
42
43 public function create(
44 ilPageObject $a_pg_obj,
45 string $a_hier_id,
46 string $a_pc_id = ""
47 ): void {
48 $this->node = $this->createPageContentNode();
49 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
50 $this->tabs_node = $this->dom->create_element("Tabs");
51 $this->tabs_node = $this->node->append_child($this->tabs_node);
52 }
53
54 protected function setTabsAttribute(
55 string $a_attr,
56 string $a_value
57 ): void {
58 if (!empty($a_value)) {
59 $this->tabs_node->set_attribute($a_attr, $a_value);
60 } else {
61 if ($this->tabs_node->has_attribute($a_attr)) {
62 $this->tabs_node->remove_attribute($a_attr);
63 }
64 }
65 }
66
70 public function setTabType(
71 string $a_type = "HorizontalTabs"
72 ): void {
73 switch ($a_type) {
77 $this->tabs_node->set_attribute("Type", $a_type);
78 break;
79 }
80 }
81
82 public function getTabType(): string
83 {
84 return $this->tabs_node->get_attribute("Type");
85 }
86
87 public function setContentWidth(string $a_val): void
88 {
89 $this->setTabsAttribute("ContentWidth", $a_val);
90 }
91
92 public function getContentWidth(): string
93 {
94 return $this->tabs_node->get_attribute("ContentWidth");
95 }
96
97 public function setContentHeight(string $a_val): void
98 {
99 $this->setTabsAttribute("ContentHeight", $a_val);
100 }
101
102 public function getContentHeight(): string
103 {
104 return $this->tabs_node->get_attribute("ContentHeight");
105 }
106
107 public function setHorizontalAlign(string $a_val): void
108 {
109 $this->setTabsAttribute("HorizontalAlign", $a_val);
110 }
111
112 public function getHorizontalAlign(): string
113 {
114 return $this->tabs_node->get_attribute("HorizontalAlign");
115 }
116
117 public function setBehavior(string $a_val): void
118 {
119 $this->setTabsAttribute("Behavior", $a_val);
120 }
121
122 public function getBehavior(): string
123 {
124 return $this->tabs_node->get_attribute("Behavior");
125 }
126
127 public function getCaptions(): array
128 {
129 $captions = array();
130 $tab_nodes = $this->tabs_node->child_nodes();
131 $k = 0;
132 for ($i = 0; $i < count($tab_nodes); $i++) {
133 if ($tab_nodes[$i]->node_name() == "Tab") {
134 $pc_id = $tab_nodes[$i]->get_attribute("PCID");
135 $hier_id = $tab_nodes[$i]->get_attribute("HierId");
136
137 $tab_node_childs = $tab_nodes[$i]->child_nodes();
138 $current_caption = "";
139 for ($j = 0; $j < count($tab_node_childs); $j++) {
140 if ($tab_node_childs[$j]->node_name() == "TabCaption") {
141 $current_caption = $tab_node_childs[$j]->get_content();
142 }
143 }
144 $captions[] = array("pos" => $k,
145 "caption" => $current_caption, "pc_id" => $pc_id, "hier_id" => $hier_id);
146 $k++;
147 }
148 }
149
150 return $captions;
151 }
152
153 public function getCaption(
154 string $a_hier_id,
155 string $a_pc_id
156 ): string {
157 $tab_nodes = $this->tabs_node->child_nodes();
158 for ($i = 0; $i < count($tab_nodes); $i++) {
159 if ($tab_nodes[$i]->node_name() == "Tab") {
160 if ($a_pc_id == $tab_nodes[$i]->get_attribute("PCID") &&
161 ($a_hier_id == $tab_nodes[$i]->get_attribute("HierId"))) {
162 $tab_node_childs = $tab_nodes[$i]->child_nodes();
163 for ($j = 0; $j < count($tab_node_childs); $j++) {
164 if ($tab_node_childs[$j]->node_name() == "TabCaption") {
165 return $tab_node_childs[$j]->get_content();
166 }
167 }
168 }
169 }
170 }
171
172 return "";
173 }
174
178 public function savePositions(
179 array $a_pos
180 ): void {
181 asort($a_pos);
182
183 // File Item
184 $childs = $this->tabs_node->child_nodes();
185 $nodes = array();
186 for ($i = 0; $i < count($childs); $i++) {
187 if ($childs[$i]->node_name() == "Tab") {
188 $pc_id = $childs[$i]->get_attribute("PCID");
189 $hier_id = $childs[$i]->get_attribute("HierId");
190 $nodes[$hier_id . ":" . $pc_id] = $childs[$i];
191 $childs[$i]->unlink($childs[$i]);
192 }
193 }
194
195 foreach ($a_pos as $k => $v) {
196 if (is_object($nodes[$k])) {
197 $nodes[$k] = $this->tabs_node->append_child($nodes[$k]);
198 }
199 }
200 }
201
202 public function saveCaptions(array $a_captions): void
203 {
204 // iterate all tab nodes
205 $tab_nodes = $this->tabs_node->child_nodes();
206 for ($i = 0; $i < count($tab_nodes); $i++) {
207 if ($tab_nodes[$i]->node_name() == "Tab") {
208 $pc_id = $tab_nodes[$i]->get_attribute("PCID");
209 $hier_id = $tab_nodes[$i]->get_attribute("HierId");
210 $k = $hier_id . ":" . $pc_id;
211 // if caption given, set it, otherwise delete caption subitem
212 if ($a_captions[$k] != "") {
214 $this->dom,
215 $tab_nodes[$i],
216 "TabCaption",
217 array(),
218 $a_captions[$k],
219 array()
220 );
221 } else {
222 ilDOMUtil::deleteAllChildsByName($tab_nodes[$i], array("TabCaption"));
223 }
224 }
225 }
226 }
227
228 public function deleteTab(
229 string $a_hier_id,
230 string $a_pc_id
231 ): void {
232 // File Item
233 $childs = $this->tabs_node->child_nodes();
234 $nodes = array();
235 for ($i = 0; $i < count($childs); $i++) {
236 if ($childs[$i]->node_name() == "Tab") {
237 if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
238 $a_hier_id == $childs[$i]->get_attribute("HierId")) {
239 $childs[$i]->unlink($childs[$i]);
240 }
241 }
242 }
243 }
244
245 public function addTab(string $a_caption): void
246 {
247 $new_item = $this->dom->create_element("Tab");
248 $new_item = $this->tabs_node->append_child($new_item);
250 $this->dom,
251 $new_item,
252 "TabCaption",
253 array(),
254 $a_caption,
255 array()
256 );
257 }
258
259 public function setTemplate(string $a_template): void
260 {
261 $this->setTabsAttribute("Template", $a_template);
262 }
263
264 public function getTemplate(): string
265 {
266 return $this->tabs_node->get_attribute("Template");
267 }
268
269 public static function getLangVars(): array
270 {
271 return array("pc_vacc", "pc_hacc", "pc_carousel");
272 }
273
274 public function setAutoTime(?int $a_val): void
275 {
276 $this->setTabsAttribute("AutoAnimWait", (string) $a_val);
277 }
278
279 public function getAutoTime(): ?int
280 {
281 $val = $this->tabs_node->get_attribute("AutoAnimWait");
282 if ($val) {
283 return (int) $val;
284 }
285 return null;
286 }
287
288 public function setRandomStart(bool $a_val): void
289 {
290 $this->setTabsAttribute("RandomStart", $a_val);
291 }
292
293 public function getRandomStart(): bool
294 {
295 return (bool) $this->tabs_node->get_attribute("RandomStart");
296 }
297
298 public function getJavascriptFiles(string $a_mode): array
299 {
301 }
302
303 public function getCssFiles(string $a_mode): array
304 {
306 }
307}
const IL_INSERT_AFTER
static getLocalJavascriptFiles()
static deleteAllChildsByName(php4DOMElement $a_parent, array $a_node_names)
delete all childs of a node by names in $a_node_names
static setFirstOptionalElement(php4DOMDocument $doc, php4DOMElement $parent_node, string $a_node_name, array $a_successors, string $a_content, array $a_attributes, bool $a_remove_childs=true)
searches for an element $a_node_name within the childs of $parent_node if no node is found,...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CAROUSEL
getJavascriptFiles(string $a_mode)
const ACCORDION_HOR
setBehavior(string $a_val)
setTabType(string $a_type="HorizontalTabs")
php4DOMElement $tabs_node
deleteTab(string $a_hier_id, string $a_pc_id)
getCssFiles(string $a_mode)
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)
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
setHorizontalAlign(string $a_val)
setNode(php4DOMElement $a_node)
Set xml node of page content.
getCaption(string $a_hier_id, string $a_pc_id)
setAutoTime(?int $a_val)
savePositions(array $a_pos)
Save positions of tabs.
setContentHeight(string $a_val)
setTemplate(string $a_template)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
$i
Definition: metadata.php:41