| 1 | <?php |
| 2 | |
| 3 | namespace wcf\data\label; |
| 4 | |
| 5 | use wcf\data\DatabaseObject; |
| 6 | use wcf\system\request\IRouteController; |
| 7 | use wcf\system\WCF; |
| 8 | use wcf\util\StringUtil; |
| 9 | |
| 10 | /** |
| 11 | * Represents a label. |
| 12 | * |
| 13 | * @author Alexander Ebert |
| 14 | * @copyright 2001-2019 WoltLab GmbH |
| 15 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
| 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 |
| 22 | */ |
| 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. |
| 28 | */ |
| 29 | public function __toString(): string |
| 30 | { |
| 31 | return $this->getTitle(); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @inheritDoc |
| 36 | */ |
| 37 | public function getTitle(): string |
| 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 | } |
| 69 | } |