Added method to remove notifications
authorAlexander Ebert <ebert@woltlab.com>
Wed, 16 Jul 2014 20:08:12 +0000 (22:08 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 16 Jul 2014 20:08:12 +0000 (22:08 +0200)
wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php

index 966a3749843af2cd39ea7e3d0b4de1c64c096d1b..a7322d3ccfe0ed5b447df472b31edaf68d10d07d 100644 (file)
@@ -578,6 +578,45 @@ class UserNotificationHandler extends SingletonFactory {
                $this->markAsConfirmed($eventName, $objectType, $recipientIDs, $objectIDs);
        }
        
+       /**
+        * Removes notifications, this method should only be invoked for delete objects.
+        * 
+        * @param       string          $objectType
+        * @param       array<integer>  $objectIDs
+        */
+       public function removeNotifications($objectType, array $objectIDs) {
+               // check given object type
+               $objectTypeObj = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.notification.objectType', $objectType);
+               if ($objectTypeObj === null) {
+                       throw new SystemException("Unknown object type ".$objectType." given");
+               }
+               
+               // get event ids
+               $sql = "SELECT  eventID
+                       FROM    wcf".WCF_N."_user_notification_event
+                       WHERE   objectTypeID = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(
+                       $objectTypeObj->objectTypeID
+               ));
+               
+               $eventIDs = array();
+               while ($row = $statement->fetchArray()) {
+                       $eventIDs[] = $row['eventID'];
+               }
+               
+               if (!empty($eventIDs)) {
+                       $conditions = new PreparedStatementConditionBuilder();
+                       $conditions->add("eventID IN (?)", array($eventIDs));
+                       $conditions->add("objectID IN (?)", array($objectIDs));
+                       
+                       $sql = "DELETE FROM     wcf".WCF_N."_user_notification
+                               ".$conditions;
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute($conditions->getParameters());
+               }
+       }
+       
        /**
         * Marks notifications as confirmed
         *