From: Gunnar Wrobel Date: Sun, 9 Jan 2011 20:46:02 +0000 (+0100) Subject: Support listing personal and all default folders. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b03aaae7d7ee4464888198e1fb355f4c4b0d728a;p=horde.git Support listing personal and all default folders. --- diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query.php index ac8d42570..088b7fe8e 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query.php @@ -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. diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Base.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Base.php index 31ad236af..489a5e036 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Base.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Base.php @@ -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. diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Cache.php index 8f6d639e8..924b92949 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Cache.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Cache.php @@ -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. diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/BaseTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/BaseTest.php index 011c6fbfa..97a90aba2 100644 --- a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/BaseTest.php +++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/BaseTest.php @@ -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() + ); + } } diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/CacheTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/CacheTest.php index c9dd17cb8..9ccb05aa8 100644 --- a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/CacheTest.php +++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/CacheTest.php @@ -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() + ); + } }