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.
}
/**
+ * 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
{
$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();
}
*/
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 {
}
}
}
+ $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
$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']
+ );
+ }
}
$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']
+ );
+ }
}