Cached folder owner list.
authorGunnar Wrobel <p@rdus.de>
Sat, 8 Jan 2011 20:32:53 +0000 (21:32 +0100)
committerGunnar Wrobel <p@rdus.de>
Sat, 8 Jan 2011 20:32:53 +0000 (21:32 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Cache.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/CacheTest.php

index d12b470..4269c7a 100644 (file)
@@ -59,7 +59,7 @@ extends Horde_Kolab_Storage_Query
      * @return array The folder owners with the folder names as key and the
      *               owner as values.
      */
-//    public function listOwners();
+    public function listOwners();
 
     /**
      * Get the default folder for a certain type.
index de3a299..714c98f 100644 (file)
@@ -34,6 +34,9 @@ implements Horde_Kolab_Storage_List_Query
     /** The folder list sorted by type */
     const BY_TYPE = 'BY_TYPE';
 
+    /** The folder owner list */
+    const OWNERS = 'OWNERS';
+
     /**
      * The queriable list.
      *
@@ -115,6 +118,17 @@ implements Horde_Kolab_Storage_List_Query
     }
 
     /**
+     * Get the folder owners.
+     *
+     * @return array The folder owners with the folder names as key and the
+     *               owner as values.
+     */
+    public function listOwners()
+    {
+        return $this->_list_cache->getQuery(self::OWNERS);
+    }
+
+    /**
      * Synchronize the query data with the information from the backend.
      *
      * @return NULL
@@ -130,5 +144,12 @@ implements Horde_Kolab_Storage_List_Query
         }
         $this->_list_cache->setQuery(self::TYPES, $types);
         $this->_list_cache->setQuery(self::BY_TYPE, $by_type);
+
+        $owners = array();
+        $namespace = $this->_list->getNamespace();
+        foreach ($this->_list->listFolders() as $folder) {
+            $owners[$folder] = $namespace->getOwner($folder);
+        }
+        $this->_list_cache->setQuery(self::OWNERS, $owners);
     }
 }
\ No newline at end of file
index 0be91df..c1f6df3 100644 (file)
@@ -94,4 +94,53 @@ extends Horde_Kolab_Storage_TestCase
         $this->assertEquals(array('INBOX/Tasks'), $query->listByType('task'));
     }
 
+    public function testListOwnersReturn()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+        $this->assertType(
+            'array',
+            $query->listOwners()
+        );
+    }
+
+    public function testListOwnerList()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+        $this->assertEquals(
+            array(
+                'INBOX' => 'test@example.com',
+                'INBOX/Calendar' => 'test@example.com',
+                'INBOX/Contacts' => 'test@example.com',
+                'INBOX/Notes' => 'test@example.com',
+                'INBOX/Tasks' => 'test@example.com',
+                'INBOX/a' => 'test@example.com',
+            ),
+            $query->listOwners()
+        );
+    }
+
+    public function testListOwnerNamespace()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getNamespaceList($factory), $factory);
+        $this->assertEquals(
+            array(
+                'INBOX' => 'test@example.com',
+                'INBOX/Calendar' => 'test@example.com',
+                'INBOX/Contacts' => 'test@example.com',
+                'INBOX/Notes' => 'test@example.com',
+                'INBOX/Tasks' => 'test@example.com',
+                'INBOX/a' => 'test@example.com',
+                'shared.Calendars/All' => 'anonymous',
+                'shared.Calendars/Others' => 'anonymous',
+                'user/example/Calendar' => 'example@example.com',
+                'user/example/Notes' => 'example@example.com',
+                'user/someone/Calendars/Events' => 'someone@example.com',
+                'user/someone/Calendars/Party' => 'someone@example.com',
+            ),
+            $query->listOwners()
+        );
+    }
 }