ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilButton.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11abstract class ilButton
12{
13 protected $type; // [int]
14 protected $id; // [string]
15 protected $caption; // [string]
16 protected $caption_is_lng_id; // [bool]
17 protected $primary; // [bool]
19 protected $onclick; // [string]
20 protected $acc_key; // [string]
21 protected $disabled; // [bool]
22 protected $css = array(); // [array]
23
24 const TYPE_SUBMIT = 1;
25 const TYPE_LINK = 2;
26
33 protected function __construct($a_type)
34 {
35 $this->setType($a_type);
36 }
37
41 public function __clone()
42 {
43 $this->setId(null);
44 }
45
51 abstract public static function getInstance();
52
53
54 //
55 // properties
56 //
57
63 protected function setType($a_value)
64 {
65 $this->type = (int)$a_value;
66 }
67
73 public function getType()
74 {
75 return $this->type;
76 }
77
83 public function setId($a_value)
84 {
85 $this->id = $a_value;
86 }
87
93 public function getId()
94 {
95 return $this->id;
96 }
97
104 public function setCaption($a_value, $a_is_lng_id = true)
105 {
106 $this->caption = $a_value;
107 $this->caption_is_lng_id = (bool)$a_is_lng_id;
108 }
109
116 public function getCaption($a_translate = true)
117 {
118 global $lng;
119
121
122 if($this->caption_is_lng_id &&
123 (bool)$a_translate)
124 {
125 $caption = $lng->txt($caption);
126 }
127
128 return $caption;
129 }
130
136 public function setPrimary($a_value)
137 {
138 $this->primary = (bool)$a_value;
139 }
140
146 public function isPrimary()
147 {
148 return $this->primary;
149 }
150
156 public function setOmitPreventDoubleSubmission($a_value)
157 {
158 $this->omit_prevent_double_submission = (bool)$a_value;
159 }
160
167 {
169 }
170
176 public function setOnClick($a_value)
177 {
178 $this->onclick = trim($a_value);
179 }
180
186 public function getOnClick()
187 {
188 return $this->onclick;
189 }
190
196 public function setAccessKey($a_value)
197 {
198 $this->acc_key = trim($a_value);
199 }
200
206 public function getAccessKey()
207 {
208 return $this->acc_key;
209 }
210
216 public function setDisabled($a_value)
217 {
218 $this->disabled = (bool)$a_value;
219 }
220
226 public function isDisabled()
227 {
228 return $this->disabled;
229 }
230
236 public function addCSSClass($a_value)
237 {
238 $this->css[] = $a_value;
239 }
240
246 public function getCSSClasses()
247 {
248 return $this->css;
249 }
250
251
252 //
253 // render
254 //
255
261 protected function gatherCssClasses()
262 {
263 $css = array_unique($this->getCSSClasses());
264
265 if($this->isPrimary())
266 {
267 $css[] = "btn-primary";
268 }
270 {
271 $css[] = "omitPreventDoubleSubmission";
272 }
273
274 return implode(" ", $css);
275 }
276
282 protected function renderAttributesHelper(array $a_attr)
283 {
284 $res = array();
285
286 foreach($a_attr as $id => $value)
287 {
288 if(trim($value))
289 {
290 $res[] = strtolower(trim($id)).'="'.$value.'"';
291 }
292 }
293
294 if(sizeof($res))
295 {
296 return " ".implode(" ", $res);
297 }
298 }
299
306 protected function renderAttributes(array $a_additional_attr = null)
307 {
308 $attr = array();
309 $attr["id"] = $this->getId();
310 $attr["class"] = $this->gatherCssClasses();
311 $attr["onclick"] = $this->getOnClick();
312
313 if($this->getAccessKey())
314 {
315 include_once("./Services/Accessibility/classes/class.ilAccessKey.php");
316 $attr["accesskey"] = ilAccessKey::getKey($this->getAccessKey());
317 }
318
319 if($this->isDisabled())
320 {
321 $attr["disabled"] = "disabled";
322 }
323
324 if(sizeof($a_additional_attr))
325 {
326 $attr = array_merge($attr, $a_additional_attr);
327 }
328
329 return $this->renderAttributesHelper($attr);
330 }
331
335 protected function prepareRender()
336 {
337 $this->addCSSClass("btn");
338 $this->addCSSClass("btn-default");
339 }
340
346 abstract public function render();
347}
static getKey($a_func_id, $lang_key="0", $a_ignore_default=false)
Get single access key.
getType()
Get button type.
__clone()
Clone instance.
const TYPE_SUBMIT
render()
Render HTML.
renderAttributesHelper(array $a_attr)
Render HTML node attributes.
setOmitPreventDoubleSubmission($a_value)
Toggle double submission prevention status.
setType($a_value)
Set button type.
getOmitPreventDoubleSubmission()
Get double submission prevention status.
gatherCssClasses()
Gather all active CSS classes.
setPrimary($a_value)
Toggle primary status.
setId($a_value)
Set id.
isPrimary()
Get primary status.
__construct($a_type)
Constructor.
setAccessKey($a_value)
Set access key.
addCSSClass($a_value)
Add CSS class.
setDisabled($a_value)
Toggle disabled status.
$omit_prevent_double_submission
getAccessKey()
Get access key.
const TYPE_LINK
getOnClick()
Get onclick.
getCaption($a_translate=true)
Get caption.
isDisabled()
Get disabled status.
getId()
Get id.
getCSSClasses()
Get CSS class(es)
renderAttributes(array $a_additional_attr=null)
Render current HTML attributes.
static getInstance()
Factory.
prepareRender()
Prepare render
setOnClick($a_value)
Set onclick.
setCaption($a_value, $a_is_lng_id=true)
Set caption.
global $lng
Definition: privfeed.php:40