Add basic reaction type icon rendering
authorJoshua Rüsweg <josh@bastelstu.be>
Tue, 10 Apr 2018 11:19:12 +0000 (13:19 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Tue, 10 Apr 2018 11:19:12 +0000 (13:19 +0200)
See #2508

com.woltlab.wcf/templates/reactionTypeIcon.tpl [new file with mode: 0644]
com.woltlab.wcf/templates/reactionTypeImage.tpl [new file with mode: 0644]
wcfsetup/install/files/acp/templates/reactionTypeIcon.tpl [new file with mode: 0644]
wcfsetup/install/files/acp/templates/reactionTypeImage.tpl [new file with mode: 0644]
wcfsetup/install/files/images/reaction/.htaccess [new file with mode: 0644]
wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php

diff --git a/com.woltlab.wcf/templates/reactionTypeIcon.tpl b/com.woltlab.wcf/templates/reactionTypeIcon.tpl
new file mode 100644 (file)
index 0000000..4075258
--- /dev/null
@@ -0,0 +1,5 @@
+<span
+       class="icon icon24 fa-{$reactionType->iconName} reactionType"
+       style="color: {$reactionType->iconColor};"
+       data-reaction-type-id="{$reactionType->reactionTypeID}"
+></span>
diff --git a/com.woltlab.wcf/templates/reactionTypeImage.tpl b/com.woltlab.wcf/templates/reactionTypeImage.tpl
new file mode 100644 (file)
index 0000000..a4577bb
--- /dev/null
@@ -0,0 +1,6 @@
+<img
+       src="{@$__wcf->getPath()}images/reaction/{$reactionType->iconFile}"
+       style="width:24px;height:24px"
+       class="reactionType"
+       data-reaction-type-id="{$reactionType->reactionTypeID}"
+/>
diff --git a/wcfsetup/install/files/acp/templates/reactionTypeIcon.tpl b/wcfsetup/install/files/acp/templates/reactionTypeIcon.tpl
new file mode 100644 (file)
index 0000000..4075258
--- /dev/null
@@ -0,0 +1,5 @@
+<span
+       class="icon icon24 fa-{$reactionType->iconName} reactionType"
+       style="color: {$reactionType->iconColor};"
+       data-reaction-type-id="{$reactionType->reactionTypeID}"
+></span>
diff --git a/wcfsetup/install/files/acp/templates/reactionTypeImage.tpl b/wcfsetup/install/files/acp/templates/reactionTypeImage.tpl
new file mode 100644 (file)
index 0000000..a4577bb
--- /dev/null
@@ -0,0 +1,6 @@
+<img
+       src="{@$__wcf->getPath()}images/reaction/{$reactionType->iconFile}"
+       style="width:24px;height:24px"
+       class="reactionType"
+       data-reaction-type-id="{$reactionType->reactionTypeID}"
+/>
diff --git a/wcfsetup/install/files/images/reaction/.htaccess b/wcfsetup/install/files/images/reaction/.htaccess
new file mode 100644 (file)
index 0000000..c8ab055
--- /dev/null
@@ -0,0 +1 @@
+# This file ensures that these folders are created during an update.
\ No newline at end of file
index 9d443dff7977670ca0f91b9908dd013a9ce0b4ee..e990e860cae9c4a9f11df200d6f6408fc5134bf8 100644 (file)
@@ -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;
+               }
+       }
 }