From f12a2816eca917bce47751e18506c002909e12fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Tue, 10 Apr 2018 13:19:12 +0200 Subject: [PATCH] Add basic reaction type icon rendering See #2508 --- .../templates/reactionTypeIcon.tpl | 5 +++ .../templates/reactionTypeImage.tpl | 6 +++ .../files/acp/templates/reactionTypeIcon.tpl | 5 +++ .../files/acp/templates/reactionTypeImage.tpl | 6 +++ .../install/files/images/reaction/.htaccess | 1 + .../data/reaction/type/ReactionType.class.php | 44 ++++++++++++++++++- 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 com.woltlab.wcf/templates/reactionTypeIcon.tpl create mode 100644 com.woltlab.wcf/templates/reactionTypeImage.tpl create mode 100644 wcfsetup/install/files/acp/templates/reactionTypeIcon.tpl create mode 100644 wcfsetup/install/files/acp/templates/reactionTypeImage.tpl create mode 100644 wcfsetup/install/files/images/reaction/.htaccess diff --git a/com.woltlab.wcf/templates/reactionTypeIcon.tpl b/com.woltlab.wcf/templates/reactionTypeIcon.tpl new file mode 100644 index 0000000000..4075258636 --- /dev/null +++ b/com.woltlab.wcf/templates/reactionTypeIcon.tpl @@ -0,0 +1,5 @@ + diff --git a/com.woltlab.wcf/templates/reactionTypeImage.tpl b/com.woltlab.wcf/templates/reactionTypeImage.tpl new file mode 100644 index 0000000000..a4577bbdef --- /dev/null +++ b/com.woltlab.wcf/templates/reactionTypeImage.tpl @@ -0,0 +1,6 @@ + diff --git a/wcfsetup/install/files/acp/templates/reactionTypeIcon.tpl b/wcfsetup/install/files/acp/templates/reactionTypeIcon.tpl new file mode 100644 index 0000000000..4075258636 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/reactionTypeIcon.tpl @@ -0,0 +1,5 @@ + diff --git a/wcfsetup/install/files/acp/templates/reactionTypeImage.tpl b/wcfsetup/install/files/acp/templates/reactionTypeImage.tpl new file mode 100644 index 0000000000..a4577bbdef --- /dev/null +++ b/wcfsetup/install/files/acp/templates/reactionTypeImage.tpl @@ -0,0 +1,6 @@ + diff --git a/wcfsetup/install/files/images/reaction/.htaccess b/wcfsetup/install/files/images/reaction/.htaccess new file mode 100644 index 0000000000..c8ab05519b --- /dev/null +++ b/wcfsetup/install/files/images/reaction/.htaccess @@ -0,0 +1 @@ +# This file ensures that these folders are created during an update. \ No newline at end of file diff --git a/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php b/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php index 9d443dff79..e990e860ca 100644 --- a/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php +++ b/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php @@ -2,6 +2,7 @@ declare(strict_types=1); namespace wcf\data\reaction\type; use wcf\data\DatabaseObject; +use wcf\system\WCF; /** * Represents an object type definition. @@ -56,7 +57,48 @@ class ReactionType extends DatabaseObject { /** * @inheritDoc */ - public function getTitle() { + protected static $databaseTableIndexName = 'reactionTypeID'; + + /** + * @inheritDoc + */ + public function getTitle():string { return WCF::getLanguage()->get($this->reactionTitle); } + + /** + * Renders the reaction icon. + * + * @return string + */ + public function renderIcon():string { + switch ($this->iconType) { + case self::ICON_TYPE_ICON: { + return WCF::getTPL()->fetch('reactionTypeIcon', 'wcf', [ + 'reactionType' => $this + ], true); + break; + } + + case self::ICON_TYPE_IMAGE: + return WCF::getTPL()->fetch('reactionTypeImage', 'wcf', [ + 'reactionType' => $this + ], true); + break; + + default: + $parameters = [ + 'renderedTemplate' => null + ]; + + EventHandler::getInstance()->fireAction($this, 'renderIcon', $parameters); + + if ($parameters['renderedTemplate']) { + return $parameters['renderedTemplate']; + } + + throw new \LogicException("Unable to render the reaction type icon with the type '". $this->type ."'."); + break; + } + } } -- 2.20.1