ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilButtonBase.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php');
3 
4 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
13 abstract 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]
25  protected $omit_prevent_double_submission; // [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  {
135  $lng = $this->lng;
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 }
renderAttributesHelper(array $a_attr)
Render HTML node attributes.
global $DIC
Definition: saml.php:7
getOnClick()
Get onclick.
static getKey($a_func_id, $lang_key="0", $a_ignore_default=false)
Get single access key.
Interface for property form input GUI classes that can be used in ilToolbarGUI.
addCSSClass($a_value)
Add CSS class.
render()
Render HTML.
setCaption($a_value, $a_is_lng_id=true)
Set caption.
isPrimary()
Get primary status.
setAccessKey($a_value)
Set access key.
setDisabled($a_value)
Toggle disabled status.
getCaption($a_translate=true)
Get caption.
prepareRender()
Prepare render.
static getInstance()
Factory.
$a_type
Definition: workflow.php:92
setOnClick($a_value)
Set onclick.
isDisabled()
Get disabled status.
getAccessKey()
Get access key.
foreach($_POST as $key=> $value) $res
applyDefaultCss($apply_default_css=null)
getOmitPreventDoubleSubmission()
Get double submission prevention status.
__clone()
Clone instance.
setPrimary($a_value)
Toggle primary status.
setType($a_value)
Set button type.
renderAttributes(array $a_additional_attr=null)
Render current HTML attributes.
getType()
Get button type.
__construct($a_type)
Constructor.
setId($a_value)
Set id.
setOmitPreventDoubleSubmission($a_value)
Toggle double submission prevention status.
getCSSClasses()
Get CSS class(es)
gatherCssClasses()
Gather all active CSS classes.