From 63e477f7ebcb048e9999d29720f1890615089635 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 9 Aug 2019 16:07:41 +0200 Subject: [PATCH] Display the top reaction of an element --- com.woltlab.wcf/templates/__topReaction.tpl | 18 ++++++++++++ .../templates/articleListItems.tpl | 5 +--- com.woltlab.wcf/templates/boxArticleList.tpl | 4 +-- syncTemplates.json | 3 +- .../files/acp/templates/__topReaction.tpl | 18 ++++++++++++ .../article/ViewableArticleList.class.php | 5 ++++ .../system/reaction/ReactionHandler.class.php | 22 ++++++++++++++ .../install/files/style/ui/reactions.scss | 29 ++++++++++++++----- wcfsetup/install/lang/de.xml | 3 +- wcfsetup/install/lang/en.xml | 3 +- 10 files changed, 93 insertions(+), 17 deletions(-) create mode 100644 com.woltlab.wcf/templates/__topReaction.tpl create mode 100644 wcfsetup/install/files/acp/templates/__topReaction.tpl diff --git a/com.woltlab.wcf/templates/__topReaction.tpl b/com.woltlab.wcf/templates/__topReaction.tpl new file mode 100644 index 0000000000..5b59d4d134 --- /dev/null +++ b/com.woltlab.wcf/templates/__topReaction.tpl @@ -0,0 +1,18 @@ +{assign var='topReaction' value=$__wcf->getReactionHandler()->getTopReaction($cachedReactions)} +{if $topReaction} + {if $render === 'icon'} + {@$topReaction[reaction]->renderIcon()} + {elseif $render === 'tiny'} + + {@$topReaction[reaction]->renderIcon()} {#$topReaction[count]} + + {elseif $render === 'short'} + + {@$topReaction[reaction]->renderIcon()} × {#$topReaction[count]} + + {elseif $render === 'full'} + + {@$topReaction[reaction]->renderIcon()} {lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang} + + {/if} +{/if} diff --git a/com.woltlab.wcf/templates/articleListItems.tpl b/com.woltlab.wcf/templates/articleListItems.tpl index e774711210..3d487d6e3a 100644 --- a/com.woltlab.wcf/templates/articleListItems.tpl +++ b/com.woltlab.wcf/templates/articleListItems.tpl @@ -55,10 +55,7 @@
{if MODULE_LIKE && $__wcf->getSession()->getPermission('user.like.canViewLike') && $article->cumulativeLikes}
- - - {#$article->cumulativeLikes} - + {include file='__topReaction' cachedReactions=$article->cachedReactions render='short'}
{/if}
diff --git a/com.woltlab.wcf/templates/boxArticleList.tpl b/com.woltlab.wcf/templates/boxArticleList.tpl index 8c2ac9e051..e71772ec05 100644 --- a/com.woltlab.wcf/templates/boxArticleList.tpl +++ b/com.woltlab.wcf/templates/boxArticleList.tpl @@ -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} diff --git a/syncTemplates.json b/syncTemplates.json index b236044664..3387a2ce26 100644 --- a/syncTemplates.json +++ b/syncTemplates.json @@ -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 index 0000000000..5b59d4d134 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/__topReaction.tpl @@ -0,0 +1,18 @@ +{assign var='topReaction' value=$__wcf->getReactionHandler()->getTopReaction($cachedReactions)} +{if $topReaction} + {if $render === 'icon'} + {@$topReaction[reaction]->renderIcon()} + {elseif $render === 'tiny'} + + {@$topReaction[reaction]->renderIcon()} {#$topReaction[count]} + + {elseif $render === 'short'} + + {@$topReaction[reaction]->renderIcon()} × {#$topReaction[count]} + + {elseif $render === 'full'} + + {@$topReaction[reaction]->renderIcon()} {lang reaction=$topReaction[reaction] count=$topReaction[count]}wcf.like.reaction.topReaction{/lang} + + {/if} +{/if} diff --git a/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php b/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php index de8231b940..10b8d1750c 100644 --- a/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php +++ b/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php @@ -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)"; } /** diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index aa12a62491..8ca0638674 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -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; + } } diff --git a/wcfsetup/install/files/style/ui/reactions.scss b/wcfsetup/install/files/style/ui/reactions.scss index 91bad0434b..7d3f08d9f8 100644 --- a/wcfsetup/install/files/style/ui/reactions.scss +++ b/wcfsetup/install/files/style/ui/reactions.scss @@ -35,20 +35,20 @@ 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; @@ -160,3 +160,16 @@ } } } + +.topReactionFull, +.topReactionShort { + > .reactionType { + vertical-align: bottom; + } +} + +.topReactionTiny > .reactionType { + height: 16px; + vertical-align: top; + width: 16px; +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index dfaabb2016..f6fdd58f7f 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3205,7 +3205,7 @@ Benutzerkontos nun in vollem Umfang nutzen.]]> - + @@ -3983,6 +3983,7 @@ Dateianhänge: + getTitle()} × {#$count}]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index ab7e82c0c8..ca4d1107ae 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3129,7 +3129,7 @@ full extend.]]> - + @@ -3929,6 +3929,7 @@ Attachments: + getTitle()} × {#$count}]]> -- 2.20.1