Initial support for Snippets and Relations
This commit is contained in:
parent
91e93fecb7
commit
39c2aee5b9
2 changed files with 87 additions and 9 deletions
|
@ -174,7 +174,7 @@ abstract class kolab_format
|
||||||
* Convert a libkolabxml vector to a PHP array
|
* Convert a libkolabxml vector to a PHP array
|
||||||
*
|
*
|
||||||
* @param object vector Object
|
* @param object vector Object
|
||||||
* @return array Indexed array contaning vector elements
|
* @return array Indexed array containing vector elements
|
||||||
*/
|
*/
|
||||||
public static function vector2array($vec, $max = PHP_INT_MAX)
|
public static function vector2array($vec, $max = PHP_INT_MAX)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,16 +24,18 @@
|
||||||
|
|
||||||
class kolab_format_configuration extends kolab_format
|
class kolab_format_configuration extends kolab_format
|
||||||
{
|
{
|
||||||
public $CTYPE = 'application/x-vnd.kolab.configuration';
|
public $CTYPE = 'application/x-vnd.kolab.configuration';
|
||||||
public $CTYPEv2 = 'application/x-vnd.kolab.configuration';
|
public $CTYPEv2 = 'application/x-vnd.kolab.configuration';
|
||||||
|
|
||||||
protected $objclass = 'Configuration';
|
protected $objclass = 'Configuration';
|
||||||
protected $read_func = 'readConfiguration';
|
protected $read_func = 'readConfiguration';
|
||||||
protected $write_func = 'writeConfiguration';
|
protected $write_func = 'writeConfiguration';
|
||||||
|
|
||||||
private $type_map = array(
|
private $type_map = array(
|
||||||
|
'category' => Configuration::TypeCategoryColor,
|
||||||
'dictionary' => Configuration::TypeDictionary,
|
'dictionary' => Configuration::TypeDictionary,
|
||||||
'category' => Configuration::TypeCategoryColor,
|
'relation' => Configuration::TypeRelation,
|
||||||
|
'snippet' => Configuration::TypeSnippet,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,6 +62,48 @@ class kolab_format_configuration extends kolab_format
|
||||||
$categories = new vectorcategorycolor;
|
$categories = new vectorcategorycolor;
|
||||||
$this->obj = new Configuration($categories);
|
$this->obj = new Configuration($categories);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'relation':
|
||||||
|
$relation = new Relation($object['name'], $object['category']);
|
||||||
|
|
||||||
|
if ($object['color']) {
|
||||||
|
$relation->setColor($object['color']);
|
||||||
|
}
|
||||||
|
if ($object['parent']) {
|
||||||
|
$relation->setParent($object['parent']);
|
||||||
|
}
|
||||||
|
if ($object['iconName']) {
|
||||||
|
$relation->setIconName($object['iconName']);
|
||||||
|
}
|
||||||
|
if ($object['priority'] > 0) {
|
||||||
|
$relation->setPriority((int) $object['priority']);
|
||||||
|
}
|
||||||
|
if (!empty($object['members'])) {
|
||||||
|
$relation->setMembers(self::array2vector($object['members']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->obj = new Configuration($relation);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'snippet':
|
||||||
|
$collection = new SnippetCollection($object['name']);
|
||||||
|
$snippets = new vectorsnippets;
|
||||||
|
|
||||||
|
foreach ((array) $object['snippets'] as $item) {
|
||||||
|
$snippet = new snippet($item['name'], $item['text']);
|
||||||
|
$snippet->setTextType(strtolower($item['type']) == 'html' ? Snippet::HTML : Snippet::Plain);
|
||||||
|
if ($item['shortcut']) {
|
||||||
|
$snippet->setShortCut($item['shortcut']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$snippets->push($snippet);
|
||||||
|
}
|
||||||
|
|
||||||
|
$collection->setSnippets($snippets);
|
||||||
|
|
||||||
|
$this->obj = new Configuration($collection);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -90,8 +134,9 @@ class kolab_format_configuration extends kolab_format
|
||||||
public function to_array($data = array())
|
public function to_array($data = array())
|
||||||
{
|
{
|
||||||
// return cached result
|
// return cached result
|
||||||
if (!empty($this->data))
|
if (!empty($this->data)) {
|
||||||
return $this->data;
|
return $this->data;
|
||||||
|
}
|
||||||
|
|
||||||
// read common object props into local data object
|
// read common object props into local data object
|
||||||
$object = parent::to_array($data);
|
$object = parent::to_array($data);
|
||||||
|
@ -111,11 +156,44 @@ class kolab_format_configuration extends kolab_format
|
||||||
case 'category':
|
case 'category':
|
||||||
// TODO: implement this
|
// TODO: implement this
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'relation':
|
||||||
|
$relation = $this->obj->relation();
|
||||||
|
|
||||||
|
$object['name'] = $relation->name();
|
||||||
|
$object['category'] = $relation->type();
|
||||||
|
$object['color'] = $relation->color();
|
||||||
|
$object['parent'] = $relation->parent();
|
||||||
|
$object['iconName'] = $relation->iconName();
|
||||||
|
$object['priority'] = $relation->priority();
|
||||||
|
$object['members'] = self::vector2array($relation->members());
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'snippet':
|
||||||
|
$collection = $this->obj->snippets();
|
||||||
|
|
||||||
|
$object['name'] = $collection->name();
|
||||||
|
$object['snippets'] = array();
|
||||||
|
|
||||||
|
$snippets = $collection->snippets();
|
||||||
|
for ($i=0; $i < $snippets->size(); $i++) {
|
||||||
|
$snippet = $snippets->get($i);
|
||||||
|
$object['snippets'][] = array(
|
||||||
|
'name' => $snippet->name(),
|
||||||
|
'text' => $snippet->text(),
|
||||||
|
'type' => $snippet->textType() == Snippet::HTML ? 'html' : 'plain',
|
||||||
|
'shortcut' => $snippet->shortCut(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// adjust content-type string
|
// adjust content-type string
|
||||||
if ($object['type'])
|
if ($object['type']) {
|
||||||
$this->CTYPE = $this->CTYPEv2 = 'application/x-vnd.kolab.configuration.' . $object['type'];
|
$this->CTYPE = $this->CTYPEv2 = 'application/x-vnd.kolab.configuration.' . $object['type'];
|
||||||
|
}
|
||||||
|
|
||||||
$this->data = $object;
|
$this->data = $object;
|
||||||
return $this->data;
|
return $this->data;
|
||||||
|
@ -130,10 +208,10 @@ class kolab_format_configuration extends kolab_format
|
||||||
{
|
{
|
||||||
$tags = array();
|
$tags = array();
|
||||||
|
|
||||||
if ($this->data['type'] == 'dictionary')
|
if ($this->data['type'] == 'dictionary') {
|
||||||
$tags = array($this->data['language']);
|
$tags = array($this->data['language']);
|
||||||
|
}
|
||||||
|
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue