Finish reading/writing of Dictionary configuration objects
This commit is contained in:
parent
ad59203f27
commit
0bd829aa6f
2 changed files with 66 additions and 24 deletions
|
@ -102,7 +102,7 @@ class kolab_config extends rcube_plugin
|
||||||
|
|
||||||
$lang = $args['language'];
|
$lang = $args['language'];
|
||||||
$dict = $this->read_dictionary($lang, true);
|
$dict = $this->read_dictionary($lang, true);
|
||||||
|
console($lang, $dict);
|
||||||
$dict['type'] = 'dictionary';
|
$dict['type'] = 'dictionary';
|
||||||
$dict['language'] = $args['language'];
|
$dict['language'] = $args['language'];
|
||||||
$dict['e'] = $args['dictionary'];
|
$dict['e'] = $args['dictionary'];
|
||||||
|
@ -113,7 +113,7 @@ class kolab_config extends rcube_plugin
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Update the object
|
// Update the object
|
||||||
// $this->default->save($dict);
|
$this->default->save($dict, 'configuration.dictionary', $dict['uid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$args['abort'] = true;
|
$args['abort'] = true;
|
||||||
|
@ -160,7 +160,7 @@ class kolab_config extends rcube_plugin
|
||||||
if (isset($this->dicts[$lang]))
|
if (isset($this->dicts[$lang]))
|
||||||
return $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) {
|
foreach ($this->folders as $folder) {
|
||||||
// we only want to read from default folder
|
// we only want to read from default folder
|
||||||
|
|
|
@ -29,6 +29,11 @@ class kolab_format_configuration extends kolab_format
|
||||||
protected $read_func = 'kolabformat::readConfiguration';
|
protected $read_func = 'kolabformat::readConfiguration';
|
||||||
protected $write_func = 'kolabformat::writeConfiguration';
|
protected $write_func = 'kolabformat::writeConfiguration';
|
||||||
|
|
||||||
|
private $type_map = array(
|
||||||
|
'dictionary' => Configuration::TypeDictionary,
|
||||||
|
'category' => Configuration::TypeCategoryColor,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
function __construct($xmldata = null)
|
function __construct($xmldata = null)
|
||||||
{
|
{
|
||||||
|
@ -45,11 +50,31 @@ class kolab_format_configuration extends kolab_format
|
||||||
{
|
{
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
// set some automatic values if missing
|
// read type-specific properties
|
||||||
# if (!empty($object['uid']))
|
switch ($object['type']) {
|
||||||
# $this->obj->setUid($object['uid']);
|
case 'dictionary':
|
||||||
|
$dict = new Dictionary($object['language']);
|
||||||
|
$dict->setEntries(self::array2vector($object['e']));
|
||||||
|
$this->obj = new Configuration($dict);
|
||||||
|
break;
|
||||||
|
|
||||||
// TODO: set object propeties
|
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['created']))
|
||||||
|
$this->obj->setCreated(self::get_datetime($object['created']));
|
||||||
|
|
||||||
|
// adjust content-type string
|
||||||
|
$this->CTYPE = 'application/x-vnd.kolab.configuration.' . $object['type'];
|
||||||
|
|
||||||
// cache this data
|
// cache this data
|
||||||
$this->data = $object;
|
$this->data = $object;
|
||||||
|
@ -61,20 +86,7 @@ class kolab_format_configuration extends kolab_format
|
||||||
*/
|
*/
|
||||||
public function is_valid()
|
public function is_valid()
|
||||||
{
|
{
|
||||||
return $this->data || (is_object($this->obj)/* && $this->obj->isValid()*/);
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,20 +101,50 @@ class kolab_format_configuration extends kolab_format
|
||||||
return $this->data;
|
return $this->data;
|
||||||
|
|
||||||
$this->init();
|
$this->init();
|
||||||
|
$type_map = array_flip($this->type_map);
|
||||||
|
|
||||||
// read object properties
|
// read object properties
|
||||||
$object = array(
|
$object = array(
|
||||||
# 'uid' => $this->obj->uid(),
|
'uid' => $this->obj->uid(),
|
||||||
# 'changed' => $this->obj->lastModified(),
|
'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;
|
$this->data = $object;
|
||||||
return $this->data;
|
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
|
* Callback for kolab_storage_cache to get object specific tags to cache
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue