ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilButtonBase.php
Go to the documentation of this file.
1<?php
2require_once('./Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php');
3
4/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
5
13abstract class ilButtonBase implements ilToolbarItem
14{
18 protected $lng;
19
20 protected $type; // [int]
21 protected $id; // [string]
22 protected $caption; // [string]
23 protected $caption_is_lng_id; // [bool]
24 protected $primary; // [bool]
26 protected $onclick; // [string]
27 protected $acc_key; // [string]
28 protected $disabled; // [bool]
29 protected $css = array(); // [array]
30
34 protected $apply_default_css = true;
35
36 const TYPE_SUBMIT = 1;
37 const TYPE_LINK = 2;
38 const TYPE_SPLIT = 3;
39 const TYPE_BUTTON = 4;
40
47 protected function __construct($a_type)
48 {
49 global $DIC;
50
51 $this->lng = $DIC->language();
52 $this->setType($a_type);
53 }
54
58 public function __clone()
59 {
60 $this->setId(null);
61 }
62
68 abstract public static function getInstance();
69
70
71 //
72 // properties
73 //
74
80 protected function setType($a_value)
81 {
82 $this->type = (int) $a_value;
83 }
84
90 public function getType()
91 {
92 return $this->type;
93 }
94
100 public function setId($a_value)
101 {
102 $this->id = $a_value;
103 }
104
110 public function getId()
111 {
112 return $this->id;
113 }
114
121 public function setCaption($a_value, $a_is_lng_id = true)
122 {
123 $this->caption = $a_value;
124 $this->caption_is_lng_id = (bool) $a_is_lng_id;
125 }
126
133 public function getCaption($a_translate = true)
134 {
136
138
139 if ($this->caption_is_lng_id &&
140 (bool) $a_translate) {
141 $caption = $lng->txt($caption);
142 }
143
144 return $caption;
145 }
146
152 public function setPrimary($a_value)
153 {
154 $this->primary = (bool) $a_value;
155 }
156
162 public function isPrimary()
163 {
164 return $this->primary;
165 }
166
172 public function setOmitPreventDoubleSubmission($a_value)
173 {
174 $this->omit_prevent_double_submission = (bool) $a_value;
175 }
176
183 {
185 }
186
192 public function setOnClick($a_value)
193 {
194 $this->onclick = trim($a_value);
195 }
196
202 public function getOnClick()
203 {
204 return $this->onclick;
205 }
206
212 public function setAccessKey($a_value)
213 {
214 $this->acc_key = trim($a_value);
215 }
216
222 public function getAccessKey()
223 {
224 return $this->acc_key;
225 }
226
232 public function setDisabled($a_value)
233 {
234 $this->disabled = (bool) $a_value;
235 }
236
242 public function isDisabled()
243 {
244 return $this->disabled;
245 }
246
252 public function addCSSClass($a_value)
253 {
254 $this->css[] = $a_value;
255 }
256
262 public function getCSSClasses()
263 {
264 return $this->css;
265 }
266
267
268 //
269 // render
270 //
271
277 protected function gatherCssClasses()
278 {
279 $css = array_unique($this->getCSSClasses());
280
281 if ($this->isPrimary()) {
282 $css[] = "btn-primary";
283 }
284 if ($this->getOmitPreventDoubleSubmission()) {
285 $css[] = "omitPreventDoubleSubmission";
286 }
287
288 return implode(" ", $css);
289 }
290
296 protected function renderAttributesHelper(array $a_attr)
297 {
298 $res = array();
299
300 foreach ($a_attr as $id => $value) {
301 if (trim($value)) {
302 $res[] = strtolower(trim($id)) . '="' . $value . '"';
303 }
304 }
305
306 if (sizeof($res)) {
307 return " " . implode(" ", $res);
308 }
309 }
310
317 protected function renderAttributes(array $a_additional_attr = null)
318 {
319 $attr = array();
320 $attr["id"] = $this->getId();
321 $attr["class"] = $this->gatherCssClasses();
322 $attr["onclick"] = $this->getOnClick();
323
324 if ($this->getAccessKey()) {
325 include_once("./Services/Accessibility/classes/class.ilAccessKey.php");
326 $attr["accesskey"] = ilAccessKey::getKey($this->getAccessKey());
327 }
328
329 if ($this->isDisabled()) {
330 $attr["disabled"] = "disabled";
331 }
332
333 if (sizeof($a_additional_attr)) {
334 $attr = array_merge($attr, $a_additional_attr);
335 }
336
337 return $this->renderAttributesHelper($attr);
338 }
339
343 protected function prepareRender()
344 {
345 if ($this->applyDefaultCss()) {
346 $this->addCSSClass("btn");
347 $this->addCSSClass("btn-default");
348 }
349 }
350
355 public function applyDefaultCss($apply_default_css = null)
356 {
357 if (null === $apply_default_css) {
359 }
360
361 $this->apply_default_css = $apply_default_css;
362 }
363
369 abstract public function render();
370
371
375 public function getToolbarHTML()
376 {
377 return $this->render();
378 }
379}
disabled()
Example showing how to plug a disabled checkbox into a form.
Definition: disabled.php:5
An exception for terminatinating execution or to throw for unit testing.
static getKey($a_func_id, $lang_key="0", $a_ignore_default=false)
Get single access key.
__clone()
Clone instance.
renderAttributesHelper(array $a_attr)
Render HTML node attributes.
setId($a_value)
Set id.
renderAttributes(array $a_additional_attr=null)
Render current HTML attributes.
setDisabled($a_value)
Toggle disabled status.
setType($a_value)
Set button type.
gatherCssClasses()
Gather all active CSS classes.
render()
Render HTML.
getCSSClasses()
Get CSS class(es)
addCSSClass($a_value)
Add CSS class.
getOnClick()
Get onclick.
prepareRender()
Prepare render.
setOmitPreventDoubleSubmission($a_value)
Toggle double submission prevention status.
setAccessKey($a_value)
Set access key.
isPrimary()
Get primary status.
getCaption($a_translate=true)
Get caption.
static getInstance()
Factory.
getAccessKey()
Get access key.
setCaption($a_value, $a_is_lng_id=true)
Set caption.
getType()
Get button type.
getOmitPreventDoubleSubmission()
Get double submission prevention status.
isDisabled()
Get disabled status.
applyDefaultCss($apply_default_css=null)
__construct($a_type)
Constructor.
setOnClick($a_value)
Set onclick.
setPrimary($a_value)
Toggle primary status.
global $DIC
Definition: goto.php:24
Interface for property form input GUI classes that can be used in ilToolbarGUI.
foreach($_POST as $key=> $value) $res