Basic share list.
authorGunnar Wrobel <p@rdus.de>
Sun, 16 Jan 2011 06:46:28 +0000 (07:46 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 17 Jan 2011 10:33:07 +0000 (11:33 +0100)
framework/Share/lib/Horde/Share/Kolab.php
framework/Share/lib/Horde/Share/Object/Kolab.php
framework/Share/test/Horde/Share/Kolab/UnitTest.php

index 82404fb..c042d7d 100644 (file)
@@ -105,7 +105,12 @@ class Horde_Share_Kolab extends Horde_Share_Base
      */
     protected function _listShares($userid, array $params = array())
     {
-        return array();
+        return array_map(
+            'rawurlencode',
+            $this->_storage->getList()
+            ->getQuery('Base')
+            ->listByType($this->_type)
+        );
 
         $key = serialize(array($userid, $params['perm'], $params['attributes']));
         if ($this->_storage === false) {
@@ -192,40 +197,29 @@ class Horde_Share_Kolab extends Horde_Share_Base
     }
 
     /**
-     * Returns a Horde_Share_Object_kolab object of the request folder.
+     * Returns a Horde_Share_Object_sql object corresponding to the given
+     * share name, with the details retrieved appropriately.
      *
-     * @param string $object  The share to fetch.
+     * @param string $name  The name of the share to retrieve.
      *
-     * @return Horde_Share_Object_kolab  The share object.
+     * @return Horde_Share_Object  The requested share.
+     * @throws Horde_Exception_NotFound
      * @throws Horde_Share_Exception
      */
-    protected function _getShare($object)
+    protected function _getShare($name)
     {
-        if (empty($object)) {
-            throw new Horde_Share_Exception('No object requested.');
-        }
-
-        /* Get the corresponding folder for this share ID */
-        $folder = $this->_storage->getByShare($object, $this->_type);
-
-        /* Does the folder exist? */
-        if (!$folder->exists()) {
-            throw new Horde_Share_Exception(sprintf(Horde_Share_Translation::t("Share \"%s\" does not exist."), $object));
-        }
-
-        /* Create the object from the folder */
-        $share = new Horde_Share_Object_Kolab($object, $this->_type);
-        $share->setFolder($folder);
-
-        return $share;
+        //@todo: get $data from the list cache.
+        return new Horde_Share_Object_Kolab($name);
     }
 
     /**
-     * Returns a Horde_Share_Object_kolab object of the requested folder.
+     * Returns a Horde_Share_Object_sql object corresponding to the given
+     * unique ID, with the details retrieved appropriately.
      *
-     * @param string $id  The id of the share to fetch.
+     * @param integer $id  The id of the share to retrieve.
      *
-     * @return Horde_Share_Object_kolab  The share object.
+     * @return Horde_Share_Object_sql  The requested share.
+     * @throws Horde_Share_Exception, Horde_Exception_NotFound
      */
     protected function _getShareById($id)
     {
@@ -244,11 +238,7 @@ class Horde_Share_Kolab extends Horde_Share_Base
     {
         $objects = array();
         foreach ($ids as $id) {
-            $result = &$this->_getShare($id);
-            if ($result instanceof PEAR_Error) {
-                return $result;
-            }
-            $objects[$id] = &$result;
+            $objects[$id] = $this->_getShare($id);
         }
         return $objects;
     }
index a97fb1c..fe7b4a4 100644 (file)
@@ -15,65 +15,29 @@ class Horde_Share_Object_Kolab extends Horde_Share_Object implements Serializabl
     const VERSION = 2;
 
     /**
-     * The Kolab folder this share is based on.
-     *
-     * @var Kolab_Folder
-     */
-    protected $_folder;
-
-    /**
-     * The Kolab folder name.
+     * The share id.
      *
      * @var string
      */
-    protected $_folder_name;
+    private $_id;
 
     /**
-     * A cache for the share attributes.
+     * The share attributes.
      *
      * @var array
      */
     protected $_data;
 
     /**
-     * Our Kolab folder list handler
-     *
-     * @var Kolab_List
-     */
-    protected $_list;
-
-    /**
      * Constructor.
      *
-     * Sets the folder name.
-     *
-     * @param string $id  The share id.
+     * @param string $id    The share id.
+     * @param array  $data  The share data.
      */
-    public function __construct($id, $type)
+    public function __construct($id, array $data = array())
     {
-        // We actually ignore the random id string that all horde apps provide
-        // as initial name and wait for a set('name', 'xyz') call. But we want
-        // to know if we should create a default share.
-        if ($id == $GLOBALS['registry']->getAuth()) {
-            $this->_data['default'] = true;
-        } else {
-            $this->_data['default'] = false;
-        }
-        $this->_type = $type;
-        $this->__wakeup();
-    }
-
-    /**
-     * Associates a Share object with this share.
-     *
-     * @param Horde_Share $shareOb  The Share object.
-     */
-    public function setShareOb($shareOb)
-    {
-        $this->_list = $shareOb->getStorage();
-        if (isset($this->_folder_name)) {
-            $this->_folder = $this->_list->getFolder($this->_folder_name);
-        }
+        $this->_id   = $id;
+        $this->_data = $data;
     }
 
     /**
@@ -85,8 +49,8 @@ class Horde_Share_Object_Kolab extends Horde_Share_Object implements Serializabl
     {
         return serialize(array(
             self::VERSION,
+            $this->_id,
             $this->_data,
-            $this->_folder_name,
             $this->_shareCallback
         ));
     }
@@ -105,8 +69,8 @@ class Horde_Share_Object_Kolab extends Horde_Share_Object implements Serializabl
             throw new Exception('Cache version change');
         }
 
-        $this->_data = $data[1];
-        $this->_folder_name = $data[2];
+        $this->_id = $data[1];
+        $this->_data = $data[2];
         if (empty($data[3])) {
             throw new Exception('Missing callback for unserializing Horde_Share_Object');
         }
@@ -138,29 +102,13 @@ class Horde_Share_Object_Kolab extends Horde_Share_Object implements Serializabl
     }
 
     /**
-     * Sets the folder for this storage object.
-     *
-     * @param string $folder  Name of the Kolab folder.
-     * @param array  $perms  The permissions of the folder if they are known.
-     */
-    public function setFolder($folder)
-    {
-        if (!isset($this->_folder)) {
-            $this->_folder = $folder;
-            $this->_folder_name = $folder->name;
-        } else {
-            throw new Horde_Share_Exception(Horde_Share_Translation::t("The share has already been initialized!"));
-        }
-    }
-
-    /**
      * Returns the ID of this share.
      *
      * @return string  The share's ID.
      */
     public function getId()
     {
-        return $this->_folder->getShareId();
+        return $this->_id;
     }
 
     /**
@@ -170,7 +118,7 @@ class Horde_Share_Object_Kolab extends Horde_Share_Object implements Serializabl
      */
     public function getName()
     {
-        return $this->_folder->getShareId();
+        return $this->_id;
     }
 
     /**
@@ -302,19 +250,6 @@ class Horde_Share_Object_Kolab extends Horde_Share_Object implements Serializabl
     }
 
     /**
-     * Delete this share.
-     *
-     * @return boolean|PEAR_Error  True on success.
-     */
-    public function delete()
-    {
-        if (!isset($this->_folder)) {
-            return $this->_folderError();
-        }
-        return $this->_folder->delete();
-    }
-
-    /**
      * Checks to see if a user has a given permission.
      *
      * @param string $userid       The userid of the user.
@@ -360,15 +295,4 @@ class Horde_Share_Object_Kolab extends Horde_Share_Object implements Serializabl
         }
         return $this->_folder->setPermission($perms, $update);
     }
-
-    /**
-     * Return a standard error in case the share has not been
-     * correctly initialized.
-     *
-     * @throws Horde_Share_Exception
-     */
-    protected function _folderError()
-    {
-        throw new Horde_Share_Exception(Horde_Share_Translation::t("The Kolab share object has not been initialized yet!"));
-    }
 }
index 4eafbd9..d14e678 100644 (file)
@@ -107,33 +107,84 @@ extends PHPUnit_Framework_TestCase
         $this->assertEquals('task', $driver->getType());
     }
 
+    public function testListIds()
+    {
+        $this->assertEquals(
+            array('INBOX%2FCalendar'),
+            array_keys(
+                $this->_getPrefilledDriver()->listShares('john')
+            )
+        );
+    }
+
+    public function testObjectId()
+    {
+        $object = new Horde_Share_Object_Kolab('test');
+        $this->assertEquals('test', $object->getId());
+    }
+
+    public function testObjectName()
+    {
+        $object = new Horde_Share_Object_Kolab('test');
+        $this->assertEquals('test', $object->getName());
+    }
+
     /**
      * @todo: Reminder: Check that external modification of the Storage system
      * works (former list->validity).
      */
 
+    private function _getPrefilledDriver()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $driver = $this->_getDriver('kronolith');
+        $storage = $factory->createFromParams(
+            array(
+                'driver' => 'mock',
+                'params' => array(
+                    'username' => 'john',
+                    'data'   => array(
+                        'user/john/Calendar' => array(
+                            'annotations' => array(
+                                '/shared/vendor/kolab/folder-type' => 'event.default',
+                            )
+                        ),
+                    ),
+                ),
+                'cache'  => new Horde_Cache(
+                    new Horde_Cache_Storage_Mock()
+                ),
+            )
+        );
+        $storage->getList()->synchronize();
+        $driver->setStorage($storage);
+        return $driver;
+    }
+
     private function _getCompleteDriver()
     {
         $factory = new Horde_Kolab_Storage_Factory();
         $driver = $this->_getDriver();
-        $driver->setStorage(
-            $factory->createFromParams(
-                array(
-                    'driver' => 'mock',
+        $storage = $factory->createFromParams(
+            array(
+                'driver' => 'mock',
+                'params' => array(
                     'data'   => array('user/john' => array()),
-                    'cache'  => new Horde_Cache(
-                        new Horde_Cache_Storage_Mock()
-                    ),
-                )
+                ),
+                'cache'  => new Horde_Cache(
+                    new Horde_Cache_Storage_Mock()
+                ),
             )
         );
+        $storage->getList()->synchronize();
+        $driver->setStorage($storage);
         return $driver;
     }
 
-    private function _getDriver()
+    private function _getDriver($app = 'mnemo')
     {
         return new Horde_Share_Kolab(
-            'mnemo', 'john', new Horde_Perms(), new Horde_Group_Test()
+            $app, 'john', new Horde_Perms(), new Horde_Group_Test()
         );
     }
 }
\ No newline at end of file