ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilButtonBase.php
Go to the documentation of this file.
1<?php
2
25abstract class ilButtonBase implements ilToolbarItem
26{
27 protected ilLanguage $lng;
28 protected int $type = 0; // [int]
29 protected ?string $id = ""; // [string]
30 protected string $caption = ""; // [string]
31 protected bool $caption_is_lng_id = false; // [bool]
32 protected bool $primary = false; // [bool]
33 protected bool $omit_prevent_double_submission = false; // [bool]
34 protected string $onclick = ""; // [string]
35 protected int $acc_key = 0;
36 protected bool $disabled = false; // [bool]
37 protected array $css = array(); // [array]
38 protected bool $apply_default_css = true;
39
40 public const TYPE_SUBMIT = 1;
41 public const TYPE_LINK = 2;
42 public const TYPE_SPLIT = 3;
43 public const TYPE_BUTTON = 4;
44
45 protected function __construct(int $a_type)
46 {
47 global $DIC;
48
49 $this->lng = $DIC->language();
50 $this->setType($a_type);
51 }
52
53 public function __clone()
54 {
55 $this->setId(null);
56 }
57
58 abstract public static function getInstance(): self;
59
60 //
61 // properties
62 //
63
64 protected function setType(int $a_value): void
65 {
66 $this->type = $a_value;
67 }
68
69 public function getType(): int
70 {
71 return $this->type;
72 }
73
74 public function setId(?string $a_value): void
75 {
76 $this->id = $a_value;
77 }
78
79 public function getId(): ?string
80 {
81 return $this->id;
82 }
83
84 public function setCaption(string $a_value, bool $a_is_lng_id = true): void
85 {
86 $this->caption = $a_value;
87 $this->caption_is_lng_id = $a_is_lng_id;
88 }
89
90 public function getCaption(bool $a_translate = true): string
91 {
93
95
96 if ($this->caption_is_lng_id &&
97 $a_translate) {
99 }
100
101 return $caption;
102 }
103
104 public function setPrimary(bool $a_value): void
105 {
106 $this->primary = $a_value;
107 }
108
109 public function isPrimary(): bool
110 {
111 return $this->primary;
112 }
113
117 public function setOmitPreventDoubleSubmission(bool $a_value): void
118 {
119 $this->omit_prevent_double_submission = $a_value;
120 }
121
122 public function getOmitPreventDoubleSubmission(): bool
123 {
125 }
126
127 public function setOnClick(string $a_value): void
128 {
129 $this->onclick = trim($a_value);
130 }
131
132 public function getOnClick(): string
133 {
134 return $this->onclick;
135 }
136
137 public function setDisabled(bool $a_value): void
138 {
139 $this->disabled = $a_value;
140 }
141
142 public function isDisabled(): bool
143 {
144 return $this->disabled;
145 }
146
147 public function addCSSClass(string $a_value): void
148 {
149 $this->css[] = $a_value;
150 }
151
152 public function getCSSClasses(): array
153 {
154 return $this->css;
155 }
156
157
158 //
159 // render
160 //
161
162 protected function gatherCssClasses(): string
163 {
164 $css = array_unique($this->getCSSClasses());
165
166 if ($this->isPrimary()) {
167 $css[] = "btn-primary";
168 }
169 if ($this->getOmitPreventDoubleSubmission()) {
170 $css[] = "omitPreventDoubleSubmission";
171 }
172
173 return implode(" ", $css);
174 }
175
176 protected function renderAttributesHelper(array $a_attr): string
177 {
178 $res = array();
179
180 foreach ($a_attr as $id => $value) {
181 if (trim((string) $value)) {
182 $res[] = strtolower(trim($id)) . '="' . $value . '"';
183 }
184 }
185
186 if (count($res)) {
187 return " " . implode(" ", $res);
188 }
189 return "";
190 }
191
195 protected function renderAttributes(?array $a_additional_attr = null): string
196 {
197 $attr = array();
198 $attr["id"] = $this->getId();
199 $attr["class"] = $this->gatherCssClasses();
200 $attr["onclick"] = $this->getOnClick();
201
202 if ($this->isDisabled()) {
203 $attr["disabled"] = "disabled";
204 }
205
206 if (count($a_additional_attr)) {
207 $attr = array_merge($attr, $a_additional_attr);
208 }
209
210 return $this->renderAttributesHelper($attr);
211 }
212
213 protected function prepareRender(): void
214 {
215 if ($this->applyDefaultCss()) {
216 $this->addCSSClass("btn");
217 $this->addCSSClass("btn-default");
218 }
219 }
220
221 public function applyDefaultCss(?bool $apply_default_css = null): ?bool
222 {
223 if (null === $apply_default_css) {
225 }
226
227 $this->apply_default_css = $apply_default_css;
228 return false;
229 }
230
231 abstract public function render(): string;
232
233 public function getToolbarHTML(): string
234 {
235 return $this->render();
236 }
237}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
bool $omit_prevent_double_submission
renderAttributesHelper(array $a_attr)
setType(int $a_value)
setOnClick(string $a_value)
getToolbarHTML()
Get input item HTML to be inserted into ilToolbarGUI.
setId(?string $a_value)
setCaption(string $a_value, bool $a_is_lng_id=true)
setDisabled(bool $a_value)
__construct(int $a_type)
applyDefaultCss(?bool $apply_default_css=null)
static getInstance()
setOmitPreventDoubleSubmission(bool $a_value)
Toggle double submission prevention status.
setPrimary(bool $a_value)
getCaption(bool $a_translate=true)
addCSSClass(string $a_value)
renderAttributes(?array $a_additional_attr=null)
Render current HTML attributes.
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26