ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
19
23 protected static $instances = 0;
24
28 protected $id = '';
29
33 protected $form_action = '';
34
38 protected $hidden;
39
43 public $items = array();
44
48 protected $lead_img = array(
49 'img' => '',
50 'alt' => '',
51 );
52
56 protected $open_form_tag = true;
57
61 protected $close_form_tag = true;
62
66 protected $form_target = "";
67
71 protected $form_name = "";
72
76 protected $prevent_double_submission = false;
77
81 protected $sticky_items = array();
82
86 protected $has_separator = false;
87
88 public function __construct()
89 {
90 self::$instances++;
91 }
92
100 public function setFormAction($a_val, $a_multipart = false, $a_target = "")
101 {
102 $this->form_action = $a_val;
103 $this->multipart = $a_multipart;
104 $this->form_target = $a_target;
105 }
106
112 public function getFormAction()
113 {
114 return $this->form_action;
115 }
116
117
124 public function setLeadingImage($a_img, $a_alt)
125 {
126 $this->lead_img = array("img" => $a_img, "alt" => $a_alt);
127 }
128
134 public function setHidden($a_val)
135 {
136 $this->hidden = $a_val;
137 }
138
144 public function getHidden()
145 {
146 return $this->hidden;
147 }
148
154 public function setId($a_val)
155 {
156 $this->id = $a_val;
157 }
158
164 public function getId()
165 {
166 return $this->id ? $this->id : self::$instances;
167 }
168
174 public function setPreventDoubleSubmission($a_val)
175 {
176 $this->prevent_double_submission = $a_val;
177 }
178
185 {
187 }
188
199 public function addButton($a_txt, $a_cmd, $a_target = "", $a_acc_key = "", $a_additional_attrs = '',
200 $a_id = "", $a_class = 'submit')
201 {
202 $this->items[] = array("type" => "button", "txt" => $a_txt, "cmd" => $a_cmd,
203 "target" => $a_target, "acc_key" => $a_acc_key, 'add_attrs' => $a_additional_attrs,
204 "id" => $a_id, "class" => $a_class);
205 }
206
218 function addFormButton($a_txt, $a_cmd, $a_acc_key = "", $a_primary = false, $a_class = false)
219 {
220 if ($a_primary) {
221 $button = ilSubmitButton::getInstance();
222 $button->setPrimary(true);
223 $button->setCaption($a_txt, false);
224 $button->setCommand($a_cmd);
225 $button->setAccessKey($a_acc_key);
226 $this->addStickyItem($button);
227 } else {
228 $this->items[] = array("type" => "fbutton", "txt" => $a_txt, "cmd" => $a_cmd,
229 "acc_key" => $a_acc_key, "primary" => $a_primary, "class" => $a_class);
230 }
231 }
232
233
240 public function addInputItem(ilToolbarItem $a_item, $a_output_label = false)
241 {
242 $this->items[] = array("type" => "input", "input" => $a_item, "label" => $a_output_label);
243 }
244
245
253 public function addStickyItem(ilToolbarItem $a_item, $a_output_label = false)
254 {
255 $this->sticky_items[] = array("item"=>$a_item, "label"=>$a_output_label);
256 }
257
258
264 public function addButtonInstance(ilButtonBase $a_button)
265 {
266 if ($a_button->isPrimary()) {
267 $this->addStickyItem($a_button);
268 } else {
269 $this->items[] = array("type" => "button_obj", "instance" => $a_button);
270 }
271 }
272
273 // bs-patch start
277 public function addDropDown($a_txt, $a_dd_html)
278 {
279 $this->items[] = array("type" => "dropdown", "txt" => $a_txt, "dd_html" => $a_dd_html);
280 }
281 // bs-patch end
282
286 public function addSeparator()
287 {
288 $this->items[] = array("type" => "separator");
289 $this->has_separator = true;
290 }
291
295 public function addText($a_text)
296 {
297 $this->items[] = array("type" => "text", "text" => $a_text);
298 }
299
303 public function addSpacer($a_width = null)
304 {
305 $this->items[] = array("type" => "spacer", "width" => $a_width);
306 }
307
308
316 public function addLink($a_caption, $a_url, $a_disabled = false)
317 {
318 $this->items[] = array("type" => "link", "txt" => $a_caption, "cmd" => $a_url, "disabled" => $a_disabled);
319 }
320
326 public function setOpenFormTag($a_val)
327 {
328 $this->open_form_tag = $a_val;
329 }
330
336 public function getOpenFormTag()
337 {
339 }
340
346 function setCloseFormTag($a_val)
347 {
348 $this->close_form_tag = $a_val;
349 }
350
356 public function getCloseFormTag()
357 {
359 }
360
366 public function setFormName($a_val)
367 {
368 $this->form_name = $a_val;
369 }
370
376 public function getFormName()
377 {
378 return $this->form_name;
379 }
380
381
387 public function getGroupedItems()
388 {
389 $groups = array();
390 $group = array();
391 foreach ($this->items as $item) {
392 if ($item['type'] == 'separator') {
393 $groups[] = $group;
394 $group = array();
395 } else {
396 $group[] = $item;
397 }
398 }
399 if (count($group)) {
400 $groups[] = $group;
401 }
402
403 return $groups;
404 }
405
409 public function getHTML()
410 {
411 global $lng;
412
414
415 if (count($this->items) || count($this->sticky_items))
416 {
417 $tpl = new ilTemplate("tpl.toolbar.html", true, true, "Services/UIComponent/Toolbar");
418 $tpl->setVariable('TOOLBAR_ID', $this->getId());
419 if (count($this->sticky_items)) {
420 $tpl_sticky = new ilTemplate("tpl.toolbar_sticky_items.html", true, true, "Services/UIComponent/Toolbar");
422 foreach ($this->sticky_items as $sticky_item)
423 {
424 if($sticky_item['label'])
425 {
426 $tpl_sticky->setCurrentBlock('input_label');
427 $tpl_sticky->setVariable('TXT_INPUT', $sticky_item['item']->getTitle());
428 $tpl_sticky->parseCurrentBlock();
429 }
430 $tpl_sticky->setCurrentBlock('sticky_item');
431 $tpl_sticky->setVariable('STICKY_ITEM_HTML', $sticky_item['item']->getToolbarHTML());
432 $tpl_sticky->parseCurrentBlock();
433 }
434 $tpl->setCurrentBlock('sticky_items');
435 $tpl->setVariable('STICKY_ITEMS', $tpl_sticky->get());
436 $tpl->parseCurrentBlock();
437 }
438
439 // Hide toggle button if only sticky items are in the toolbar
440 if (count($this->items) == 0) {
441 $tpl->setVariable('HIDE_TOGGLE_CLASS', ' hidden');
442 }
443
444 $markup_items = '';
445 foreach($this->getGroupedItems() as $i => $group)
446 {
447 $tpl_items = new ilTemplate("tpl.toolbar_items.html", true, true, "Services/UIComponent/Toolbar");
448 if ($i > 0) {
449 static $tpl_separator;
450 if ($tpl_separator === null) {
451 $tpl_separator = new ilTemplate('tpl.toolbar_separator.html', true, true, 'Services/UIComponent/Toolbar');
452 }
453 $tpl_separator->touchBlock('separator');
454 $markup_items .= $tpl_separator->get();
455 }
456 foreach ($group as $item) {
457 switch ($item["type"])
458 {
459 case "button":
460 $tpl_items->setCurrentBlock("button");
461 $tpl_items->setVariable("BTN_TXT", $item["txt"]);
462 $tpl_items->setVariable("BTN_LINK", $item["cmd"]);
463 if ($item["target"] != "")
464 {
465 $tpl_items->setVariable("BTN_TARGET", 'target="'.$item["target"].'"');
466 }
467 if ($item["id"] != "")
468 {
469 $tpl_items->setVariable("BID", 'id="'.$item["id"].'"');
470 }
471 if ($item["acc_key"] != "")
472 {
473 include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
474 $tpl_items->setVariable("BTN_ACC_KEY",
475 ilAccessKeyGUI::getAttribute($item["acc_key"]));
476 }
477 if(($item['add_attrs']))
478 {
479 $tpl_items->setVariable('BTN_ADD_ARG',$item['add_attrs']);
480 }
481 $tpl_items->setVariable('BTN_CLASS',$item['class']);
482 $tpl_items->parseCurrentBlock();
483 $tpl_items->touchBlock("item");
484 break;
485
486 case "fbutton":
487 $tpl_items->setCurrentBlock("form_button");
488 $tpl_items->setVariable("SUB_TXT", $item["txt"]);
489 $tpl_items->setVariable("SUB_CMD", $item["cmd"]);
490 if($item["primary"])
491 {
492 $tpl_items->setVariable("SUB_CLASS", " emphsubmit");
493 }
494 else if($item["class"])
495 {
496 $tpl_items->setVariable("SUB_CLASS", " ".$item["class"]);
497 }
498 $tpl_items->parseCurrentBlock();
499 $tpl_items->touchBlock("item");
500 break;
501
502 case "button_obj":
503 $tpl_items->setCurrentBlock("button_instance");
504 $tpl_items->setVariable("BUTTON_OBJ", $item["instance"]->render());
505 $tpl_items->parseCurrentBlock();
506 $tpl_items->touchBlock("item");
507 break;
508
509 case "input":
510 if ($item["label"])
511 {
512 $tpl_items->setCurrentBlock("input_label");
513 $tpl_items->setVariable("TXT_INPUT", $item["input"]->getTitle());
514 $tpl_items->parseCurrentBlock();
515 }
516 $tpl_items->setCurrentBlock("input");
517 $tpl_items->setVariable("INPUT_HTML", $item["input"]->getToolbarHTML());
518 $tpl_items->parseCurrentBlock();
519 $tpl_items->touchBlock("item");
520 break;
521
522 // bs-patch start
523 case "dropdown":
524 $tpl_items->setCurrentBlock("dropdown");
525 $tpl_items->setVariable("TXT_DROPDOWN", $item["txt"]);
526 $tpl_items->setVariable("DROP_DOWN", $item["dd_html"]);
527 $tpl_items->parseCurrentBlock();
528 $tpl_items->touchBlock("item");
529 break;
530 // bs-patch end
531 case "text":
532 $tpl_items->setCurrentBlock("text");
533 $tpl_items->setVariable("VAL_TEXT", $item["text"]);
534 $tpl_items->touchBlock("item");
535 break;
536
537 case "spacer":
538 $tpl_items->touchBlock("spacer");
539 if(!$item["width"])
540 {
541 $item["width"] = 2;
542 }
543 $tpl_items->setVariable("SPACER_WIDTH", $item["width"]);
544 $tpl_items->touchBlock("item");
545 break;
546
547 case "link":
548 if ($item["disabled"] == false) {
549 $tpl_items->setCurrentBlock("link");
550 $tpl_items->setVariable("LINK_TXT", $item["txt"]);
551 $tpl_items->setVariable("LINK_URL", $item["cmd"]);
552 $tpl_items->parseCurrentBlock();
553 $tpl_items->touchBlock("item");
554 break;
555 }
556 else {
557 $tpl_items->setCurrentBlock("link_disabled");
558 $tpl_items->setVariable("LINK_DISABLED_TXT", $item["txt"]);
559 //$tpl_items->setVariable("LINK_URL", $item["cmd"]);
560 $tpl_items->parseCurrentBlock();
561 $tpl_items->touchBlock("item");
562 break;
563 }
564 }
565 }
566 $li = (count($group) > 1) ? "<li class='ilToolbarGroup'>" : "<li>";
567 $markup_items .= $li . $tpl_items->get() . '</li>';
568 }
569
570 $tpl->setVariable('ITEMS', $markup_items);
571 $tpl->setVariable("TXT_FUNCTIONS", $lng->txt("functions"));
572 if ($this->lead_img["img"] != "")
573 {
574 $tpl->setCurrentBlock("lead_image");
575 $tpl->setVariable("IMG_SRC", $this->lead_img["img"]);
576 $tpl->setVariable("IMG_ALT", $this->lead_img["alt"]);
577 $tpl->parseCurrentBlock();
578 }
579
580 // form?
581 if ($this->getFormAction() != "")
582 {
583 if ($this->getOpenFormTag())
584 {
585 $tpl->setCurrentBlock("form_open");
586 $tpl->setVariable("FORMACTION", $this->getFormAction());
587 if($this->getPreventDoubleSubmission())
588 {
589 $tpl->setVariable("FORM_CLASS", "preventDoubleSubmission");
590 }
591 if ($this->multipart)
592 {
593 $tpl->setVariable("ENC_TYPE", 'enctype="multipart/form-data"');
594 }
595 if ($this->form_target != "")
596 {
597 $tpl->setVariable("TARGET", ' target="'.$this->form_target.'" ');
598 }
599 if ($this->form_name != "")
600 {
601 $tpl->setVariable("FORMNAME", 'name="'.$this->getFormName().'"');
602 }
603
604 $tpl->parseCurrentBlock();
605 }
606 if ($this->getCloseFormTag())
607 {
608 $tpl->touchBlock("form_close");
609 }
610 }
611
612 // id
613 if ($this->getId() != "")
614 {
615 $tpl->setVariable("ID", ' id="'.$this->getId().'" ');
616 }
617
618 // hidden style
619 if ($this->getHidden())
620 {
621 $tpl->setVariable("HIDDEN_CLASS", 'ilNoDisplay');
622 }
623
624 return $tpl->get();
625 }
626 return "";
627 }
628
629
633 public function getItems()
634 {
635 return $this->items;
636 }
637
638
642 public function setItems($items)
643 {
644 $this->items = $items;
645 }
646
647
654 {
655 if (count($this->items) == 1 && count($this->sticky_items) == 0) {
656 $supported_types = array('button', 'fbutton', 'button_obj');
657 $item = $this->items[0];
658 if (!in_array($item['type'], $supported_types)) {
659 return;
660 }
661 $button = null;
662 switch ($item['type']) {
663 case 'button_obj':
664 $button = $item['instance'];
665 break;
666 case 'fbutton':
667 $button = ilSubmitButton::getInstance();
668 $button->setPrimary($item['primary']);
669 $button->setCaption($item['txt'], false);
670 $button->setCommand($item['cmd']);
671 $button->setAccessKey($item['acc_key']);
672 break;
673 case 'button':
674 $button = ilLinkButton::getInstance();
675 $button->setCaption($item['txt'], false);
676 $button->setUrl($item['cmd']);
677 $button->setTarget($item['target']);
678 $button->setId($item['id']);
679 $button->setAccessKey($item['acc_key']);
680 break;
681 }
682 $this->addStickyItem($button);
683 $this->items = array();
684 }
685 }
686}
global $tpl
Definition: ilias.php:8
static getAttribute($a_func_id)
Get accesskey HTML attribute.
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.
getOpenFormTag()
Get open form tag.
setId($a_val)
Set id.
addStickyItem(ilToolbarItem $a_item, $a_output_label=false)
Add a sticky item.
setFormAction($a_val, $a_multipart=false, $a_target="")
Set form action (if form action is set, toolbar is wrapped into form tags)
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.
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.
addButton($a_txt, $a_cmd, $a_target="", $a_acc_key="", $a_additional_attrs='', $a_id="", $a_class='submit')
Add button to toolbar.
addLink($a_caption, $a_url, $a_disabled=false)
Add link.
getCloseFormTag()
Get close form tag.
setHidden($a_val)
Set hidden.
getFormName()
Get form name.
addDropDown($a_txt, $a_dd_html)
Add input item.
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)
Interface for property form input GUI classes that can be used in ilToolbarGUI.
global $lng
Definition: privfeed.php:40