Display the top reaction of an element
authorAlexander Ebert <ebert@woltlab.com>
Fri, 9 Aug 2019 14:07:41 +0000 (16:07 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 9 Aug 2019 14:07:41 +0000 (16:07 +0200)
com.woltlab.wcf/templates/__topReaction.tpl [new file with mode: 0644]
com.woltlab.wcf/templates/articleListItems.tpl
com.woltlab.wcf/templates/boxArticleList.tpl
syncTemplates.json
wcfsetup/install/files/acp/templates/__topReaction.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php
wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php
wcfsetup/install/files/style/ui/reactions.scss
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

diff --git a/com.woltlab.wcf/templates/__topReaction.tpl b/com.woltlab.wcf/templates/__topReaction.tpl
new file mode 100644 (file)
index 0000000..5b59d4d
--- /dev/null
@@ -0,0 +1,18 @@
+{assign var='topReaction' value=$__wcf->getReactionHandler()->getTopReaction($cachedReactions)}
+{if $topReaction}
+       {if $render === 'icon'}
+               <span class="jsTooltip" title="{lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang}">{@$topReaction[reaction]->renderIcon()}</span>
+       {elseif $render === 'tiny'}
+               <span class="topReactionTiny jsTooltip" title="{lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang}">
+                       {@$topReaction[reaction]->renderIcon()} {#$topReaction[count]}
+               </span>
+       {elseif $render === 'short'}
+               <span class="topReactionShort jsTooltip" title="{lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang}">
+                       {@$topReaction[reaction]->renderIcon()} × {#$topReaction[count]}
+               </span>
+       {elseif $render === 'full'}
+               <span class="topReactionFull">
+                       {@$topReaction[reaction]->renderIcon()} {lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang}
+               </span>
+       {/if}
+{/if}
index e774711210b0896eb263dc87b481c6cf129e1d91..3d487d6e3a882af39debd6628fb2120c1911d885 100644 (file)
                                <div class="contentItemMetaIcons">
                                        {if MODULE_LIKE && $__wcf->getSession()->getPermission('user.like.canViewLike') && $article->cumulativeLikes}
                                                <div class="contentItemMetaIcon">
-                                                       <span class="icon icon16 fa-smile-o"></span>
-                                                       <span aria-label="{lang reactions=$article->cumulativeLikes}wcf.like.reaction.label{/lang}">
-                                                               {#$article->cumulativeLikes}
-                                                       </span>
+                                                       {include file='__topReaction' cachedReactions=$article->cachedReactions render='short'}
                                                </div>
                                        {/if}
                                        <div class="contentItemMetaIcon">
index 8c2ac9e051c5ea1307ec49f0db4f1cb83d59dd24..e71772ec0589bbae1d1a31df59d3ea79e905300d 100644 (file)
@@ -15,8 +15,8 @@
                                                        {elseif $boxSortField == 'comments'}
                                                                {$boxArticle->getDiscussionProvider()->getDiscussionCountPhrase()}
                                                        {elseif $boxSortField == 'cumulativeLikes'}
-                                                               {if MODULE_LIKE && $__wcf->getSession()->getPermission('user.like.canViewLike') && ($boxArticle->likes || $boxArticle->dislikes)}
-                                                                       {lang reactions=$boxArticle->cumulativeLikes}wcf.like.reaction.label{/lang}
+                                                               {if MODULE_LIKE && $__wcf->getSession()->getPermission('user.like.canViewLike') && $boxArticle->cachedReactions}
+                                                                       {include file='__topReaction' cachedReactions=$boxArticle->cachedReactions render='full'}
                                                                {/if}
                                                        {/if}
                                                </small>
index b236044664c074c21ba842500e0a03b2e8d150a0..3387a2ce26f4dcf13bd8be145fdfcc25d494ec18 100644 (file)
@@ -39,6 +39,7 @@
     "__tabTabMenuFormContainer",
     "__tagFormField",
     "__textFormField",
+    "__topReaction",
     "__uploadFormField",
     "__userFormField",
     "__usernameFormField",
@@ -79,4 +80,4 @@
     "wysiwyg",
     "wysiwygToolbar"
   ]
-}
+}
\ No newline at end of file
diff --git a/wcfsetup/install/files/acp/templates/__topReaction.tpl b/wcfsetup/install/files/acp/templates/__topReaction.tpl
new file mode 100644 (file)
index 0000000..5b59d4d
--- /dev/null
@@ -0,0 +1,18 @@
+{assign var='topReaction' value=$__wcf->getReactionHandler()->getTopReaction($cachedReactions)}
+{if $topReaction}
+       {if $render === 'icon'}
+               <span class="jsTooltip" title="{lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang}">{@$topReaction[reaction]->renderIcon()}</span>
+       {elseif $render === 'tiny'}
+               <span class="topReactionTiny jsTooltip" title="{lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang}">
+                       {@$topReaction[reaction]->renderIcon()} {#$topReaction[count]}
+               </span>
+       {elseif $render === 'short'}
+               <span class="topReactionShort jsTooltip" title="{lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang}">
+                       {@$topReaction[reaction]->renderIcon()} × {#$topReaction[count]}
+               </span>
+       {elseif $render === 'full'}
+               <span class="topReactionFull">
+                       {@$topReaction[reaction]->renderIcon()} {lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang}
+               </span>
+       {/if}
+{/if}
index de8231b9402ca5a6eaff5a83c85f61b55a8df310..10b8d1750c2afc73aec0af4cb902eb93d273e2b5 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\data\article;
 use wcf\data\article\content\ViewableArticleContentList;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\label\object\ArticleLabelObjectHandler;
+use wcf\system\reaction\ReactionHandler;
 use wcf\system\visitTracker\VisitTracker;
 use wcf\system\WCF;
 
@@ -44,6 +45,10 @@ class ViewableArticleList extends ArticleList {
                        $this->sqlSelects .= 'tracked_visit.visitTime';
                        $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_tracked_visit tracked_visit ON (tracked_visit.objectTypeID = ".VisitTracker::getInstance()->getObjectTypeID('com.woltlab.wcf.article')." AND tracked_visit.objectID = article.articleID AND tracked_visit.userID = ".WCF::getUser()->userID.")";
                }
+               
+               if (!empty($this->sqlSelects)) $this->sqlSelects .= ',';
+               $this->sqlSelects .= "like_object.cachedReactions";
+               $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_like_object like_object ON (like_object.objectTypeID = ".ReactionHandler::getInstance()->getObjectType('com.woltlab.wcf.likeableArticle')->objectTypeID." AND like_object.objectID = article.articleID)";
        }
        
        /**
index aa12a62491bbb713f45374e09ca09c10c5088c80..8ca0638674566e9d604b142da7f6cd8b91a419b0 100644 (file)
@@ -734,4 +734,26 @@ class ReactionHandler extends SingletonFactory {
                
                return $firstReactionType ? $firstReactionType->reactionTypeID : null;
        }
+       
+       /**
+        * @param string|null $cachedReactions
+        * @return array|null
+        * @since 5.2
+        */
+       public function getTopReaction($cachedReactions) {
+               if ($cachedReactions) {
+                       $cachedReactions = @unserialize($cachedReactions);
+                       
+                       if (is_array($cachedReactions) && !empty($cachedReactions)) {
+                               asort($cachedReactions, SORT_NUMERIC);
+                               
+                               return [
+                                       'count' => current($cachedReactions),
+                                       'reaction' => ReactionTypeCache::getInstance()->getReactionTypeByID(key($cachedReactions)),
+                               ];
+                       }
+               }
+               
+               return null;
+       }
 }
index 91bad0434b3ce42729228fde68a4462120ec2e24..7d3f08d9f86779c7108f04567b530238e8060c10 100644 (file)
        flex-wrap: wrap;
        margin: -5px -5px 0 0;
        
-       .reactionCount{
-               @include wcfFontSmall;
-               
-               &::before {
-                       content: ' × ';
-               }
-       }
-       
        &.reactionSummaryListTiny .reactionType {
                width: 16px;
                height: 16px;
        }
 }
 
+.reactionCount{
+       @include wcfFontSmall;
+       
+       &::before {
+               content: ' × ';
+       }
+}
+
 .reactCountButton {
        color: $wcfContentDimmedText;
        flex: 0 0 auto;
                }
        }
 }
+
+.topReactionFull,
+.topReactionShort {
+       > .reactionType {
+               vertical-align: bottom;
+       }
+}
+
+.topReactionTiny > .reactionType {
+       height: 16px;
+       vertical-align: top;
+       width: 16px;
+}
index dfaabb2016c9138b07f713288b1259470a3e442b..f6fdd58f7f6d31bb8e7805acc4eb8252cef24b69 100644 (file)
@@ -3205,7 +3205,7 @@ Benutzerkontos nun in vollem Umfang nutzen.]]></item>
                <item name="wcf.article.comment"><![CDATA[Artikel-Kommentar]]></item>
                <item name="wcf.article.commentResponse"><![CDATA[Antwort auf Artikel-Kommentar]]></item>
                <item name="wcf.article.sortField.comments"><![CDATA[Kommentare]]></item>
-               <item name="wcf.article.sortField.cumulativeLikes"><![CDATA[Likes]]></item>
+               <item name="wcf.article.sortField.cumulativeLikes"><![CDATA[Reaktionen]]></item>
                <item name="wcf.article.sortField.random"><![CDATA[Zufällig]]></item>
                <item name="wcf.article.sortField.time"><![CDATA[Datum]]></item>
                <item name="wcf.article.sortField.views"><![CDATA[Zugriffe]]></item>
@@ -3983,6 +3983,7 @@ Dateianhänge:
                <item name="wcf.like.reaction.label"><![CDATA[{#$reactions} Reaktion{if $reactions != 1}en{/if}]]></item>
                <item name="wcf.like.reaction.more"><![CDATA[Weitere Reaktionen]]></item>
                <item name="wcf.like.reaction.noMoreEntries"><![CDATA[Keine weiteren Reaktionen]]></item>
+               <item name="wcf.like.reaction.topReaction"><![CDATA[{$reaction->getTitle()} × {#$count}]]></item>
                <item name="wcf.like.reactionsReceived"><![CDATA[Erhaltene Reaktionen]]></item>
                <item name="wcf.like.reactionsGiven"><![CDATA[Vergebene Reaktionen]]></item>
        </category>
index ab7e82c0c8eacdc644568af0b5ccd5e00b9e6c46..ca4d1107ae431c8721cfcf5f4cdd28399f8d9466 100644 (file)
@@ -3129,7 +3129,7 @@ full extend.]]></item>
                <item name="wcf.article.comment"><![CDATA[Article Comment]]></item>
                <item name="wcf.article.commentResponse"><![CDATA[Reply to Article Comment]]></item>
                <item name="wcf.article.sortField.comments"><![CDATA[Comments]]></item>
-               <item name="wcf.article.sortField.cumulativeLikes"><![CDATA[Likes]]></item>
+               <item name="wcf.article.sortField.cumulativeLikes"><![CDATA[Reactions]]></item>
                <item name="wcf.article.sortField.random"><![CDATA[Random]]></item>
                <item name="wcf.article.sortField.time"><![CDATA[Date]]></item>
                <item name="wcf.article.sortField.views"><![CDATA[Views]]></item>
@@ -3929,6 +3929,7 @@ Attachments:
                <item name="wcf.like.reaction.label"><![CDATA[{#$reactions} reaction{if $reactions != 1}s{/if}]]></item>
                <item name="wcf.like.reaction.more"><![CDATA[More Reactions]]></item>
                <item name="wcf.like.reaction.noMoreEntries"><![CDATA[There are no new reactions at the moment.]]></item>
+               <item name="wcf.like.reaction.topReaction"><![CDATA[{$reaction->getTitle()} × {#$count}]]></item>
                <item name="wcf.like.reactionsReceived"><![CDATA[Reactions Received]]></item>
                <item name="wcf.like.reactionsGiven"><![CDATA[Reactions Given]]></item>
        </category>