Add a function to set a object visit by given userIDs (#2159)
authorCyperghost <olaf_schmitz_1@t-online.de>
Tue, 3 Jan 2017 18:39:28 +0000 (19:39 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 3 Jan 2017 18:39:28 +0000 (19:39 +0100)
* Add a function to set a object visit by given userIDs

* Add transaction and reformat code

* Add whitspaces

* fix indentation

wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php

index 79b4c8466e2733a360c06363a4794c757e2a0290..6f895241e7bab84adb1c2129a9b0ec8cfc2f4246 100644 (file)
@@ -148,6 +148,30 @@ class VisitTracker extends SingletonFactory {
                }
        }
        
+       /**
+        * Tracks an object visit for the users with the given ids.
+        *
+        * @param   string      $objectType
+        * @param   integer     $objectID
+        * @param   integer[]   $userIDs
+        * @param   int         $time
+        */
+       public function trackObjectVisitByUserIDs($objectType, $objectID, array $userIDs, $time = TIME_NOW) {
+               // save visit
+               $sql = "REPLACE INTO wcf".WCF_N."_tracked_visit
+                                       (objectTypeID, objectID, userID, visitTime)
+                       VALUES          (?, ?, ?, ?)";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $objectTypeID = $this->getObjectTypeID($objectType);
+               WCF::getDB()->beginTransaction();
+               
+               foreach ($userIDs as $userID) {
+                       $statement->execute([$objectTypeID, $objectID, $userID, $time]);
+               }
+               
+               WCF::getDB()->commitTransaction();
+       }
+       
        /**
         * Tracks an object visit.
         *