From: Joshua Rüsweg Date: Mon, 8 Oct 2018 09:03:29 +0000 (+0200) Subject: Add neutral reaction count on like objects X-Git-Tag: 5.2.0_Alpha_1~364^2~11 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=fcf006de2c9cb2ca7ed284e8c0401090d9dc6e8f;p=GitHub%2FWoltLab%2FWCF.git Add neutral reaction count on like objects See #2508 --- diff --git a/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php b/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php index 9ac2d813b2..41a06a7cf4 100644 --- a/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php +++ b/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php @@ -21,6 +21,7 @@ use wcf\util\JSON; * @property-read integer|null $objectUserID id of the user who created the liked object or null if user has been deleted or object was created by guest * @property-read integer $likes number of likes of the liked object * @property-read integer $dislikes number of dislikes of the liked object + * @property-read integer $neutralReactions number of neutral reactions on the liked object * @property-read integer $cumulativeLikes cumulative result of likes (counting +1) and dislikes (counting -1) * @property-read string $cachedUsers serialized array with the ids and names of the three users who liked (+1) the object last * @property-read string $cachedReactions serialized array with the reactionTypeIDs and the count of the reactions diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index c7f503ad9a..cc3a0490c9 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -402,6 +402,7 @@ class ReactionHandler extends SingletonFactory { if ($likeObject->likeObjectID) { $likes = $likeObject->likes; $dislikes = $likeObject->dislikes; + $neutralReactions = $likeObject->neutralReactions; $cumulativeLikes = $likeObject->cumulativeLikes; if ($likeObject->cachedReactions !== null) { @@ -424,6 +425,9 @@ class ReactionHandler extends SingletonFactory { $dislikes--; $cumulativeLikes++; } + else { + $neutralReactions--; + } if (isset($cachedReactions[$like->getReactionType()->reactionTypeID])) { if (--$cachedReactions[$like->getReactionType()->reactionTypeID] == 0) { @@ -440,6 +444,9 @@ class ReactionHandler extends SingletonFactory { $dislikes++; $cumulativeLikes--; } + else { + $neutralReactions++; + } if (isset($cachedReactions[$reactionType->reactionTypeID])) { $cachedReactions[$reactionType->reactionTypeID]++; @@ -452,6 +459,7 @@ class ReactionHandler extends SingletonFactory { $updateData = [ 'likes' => $likes, 'dislikes' => $dislikes, + 'neutralReactions' => $neutralReactions, 'cumulativeLikes' => $cumulativeLikes, 'cachedReactions' => serialize($cachedReactions) ]; @@ -473,6 +481,7 @@ class ReactionHandler extends SingletonFactory { 'objectUserID' => $likeable->getUserID() ?: null, 'likes' => ($reactionType->isPositive()) ? 1 : 0, 'dislikes' => ($reactionType->isNegative()) ? 1 : 0, + 'neutralReactions' => ($reactionType->isNeutral()) ? 1 : 0, 'cumulativeLikes' => $cumulativeLikes, 'cachedReactions' => serialize($cachedReactions) ]); diff --git a/wcfsetup/install/files/lib/system/worker/LikeRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/LikeRebuildDataWorker.class.php index 66be02aa81..de4055b9c4 100644 --- a/wcfsetup/install/files/lib/system/worker/LikeRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/LikeRebuildDataWorker.class.php @@ -72,18 +72,22 @@ class LikeRebuildDataWorker extends AbstractRebuildDataWorker { $likeObjectData[$like->objectTypeID][$like->objectID] = [ 'likes' => 0, 'dislikes' => 0, + 'neutralReactions' => 0, 'cumulativeLikes' => 0, 'objectUserID' => $like->objectUserID, 'cachedReactions' => [] ]; } - if ($like->likeValue == Like::LIKE) { + if ($like->isLike()) { $likeObjectData[$like->objectTypeID][$like->objectID]['likes']++; } - else { + else if ($like->isDislike()) { $likeObjectData[$like->objectTypeID][$like->objectID]['dislikes']++; } + else { + $likeObjectData[$like->objectTypeID][$like->objectID]['neutralReactions']++; + } $likeObjectData[$like->objectTypeID][$like->objectID]['cumulativeLikes'] += $like->likeValue; if (!isset($likeObjectData[$like->objectTypeID][$like->objectID]['cachedReactions'][$like->getReactionType()->reactionTypeID])) { @@ -97,10 +101,11 @@ class LikeRebuildDataWorker extends AbstractRebuildDataWorker { UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $itemsToUser, false); $sql = "INSERT INTO wcf".WCF_N."_like_object - (objectTypeID, objectID, objectUserID, likes, dislikes, cumulativeLikes, cachedReactions) - VALUES (?, ?, ?, ?, ?, ?, ?) + (objectTypeID, objectID, objectUserID, likes, dislikes, neutralReactions, cumulativeLikes, cachedReactions) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE likes = likes + VALUES(likes), dislikes = dislikes + VALUES(dislikes), + neutralReactions = neutralReactions + VALUES(neutralReactions), cumulativeLikes = cumulativeLikes + VALUES(cumulativeLikes), cachedReactions = VALUES(cachedReactions)"; $statement = WCF::getDB()->prepareStatement($sql); @@ -114,6 +119,7 @@ class LikeRebuildDataWorker extends AbstractRebuildDataWorker { $data['objectUserID'], $data['likes'], $data['dislikes'], + $data['neutralReactions'], $data['cumulativeLikes'], serialize($data['cachedReactions']) ]); diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index b8b6ed5786..80786e7644 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -647,6 +647,7 @@ CREATE TABLE wcf1_like_object ( objectUserID INT(10), likes MEDIUMINT(7) NOT NULL DEFAULT 0, dislikes MEDIUMINT(7) NOT NULL DEFAULT 0, + neutralReactions MEDIUMINT(7) NOT NULL DEFAULT 0, cumulativeLikes MEDIUMINT(7) NOT NULL DEFAULT 0, cachedUsers TEXT, cachedReactions TEXT,