ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDataCollectionLinkButton.php
Go to the documentation of this file.
1 <?php
9 
10  protected $attributes;
11 
12  protected $useWrapper = false;
13 
17  public function isUseWrapper()
18  {
19  return $this->useWrapper;
20  }
21 
25  public function setUseWrapper($useWrapper)
26  {
27  $this->useWrapper = $useWrapper;
28  }
29 
30  public static function getInstance()
31  {
32  return new self(self::TYPE_DATACOLLECTION_LINK);
33  }
34 
35  public function prepareRender() {
37 
38  $this->addAttribute('href', ($this->getUrl() ? $this->getUrl() : "#"));
39  $this->addAttribute('target', $this->getTarget());
40  }
41 
42  public function render() {
43  $this->prepareRender();
44 
45  $output = '';
46  if($this->useWrapper) {
47  $output .= '<div'.$this->renderAttributesHelper($this->attributes['wrapper']).'>';
48  }
49 
50  $output .= '<a'.$this->renderAttributes($this->attributes['default']).'>'.$this->renderCaption().'</a>';
51 
52  if($this->useWrapper) {
53  $output .= '</div>';
54  }
55  return $output;
56  }
57 
58  public function addAttribute($key, $value, $wrapper = false) {
59  $this->attributes[$this->getGroupKey($wrapper)][$key] = $value;
60  }
61 
62  public function removeAttribute($key, $wrapper = false) {
63  if(isset($this->attributes[$this->getGroupKey($wrapper)][$key])) {
64  unset($this->attributes[$this->getGroupKey($wrapper)][$key]);
65  return true;
66  }
67  return false;
68  }
69 
70  public function getAttribute($key, $wrapper = false) {
71  if(isset($this->attributes[$this->getGroupKey($wrapper)][$key])) {
72  return $this->attributes[$this->getGroupKey($wrapper)][$key];
73  }
74  return null;
75  }
76 
77  protected function getGroupKey($wrapper) {
78  return ($wrapper)? 'wrapper' : 'default';
79  }
80 }