Added 'categoryName' for object type definitions
authorAlexander Ebert <ebert@woltlab.com>
Fri, 14 Sep 2012 12:22:53 +0000 (14:22 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 14 Sep 2012 12:22:53 +0000 (14:22 +0200)
wcfsetup/install/files/lib/data/object/type/ObjectTypeCache.class.php
wcfsetup/install/files/lib/system/cache/builder/ObjectTypeCacheBuilder.class.php
wcfsetup/install/files/lib/system/package/plugin/ObjectTypeDefinitionPackageInstallationPlugin.class.php
wcfsetup/setup/db/install.sql

index c348ee3c4868eb54afedf8b269a9847f622f5071..b3d74f56cdbc0f934c9cde8431fb74b46c6dfed4 100644 (file)
@@ -20,6 +20,12 @@ class ObjectTypeCache extends SingletonFactory {
         */
        protected $definitions = array();
        
+       /**
+        * object type definition ids grouped by category name
+        * @var array<integer>
+        */
+       protected $definitionsByCategory = array();
+       
        /**
         * object type definitions sorted by name
         * @var array<wcf\data\object\type\definition\ObjectTypeDefinition>
@@ -44,6 +50,7 @@ class ObjectTypeCache extends SingletonFactory {
        protected function init() {
                // get definition cache
                CacheHandler::getInstance()->addResource('objectType-'.PACKAGE_ID, WCF_DIR.'cache/cache.objectType-'.PACKAGE_ID.'.php', 'wcf\system\cache\builder\ObjectTypeCacheBuilder');
+               $this->definitionsByCategory = CacheHandler::getInstance()->get('objectType-'.PACKAGE_ID, 'categories');
                $this->definitions = CacheHandler::getInstance()->get('objectType-'.PACKAGE_ID, 'definitions');
                foreach ($this->definitions as $definition) {
                        $this->definitionsByName[$definition->definitionName] = $definition;
@@ -89,6 +96,25 @@ class ObjectTypeCache extends SingletonFactory {
                return null;
        }
        
+       /**
+        * Returns a list of definitions by category name or 'null' if category name is invalid.
+        * 
+        * @param       string          $categoryName
+        * @return      array<wcf\data\object\type\definition\ObjectTypeDefinition>
+        */
+       public function getDefinitionsByCategory($categoryName) {
+               if (isset($this->definitionsByCategory[$categoryName])) {
+                       $definitions = array();
+                       foreach ($this->definitionsByCategory[$categoryName] as $definitionID) {
+                               $definitions[$definitionID] = $this->getDefinition($definitionID);
+                       }
+                       
+                       return $definitions;
+               }
+               
+               return null;
+       }
+       
        /**
         * Gets an object type by id
         * 
index 00242ebefcb5e9bc30278dbea833bb24ec07fdf1..fcba671c267485aa0e394322e51bbd9f344f4919 100644 (file)
@@ -21,6 +21,7 @@ class ObjectTypeCacheBuilder implements ICacheBuilder {
        public function getData(array $cacheResource) {
                list($cache, $packageID) = explode('-', $cacheResource['cache']);
                $data = array(
+                       'categories' => array(),
                        'definitions' => array(),
                        'objectTypes' => array()
                );
@@ -36,6 +37,14 @@ class ObjectTypeCacheBuilder implements ICacheBuilder {
                $statement->execute(array($packageID));
                while ($row = $statement->fetchArray()) {
                        $data['definitions'][$row['definitionID']] = new ObjectTypeDefinition(null, $row);
+                       
+                       if ($row['categoryName']) {
+                               if (!isset($data['categories'][$row['categoryName']])) {
+                                       $data['categories'][$row['categoryName']] = array();
+                               }
+                               
+                               $data['categories'][$row['categoryName']][] = $row['definitionID'];
+                       }
                }
 
                // get object types
index d350ec3f9a9d9fee9663303c372bef8be5aef5ff..90f79563205db4e32bb3e18eebb93f37c7b78d23 100644 (file)
@@ -50,7 +50,8 @@ class ObjectTypeDefinitionPackageInstallationPlugin extends AbstractXMLPackageIn
        protected function prepareImport(array $data) {
                return array(
                        'interfaceName' => (isset($data['elements']['interfacename']) ? $data['elements']['interfacename'] : ''),
-                       'definitionName' => $data['elements']['name']
+                       'definitionName' => $data['elements']['name'],
+                       'categoryName' => (isset($data['elements']['categoryname']) ? $data['elements']['categoryname'] : '')
                );
        }
        
index f1a9980636695725f0656eb7d3b7ab7ad88b4cca..8dbabbe0ad27014aa319fc8a84c0459175492dcb 100644 (file)
@@ -279,6 +279,7 @@ CREATE TABLE wcf1_object_type_definition (
        definitionName VARCHAR(255) NOT NULL,
        packageID INT(10) NOT NULL,
        interfaceName VARCHAR(255) NOT NULL DEFAULT '',
+       categoryName VARCHAR(80) NOT NULL DEFAULT '',
        UNIQUE KEY definitionName (definitionName, packageID)
 );