Moved collapsible handler into user namespace
authorAlexander Ebert <ebert@woltlab.com>
Wed, 19 Oct 2011 14:38:23 +0000 (16:38 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 19 Oct 2011 14:38:23 +0000 (16:38 +0200)
Renamed to reflect the user-related behavior

wcfsetup/install/files/lib/system/user/UserCollapsibleContentHandler.class.php [deleted file]
wcfsetup/install/files/lib/system/user/collapsible/content/ICollapsibleContentAction.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php [new file with mode: 0644]
wcfsetup/setup/db/install.sql

diff --git a/wcfsetup/install/files/lib/system/user/UserCollapsibleContentHandler.class.php b/wcfsetup/install/files/lib/system/user/UserCollapsibleContentHandler.class.php
deleted file mode 100644 (file)
index abc0a8f..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-<?php
-namespace wcf\system\user;
-use wcf\data\object\type\ObjectTypeCache;
-use wcf\system\SingletonFactory;
-use wcf\system\WCF;
-
-/**
- * Provides methods for handling collapsible containers.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2011 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.user
- * @category   Community Framework
- */
-class UserCollapsibleContentHandler extends SingletonFactory {
-       /**
-        * object type cache
-        * @var array<array>
-        */
-       protected $cache = null;
-       
-       /**
-        * list of collapsed object ids per object type id
-        * @var array<array>
-        */
-       protected $collapsedContent = array();
-       
-       /**
-        * @see wcf\system\SingletonFactory::init()
-        */
-       protected function init() {
-               $this->cache = array(
-                       'objectTypes' => array(),
-                       'objectTypeIDs' => array()
-               );
-               
-               $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.collapsibleContent');
-               foreach ($objectTypes as $objectType) {
-                       $this->cache['objectTypes'][$objectType->objectTypeID] = $objectType;
-                       $this->cache['objectTypeIDs'][$objectType->objectType] = $objectType->objectTypeID;
-               }
-       }
-       
-       /**
-        * Returns the object type id based upon specified object type name. Returns
-        * null, if object type is unknown.
-        * 
-        * @param       string          $objectType
-        * @return      integer
-        */
-       public function getObjectTypeID($objectType) {
-               if (isset($this->cache['objectTypeIDs'][$objectType])) {
-                       return $this->cache['objectTypeIDs'][$objectType];
-               }
-               
-               return null;
-       }
-       
-       /**
-        * Returns a list of object ids being collapsed by current user.
-        * 
-        * @param       integer         $objectTypeID
-        * @return      array<integer>
-        */
-       public function getCollapsedContent($objectTypeID) {
-               if (!isset($this->collapsedContent[$objectTypeID])) {
-                       $this->collapsedContent[$objectTypeID] = array();
-                       
-                       if (WCF::getUser()->userID) {
-                               $sql = "SELECT  objectID
-                                       FROM    wcf".WCF_N."_collapsible_content
-                                       WHERE   objectTypeID = ?
-                                       AND userID = ?";
-                               $statement = WCF::getDB()->prepareStatement($sql);
-                               $statement->execute(array(
-                                       $objectTypeID,
-                                       WCF::getUser()->userID
-                               ));
-                               while ($row = $statement->fetchArray()) {
-                                       $this->collapsedContent[$objectTypeID][] = $row['objectID'];
-                               }
-                       }
-                       else {
-                               $collapsedContent = WCF::getSession()->getVar('collapsedContent');
-                               if ($collapsedContent !== null && is_array($collapsedContent)) {
-                                       if (isset($collapsedContent[$objectTypeID])) {
-                                               $this->collapsedContent[$objectTypeID] = $collapsedContent[$objectTypeID];
-                                       }
-                               }
-                       }
-               }
-               
-               return $this->collapsedContent[$objectTypeID];
-       }
-       
-       /**
-        * Marks content as collapsed.
-        * 
-        * @param       integer         $objectTypeID
-        * @param       integer         $objectID
-        */
-       public function markAsCollapsed($objectTypeID, $objectID) {
-               if (WCF::getUser()->userID) {
-                       $sql = "SELECT  *
-                               FROM    wcf".WCF_N."_collapsible_content
-                               WHERE   objectTypeID = ?
-                                       AND objectID = ?
-                                       AND userID = ?";
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(array(
-                               $objectTypeID,
-                               $objectID,
-                               WCF::getUser()->userID
-                       ));
-                       $row = $statement->fetchArray();
-                       
-                       if (!$row) {
-                               $sql = "INSERT INTO     wcf".WCF_N."_collapsible_content
-                                                       (objectTypeID, objectID, userID)
-                                       VALUES          (?, ?, ?)";
-                               $statement = WCF::getDB()->prepareStatement($sql);
-                               $statement->execute(array(
-                                       $objectTypeID,
-                                       $objectID,
-                                       WCF::getUser()->userID
-                               ));
-                       }
-               }
-               else {
-                       $collapsedContent = WCF::getSession()->getVar('collapsedContent');
-                       if ($collapsedContent === null || !is_array($collapsedContent)) {
-                               $collapsedContent = array();
-                       }
-                       
-                       if (!in_array($objectID, $collapsedContent)) {
-                               $collapsedContent[$objectTypeID] = array();
-                       }
-                       
-                       $collapsedContent[$objectTypeID][] = $objectID;
-                       WCF::getSession()->register('collapsedContent', $collapsedContent);
-               }
-       }
-       
-       /**
-        * Marks content as opened, thus removing the collapsed marking.
-        * 
-        * @param       integer         $objectTypeID
-        * @param       integer         $objectID
-        */
-       public function markAsOpened($objectTypeID, $objectID) {
-               if (WCF::getUser()->userID) {
-                       $sql = "DELETE FROM     wcf".WCF_N."_collapsible_content
-                               WHERE           objectTypeID = ?
-                                               AND objectID = ?
-                                               AND userID = ?";
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(array(
-                               $objectTypeID,
-                               $objectID,
-                               WCF::getUser()->userID
-                       ));
-               }
-               else {
-                       $collapsedContent = WCF::getSession()->getVar('collapsedContent');
-                       if ($collapsedContent === null || !is_array($collapsedContent)) {
-                               $collapsedContent = array();
-                       }
-                       
-                       if (isset($collapsedContent[$objectTypeID])) {
-                               foreach ($collapsedContent[$objectTypeID] as $index => $collapsedObjectID) {
-                                       if ($collapsedObjectID == $objectID) {
-                                               unset($collapsedContent[$objectTypeID][$index]);
-                                       }
-                               }
-                       }
-                       
-                       WCF::getSession()->register('collapsedContent', $collapsedContent);
-               }
-       }
-}
diff --git a/wcfsetup/install/files/lib/system/user/collapsible/content/ICollapsibleContentAction.class.php b/wcfsetup/install/files/lib/system/user/collapsible/content/ICollapsibleContentAction.class.php
new file mode 100644 (file)
index 0000000..6d80be2
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+namespace wcf\system\user\collapsible\content;
+
+/**
+ * Provides basic methods to toggle container content.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.user.collapsible.content
+ * @category   Community Framework
+ */
+interface ICollapsibleContentAction {
+       /**
+        * Validates required parameters.
+        */
+       public function validateToggleContainer();
+       
+       /**
+        * Toggles the visibility of container content.
+        */
+       public function toggleContainer();
+}
diff --git a/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php b/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php
new file mode 100644 (file)
index 0000000..6463bf8
--- /dev/null
@@ -0,0 +1,182 @@
+<?php
+namespace wcf\system\user\collapsible\content;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\SingletonFactory;
+use wcf\system\WCF;
+
+/**
+ * Provides methods for handling collapsible containers.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.user.collapsible.content
+ * @category   Community Framework
+ */
+class UserCollapsibleContentHandler extends SingletonFactory {
+       /**
+        * object type cache
+        * @var array<array>
+        */
+       protected $cache = null;
+       
+       /**
+        * list of collapsed object ids per object type id
+        * @var array<array>
+        */
+       protected $collapsedContent = array();
+       
+       /**
+        * @see wcf\system\SingletonFactory::init()
+        */
+       protected function init() {
+               $this->cache = array(
+                       'objectTypes' => array(),
+                       'objectTypeIDs' => array()
+               );
+               
+               $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.collapsibleContent');
+               foreach ($objectTypes as $objectType) {
+                       $this->cache['objectTypes'][$objectType->objectTypeID] = $objectType;
+                       $this->cache['objectTypeIDs'][$objectType->objectType] = $objectType->objectTypeID;
+               }
+       }
+       
+       /**
+        * Returns the object type id based upon specified object type name. Returns
+        * null, if object type is unknown.
+        * 
+        * @param       string          $objectType
+        * @return      integer
+        */
+       public function getObjectTypeID($objectType) {
+               if (isset($this->cache['objectTypeIDs'][$objectType])) {
+                       return $this->cache['objectTypeIDs'][$objectType];
+               }
+               
+               return null;
+       }
+       
+       /**
+        * Returns a list of object ids being collapsed by current user.
+        * 
+        * @param       integer         $objectTypeID
+        * @return      array<integer>
+        */
+       public function getCollapsedContent($objectTypeID) {
+               if (!isset($this->collapsedContent[$objectTypeID])) {
+                       $this->collapsedContent[$objectTypeID] = array();
+                       
+                       if (WCF::getUser()->userID) {
+                               $sql = "SELECT  objectID
+                                       FROM    wcf".WCF_N."_user_collapsible_content
+                                       WHERE   objectTypeID = ?
+                                       AND userID = ?";
+                               $statement = WCF::getDB()->prepareStatement($sql);
+                               $statement->execute(array(
+                                       $objectTypeID,
+                                       WCF::getUser()->userID
+                               ));
+                               while ($row = $statement->fetchArray()) {
+                                       $this->collapsedContent[$objectTypeID][] = $row['objectID'];
+                               }
+                       }
+                       else {
+                               $collapsedContent = WCF::getSession()->getVar('collapsedContent');
+                               if ($collapsedContent !== null && is_array($collapsedContent)) {
+                                       if (isset($collapsedContent[$objectTypeID])) {
+                                               $this->collapsedContent[$objectTypeID] = $collapsedContent[$objectTypeID];
+                                       }
+                               }
+                       }
+               }
+               
+               return $this->collapsedContent[$objectTypeID];
+       }
+       
+       /**
+        * Marks content as collapsed.
+        * 
+        * @param       integer         $objectTypeID
+        * @param       integer         $objectID
+        */
+       public function markAsCollapsed($objectTypeID, $objectID) {
+               if (WCF::getUser()->userID) {
+                       $sql = "SELECT  *
+                               FROM    wcf".WCF_N."_user_collapsible_content
+                               WHERE   objectTypeID = ?
+                                       AND objectID = ?
+                                       AND userID = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array(
+                               $objectTypeID,
+                               $objectID,
+                               WCF::getUser()->userID
+                       ));
+                       $row = $statement->fetchArray();
+                       
+                       if (!$row) {
+                               $sql = "INSERT INTO     wcf".WCF_N."_user_collapsible_content
+                                                       (objectTypeID, objectID, userID)
+                                       VALUES          (?, ?, ?)";
+                               $statement = WCF::getDB()->prepareStatement($sql);
+                               $statement->execute(array(
+                                       $objectTypeID,
+                                       $objectID,
+                                       WCF::getUser()->userID
+                               ));
+                       }
+               }
+               else {
+                       $collapsedContent = WCF::getSession()->getVar('collapsedContent');
+                       if ($collapsedContent === null || !is_array($collapsedContent)) {
+                               $collapsedContent = array();
+                       }
+                       
+                       if (!in_array($objectID, $collapsedContent)) {
+                               $collapsedContent[$objectTypeID] = array();
+                       }
+                       
+                       $collapsedContent[$objectTypeID][] = $objectID;
+                       WCF::getSession()->register('collapsedContent', $collapsedContent);
+               }
+       }
+       
+       /**
+        * Marks content as opened, thus removing the collapsed marking.
+        * 
+        * @param       integer         $objectTypeID
+        * @param       integer         $objectID
+        */
+       public function markAsOpened($objectTypeID, $objectID) {
+               if (WCF::getUser()->userID) {
+                       $sql = "DELETE FROM     wcf".WCF_N."_user_collapsible_content
+                               WHERE           objectTypeID = ?
+                                               AND objectID = ?
+                                               AND userID = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array(
+                               $objectTypeID,
+                               $objectID,
+                               WCF::getUser()->userID
+                       ));
+               }
+               else {
+                       $collapsedContent = WCF::getSession()->getVar('collapsedContent');
+                       if ($collapsedContent === null || !is_array($collapsedContent)) {
+                               $collapsedContent = array();
+                       }
+                       
+                       if (isset($collapsedContent[$objectTypeID])) {
+                               foreach ($collapsedContent[$objectTypeID] as $index => $collapsedObjectID) {
+                                       if ($collapsedObjectID == $objectID) {
+                                               unset($collapsedContent[$objectTypeID][$index]);
+                                       }
+                               }
+                       }
+                       
+                       WCF::getSession()->register('collapsedContent', $collapsedContent);
+               }
+       }
+}
index f91162fb3fc2155b31aea4fc5ea7d4c8892bc92d..94e0b5c36ff26259a1a84c09cb39447fb741ae5b 100644 (file)
@@ -133,14 +133,6 @@ CREATE TABLE wcf1_clipboard_page (
        actionID INT(10) NOT NULL DEFAULT 0
 );
 
-DROP TABLE IF EXISTS wcf1_collapsible_content;
-CREATE TABLE wcf1_collapsible_content (
-       objectTypeID INT(10) NOT NULL,
-       objectID INT(10) NOT NULL,
-       userID INT(10) NOT NULL,
-       UNIQUE KEY (objectTypeID, objectID, userID)
-);
-
 DROP TABLE IF EXISTS wcf1_core_object;
 CREATE TABLE wcf1_core_object (
        objectID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -616,6 +608,14 @@ CREATE TABLE wcf1_user (
        KEY styleID (styleID)
 );
 
+DROP TABLE IF EXISTS wcf1_user_collapsible_content;
+CREATE TABLE wcf1_user_collapsible_content (
+       objectTypeID INT(10) NOT NULL,
+       objectID INT(10) NOT NULL,
+       userID INT(10) NOT NULL,
+       UNIQUE KEY (objectTypeID, objectID, userID)
+);
+
 DROP TABLE IF EXISTS wcf1_user_group;
 CREATE TABLE wcf1_user_group (
        groupID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -758,9 +758,6 @@ ALTER TABLE wcf1_clipboard_item_type ADD FOREIGN KEY (packageID) REFERENCES wcf1
 ALTER TABLE wcf1_clipboard_page ADD FOREIGN KEY (actionID) REFERENCES wcf1_clipboard_action (actionID) ON DELETE CASCADE;
 ALTER TABLE wcf1_clipboard_page ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
 
-ALTER TABLE wcf1_collapsible_content ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE;
-ALTER TABLE wcf1_collapsible_content ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;
-
 ALTER TABLE wcf1_core_object ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
 
 ALTER TABLE wcf1_cronjob ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
@@ -845,6 +842,9 @@ ALTER TABLE wcf1_template ADD FOREIGN KEY (templateGroupID) REFERENCES wcf1_temp
 
 ALTER TABLE wcf1_template_listener ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
 
+ALTER TABLE wcf1_user_collapsible_content ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE;
+ALTER TABLE wcf1_user_collapsible_content ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;
+
 ALTER TABLE wcf1_user_group_option ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
 
 ALTER TABLE wcf1_user_group_option_category ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;