ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPCTabsGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once("./Services/COPage/classes/class.ilPCTabs.php");
5require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
6
18{
22 protected $db;
23
27 protected $tabs;
28
32 protected $toolbar;
33
38 public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
39 {
40 global $DIC;
41
42 $this->tpl = $DIC["tpl"];
43 $this->ctrl = $DIC->ctrl();
44 $this->lng = $DIC->language();
45 $this->db = $DIC->database();
46 $this->tabs = $DIC->tabs();
47 $this->toolbar = $DIC->toolbar();
48 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
49 }
50
54 public function executeCommand()
55 {
56 // get next class that processes or forwards current command
57 $next_class = $this->ctrl->getNextClass($this);
58
59 // get current command
60 $cmd = $this->ctrl->getCmd();
61
62 switch ($next_class) {
63 default:
64 $ret = $this->$cmd();
65 break;
66 }
67
68 return $ret;
69 }
70
74 public function insert($a_omit_form_init = false)
75 {
77
79
80 if (!$a_omit_form_init) {
81 $this->initForm("create");
82 }
83 $html = $this->form->getHTML();
84 $tpl->setContent($html);
85 }
86
90 public function editProperties(bool $omit_form_init = false)
91 {
92 $ilCtrl = $this->ctrl;
95
97 $this->setTabs();
98
99 if (!$omit_form_init) {
100 $this->initForm();
101 $this->getFormValues();
102 }
103 $html = $this->form->getHTML();
104 $tpl->setContent($html);
105 }
106
110 public function initForm($a_mode = "edit")
111 {
112 $ilCtrl = $this->ctrl;
115
116 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
118
119 // edit form
120 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
121 $this->form = new ilPropertyFormGUI();
122 $this->form->setFormAction($ilCtrl->getFormAction($this));
123 if ($a_mode != "edit") {
124 $this->form->setTitle($lng->txt("cont_ed_insert_tabs"));
125 } else {
126 $this->form->setTitle($lng->txt("cont_edit_tabs"));
127 }
128
129
130 // type selection
131 $radg = new ilRadioGroupInputGUI($lng->txt("cont_type"), "type");
132 $radg->setValue(ilPCTabs::ACCORDION_VER);
133
134 // type: vertical accordion
135 $op1 = new ilRadioOption($lng->txt("cont_tabs_acc_ver"), ilPCTabs::ACCORDION_VER);
136
137 $templ = $this->getTemplateOptions("vaccordion");
138 require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
139 if (count($templ) > 0) {
140 $vchar_prop = new ilAdvSelectInputGUI(
141 $this->lng->txt("cont_characteristic"),
142 "vaccord_templ"
143 );
144 foreach ($templ as $k => $te) {
145 $t = explode(":", $k);
146 $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both" class="small">' . $te . "</div>";
147 $vchar_prop->addOption($k, $te, $html);
148 if ($t[2] == "VerticalAccordion") {
149 $vchar_prop->setValue($k);
150 }
151 }
152 $op1->addSubItem($vchar_prop);
153 } else {
154 $vchar_prop = new ilHiddenInputGUI("vaccord_templ");
155 $this->form->addItem($vchar_prop);
156 }
157 $radg->addOption($op1);
158
159
160
161 // type: horizontal accordion
162 $op2 = new ilRadioOption($lng->txt("cont_tabs_acc_hor"), ilPCTabs::ACCORDION_HOR);
163
164 $templ = $this->getTemplateOptions("haccordion");
165 if (count($templ) > 0) {
166 $hchar_prop = new ilAdvSelectInputGUI(
167 $this->lng->txt("cont_characteristic"),
168 "haccord_templ"
169 );
170 foreach ($templ as $k => $te) {
171 $t = explode(":", $k);
172 $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both" class="small">' . $te . "</div>";
173 $hchar_prop->addOption($k, $te, $html);
174 if ($t[2] == "HorizontalAccordion") {
175 $hchar_prop->setValue($k);
176 }
177 }
178 $op2->addSubItem($hchar_prop);
179 } else {
180 $hchar_prop = new ilHiddenInputGUI("haccord_templ");
181 $this->form->addItem($hchar_prop);
182 }
183
184 $radg->addOption($op2);
185
186 // type: carousel
187 $op3 = new ilRadioOption($lng->txt("cont_tabs_carousel"), ilPCTabs::CAROUSEL);
188 $templ = $this->getTemplateOptions("carousel");
189 require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
190 if (count($templ) > 0) {
191 $cchar_prop = new ilAdvSelectInputGUI(
192 $this->lng->txt("cont_characteristic"),
193 "carousel_templ"
194 );
195 foreach ($templ as $k => $te) {
196 $t = explode(":", $k);
197 $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both" class="small">' . $te . "</div>";
198 $cchar_prop->addOption($k, $te, $html);
199 if ($t[2] == "Carousel") {
200 $cchar_prop->setValue($k);
201 }
202 }
203 $op3->addSubItem($cchar_prop);
204 } else {
205 $cchar_prop = new ilHiddenInputGUI("carousel_templ");
206 $this->form->addItem($cchar_prop);
207 }
208
209 $radg->addOption($op3);
210 $this->form->addItem($radg);
211
212
213 // number of initial tabs
214 if ($a_mode == "create") {
215 $nr_prop = new ilSelectInputGUI(
216 $lng->txt("cont_number_of_tabs"),
217 "nr"
218 );
219 $nrs = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6,
220 7 => 7, 8 => 8, 9 => 9, 10 => 10);
221 $nr_prop->setOptions($nrs);
222 $this->form->addItem($nr_prop);
223 }
224
225 $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_width"), "content_width");
226 $ni->setMaxLength(4);
227 $ni->setSize(4);
228 $this->form->addItem($ni);
229
230 $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_height"), "content_height");
231 $ni->setMaxLength(4);
232 $ni->setSize(4);
233 $this->form->addItem($ni);
234
235 // behaviour
236 $options = array(
237 "AllClosed" => $lng->txt("cont_all_closed"),
238 "FirstOpen" => $lng->txt("cont_first_open"),
239 "ForceAllOpen" => $lng->txt("cont_force_all_open"),
240 );
241 $si = new ilSelectInputGUI($this->lng->txt("cont_behavior"), "vbehavior");
242 $si->setOptions($options);
243 $op1->addSubItem($si);
244 $si = new ilSelectInputGUI($this->lng->txt("cont_behavior"), "hbehavior");
245 $si->setOptions($options);
246 $op2->addSubItem($si);
247
248
249 // alignment
250 $align_opts = array("Left" => $lng->txt("cont_left"),
251 "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
252 "LeftFloat" => $lng->txt("cont_left_float"),
253 "RightFloat" => $lng->txt("cont_right_float"));
254 $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "valign");
255 $align->setOptions($align_opts);
256 $align->setValue("Center");
257 //$align->setInfo($lng->txt("cont_tabs_hor_align_info"));
258 $op1->addSubItem($align);
259 $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "calign");
260 $align->setOptions($align_opts);
261 $align->setValue("Center");
262 $op3->addSubItem($align);
263
264 // carousel: time
265 $ti = new ilNumberInputGUI($this->lng->txt("cont_auto_time"), "auto_time");
266 $ti->setMaxLength(6);
267 $ti->setSize(6);
268 $ti->setSuffix("ms");
269 $ti->setMinValue(100);
270 $op3->addSubItem($ti);
271
272 // carousel: random start
273 $cb = new ilCheckboxInputGUI($this->lng->txt("cont_rand_start"), "rand_start");
274 //$cb->setOptionTitle($this->lng->txt(""));
275 //$cb->setInfo($this->lng->txt(""));
276 $op3->addSubItem($cb);
277
278
279 // save/cancel buttons
280 if ($a_mode == "create") {
281 $this->form->addCommandButton("create_section", $lng->txt("save"));
282 $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
283 } else {
284 $this->form->addCommandButton("update", $lng->txt("save"));
285 $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
286 }
287 }
288
292 public function getFormValues()
293 {
294 $values["type"] = $this->content_obj->getTabType();
295 $values["content_width"] = $this->content_obj->getContentWidth();
296 $values["content_height"] = $this->content_obj->getContentHeight();
297 $values["valign"] = $this->content_obj->getHorizontalAlign();
298 $values["calign"] = $this->content_obj->getHorizontalAlign();
299 $values["vbehavior"] = $this->content_obj->getBehavior();
300 $values["hbehavior"] = $this->content_obj->getBehavior();
301
302 $values["auto_time"] = $this->content_obj->getAutoTime();
303 $values["rand_start"] = $this->content_obj->getRandomStart();
304
305 $this->form->setValuesByArray($values);
306
307 if ($values["type"] == ilPCTabs::ACCORDION_VER) {
308 $va = $this->form->getItemByPostVar("vaccord_templ");
309 $v = "t:" .
310 ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
311 $this->content_obj->getTemplate();
312 $va->setValue($v);
313 }
314 if ($values["type"] == ilPCTabs::ACCORDION_HOR) {
315 $ha = $this->form->getItemByPostVar("haccord_templ");
316 $v = "t:" .
317 ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
318 $this->content_obj->getTemplate();
319 $ha->setValue($v);
320 }
321 if ($values["type"] == ilPCTabs::CAROUSEL) {
322 $ca = $this->form->getItemByPostVar("carousel_templ");
323 $v = "t:" .
324 ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
325 $this->content_obj->getTemplate();
326 $ca->setValue($v);
327 }
328 }
329
330 protected function checkWidthHeight(ilPropertyFormGUI $form) : bool
331 {
332 $ok = true;
333 if ($form->getInput("type") === ilPCTabs::ACCORDION_HOR) {
334 if ($form->getInput("content_width") === "") {
335 $form->getItemByPostVar("content_width")
336 ->setAlert($this->lng->txt("cont_hacc_needs_width"));
337 $ok = false;
338 }
339 if ($form->getInput("content_height") === "") {
340 $form->getItemByPostVar("content_height")
341 ->setAlert($this->lng->txt("cont_hacc_needs_height"));
342 $ok = false;
343 }
344 }
345 return $ok;
346 }
347
351 public function create()
352 {
355
356 $this->initForm("create");
357 if ($this->form->checkInput() && $this->checkWidthHeight($this->form)) {
358 $this->content_obj = new ilPCTabs($this->getPage());
359 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
360
361 $this->setPropertiesByForm();
362
363 for ($i = 0; $i < (int) $_POST["nr"]; $i++) {
364 $this->content_obj->addTab($lng->txt("cont_new_tab"));
365 }
366
367 $this->updated = $this->pg_obj->update();
368
369 if ($this->updated === true) {
370 $this->afterCreation();
371 //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
372 } else {
373 $this->insert();
374 }
375 } else {
376 $this->form->setValuesByPost();
377 $this->insert(true);
378 // return $this->form->getHtml();
379 }
380 }
381
385 public function afterCreation()
386 {
387 $ilCtrl = $this->ctrl;
388
389 $this->pg_obj->stripHierIDs();
390 $this->pg_obj->addHierIDs();
391 $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
392 $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
393 $this->content_obj->setHierId($this->content_obj->readHierId());
394 $this->setHierId($this->content_obj->readHierId());
395 $this->content_obj->setPCId($this->content_obj->readPCId());
396 $this->edit();
397 }
398
405 public function setPropertiesByForm()
406 {
408 $f = $this->form;
409
410 $c->setTabType($f->getInput("type"));
411
412 $c->setContentWidth($f->getInput("content_width"));
413 $c->setContentHeight($f->getInput("content_height"));
414 $c->setTemplate("");
415 switch ($_POST["type"]) {
417 $t = explode(":", $f->getInput("vaccord_templ"));
418 $c->setTemplate($t[2]);
419 $c->setBehavior($f->getInput("vbehavior"));
420 $c->setHorizontalAlign($f->getInput("valign"));
421 break;
422
424 $t = explode(":", $f->getInput("haccord_templ"));
425 $c->setTemplate($t[2]);
426 $c->setBehavior($f->getInput("hbehavior"));
427 break;
428
430 $t = explode(":", $f->getInput("carousel_templ"));
431 $c->setTemplate($t[2]);
432 $c->setHorizontalAlign($f->getInput("calign"));
433 $c->setAutoTime($f->getInput("auto_time"));
434 $c->setRandomStart($f->getInput("rand_start"));
435 break;
436 }
437 }
438
439
443 public function update()
444 {
445 $this->initForm();
446 $this->updated = false;
447 if ($this->form->checkInput() && $this->checkWidthHeight($this->form)) {
448 $this->setPropertiesByForm();
449 $this->updated = $this->pg_obj->update();
450 } else {
451 $this->form->setValuesByPost();
452 $this->editProperties(true);
453 return;
454 }
455 if ($this->updated === true) {
456 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
457 $this->ctrl->redirect($this, "editProperties");
458 //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
459 } else {
460 $this->pg_obj->addHierIDs();
461 $this->editProperties();
462 }
463 }
464
465 //
466 // Edit Tabs
467 //
468
469
473 public function edit()
474 {
476 $ilTabs = $this->tabs;
477 $ilCtrl = $this->ctrl;
478 $ilToolbar = $this->toolbar;
480
481 $ilToolbar->addButton(
482 $lng->txt("cont_add_tab"),
483 $ilCtrl->getLinkTarget($this, "addTab")
484 );
485
486 $this->setTabs();
487 $ilTabs->activateTab("cont_tabs");
488 include_once("./Services/COPage/classes/class.ilPCTabsTableGUI.php");
489 $table_gui = new ilPCTabsTableGUI($this, "edit", $this->content_obj);
490 $tpl->setContent($table_gui->getHTML());
491 }
492
496 public function saveTabs()
497 {
498 $ilCtrl = $this->ctrl;
500
501 if (is_array($_POST["caption"])) {
502 $captions = ilUtil::stripSlashesArray($_POST["caption"]);
503 $this->content_obj->saveCaptions($captions);
504 }
505 if (is_array($_POST["position"])) {
506 $positions = ilUtil::stripSlashesArray($_POST["position"]);
507 $this->content_obj->savePositions($positions);
508 }
509 $this->updated = $this->pg_obj->update();
510 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
511 $ilCtrl->redirect($this, "edit");
512 }
513
517 public function addTab()
518 {
520 $ilCtrl = $this->ctrl;
521
522 $this->content_obj->addTab($lng->txt("cont_new_tab"));
523 $this->updated = $this->pg_obj->update();
524
525 ilUtil::sendSuccess($lng->txt("cont_added_tab"), true);
526 $ilCtrl->redirect($this, "edit");
527 }
528
532 public function confirmTabsDeletion()
533 {
534 $ilCtrl = $this->ctrl;
537
538 $this->setTabs();
539
540 if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0) {
541 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
542 $ilCtrl->redirect($this, "edit");
543 } else {
544 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
545 $cgui = new ilConfirmationGUI();
546 $cgui->setFormAction($ilCtrl->getFormAction($this));
547 $cgui->setHeaderText($lng->txt("cont_tabs_confirm_deletion"));
548 $cgui->setCancel($lng->txt("cancel"), "cancelTabDeletion");
549 $cgui->setConfirm($lng->txt("delete"), "deleteTabs");
550
551 foreach ($_POST["tid"] as $k => $i) {
552 $id = explode(":", $k);
553 $cgui->addItem(
554 "tid[]",
555 $k,
556 $this->content_obj->getCaption($id[0], $id[1])
557 );
558 }
559
560 $tpl->setContent($cgui->getHTML());
561 }
562 }
563
567 public function cancelTabDeletion()
568 {
569 $ilCtrl = $this->ctrl;
570 $ilCtrl->redirect($this, "edit");
571 }
572
576 public function deleteTabs()
577 {
578 $ilCtrl = $this->ctrl;
579
580 if (is_array($_POST["tid"])) {
581 foreach ($_POST["tid"] as $tid) {
582 $ids = explode(":", $tid);
583 $this->content_obj->deleteTab($ids[0], $ids[1]);
584 }
585 }
586 $this->updated = $this->pg_obj->update();
587
588 $ilCtrl->redirect($this, "edit");
589 }
590
591
595 public function setTabs()
596 {
597 $ilTabs = $this->tabs;
598 $ilCtrl = $this->ctrl;
600
601 $ilTabs->setBackTarget(
602 $lng->txt("pg"),
603 $this->ctrl->getParentReturn($this)
604 );
605
606 $ilTabs->addTarget(
607 "cont_tabs",
608 $ilCtrl->getLinkTarget($this, "edit"),
609 "edit",
610 get_class($this)
611 );
612
613 $ilTabs->addTarget(
614 "cont_edit_tabs",
615 $ilCtrl->getLinkTarget($this, "editProperties"),
616 "editProperties",
617 get_class($this)
618 );
619 }
620}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static addCss()
Add required css.
This class represents an advanced selection list property in a property form.
This class represents a checkbox property in a property form.
Confirmation screen class.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
static _lookupTemplateIdByName($a_style_id, $a_name)
Lookup table template preview.
Class ilPCTabsGUI.
cancelTabDeletion()
Cancel tab deletion.
update()
Save tabs properties in db and return to page edit screen.
confirmTabsDeletion()
Confirm tabs deletion.
afterCreation()
After creation processing.
insert($a_omit_form_init=false)
Insert new tabs.
deleteTabs()
Delete Tabs.
initForm($a_mode="edit")
Insert tabs form.
edit()
List all tabs.
checkWidthHeight(ilPropertyFormGUI $form)
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
getFormValues()
Get form values.
executeCommand()
execute command
setTabs()
Set tabs.
setPropertiesByForm()
Set properties by post.
create()
Create new tabs in dom and update page in db.
addTab()
Save tabs properties in db and return to page edit screen.
editProperties(bool $omit_form_init=false)
Edit tabs.
saveTabs()
Save tabs properties in db and return to page edit screen.
TableGUI class for tabs.
Class ilPCTabs.
const CAROUSEL
const ACCORDION_HOR
const ACCORDION_VER
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getTemplateOptions($a_type)
Get table templates.
displayValidationError()
display validation errors
setHierId($a_hier_id)
get hierarchical id in dom object
This class represents a property form user interface.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static stripSlashesArray($a_arr, $a_strip_html=true, $a_allow="")
Strip slashes from array.
$c
Definition: cli.php:37
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
global $ilDB