ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilToolbarGUI.php
Go to the documentation of this file.
1<?php
2require_once('./Services/UIComponent/Button/classes/class.ilSubmitButton.php');
3require_once('./Services/UIComponent/Button/classes/class.ilLinkButton.php');
4
5/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
6
18{
22 protected $lng;
23
24
28 protected static $instances = 0;
29
33 protected $id = '';
34
38 protected $form_action = '';
39
43 protected $hidden;
44
48 public $items = array();
49
53 protected $lead_img = array(
54 'img' => '',
55 'alt' => '',
56 );
57
61 protected $open_form_tag = true;
62
66 protected $close_form_tag = true;
67
71 protected $form_target = "";
72
76 protected $form_name = "";
77
81 protected $prevent_double_submission = false;
82
86 protected $sticky_items = array();
87
91 protected $has_separator = false;
92
93 public function __construct()
94 {
95 global $DIC;
96 $this->lng = $DIC->language();
97
98 $this->ui = $DIC->ui();
99
100 self::$instances++;
101 }
102
110 public function setFormAction($a_val, $a_multipart = false, $a_target = "")
111 {
112 $this->form_action = $a_val;
113 $this->multipart = $a_multipart;
114 $this->form_target = $a_target;
115 }
116
122 public function getFormAction()
123 {
124 return $this->form_action;
125 }
126
127
134 public function setLeadingImage($a_img, $a_alt)
135 {
136 $this->lead_img = array("img" => $a_img, "alt" => $a_alt);
137 }
138
144 public function setHidden($a_val)
145 {
146 $this->hidden = $a_val;
147 }
148
154 public function getHidden()
155 {
156 return $this->hidden;
157 }
158
164 public function setId($a_val)
165 {
166 $this->id = $a_val;
167 }
168
174 public function getId()
175 {
176 return $this->id ? $this->id : self::$instances;
177 }
178
184 public function setPreventDoubleSubmission($a_val)
185 {
186 $this->prevent_double_submission = $a_val;
187 }
188
195 {
197 }
198
209 public function addButton(
210 $a_txt,
211 $a_cmd,
212 $a_target = "",
213 $a_acc_key = "",
214 $a_additional_attrs = '',
215 $a_id = "",
216 $a_class = 'submit'
217 ) {
218 $this->items[] = array("type" => "button", "txt" => $a_txt, "cmd" => $a_cmd,
219 "target" => $a_target, "acc_key" => $a_acc_key, 'add_attrs' => $a_additional_attrs,
220 "id" => $a_id, "class" => $a_class);
221 }
222
234 public function addFormButton($a_txt, $a_cmd, $a_acc_key = "", $a_primary = false, $a_class = false)
235 {
236 if ($a_primary) {
237 $button = ilSubmitButton::getInstance();
238 $button->setPrimary(true);
239 $button->setCaption($a_txt, false);
240 $button->setCommand($a_cmd);
241 $button->setAccessKey($a_acc_key);
242 $this->addStickyItem($button);
243 } else {
244 $this->items[] = array("type" => "fbutton", "txt" => $a_txt, "cmd" => $a_cmd,
245 "acc_key" => $a_acc_key, "primary" => $a_primary, "class" => $a_class);
246 }
247 }
248
249
256 public function addInputItem(ilToolbarItem $a_item, $a_output_label = false)
257 {
258 $this->items[] = array("type" => "input", "input" => $a_item, "label" => $a_output_label);
259 }
260
261
269 public function addStickyItem($a_item, $a_output_label = false)
270 {
271 $this->sticky_items[] = array("item" => $a_item, "label" => $a_output_label);
272 }
273
274
280 public function addButtonInstance(ilButtonBase $a_button)
281 {
282 if ($a_button->isPrimary()) {
283 $this->addStickyItem($a_button);
284 } else {
285 $this->items[] = array("type" => "button_obj", "instance" => $a_button);
286 }
287 }
288
292 public function addDropDown($a_txt, $a_dd_html)
293 {
294 $this->items[] = array("type" => "dropdown", "txt" => $a_txt, "dd_html" => $a_dd_html);
295 }
296
301 {
302 $this->items[] = array("type" => "adv_sel_list", "list" => $adv);
303 }
304
305
309 public function addSeparator()
310 {
311 $this->items[] = array("type" => "separator");
312 $this->has_separator = true;
313 }
314
318 public function addText($a_text)
319 {
320 $this->items[] = array("type" => "text", "text" => $a_text);
321 }
322
326 public function addSpacer($a_width = null)
327 {
328 $this->items[] = array("type" => "spacer", "width" => $a_width);
329 }
330
334 public function addComponent(\ILIAS\UI\Component\Component $a_comp)
335 {
336 $this->items[] = array("type" => "component", "component" => $a_comp);
337 }
338
346 public function addLink($a_caption, $a_url, $a_disabled = false)
347 {
348 $this->items[] = array("type" => "link", "txt" => $a_caption, "cmd" => $a_url, "disabled" => $a_disabled);
349 }
350
356 public function setOpenFormTag($a_val)
357 {
358 $this->open_form_tag = $a_val;
359 }
360
366 public function getOpenFormTag()
367 {
369 }
370
376 public function setCloseFormTag($a_val)
377 {
378 $this->close_form_tag = $a_val;
379 }
380
386 public function getCloseFormTag()
387 {
389 }
390
396 public function setFormName($a_val)
397 {
398 $this->form_name = $a_val;
399 }
400
406 public function getFormName()
407 {
408 return $this->form_name;
409 }
410
411
417 public function getGroupedItems()
418 {
419 $groups = array();
420 $group = array();
421 foreach ($this->items as $item) {
422 if ($item['type'] == 'separator') {
423 $groups[] = $group;
424 $group = array();
425 } else {
426 $group[] = $item;
427 }
428 }
429 if (count($group)) {
430 $groups[] = $group;
431 }
432
433 return $groups;
434 }
435
439 public function getHTML()
440 {
442
444
445 if (count($this->items) || count($this->sticky_items)) {
446 $tpl = new ilTemplate("tpl.toolbar.html", true, true, "Services/UIComponent/Toolbar");
447 $tpl->setVariable('TOOLBAR_ID', $this->getId());
448 if (count($this->sticky_items)) {
449 $tpl_sticky = new ilTemplate("tpl.toolbar_sticky_items.html", true, true, "Services/UIComponent/Toolbar");
451 foreach ($this->sticky_items as $sticky_item) {
452 if ($sticky_item['label']) {
453 $tpl_sticky->setCurrentBlock('input_label');
454 $tpl_sticky->setVariable('INPUT_ID', $sticky_item['item']->getFieldId());
455 $tpl_sticky->setVariable('TXT_INPUT', $sticky_item['item']->getTitle());
456 $tpl_sticky->parseCurrentBlock();
457 }
458
459 if ($sticky_item['item'] instanceof ilToolbarItem) {
460 $tpl_sticky->setCurrentBlock('sticky_item');
461 $tpl_sticky->setVariable('STICKY_ITEM_HTML', $sticky_item['item']->getToolbarHTML());
462 $tpl_sticky->parseCurrentBlock();
463 } elseif ($sticky_item['item'] instanceof \ILIAS\UI\Component\Component) {
464 $tpl_sticky->setCurrentBlock("sticky_item");
465 $tpl_sticky->setVariable("STICKY_ITEM_HTML", $this->ui->renderer()->render($sticky_item['item']));
466 $tpl_sticky->parseCurrentBlock();
467 }
468 }
469 $tpl->setCurrentBlock('sticky_items');
470 $tpl->setVariable('STICKY_ITEMS', $tpl_sticky->get());
471 $tpl->parseCurrentBlock();
472 }
473
474 // Hide toggle button if only sticky items are in the toolbar
475 if (count($this->items) == 0) {
476 $tpl->setVariable('HIDE_TOGGLE_CLASS', ' hidden');
477 }
478
479 $markup_items = '';
480 foreach ($this->getGroupedItems() as $i => $group) {
481 $tpl_items = new ilTemplate("tpl.toolbar_items.html", true, true, "Services/UIComponent/Toolbar");
482 if ($i > 0) {
483 static $tpl_separator;
484 if ($tpl_separator === null) {
485 $tpl_separator = new ilTemplate('tpl.toolbar_separator.html', true, true, 'Services/UIComponent/Toolbar');
486 }
487 $tpl_separator->touchBlock('separator');
488 $markup_items .= $tpl_separator->get();
489 }
490 foreach ($group as $item) {
491 switch ($item["type"]) {
492 case "button":
493 $tpl_items->setCurrentBlock("button");
494 $tpl_items->setVariable("BTN_TXT", $item["txt"]);
495 $tpl_items->setVariable("BTN_LINK", $item["cmd"]);
496 if ($item["target"] != "") {
497 $tpl_items->setVariable("BTN_TARGET", 'target="' . $item["target"] . '"');
498 }
499 if ($item["id"] != "") {
500 $tpl_items->setVariable("BID", 'id="' . $item["id"] . '"');
501 }
502 if ($item["acc_key"] != "") {
503 include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
504 $tpl_items->setVariable(
505 "BTN_ACC_KEY",
506 ilAccessKeyGUI::getAttribute($item["acc_key"])
507 );
508 }
509 if (($item['add_attrs'])) {
510 $tpl_items->setVariable('BTN_ADD_ARG', $item['add_attrs']);
511 }
512 $tpl_items->setVariable('BTN_CLASS', $item['class']);
513 $tpl_items->parseCurrentBlock();
514 $tpl_items->touchBlock("item");
515 break;
516
517 case "fbutton":
518 $tpl_items->setCurrentBlock("form_button");
519 $tpl_items->setVariable("SUB_TXT", $item["txt"]);
520 $tpl_items->setVariable("SUB_CMD", $item["cmd"]);
521 if ($item["primary"]) {
522 $tpl_items->setVariable("SUB_CLASS", " emphsubmit");
523 } elseif ($item["class"]) {
524 $tpl_items->setVariable("SUB_CLASS", " " . $item["class"]);
525 }
526 $tpl_items->parseCurrentBlock();
527 $tpl_items->touchBlock("item");
528 break;
529
530 case "button_obj":
531 $tpl_items->setCurrentBlock("button_instance");
532 $tpl_items->setVariable("BUTTON_OBJ", $item["instance"]->render());
533 $tpl_items->parseCurrentBlock();
534 $tpl_items->touchBlock("item");
535 break;
536
537 case "input":
538 if ($item["label"]) {
539 $tpl_items->setCurrentBlock("input_label");
540 $tpl_items->setVariable("TXT_INPUT", $item["input"]->getTitle());
541 $tpl_items->setVariable("INPUT_ID", $item["input"]->getFieldId());
542 $tpl_items->parseCurrentBlock();
543 }
544 $tpl_items->setCurrentBlock("input");
545 $tpl_items->setVariable("INPUT_HTML", $item["input"]->getToolbarHTML());
546 $tpl_items->parseCurrentBlock();
547 $tpl_items->touchBlock("item");
548 break;
549
550 // bs-patch start
551 case "dropdown":
552 $tpl_items->setCurrentBlock("dropdown");
553 $tpl_items->setVariable("TXT_DROPDOWN", $item["txt"]);
554 $tpl_items->setVariable("DROP_DOWN", $item["dd_html"]);
555 $tpl_items->parseCurrentBlock();
556 $tpl_items->touchBlock("item");
557 break;
558 // bs-patch end
559 case "text":
560 $tpl_items->setCurrentBlock("text");
561 $tpl_items->setVariable("VAL_TEXT", $item["text"]);
562 $tpl_items->touchBlock("item");
563 break;
564
565 case "component":
566 $tpl_items->setCurrentBlock("component");
567 $tpl_items->setVariable("COMPONENT", $this->ui->renderer()->render($item["component"]));
568 $tpl_items->touchBlock("item");
569 break;
570
571 case "adv_sel_list":
572 $tpl_items->setCurrentBlock("component");
573 $tpl_items->setVariable("COMPONENT", $item["list"]->getHTML());
574 $tpl_items->touchBlock("item");
575 break;
576
577
578 case "spacer":
579 $tpl_items->touchBlock("spacer");
580 if (!$item["width"]) {
581 $item["width"] = 2;
582 }
583 $tpl_items->setVariable("SPACER_WIDTH", $item["width"]);
584 $tpl_items->touchBlock("item");
585 break;
586
587 case "link":
588 if ($item["disabled"] == false) {
589 $tpl_items->setCurrentBlock("link");
590 $tpl_items->setVariable("LINK_TXT", $item["txt"]);
591 $tpl_items->setVariable("LINK_URL", $item["cmd"]);
592 $tpl_items->parseCurrentBlock();
593 $tpl_items->touchBlock("item");
594 break;
595 } else {
596 $tpl_items->setCurrentBlock("link_disabled");
597 $tpl_items->setVariable("LINK_DISABLED_TXT", $item["txt"]);
598 //$tpl_items->setVariable("LINK_URL", $item["cmd"]);
599 $tpl_items->parseCurrentBlock();
600 $tpl_items->touchBlock("item");
601 break;
602 }
603 }
604 }
605 $li = (count($group) > 1) ? "<li class='ilToolbarGroup'>" : "<li>";
606 $markup_items .= $li . $tpl_items->get() . '</li>';
607 }
608
609 $tpl->setVariable('ITEMS', $markup_items);
610 $tpl->setVariable("TXT_FUNCTIONS", $lng->txt("functions"));
611 if ($this->lead_img["img"] != "") {
612 $tpl->setCurrentBlock("lead_image");
613 $tpl->setVariable("IMG_SRC", $this->lead_img["img"]);
614 $tpl->setVariable("IMG_ALT", $this->lead_img["alt"]);
615 $tpl->parseCurrentBlock();
616 }
617
618 // form?
619 if ($this->getFormAction() != "") {
620 // #18947
621 $GLOBALS["tpl"]->addJavaScript("Services/Form/js/Form.js");
622
623 if ($this->getOpenFormTag()) {
624 $tpl->setCurrentBlock("form_open");
625 $tpl->setVariable("FORMACTION", $this->getFormAction());
626 if ($this->getPreventDoubleSubmission()) {
627 $tpl->setVariable("FORM_CLASS", "preventDoubleSubmission");
628 }
629 if ($this->multipart) {
630 $tpl->setVariable("ENC_TYPE", 'enctype="multipart/form-data"');
631 }
632 if ($this->form_target != "") {
633 $tpl->setVariable("TARGET", ' target="' . $this->form_target . '" ');
634 }
635 if ($this->form_name != "") {
636 $tpl->setVariable("FORMNAME", 'name="' . $this->getFormName() . '"');
637 }
638
639 $tpl->parseCurrentBlock();
640 }
641 if ($this->getCloseFormTag()) {
642 $tpl->touchBlock("form_close");
643 }
644 }
645
646 // id
647 if ($this->getId() != "") {
648 $tpl->setVariable("ID", ' id="' . $this->getId() . '" ');
649 }
650
651 // hidden style
652 if ($this->getHidden()) {
653 $tpl->setVariable("HIDDEN_CLASS", 'ilNoDisplay');
654 }
655
656 return $tpl->get();
657 }
658 return "";
659 }
660
661
665 public function getItems()
666 {
667 return $this->items;
668 }
669
670
674 public function setItems($items)
675 {
676 $this->items = $items;
677 }
678
679
686 {
687 if (count($this->items) == 1 && count($this->sticky_items) == 0) {
688 $supported_types = array('button', 'fbutton', 'button_obj');
689 $item = $this->items[0];
690 if (!in_array($item['type'], $supported_types)) {
691 return;
692 }
693 $button = null;
694 switch ($item['type']) {
695 case 'button_obj':
696 $button = $item['instance'];
697 break;
698 case 'fbutton':
699 $button = ilSubmitButton::getInstance();
700 $button->setPrimary($item['primary']);
701 $button->setCaption($item['txt'], false);
702 $button->setCommand($item['cmd']);
703 $button->setAccessKey($item['acc_key']);
704 break;
705 case 'button':
706 $button = ilLinkButton::getInstance();
707 $button->setCaption($item['txt'], false);
708 $button->setUrl($item['cmd']);
709 $button->setTarget($item['target']);
710 $button->setId($item['id']);
711 $button->setAccessKey($item['acc_key']);
712 break;
713 }
714 $this->addStickyItem($button);
715 $this->items = array();
716 }
717 }
718}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
static getAttribute($a_func_id)
Get accesskey HTML attribute.
User interface class for advanced drop-down selection lists.
isPrimary()
Get primary status.
static getInstance()
Factory.
static getInstance()
Factory.
special template class to simplify handling of ITX/PEAR
setLeadingImage($a_img, $a_alt)
Set leading image.
getFormAction()
Get form action.
setPreventDoubleSubmission($a_val)
Set prevent double submission.
addButtonInstance(ilButtonBase $a_button)
Add button instance.
addAdvancedSelectionList(ilAdvancedSelectionListGUI $adv)
getOpenFormTag()
Get open form tag.
setId($a_val)
Set id.
setFormAction($a_val, $a_multipart=false, $a_target="")
Set form action (if form action is set, toolbar is wrapped into form tags)
addStickyItem($a_item, $a_output_label=false)
Add a sticky item.
addInputItem(ilToolbarItem $a_item, $a_output_label=false)
Add input item.
addSpacer($a_width=null)
Add spacer.
setCloseFormTag($a_val)
Set close form tag.
addFormButton($a_txt, $a_cmd, $a_acc_key="", $a_primary=false, $a_class=false)
Add form button to toolbar.
addComponent(\ILIAS\UI\Component\Component $a_comp)
Add component.
getPreventDoubleSubmission()
Get prevent double submission.
addText($a_text)
Add text.
applyAutoStickyToSingleElement()
If the toolbar consists of only one button, make it sticky Note: Atm this is only possible for button...
getHidden()
Get hidden.
addLink($a_caption, $a_url, $a_disabled=false)
Add link.
getCloseFormTag()
Get close form tag.
setHidden($a_val)
Set hidden.
addButton( $a_txt, $a_cmd, $a_target="", $a_acc_key="", $a_additional_attrs='', $a_id="", $a_class='submit')
Add button to toolbar.
getFormName()
Get form name.
addDropDown($a_txt, $a_dd_html)
Add Dropdown.
setOpenFormTag($a_val)
Set open form tag.
setFormName($a_val)
Set form name.
addSeparator()
Add separator.
getGroupedItems()
Get all groups (items separated by a separator)
global $DIC
Definition: goto.php:24
Interface for property form input GUI classes that can be used in ilToolbarGUI.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:24
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
ui()
Definition: ui.php:5