ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
15  protected $type; // [int]
16  protected $id; // [string]
17  protected $caption; // [string]
18  protected $caption_is_lng_id; // [bool]
19  protected $primary; // [bool]
20  protected $omit_prevent_double_submission; // [bool]
21  protected $onclick; // [string]
22  protected $acc_key; // [string]
23  protected $disabled; // [bool]
24  protected $css = array(); // [array]
25 
29  protected $apply_default_css = true;
30 
31  const TYPE_SUBMIT = 1;
32  const TYPE_LINK = 2;
33  const TYPE_SPLIT = 3;
34  const TYPE_BUTTON = 4;
35 
42  protected function __construct($a_type)
43  {
44  $this->setType($a_type);
45  }
46 
50  public function __clone()
51  {
52  $this->setId(null);
53  }
54 
60  abstract public static function getInstance();
61 
62 
63  //
64  // properties
65  //
66 
72  protected function setType($a_value)
73  {
74  $this->type = (int)$a_value;
75  }
76 
82  public function getType()
83  {
84  return $this->type;
85  }
86 
92  public function setId($a_value)
93  {
94  $this->id = $a_value;
95  }
96 
102  public function getId()
103  {
104  return $this->id;
105  }
106 
113  public function setCaption($a_value, $a_is_lng_id = true)
114  {
115  $this->caption = $a_value;
116  $this->caption_is_lng_id = (bool)$a_is_lng_id;
117  }
118 
125  public function getCaption($a_translate = true)
126  {
127  global $lng;
128 
130 
131  if($this->caption_is_lng_id &&
132  (bool)$a_translate)
133  {
134  $caption = $lng->txt($caption);
135  }
136 
137  return $caption;
138  }
139 
145  public function setPrimary($a_value)
146  {
147  $this->primary = (bool)$a_value;
148  }
149 
155  public function isPrimary()
156  {
157  return $this->primary;
158  }
159 
165  public function setOmitPreventDoubleSubmission($a_value)
166  {
167  $this->omit_prevent_double_submission = (bool)$a_value;
168  }
169 
176  {
178  }
179 
185  public function setOnClick($a_value)
186  {
187  $this->onclick = trim($a_value);
188  }
189 
195  public function getOnClick()
196  {
197  return $this->onclick;
198  }
199 
205  public function setAccessKey($a_value)
206  {
207  $this->acc_key = trim($a_value);
208  }
209 
215  public function getAccessKey()
216  {
217  return $this->acc_key;
218  }
219 
225  public function setDisabled($a_value)
226  {
227  $this->disabled = (bool)$a_value;
228  }
229 
235  public function isDisabled()
236  {
237  return $this->disabled;
238  }
239 
245  public function addCSSClass($a_value)
246  {
247  $this->css[] = $a_value;
248  }
249 
255  public function getCSSClasses()
256  {
257  return $this->css;
258  }
259 
260 
261  //
262  // render
263  //
264 
270  protected function gatherCssClasses()
271  {
272  $css = array_unique($this->getCSSClasses());
273 
274  if($this->isPrimary())
275  {
276  $css[] = "btn-primary";
277  }
278  if($this->getOmitPreventDoubleSubmission())
279  {
280  $css[] = "omitPreventDoubleSubmission";
281  }
282 
283  return implode(" ", $css);
284  }
285 
291  protected function renderAttributesHelper(array $a_attr)
292  {
293  $res = array();
294 
295  foreach($a_attr as $id => $value)
296  {
297  if(trim($value))
298  {
299  $res[] = strtolower(trim($id)).'="'.$value.'"';
300  }
301  }
302 
303  if(sizeof($res))
304  {
305  return " ".implode(" ", $res);
306  }
307  }
308 
315  protected function renderAttributes(array $a_additional_attr = null)
316  {
317  $attr = array();
318  $attr["id"] = $this->getId();
319  $attr["class"] = $this->gatherCssClasses();
320  $attr["onclick"] = $this->getOnClick();
321 
322  if($this->getAccessKey())
323  {
324  include_once("./Services/Accessibility/classes/class.ilAccessKey.php");
325  $attr["accesskey"] = ilAccessKey::getKey($this->getAccessKey());
326  }
327 
328  if($this->isDisabled())
329  {
330  $attr["disabled"] = "disabled";
331  }
332 
333  if(sizeof($a_additional_attr))
334  {
335  $attr = array_merge($attr, $a_additional_attr);
336  }
337 
338  return $this->renderAttributesHelper($attr);
339  }
340 
344  protected function prepareRender()
345  {
346  if($this->applyDefaultCss())
347  {
348  $this->addCSSClass("btn");
349  $this->addCSSClass("btn-default");
350  }
351  }
352 
357  public function applyDefaultCss($apply_default_css = null)
358  {
359  if(null === $apply_default_css)
360  {
362  }
363 
364  $this->apply_default_css = $apply_default_css;
365  }
366 
372  abstract public function render();
373 
374 
378  public function getToolbarHTML()
379  {
380  return $this->render();
381  }
382 }
renderAttributesHelper(array $a_attr)
Render HTML node attributes.
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:93
setOnClick($a_value)
Set onclick.
isDisabled()
Get disabled status.
getAccessKey()
Get access key.
applyDefaultCss($apply_default_css=null)
getOmitPreventDoubleSubmission()
Get double submission prevention status.
__clone()
Clone instance.
Create styles array
The data for the language used.
setPrimary($a_value)
Toggle primary status.
global $lng
Definition: privfeed.php:17
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.