Commit | Line | Data |
---|---|---|
3b75466f | 1 | <?php |
a9229942 | 2 | |
3b75466f | 3 | namespace wcf\data\label; |
a9229942 | 4 | |
3b75466f MW |
5 | use wcf\data\DatabaseObject; |
6 | use wcf\system\request\IRouteController; | |
7 | use wcf\system\WCF; | |
d158b05a | 8 | use wcf\util\StringUtil; |
3b75466f MW |
9 | |
10 | /** | |
11 | * Represents a label. | |
e9335ed9 | 12 | * |
a9229942 TD |
13 | * @author Alexander Ebert |
14 | * @copyright 2001-2019 WoltLab GmbH | |
15 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
a9229942 TD |
16 | * |
17 | * @property-read int $labelID unique id of the label | |
18 | * @property-read int $groupID id of the label group the label belongs to | |
19 | * @property-read string $label label text or name of language item which contains the label text | |
20 | * @property-read string $cssClassName css class name used when displaying the label | |
21 | * @property-read int $showOrder position of the label in relation to the other labels in the label group | |
3b75466f | 22 | */ |
a9229942 TD |
23 | class Label extends DatabaseObject implements IRouteController |
24 | { | |
25 | /** | |
26 | * Returns the label's textual representation if a label is treated as a | |
27 | * string. | |
a9229942 | 28 | */ |
83c324d3 | 29 | public function __toString(): string |
a9229942 TD |
30 | { |
31 | return $this->getTitle(); | |
32 | } | |
33 | ||
34 | /** | |
35 | * @inheritDoc | |
36 | */ | |
a4a634aa | 37 | public function getTitle(): string |
a9229942 TD |
38 | { |
39 | return WCF::getLanguage()->get($this->label); | |
40 | } | |
41 | ||
42 | /** | |
43 | * Returns label CSS class names. | |
44 | * | |
45 | * @return string | |
46 | */ | |
47 | public function getClassNames() | |
48 | { | |
49 | if ($this->cssClassName == 'none') { | |
50 | return ''; | |
51 | } | |
52 | ||
53 | return $this->cssClassName; | |
54 | } | |
55 | ||
56 | /** | |
57 | * Returns the HTML representation of the label. | |
58 | * | |
59 | * @param string $additionalClasses | |
60 | * @return string | |
61 | * @since 5.3 | |
62 | */ | |
63 | public function render($additionalClasses = '') | |
64 | { | |
65 | return '<span class="badge label' . ($this->getClassNames() ? ' ' . $this->getClassNames() : '') | |
66 | . ($additionalClasses ? ' ' . $additionalClasses : '') . '">' | |
67 | . StringUtil::encodeHTML($this->getTitle()) . '</span>'; | |
68 | } | |
3b75466f | 69 | } |