Add method in LikeObject to get the reactionCache
authorJoshua Rüsweg <josh@bastelstu.be>
Tue, 17 Apr 2018 17:50:04 +0000 (19:50 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Tue, 17 Apr 2018 17:50:04 +0000 (19:50 +0200)
See #2508

wcfsetup/install/files/lib/data/like/object/LikeObject.class.php

index 71d76a9408d2ac767c2f8f47a6f937f13310b6f9..bbb897028b4614185efff792c714a6a1daa36fec 100644 (file)
@@ -42,6 +42,12 @@ class LikeObject extends DatabaseObject {
         */
        protected $users = [];
        
+       /**
+        * A list with all reaction counts. 
+        * @var integer[] 
+        */
+       protected $reactions = [];
+       
        /**
         * @inheritDoc
         */
@@ -59,12 +65,24 @@ class LikeObject extends DatabaseObject {
                                }
                        }
                }
+               
+               // get user objects from cache
+               if (!empty($data['cachedReactions'])) {
+                       $cachedReactions = @unserialize($data['cachedReactions']);
+                       
+                       if (is_array($cachedReactions)) {
+                               $this->reactions = $cachedReactions;
+                       }
+               }
+               
+               
        }
        
        /**
         * Returns the first 3 users who liked this object.
         * 
         * @return      User[]
+        * @deprecated  since 3.2, this value is no longer maintained
         */
        public function getUsers() {
                return $this->users;
@@ -83,6 +101,17 @@ class LikeObject extends DatabaseObject {
                return $this->likedObject;
        }
        
+       /**
+        * Returns all reaction counts for this object. Reactions without any count won't be saved in the array. 
+        * So this method returns an empty array, if this object has no reactions.
+        * 
+        * @return      integer[]
+        * @since       3.2
+        */
+       public function getReactions(): array {
+               return $this->reactions; 
+       }
+       
        /**
         * Sets the liked object.
         *