ILIAS  release_8 Revision v8.24
class.ilDclLinkButton.php
Go to the documentation of this file.
1<?php
2
20{
21 public const TYPE_DATACOLLECTION_LINK = 99;
22 protected array $attributes;
23 protected bool $useWrapper = false;
24
25 public function isUseWrapper(): bool
26 {
27 return $this->useWrapper;
28 }
29
30 public function setUseWrapper(bool $useWrapper): void
31 {
32 $this->useWrapper = $useWrapper;
33 }
34
35 public static function getInstance(): self
36 {
37 return new self(self::TYPE_DATACOLLECTION_LINK);
38 }
39
40 protected function prepareRender(): void
41 {
42 parent::prepareRender();
43
44 $this->addAttribute('href', ($this->getUrl() ?: "#"));
45 $this->addAttribute('target', $this->getTarget());
46 }
47
48 public function render(): string
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 public function addAttribute(string $key, string $value, bool $wrapper = false): void
67 {
68 $this->attributes[$this->getGroupKey($wrapper)][$key] = $value;
69 }
70
71 public function removeAttribute(string $key, $wrapper = false): bool
72 {
73 if (isset($this->attributes[$this->getGroupKey($wrapper)][$key])) {
74 unset($this->attributes[$this->getGroupKey($wrapper)][$key]);
75
76 return true;
77 }
78
79 return false;
80 }
81
82 public function getAttribute(string $key, bool $wrapper = false): ?string
83 {
84 if (isset($this->attributes[$this->getGroupKey($wrapper)][$key])) {
85 return $this->attributes[$this->getGroupKey($wrapper)][$key];
86 }
87
88 return null;
89 }
90
91 protected function getGroupKey($wrapper): string
92 {
93 return ($wrapper) ? 'wrapper' : 'default';
94 }
95}
renderAttributesHelper(array $a_attr)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
removeAttribute(string $key, $wrapper=false)
getAttribute(string $key, bool $wrapper=false)
addAttribute(string $key, string $value, bool $wrapper=false)
setUseWrapper(bool $useWrapper)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renderAttributes(array $a_additional_attr=null)
Render current HTML attributes.
string $key
Consumer key/client ID value.
Definition: System.php:193