Support listing personal and all default folders.
authorGunnar Wrobel <p@rdus.de>
Sun, 9 Jan 2011 20:46:02 +0000 (21:46 +0100)
committerGunnar Wrobel <p@rdus.de>
Sun, 9 Jan 2011 20:46:02 +0000 (21:46 +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 ac8d425..088b7fe 100644 (file)
@@ -62,6 +62,15 @@ extends Horde_Kolab_Storage_Query
     public function listOwners();
 
     /**
+     * Return the list of default folders.
+     *
+     * @return array An array with owners as keys and another array as
+     *               value. The second array associates type (key) with the
+     *               corresponding default folder (value).
+     */
+    public function listDefaults();
+
+    /**
      * Get the default folder for a certain type.
      *
      * @param string $type The type of the share/folder.
index 31ad236..489a5e0 100644 (file)
@@ -121,6 +121,45 @@ implements Horde_Kolab_Storage_List_Query
     }
 
     /**
+     * Return the list of personal default folders.
+     *
+     * @return array An array that associates type (key) with the corresponding
+     *               default folder name (value).
+     */
+    public function listPersonalDefaults()
+    {
+        $result = array();
+        $namespace = $this->_list->getNamespace();
+        foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
+            if ($annotation->isDefault()
+                && ($namespace->matchNamespace($folder)->getType()
+                    == Horde_Kolab_Storage_Folder_Namespace::PERSONAL)) {
+                $result[$annotation->getType()] = $folder;
+            }
+        }
+        return $result;
+    }
+
+    /**
+     * Return the list of default folders.
+     *
+     * @return array An array with owners as keys and another array as
+     *               value. The second array associates type (key) with the
+     *               corresponding default folder (value).
+     */
+    public function listDefaults()
+    {
+        $result = array();
+        $namespace = $this->_list->getNamespace();
+        foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
+            if ($annotation->isDefault()) {
+                $result[$namespace->getOwner($folder)][$annotation->getType()] = $folder;
+            }
+        }
+        return $result;
+    }
+
+    /**
      * Get the default folder for a certain type.
      *
      * @param string $type The type of the share/folder.
index 8f6d639..924b929 100644 (file)
@@ -135,6 +135,29 @@ implements Horde_Kolab_Storage_List_Query
     }
 
     /**
+     * Return the list of personal default folders.
+     *
+     * @return array An array that associates type (key) with the corresponding
+     *               default folder name (value).
+     */
+    public function listPersonalDefaults()
+    {
+        return $this->_list_cache->getQuery(self::PERSONAL_DEFAULTS);
+    }
+
+    /**
+     * Return the list of default folders.
+     *
+     * @return array An array with owners as keys and another array as
+     *               value. The second array associates type (key) with the
+     *               corresponding default folder (value).
+     */
+    public function listDefaults()
+    {
+        return $this->_list_cache->getQuery(self::DEFAULTS);
+    }
+
+    /**
      * Get the default folder for a certain type.
      *
      * @param string $type The type of the share/folder.
index 011c6fb..97a90ab 100644 (file)
@@ -263,4 +263,36 @@ extends Horde_Kolab_Storage_TestCase
         $query = $factory->createListQuery('Base', $this->getDoubleEventList($factory));
         $query->getForeignDefault('someone@example.com', 'event');
     }
+
+    public function testListPersonalDefaults()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+        $this->assertEquals(
+            array(
+                'contact' => 'INBOX/Contacts',
+                'event' => 'INBOX/Calendar',
+                'note' => 'INBOX/Notes',
+                'task' => 'INBOX/Tasks'
+            ),
+            $query->listPersonalDefaults()
+        );
+    }
+
+    public function testListDefaults()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getForeignDefaultList($factory));
+        $this->assertEquals(
+            array(
+                'example@example.com' => array(
+                    'event' => 'user/example/Calendar'
+                ),
+                'someone@example.com' => array(
+                    'event' => 'user/someone/Calendars/Events'
+                )
+            ),
+            $query->listDefaults()
+        );
+    }
 }
index c9dd17c..9ccb05a 100644 (file)
@@ -270,4 +270,36 @@ extends Horde_Kolab_Storage_TestCase
         $query = $this->getCachedQueryForList($this->getDoubleEventList($factory), $factory);
         $query->getForeignDefault('someone@example.com', 'event');
     }
+
+    public function testListPersonalDefaults()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+        $this->assertEquals(
+            array(
+                'contact' => 'INBOX/Contacts',
+                'event' => 'INBOX/Calendar',
+                'note' => 'INBOX/Notes',
+                'task' => 'INBOX/Tasks'
+            ),
+            $query->listPersonalDefaults()
+        );
+    }
+
+    public function testListDefaults()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $this->getCachedQueryForList($this->getForeignDefaultList($factory), $factory);
+        $this->assertEquals(
+            array(
+                'example@example.com' => array(
+                    'event' => 'user/example/Calendar'
+                ),
+                'someone@example.com' => array(
+                    'event' => 'user/someone/Calendars/Events'
+                )
+            ),
+            $query->listDefaults()
+        );
+    }
 }