ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilModalGUI.php
Go to the documentation of this file.
1 <?php
2 
27 {
28  protected string $heading = "";
29  protected string $body = "";
30  protected string $id = "";
31 
32  public const TYPE_LARGE = "large";
33  public const TYPE_MEDIUM = "medium";
34  public const TYPE_SMALL = "small";
35 
36  protected string $type = self::TYPE_MEDIUM;
37  protected array $buttons = array();
38 
39  protected function __construct()
40  {
41  }
42 
43  public static function getInstance(): self
44  {
45  return new ilModalGUI();
46  }
47 
48  public function setId(string $a_val): void
49  {
50  $this->id = $a_val;
51  }
52 
53  public function getId(): string
54  {
55  return $this->id;
56  }
57 
58  public function setHeading(string $a_val): void
59  {
60  $this->heading = $a_val;
61  }
62 
63 
64  public function getHeading(): string
65  {
66  return $this->heading;
67  }
68 
69  public function setBody(string $a_val): void
70  {
71  $this->body = $a_val;
72  }
73 
74  public function getBody(): string
75  {
76  return $this->body;
77  }
78 
84  public function setType(string $a_val): void
85  {
86  $this->type = $a_val;
87  }
88 
89  public function getType(): string
90  {
91  return $this->type;
92  }
93 
94  public function addButton(ilButtonBase $but): void
95  {
96  $this->buttons[] = $but;
97  }
98 
103  public function getButtons(): array
104  {
105  return $this->buttons;
106  }
107 
108  public function getHTML(): string
109  {
110  $tpl = new ilTemplate("tpl.modal.html", true, true, "components/ILIAS/UIComponent/Modal");
111 
112  if (count($this->getButtons()) > 0) {
113  foreach ($this->getButtons() as $b) {
114  $tpl->setCurrentBlock("button");
115  $tpl->setVariable("BUTTON", $b->render());
116  $tpl->parseCurrentBlock();
117  }
118  $tpl->setCurrentBlock("footer");
119  $tpl->parseCurrentBlock();
120  }
121 
122  $tpl->setVariable("HEADING", $this->getHeading());
123 
124  $tpl->setVariable("MOD_ID", $this->getId());
125  $tpl->setVariable("BODY", $this->getBody());
126 
127  switch ($this->getType()) {
128  case self::TYPE_LARGE:
129  $tpl->setVariable("CLASS", "modal-lg");
130  break;
131 
132  case self::TYPE_SMALL:
133  $tpl->setVariable("CLASS", "modal-sm");
134  break;
135  }
136 
137  return $tpl->get();
138  }
139 
140  public static function initJS(ilGlobalTemplateInterface $a_main_tpl = null): void
141  {
142  global $DIC;
143 
144  $tpl = $a_main_tpl ?? $DIC["tpl"];
145 
146  $tpl->addJavaScript("assets/js/LegacyModal.js");
147  }
148 }
setType(string $a_val)
Set type.
static initJS(ilGlobalTemplateInterface $a_main_tpl=null)
getButtons()
Get buttons.
setBody(string $a_val)
setId(string $a_val)
addButton(ilButtonBase $but)
global $DIC
Definition: shib_login.php:25
setHeading(string $a_val)
static getInstance()
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...