Add UserCollapsibleContentHandler::resetAll()
authorMatthias Schmidt <gravatronics@live.com>
Wed, 31 Dec 2014 16:09:49 +0000 (17:09 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 31 Dec 2014 16:09:49 +0000 (17:09 +0100)
wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php

index b40104df37cdbf3b9cb172a366c5c70da5aac89b..b949f0d28200d953cdc5c67f00c89942dbce9cd4 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\user\collapsible\content;
 use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\SystemException;
 use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\SingletonFactory;
@@ -247,4 +248,31 @@ class UserCollapsibleContentHandler extends SingletonFactory {
                        WCF::getSession()->register('collapsedContent', $collapsedContent);
                }
        }
+       
+       /**
+        * Deletes the saved states for a specific object or all objects of a
+        * specific object type for all users.
+        * 
+        * @param       string          $objectType
+        * @param       integer         $objectID
+        */
+       public function resetAll($objectType, $objectID = null) {
+               $objectTypeID = $this->getObjectTypeID($objectType);
+               if (!$objectTypeID) {
+                       throw new SystemException("Unknown collapsible object type '".$objectType."'");
+               }
+               
+               $conditionBuilder = new PreparedStatementConditionBuilder();
+               $conditionBuilder->add('objectTypeID = ?', array($objectTypeID));
+               if ($objectID) {
+                       $conditionBuilder->add('objectID = ?', array($objectID));
+               }
+               
+               $sql = "DELETE FROM     wcf".WCF_N."_user_collapsible_content
+                       ".$conditionBuilder;
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute($conditionBuilder->getParameters());
+               
+               UserStorageHandler::getInstance()->resetAll('collapsedContent-'.$objectTypeID);
+       }
 }