*/
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) {
}
/**
- * 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)
{
{
$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;
}
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;
}
/**
{
return serialize(array(
self::VERSION,
+ $this->_id,
$this->_data,
- $this->_folder_name,
$this->_shareCallback
));
}
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');
}
}
/**
- * 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;
}
/**
*/
public function getName()
{
- return $this->_folder->getShareId();
+ return $this->_id;
}
/**
}
/**
- * 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.
}
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!"));
- }
}
$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