summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2012-06-06 08:24:28 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2012-06-06 08:24:28 (GMT)
commit0bd829aa6f9ba4948045a1f7ef69c1146c4d5bac (patch)
tree82ca31e128ca96edf7cbbf86eb3f025742b773b0
parentad59203f274940e9263a6bdd86c0cb5abe914b2a (diff)
downloadroundcubemail-plugins-kolab-0bd829aa6f9ba4948045a1f7ef69c1146c4d5bac.tar.gz
Finish reading/writing of Dictionary configuration objects
-rw-r--r--plugins/kolab_config/kolab_config.php6
-rw-r--r--plugins/libkolab/lib/kolab_format_configuration.php82
2 files changed, 65 insertions, 23 deletions
diff --git a/plugins/kolab_config/kolab_config.php b/plugins/kolab_config/kolab_config.php
index 3433056..9135467 100644
--- a/plugins/kolab_config/kolab_config.php
+++ b/plugins/kolab_config/kolab_config.php
@@ -102,7 +102,7 @@ class kolab_config extends rcube_plugin
$lang = $args['language'];
$dict = $this->read_dictionary($lang, true);
-
+console($lang, $dict);
$dict['type'] = 'dictionary';
$dict['language'] = $args['language'];
$dict['e'] = $args['dictionary'];
@@ -113,7 +113,7 @@ class kolab_config extends rcube_plugin
}
else {
// Update the object
- // $this->default->save($dict);
+ $this->default->save($dict, 'configuration.dictionary', $dict['uid']);
}
$args['abort'] = true;
@@ -160,7 +160,7 @@ class kolab_config extends rcube_plugin
if (isset($this->dicts[$lang]))
return $this->dicts[$lang];
- $query = array(array('type','=','configuration.dictionary'), array('tags','=',' '.$lang.' '));
+ $query = array(array('type','=','configuration.dictionary'), array('tags','=',$lang));
foreach ($this->folders as $folder) {
// we only want to read from default folder
diff --git a/plugins/libkolab/lib/kolab_format_configuration.php b/plugins/libkolab/lib/kolab_format_configuration.php
index 5ef0fa7..974fc45 100644
--- a/plugins/libkolab/lib/kolab_format_configuration.php
+++ b/plugins/libkolab/lib/kolab_format_configuration.php
@@ -29,6 +29,11 @@ class kolab_format_configuration extends kolab_format
protected $read_func = 'kolabformat::readConfiguration';
protected $write_func = 'kolabformat::writeConfiguration';
+ private $type_map = array(
+ 'dictionary' => Configuration::TypeDictionary,
+ 'category' => Configuration::TypeCategoryColor,
+ );
+
function __construct($xmldata = null)
{
@@ -45,11 +50,31 @@ class kolab_format_configuration extends kolab_format
{
$this->init();
+ // read type-specific properties
+ switch ($object['type']) {
+ case 'dictionary':
+ $dict = new Dictionary($object['language']);
+ $dict->setEntries(self::array2vector($object['e']));
+ $this->obj = new Configuration($dict);
+ break;
+
+ case 'category':
+ // TODO: implement this
+ $categories = new vectorcategorycolor;
+ $this->obj = new Configuration($categories);
+ break;
+ default:
+ return false;
+ }
+
// set some automatic values if missing
-# if (!empty($object['uid']))
-# $this->obj->setUid($object['uid']);
+ if (!empty($object['uid']))
+ $this->obj->setUid($object['uid']);
+ if (!empty($object['created']))
+ $this->obj->setCreated(self::get_datetime($object['created']));
- // TODO: set object propeties
+ // adjust content-type string
+ $this->CTYPE = 'application/x-vnd.kolab.configuration.' . $object['type'];
// cache this data
$this->data = $object;
@@ -61,20 +86,7 @@ class kolab_format_configuration extends kolab_format
*/
public function is_valid()
{
- return $this->data || (is_object($this->obj)/* && $this->obj->isValid()*/);
- }
-
- /**
- * Load data from old Kolab2 format
- */
- public function fromkolab2($record)
- {
- $object = array(
- 'uid' => $record['uid'],
- 'changed' => $record['last-modification-date'],
- );
-
- $this->data = $object + $record;
+ return $this->data || (is_object($this->obj) && $this->obj->isValid());
}
/**
@@ -89,21 +101,51 @@ class kolab_format_configuration extends kolab_format
return $this->data;
$this->init();
+ $type_map = array_flip($this->type_map);
// read object properties
$object = array(
-# 'uid' => $this->obj->uid(),
-# 'changed' => $this->obj->lastModified(),
+ 'uid' => $this->obj->uid(),
+ 'created' => self::php_datetime($this->obj->created()),
+ 'changed' => self::php_datetime($this->obj->lastModified()),
+ 'type' => $type_map[$this->obj->type()],
);
+ // read type-specific properties
+ switch ($object['type']) {
+ case 'dictionary':
+ $dict = $this->obj->dictionary();
+ $object['language'] = $dict->language();
+ $object['e'] = self::vector2array($dict->entries());
+ break;
- // TODO: read object properties
+ case 'category':
+ // TODO: implement this
+ break;
+ }
+
+ // adjust content-type string
+ if ($object['type'])
+ $this->CTYPE = 'application/x-vnd.kolab.configuration.' . $object['type'];
$this->data = $object;
return $this->data;
}
/**
+ * Load data from old Kolab2 format
+ */
+ public function fromkolab2($record)
+ {
+ $object = array(
+ 'uid' => $record['uid'],
+ 'changed' => $record['last-modification-date'],
+ );
+
+ $this->data = $object + $record;
+ }
+
+ /**
* Callback for kolab_storage_cache to get object specific tags to cache
*
* @return array List of tags to save in cache