ILIAS  release_8 Revision v8.24
class.ilPCTabsGUI.php
Go to the documentation of this file.
1<?php
2
24{
26 protected ilDBInterface $db;
27 protected ilTabsGUI $tabs;
29
30 public function __construct(
31 ilPageObject $a_pg_obj,
32 ?ilPageContent $a_content_obj,
33 string $a_hier_id,
34 string $a_pc_id = ""
35 ) {
36 global $DIC;
37
38 $this->tpl = $DIC["tpl"];
39 $this->ctrl = $DIC->ctrl();
40 $this->lng = $DIC->language();
41 $this->db = $DIC->database();
42 $this->tabs = $DIC->tabs();
43 $this->toolbar = $DIC->toolbar();
44 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
45 }
46
47 public function executeCommand(): void
48 {
49 // get next class that processes or forwards current command
50 $next_class = $this->ctrl->getNextClass($this);
51
52 // get current command
53 $cmd = $this->ctrl->getCmd();
54
55 switch ($next_class) {
56 default:
57 $this->$cmd();
58 break;
59 }
60 }
61
65 public function insert(
66 bool $a_omit_form_init = false
67 ): void {
68 $tpl = $this->tpl;
69
71
72 if (!$a_omit_form_init) {
73 $this->initForm("create");
74 }
75 $html = $this->form->getHTML();
76 $tpl->setContent($html);
77 }
78
79 public function editProperties(bool $init_form = true): void
80 {
82
83 $this->displayValidationError();
84 $this->setTabs();
85
86 if ($init_form) {
87 $this->initForm();
88 $this->getFormValues();
89 }
90 $html = $this->form->getHTML();
91 $tpl->setContent($html);
92 }
93
94 public function initForm(
95 string $a_mode = "edit"
96 ): void {
97 $ilCtrl = $this->ctrl;
99
101
102 // edit form
103 $this->form = new ilPropertyFormGUI();
104 $this->form->setFormAction($ilCtrl->getFormAction($this));
105 if ($a_mode != "edit") {
106 $this->form->setTitle($lng->txt("cont_ed_insert_tabs"));
107 } else {
108 $this->form->setTitle($lng->txt("cont_edit_tabs"));
109 }
110
111
112 // type selection
113 $radg = new ilRadioGroupInputGUI($lng->txt("cont_type"), "type");
114 $radg->setValue(ilPCTabs::ACCORDION_VER);
115
116 // type: vertical accordion
117 $op1 = new ilRadioOption($lng->txt("cont_tabs_acc_ver"), ilPCTabs::ACCORDION_VER);
118
119 $templ = $this->getTemplateOptions("vaccordion");
120 if (count($templ) > 0) {
121 $vchar_prop = new ilAdvSelectInputGUI(
122 $this->lng->txt("cont_characteristic"),
123 "vaccord_templ"
124 );
125 foreach ($templ as $k => $te) {
126 $t = explode(":", $k);
127 $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both" class="small">' . $te . "</div>";
128 $vchar_prop->addOption($k, $te, $html);
129 if ($t[2] == "VerticalAccordion") {
130 $vchar_prop->setValue($k);
131 }
132 }
133 $op1->addSubItem($vchar_prop);
134 } else {
135 $vchar_prop = new ilHiddenInputGUI("vaccord_templ");
136 $this->form->addItem($vchar_prop);
137 }
138 $radg->addOption($op1);
139
140
141
142 // type: horizontal accordion
143 $op2 = new ilRadioOption($lng->txt("cont_tabs_acc_hor"), ilPCTabs::ACCORDION_HOR);
144
145 $templ = $this->getTemplateOptions("haccordion");
146 if (count($templ) > 0) {
147 $hchar_prop = new ilAdvSelectInputGUI(
148 $this->lng->txt("cont_characteristic"),
149 "haccord_templ"
150 );
151 foreach ($templ as $k => $te) {
152 $t = explode(":", $k);
153 $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both" class="small">' . $te . "</div>";
154 $hchar_prop->addOption($k, $te, $html);
155 if ($t[2] == "HorizontalAccordion") {
156 $hchar_prop->setValue($k);
157 }
158 }
159 $op2->addSubItem($hchar_prop);
160 } else {
161 $hchar_prop = new ilHiddenInputGUI("haccord_templ");
162 $this->form->addItem($hchar_prop);
163 }
164
165 $radg->addOption($op2);
166
167 // type: carousel
168 $op3 = new ilRadioOption($lng->txt("cont_tabs_carousel"), ilPCTabs::CAROUSEL);
169 $templ = $this->getTemplateOptions("carousel");
170 if (count($templ) > 0) {
171 $cchar_prop = new ilAdvSelectInputGUI(
172 $this->lng->txt("cont_characteristic"),
173 "carousel_templ"
174 );
175 foreach ($templ as $k => $te) {
176 $t = explode(":", $k);
177 $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both" class="small">' . $te . "</div>";
178 $cchar_prop->addOption($k, $te, $html);
179 if ($t[2] == "Carousel") {
180 $cchar_prop->setValue($k);
181 }
182 }
183 $op3->addSubItem($cchar_prop);
184 } else {
185 $cchar_prop = new ilHiddenInputGUI("carousel_templ");
186 $this->form->addItem($cchar_prop);
187 }
188
189 $radg->addOption($op3);
190 $this->form->addItem($radg);
191
192
193 // number of initial tabs
194 if ($a_mode == "create") {
195 $nr_prop = new ilSelectInputGUI(
196 $lng->txt("cont_number_of_tabs"),
197 "nr"
198 );
199 $nrs = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6,
200 7 => 7, 8 => 8, 9 => 9, 10 => 10);
201 $nr_prop->setOptions($nrs);
202 $this->form->addItem($nr_prop);
203 }
204
205 $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_width"), "content_width");
206 $ni->setMaxLength(4);
207 $ni->setSize(4);
208 $this->form->addItem($ni);
209
210 $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_height"), "content_height");
211 $ni->setMaxLength(4);
212 $ni->setSize(4);
213 $this->form->addItem($ni);
214
215 // behaviour
216 $options = array(
217 "AllClosed" => $lng->txt("cont_all_closed"),
218 "FirstOpen" => $lng->txt("cont_first_open"),
219 "ForceAllOpen" => $lng->txt("cont_force_all_open"),
220 );
221 $si = new ilSelectInputGUI($this->lng->txt("cont_behavior"), "vbehavior");
222 $si->setOptions($options);
223 $op1->addSubItem($si);
224 $si = new ilSelectInputGUI($this->lng->txt("cont_behavior"), "hbehavior");
225 $si->setOptions($options);
226 $op2->addSubItem($si);
227
228
229 // alignment
230 $align_opts = array("Left" => $lng->txt("cont_left"),
231 "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
232 "LeftFloat" => $lng->txt("cont_left_float"),
233 "RightFloat" => $lng->txt("cont_right_float"));
234 $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "valign");
235 $align->setOptions($align_opts);
236 $align->setValue("Center");
237 //$align->setInfo($lng->txt("cont_tabs_hor_align_info"));
238 $op1->addSubItem($align);
239 $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "calign");
240 $align->setOptions($align_opts);
241 $align->setValue("Center");
242 $op3->addSubItem($align);
243
244 // carousel: time
245 $ti = new ilNumberInputGUI($this->lng->txt("cont_auto_time"), "auto_time");
246 $ti->setMaxLength(6);
247 $ti->setSize(6);
248 $ti->setSuffix("ms");
249 $ti->setMinValue(100);
250 $op3->addSubItem($ti);
251
252 // carousel: random start
253 $cb = new ilCheckboxInputGUI($this->lng->txt("cont_rand_start"), "rand_start");
254 //$cb->setOptionTitle($this->lng->txt(""));
255 //$cb->setInfo($this->lng->txt(""));
256 $op3->addSubItem($cb);
257
258
259 // save/cancel buttons
260 if ($a_mode == "create") {
261 $this->form->addCommandButton("create_section", $lng->txt("save"));
262 $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
263 } else {
264 $this->form->addCommandButton("update", $lng->txt("save"));
265 $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
266 }
267 }
268
269 public function getFormValues(): void
270 {
271 $values["type"] = $this->content_obj->getTabType();
272 $values["content_width"] = $this->content_obj->getContentWidth();
273 $values["content_height"] = $this->content_obj->getContentHeight();
274 $values["valign"] = $this->content_obj->getHorizontalAlign();
275 $values["calign"] = $this->content_obj->getHorizontalAlign();
276 $values["vbehavior"] = $this->content_obj->getBehavior();
277 $values["hbehavior"] = $this->content_obj->getBehavior();
278
279 $values["auto_time"] = $this->content_obj->getAutoTime();
280 $values["rand_start"] = $this->content_obj->getRandomStart();
281
282 $this->form->setValuesByArray($values);
283
284 if ($values["type"] == ilPCTabs::ACCORDION_VER) {
285 $va = $this->form->getItemByPostVar("vaccord_templ");
286 $v = "t:" .
287 ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
288 $this->content_obj->getTemplate();
289 $va->setValue($v);
290 }
291 if ($values["type"] == ilPCTabs::ACCORDION_HOR) {
292 $ha = $this->form->getItemByPostVar("haccord_templ");
293 $v = "t:" .
294 ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
295 $this->content_obj->getTemplate();
296 $ha->setValue($v);
297 }
298 if ($values["type"] == ilPCTabs::CAROUSEL) {
299 $ca = $this->form->getItemByPostVar("carousel_templ");
300 $v = "t:" .
301 ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
302 $this->content_obj->getTemplate();
303 $ca->setValue($v);
304 }
305 }
306
307 protected function checkWidthHeight(ilPropertyFormGUI $form): bool
308 {
309 $ok = true;
310 if ($form->getInput("type") === ilPCTabs::ACCORDION_HOR) {
311 if ($form->getInput("content_width") == "") {
312 $form->getItemByPostVar("content_width")
313 ->setAlert($this->lng->txt("cont_hacc_needs_width"));
314 $ok = false;
315 }
316 if ($form->getInput("content_height") == "") {
317 $form->getItemByPostVar("content_height")
318 ->setAlert($this->lng->txt("cont_hacc_needs_height"));
319 $ok = false;
320 }
321 }
322 return $ok;
323 }
324
325 public function create(): void
326 {
328
329 $this->initForm("create");
330 if ($this->form->checkInput() && $this->checkWidthHeight($this->form)) {
331 $this->content_obj = new ilPCTabs($this->getPage());
332 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
333
334 $this->setPropertiesByForm();
335
336 for ($i = 0; $i < $this->request->getInt("nr"); $i++) {
337 $this->content_obj->addTab($lng->txt("cont_new_tab"));
338 }
339
340 $this->updated = $this->pg_obj->update();
341
342 if ($this->updated === true) {
343 $this->afterCreation();
344 } else {
345 $this->insert();
346 }
347 } else {
348 $this->form->setValuesByPost();
349 $this->insert(true);
350 }
351 }
352
353 public function afterCreation(): void
354 {
355 $ilCtrl = $this->ctrl;
356
357 $this->pg_obj->stripHierIDs();
358 $this->pg_obj->addHierIDs();
359 $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
360 $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
361 $this->content_obj->setHierId($this->content_obj->readHierId());
362 $this->setHierId($this->content_obj->readHierId());
363 $this->content_obj->setPcId($this->content_obj->readPCId());
364 $this->edit();
365 }
366
367 public function setPropertiesByForm(): void
368 {
369 $c = $this->content_obj;
370 $f = $this->form;
371
372 $c->setTabType($f->getInput("type"));
373
374 $c->setContentWidth((string) $f->getInput("content_width"));
375 $c->setContentHeight((string) $f->getInput("content_height"));
376 $c->setTemplate("");
377 switch ($this->request->getString("type")) {
379 $t = explode(":", $f->getInput("vaccord_templ"));
380 $c->setTemplate($t[2] ?? "");
381 $c->setBehavior($f->getInput("vbehavior"));
382 $c->setHorizontalAlign($f->getInput("valign"));
383 break;
384
386 $t = explode(":", $f->getInput("haccord_templ"));
387 $c->setTemplate($t[2] ?? "");
388 $c->setBehavior($f->getInput("hbehavior"));
389 break;
390
392 $t = explode(":", $f->getInput("carousel_templ"));
393 $c->setTemplate($t[2] ?? "");
394 $c->setHorizontalAlign($f->getInput("calign"));
395 $c->setAutoTime($f->getInput("auto_time"));
396 $c->setRandomStart($f->getInput("rand_start"));
397 break;
398 }
399 }
400
401 public function update(): void
402 {
403 $this->initForm();
404 $this->updated = false;
405 if ($this->form->checkInput() && $this->checkWidthHeight($this->form)) {
406 $this->setPropertiesByForm();
407 $this->updated = $this->pg_obj->update();
408 } else {
409 $this->form->setValuesByPost();
410 $this->editProperties(false);
411 return;
412 }
413 if ($this->updated === true) {
414 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
415 $this->ctrl->redirect($this, "editProperties");
416 } else {
417 $this->pg_obj->addHierIDs();
418 $this->editProperties(false);
419 }
420 }
421
422 public function edit(): void
423 {
425 $ilTabs = $this->tabs;
426 $ilCtrl = $this->ctrl;
427 $ilToolbar = $this->toolbar;
429
430 $ilToolbar->addButton(
431 $lng->txt("cont_add_tab"),
432 $ilCtrl->getLinkTarget($this, "addTab")
433 );
434
435 $this->setTabs();
436 $ilTabs->activateTab("cont_tabs");
438 $tabs = $this->content_obj;
439 $table_gui = new ilPCTabsTableGUI($this, "edit", $tabs);
440 $tpl->setContent($table_gui->getHTML());
441 }
442
446 public function saveTabs(): void
447 {
448 $ilCtrl = $this->ctrl;
450
451 $captions = $this->request->getStringArray("caption");
452 $positions = $this->request->getStringArray("position");
453 if (count($captions) > 0) {
454 $this->content_obj->saveCaptions($captions);
455 }
456 if (count($positions)) {
457 $this->content_obj->savePositions($positions);
458 }
459 $this->updated = $this->pg_obj->update();
460 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
461 $ilCtrl->redirect($this, "edit");
462 }
463
467 public function addTab(): void
468 {
470 $ilCtrl = $this->ctrl;
471
472 $this->content_obj->addTab($lng->txt("cont_new_tab"));
473 $this->updated = $this->pg_obj->update();
474
475 $this->tpl->setOnScreenMessage('success', $lng->txt("cont_added_tab"), true);
476 $ilCtrl->redirect($this, "edit");
477 }
478
479 public function confirmTabsDeletion(): void
480 {
481 $ilCtrl = $this->ctrl;
484
485 $this->setTabs();
486
487 $tids = $this->request->getStringArray("tid");
488 if (count($tids) == 0) {
489 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
490 $ilCtrl->redirect($this, "edit");
491 } else {
492 $cgui = new ilConfirmationGUI();
493 $cgui->setFormAction($ilCtrl->getFormAction($this));
494 $cgui->setHeaderText($lng->txt("cont_tabs_confirm_deletion"));
495 $cgui->setCancel($lng->txt("cancel"), "cancelTabDeletion");
496 $cgui->setConfirm($lng->txt("delete"), "deleteTabs");
497
498 foreach ($tids as $k => $i) {
499 $id = explode(":", $k);
500 $cgui->addItem(
501 "tid[]",
502 $k,
503 $this->content_obj->getCaption($id[0], $id[1])
504 );
505 }
506
507 $tpl->setContent($cgui->getHTML());
508 }
509 }
510
511 public function cancelTabDeletion(): void
512 {
513 $ilCtrl = $this->ctrl;
514 $ilCtrl->redirect($this, "edit");
515 }
516
517 public function deleteTabs(): void
518 {
519 $ilCtrl = $this->ctrl;
520
521 $tids = $this->request->getStringArray("tid");
522 foreach ($tids as $tid) {
523 $ids = explode(":", $tid);
524 $this->content_obj->deleteTab($ids[0], $ids[1]);
525 }
526 $this->updated = $this->pg_obj->update();
527
528 $ilCtrl->redirect($this, "edit");
529 }
530
531 public function setTabs(): void
532 {
533 $ilTabs = $this->tabs;
534 $ilCtrl = $this->ctrl;
536
537 $ilTabs->setBackTarget(
538 $lng->txt("pg"),
539 $this->ctrl->getParentReturn($this)
540 );
541
542 $ilTabs->addTarget(
543 "cont_tabs",
544 $ilCtrl->getLinkTarget($this, "edit"),
545 "edit",
546 get_class($this)
547 );
548
549 $ilTabs->addTarget(
550 "cont_edit_tabs",
551 $ilCtrl->getLinkTarget($this, "editProperties"),
552 "editProperties",
553 get_class($this)
554 );
555 }
556}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static addCss()
Add required css.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a number property in a property form.
static _lookupTemplateIdByName(int $a_style_id, string $a_name)
Lookup table template preview.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
editProperties(bool $init_form=true)
insert(bool $a_omit_form_init=false)
Insert new tabs.
checkWidthHeight(ilPropertyFormGUI $form)
ilDBInterface $db
ilPropertyFormGUI $form
addTab()
Save tabs properties in db and return to page edit screen.
ilToolbarGUI $toolbar
initForm(string $a_mode="edit")
saveTabs()
Save tabs properties in db and return to page edit screen.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CAROUSEL
const ACCORDION_HOR
const ACCORDION_VER
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
setContent(string $a_html)
Sets content for standard template.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd)
$lng