ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDclLinkButton.php
Go to the documentation of this file.
1<?php
2
9{
11 protected $attributes;
12 protected $useWrapper = false;
13
14
18 public function isUseWrapper()
19 {
20 return $this->useWrapper;
21 }
22
23
27 public function setUseWrapper($useWrapper)
28 {
29 $this->useWrapper = $useWrapper;
30 }
31
32
33 public static function getInstance()
34 {
35 return new self(self::TYPE_DATACOLLECTION_LINK);
36 }
37
38
39 public function prepareRender()
40 {
41 parent::prepareRender();
42
43 $this->addAttribute('href', ($this->getUrl() ? $this->getUrl() : "#"));
44 $this->addAttribute('target', $this->getTarget());
45 }
46
47
48 public function render()
49 {
50 $this->prepareRender();
51
52 $output = '';
53 if ($this->useWrapper) {
54 $output .= '<div' . $this->renderAttributesHelper($this->attributes['wrapper']) . '>';
55 }
56
57 $output .= '<a' . $this->renderAttributes($this->attributes['default']) . '>' . $this->renderCaption() . '</a>';
58
59 if ($this->useWrapper) {
60 $output .= '</div>';
61 }
62
63 return $output;
64 }
65
66
67 public function addAttribute($key, $value, $wrapper = false)
68 {
69 $this->attributes[$this->getGroupKey($wrapper)][$key] = $value;
70 }
71
72
73 public function removeAttribute($key, $wrapper = false)
74 {
75 if (isset($this->attributes[$this->getGroupKey($wrapper)][$key])) {
76 unset($this->attributes[$this->getGroupKey($wrapper)][$key]);
77
78 return true;
79 }
80
81 return false;
82 }
83
84
85 public function getAttribute($key, $wrapper = false)
86 {
87 if (isset($this->attributes[$this->getGroupKey($wrapper)][$key])) {
88 return $this->attributes[$this->getGroupKey($wrapper)][$key];
89 }
90
91 return null;
92 }
93
94
95 protected function getGroupKey($wrapper)
96 {
97 return ($wrapper) ? 'wrapper' : 'default';
98 }
99}
An exception for terminatinating execution or to throw for unit testing.
renderAttributesHelper(array $a_attr)
Render HTML node attributes.
getAttribute($key, $wrapper=false)
static getInstance()
Factory.
removeAttribute($key, $wrapper=false)
prepareRender()
Prepare render.
setUseWrapper($useWrapper)
addAttribute($key, $value, $wrapper=false)
getTarget()
Get target.
renderCaption()
Prepare caption for render.
renderAttributes(array $a_additional_attr=null)
Render current HTML attributes.string