Support returning basic folder data from the cache.
authorGunnar Wrobel <p@rdus.de>
Mon, 17 Jan 2011 09:17:32 +0000 (10:17 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 17 Jan 2011 09:17:32 +0000 (10:17 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Base.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Cache.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/BaseTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/CacheTest.php

index 088b7fe..2d95b1f 100644 (file)
@@ -45,6 +45,15 @@ extends Horde_Kolab_Storage_Query
     public function listFolderTypeAnnotations();
 
     /**
+     * List basic folder data for the folders of a specific type.
+     *
+     * @param string $type The folder type the listing should be limited to.
+     *
+     * @return array The list of folders.
+     */
+    public function dataByType($type);
+
+    /**
      * List all folders of a specific type.
      *
      * @param string $type The folder type the listing should be limited to.
index 489a5e0..ffb6b8b 100644 (file)
@@ -105,6 +105,28 @@ implements Horde_Kolab_Storage_List_Query
     }
 
     /**
+     * List basic folder data for the folders of a specific type.
+     *
+     * @param string $type The folder type the listing should be limited to.
+     *
+     * @return array The list of folders.
+     */
+    public function dataByType($type)
+    {
+        $result = array();
+        $namespace = $this->_list->getNamespace();
+        foreach ($this->listTypes() as $folder => $folder_type) {
+            if ($folder_type == $type) {
+                $result[$folder] = array(
+                    'owner' => $namespace->getOwner($folder),
+                    'name' => $namespace->getTitle($folder),
+                );
+            }
+        }
+        return $result;
+    }
+
+    /**
      * Get the folder owners.
      *
      * @return array The folder owners with the folder names as key and the
index 924b929..7ab28c9 100644 (file)
@@ -117,7 +117,24 @@ implements Horde_Kolab_Storage_List_Query
     {
         $by_type = $this->_list_cache->getQuery(self::BY_TYPE);
         if (isset($by_type[$type])) {
-            return $by_type[$type];
+            return array_keys($by_type[$type]);
+        } else {
+            return array();
+        }
+    }
+
+    /**
+     * List basic folder data for the folders of a specific type.
+     *
+     * @param string $type The folder type the listing should be limited to.
+     *
+     * @return array The list of folders.
+     */
+    public function dataByType($type)
+    {
+        $data_by_type = $this->_list_cache->getQuery(self::BY_TYPE);
+        if (isset($data_by_type[$type])) {
+            return $data_by_type[$type];
         } else {
             return array();
         }
@@ -199,30 +216,30 @@ implements Horde_Kolab_Storage_List_Query
      */
     public function synchronize()
     {
-        $types = array();
-        $by_type = array();
-        foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
-            $type = $annotation->getType();
-            $types[$folder] = $type;
-            $by_type[$type][] = $folder;
-        }
-        $this->_list_cache->setQuery(self::TYPES, $types);
-        $this->_list_cache->setQuery(self::BY_TYPE, $by_type);
+        $namespace = $this->_list->getNamespace();
 
         $owners = array();
-        $namespace = $this->_list->getNamespace();
         foreach ($this->_list->listFolders() as $folder) {
             $owners[$folder] = $namespace->getOwner($folder);
         }
         $this->_list_cache->setQuery(self::OWNERS, $owners);
 
+        $types = array();
+        $by_type = array();
         $personal_defaults = array();
         $defaults = array();
-        $namespace = $this->_list->getNamespace();
+
         foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
+            $type = $annotation->getType();
+            $owner = $namespace->getOwner($folder);
+            $title = $namespace->getTitle($folder);
+
+            $types[$folder] = $type;
+            $by_type[$type][$folder] = array(
+                'owner' => $owner, 'name' => $title
+            );
+
             if ($annotation->isDefault()) {
-                $type = $annotation->getType();
-                $owner = $namespace->getOwner($folder);
                 if (!isset($defaults[$owner][$type])) {
                     $defaults[$owner][$type] = $folder;
                 } else {
@@ -252,6 +269,8 @@ implements Horde_Kolab_Storage_List_Query
                 }
             }
         }
+        $this->_list_cache->setQuery(self::TYPES, $types);
+        $this->_list_cache->setQuery(self::BY_TYPE, $by_type);
         $this->_list_cache->setQuery(self::DEFAULTS, $defaults);
         $this->_list_cache->setQuery(
             self::PERSONAL_DEFAULTS, $personal_defaults
index 97a90ab..cba65b5 100644 (file)
@@ -295,4 +295,47 @@ extends Horde_Kolab_Storage_TestCase
             $query->listDefaults()
         );
     }
+
+    public function testDataByTypeReturnsArray()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getNullList($factory));
+        $this->assertType('array', $query->dataByType('test'));
+    }
+
+    public function testListCalendarsListsCalendarData()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+        $this->assertEquals(array('INBOX/Calendar'), array_keys($query->dataByType('event')));
+    }
+
+    public function testListTasklistsListsTasklistData()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+        $this->assertEquals(array('INBOX/Tasks'), array_keys($query->dataByType('task')));
+    }
+
+    public function testListDataHasOwner()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+        $data = $query->dataByType('event');
+        $this->assertEquals(
+            'test@example.com',
+            $data['INBOX/Calendar']['owner']
+        );
+    }
+
+    public function testListDataHasTitle()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+        $data = $query->dataByType('event');
+        $this->assertEquals(
+            'Calendar',
+            $data['INBOX/Calendar']['name']
+        );
+    }
 }
index 9ccb05a..844c8d0 100644 (file)
@@ -302,4 +302,47 @@ extends Horde_Kolab_Storage_TestCase
             $query->listDefaults()
         );
     }
+
+    public function testDataByTypeReturnsArray()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getNullList($factory), $factory);
+        $this->assertType('array', $query->dataByType('test'));
+    }
+
+    public function testListCalendarsListsCalendarData()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+        $this->assertEquals(array('INBOX/Calendar'), array_keys($query->dataByType('event')));
+    }
+
+    public function testListTasklistsListsTasklistData()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+        $this->assertEquals(array('INBOX/Tasks'), array_keys($query->dataByType('task')));
+    }
+
+    public function testListDataHasOwner()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+        $data = $query->dataByType('event');
+        $this->assertEquals(
+            'test@example.com',
+            $data['INBOX/Calendar']['owner']
+        );
+    }
+
+    public function testListDataHasTitle()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+        $data = $query->dataByType('event');
+        $this->assertEquals(
+            'Calendar',
+            $data['INBOX/Calendar']['name']
+        );
+    }
 }