2 namespace wcf\data\trophy
;
3 use wcf\data\trophy\category\TrophyCategory
;
4 use wcf\data\trophy\category\TrophyCategoryCache
;
5 use wcf\data\DatabaseObject
;
6 use wcf\data\ITitledLinkObject
;
7 use wcf\system\event\EventHandler
;
8 use wcf\system\request\IRouteController
;
9 use wcf\system\request\LinkHandler
;
11 use wcf\util\StringUtil
;
14 * Represents a user trophy.
16 * @author Joshua Ruesweg
17 * @copyright 2001-2017 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package WoltLabSuite\Core\Data\Trophy
22 * @property-read integer $trophyID unique id for the trophy
23 * @property-read string $title the trophy title
24 * @property-read integer $description the trophy description
25 * @property-read integer $categoryID the categoryID of the trophy
26 * @property-read integer $type the trophy type
27 * @property-read string $iconFile the file location of the icon
28 * @property-read string $iconName the icon name
29 * @property-read string $iconColor the icon color
30 * @property-read string $badgeColor the icon badge color
31 * @property-read integer $isDisabled `1` if the trophy is disabled
32 * @property-read integer $awardAutomatically `1` if the trophy is awarded automatically
34 class Trophy
extends DatabaseObject
implements ITitledLinkObject
, IRouteController
{
36 * The type value, if this trophy is an image trophy.
42 * The type value, if this trophy is a badge trophy (based on CSS icons).
48 * The default icon size.
50 const DEFAULT_SIZE
= 32;
55 public function getTitle() {
56 return WCF
::getLanguage()->get($this->title
);
62 public function getLink() {
63 return LinkHandler
::getInstance()->getLink('Trophy', [
65 'forceFrontend' => true
72 * @param integer $size
75 public function renderTrophy($size = self
::DEFAULT_SIZE
) {
76 switch ($this->type
) {
77 case self
::TYPE_IMAGE
: {
78 return WCF
::getTPL()->fetch('trophyImage', 'wcf', [
85 case self
::TYPE_BADGE
:
86 return WCF
::getTPL()->fetch('trophyBadge', 'wcf', [
94 'renderedTemplate' => null,
98 EventHandler
::getInstance()->fireAction($this, 'renderTrophy', $parameters);
100 if ($parameters['renderedTemplate']) {
101 return $parameters['renderedTemplate'];
104 throw new \
LogicException("Unable to render the trophy with the type '". $this->type
."'.");
110 * Returns the category for this trophy.
112 * @return TrophyCategory
114 public function getCategory() {
115 return TrophyCategoryCache
::getInstance()->getCategoryByID($this->categoryID
);
119 * Returns true if the current trophy is disabled. Returns also true if the trophy category is disabled.
123 public function isDisabled() {
124 if ($this->isDisabled
) {
128 if ($this->getCategory()->isDisabled
) {
136 * Returns the parsed description for the trophy.
140 public function getDescription() {
141 return nl2br(StringUtil
::encodeHTML(WCF
::getLanguage()->get($this->description
)), false);