Add new user values for positive, negative, neutral received reactions
authorJoshua Rüsweg <josh@bastelstu.be>
Sun, 27 May 2018 19:07:31 +0000 (21:07 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Sun, 27 May 2018 19:07:31 +0000 (21:07 +0200)
See #2508

wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php
wcfsetup/setup/db/install.sql

index 3a23a28ee5214eba5981e1d45a629d79071546f3..ae07e29f05300685b6542639669e57088e1e9851 100644 (file)
@@ -418,36 +418,59 @@ class ReactionHandler extends SingletonFactory {
                                        if ($like->getReactionType()->isPositive()) {
                                                $userEditor = new UserEditor(UserRuntimeCache::getInstance()->getObject($likeable->getUserID()));
                                                $userEditor->updateCounters([
-                                                       'likesReceived' => -1
+                                                       'likesReceived' => -1, 
+                                                       'positiveReactionsReceived' => -1
                                                ]);
                                        }
-                               }
-                       } 
-                       else {
-                               if ($like->likeID) {
-                                       if ($like->getReactionType()->isPositive() && !$reactionType->isPositive()) {
+                                       else if ($like->getReactionType()->isNegative()) {
                                                $userEditor = new UserEditor(UserRuntimeCache::getInstance()->getObject($likeable->getUserID()));
                                                $userEditor->updateCounters([
-                                                       'likesReceived' => -1
+                                                       'negativeReactionsReceived' => -1
                                                ]);
                                        }
-                                       else if (!$like->getReactionType()->isPositive() && $reactionType->isPositive()) {
+                                       else if ($like->getReactionType()->isNeutral()) {
                                                $userEditor = new UserEditor(UserRuntimeCache::getInstance()->getObject($likeable->getUserID()));
                                                $userEditor->updateCounters([
-                                                       'likesReceived' => 1
+                                                       'neutralReactionsReceived' => -1
                                                ]);
                                        }
                                }
-                               else if ($reactionType->isPositive()) {
-                                       // update new
-                                       $userEditor = new UserEditor(UserRuntimeCache::getInstance()->getObject($likeable->getUserID()));
-                                       $userEditor->updateCounters([
-                                               'likesReceived' => 1
-                                       ]);
+                       } 
+                       else {
+                               $counters = [
+                                       'likesReceived' => 0,
+                                       'positiveReactionsReceived' => 0,
+                                       'negativeReactionsReceived' => 0,
+                                       'neutralReactionsReceived' => 0
+                               ];
+                               
+                               if ($like->likeID) {
+                                       if ($like->getReactionType()->isPositive()) {
+                                               $counters['likesReceived']--;
+                                               $counters['positiveReactionsReceived']--;
+                                       }
+                                       else if ($like->getReactionType()->isNegative()) {
+                                               $counters['negativeReactionsReceived']--;
+                                       }
+                                       else if ($like->getReactionType()->isNeutral()) {
+                                               $counters['neutralReactionsReceived']--;
+                                       }
+                               }
+                               
+                               if ($reactionType->isPositive()) {
+                                       $counters['likesReceived']++;
+                                       $counters['positiveReactionsReceived']++;
                                }
+                               else if ($reactionType->isNegative()) {
+                                       $counters['negativeReactionsReceived']++;
+                               }
+                               else if ($reactionType->isNeutral()) {
+                                       $counters['neutralReactionsReceived']++;
+                               }
+                               
+                               $userEditor = new UserEditor(UserRuntimeCache::getInstance()->getObject($likeable->getUserID()));
+                               $userEditor->updateCounters($counters);
                        }
-                       
-                       // @TODO update new user values positiveReactionsReceived, negativeReactionsReceived, neutralReactionsReceived
                }
        }
        
index f09784ca8106c81d898182531d4afc2cf5747692..b36ff42439e972a7c14c3b69a6c6ea8ea68f64b2 100644 (file)
@@ -1447,6 +1447,9 @@ CREATE TABLE wcf1_user (
        disableCoverPhoto TINYINT(1) NOT NULL DEFAULT 0,
        disableCoverPhotoReason TEXT,
        disableCoverPhotoExpires INT(10) NOT NULL DEFAULT 0,
+       positiveReactionsReceived MEDIUMINT(7) NOT NULL DEFAULT 0,
+       negativeReactionsReceived MEDIUMINT(7) NOT NULL DEFAULT 0,
+       neutralReactionsReceived MEDIUMINT(7) NOT NULL DEFAULT 0,
        
        KEY username (username),
        KEY email (email),
@@ -1456,6 +1459,9 @@ CREATE TABLE wcf1_user (
        KEY registrationData (registrationIpAddress, registrationDate),
        KEY activityPoints (activityPoints),
        KEY likesReceived (likesReceived),
+       KEY positiveReactionsReceived (positiveReactionsReceived),
+       KEY negativeReactionsReceived (negativeReactionsReceived),
+       KEY neutralReactionsReceived (neutralReactionsReceived),
        KEY authData (authData),
        KEY trophyPoints (trophyPoints)
 );