summaryrefslogtreecommitdiff
path: root/plugins/libkolab/lib/kolab_format_configuration.php
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-05-18 12:45:23 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-05-18 12:45:23 (GMT)
commit39c2aee5b9820154cca3c9930db1268325498ba0 (patch)
treef89d0025a83a7936d7744f7a31405d0aaa29b320 /plugins/libkolab/lib/kolab_format_configuration.php
parent91e93fecb779852dbf9c6ab2da883f46f761b515 (diff)
downloadroundcubemail-plugins-kolab-39c2aee5b9820154cca3c9930db1268325498ba0.tar.gz
Initial support for Snippets and Relations
Diffstat (limited to 'plugins/libkolab/lib/kolab_format_configuration.php')
-rw-r--r--plugins/libkolab/lib/kolab_format_configuration.php94
1 files changed, 86 insertions, 8 deletions
diff --git a/plugins/libkolab/lib/kolab_format_configuration.php b/plugins/libkolab/lib/kolab_format_configuration.php
index 5a8d3ff..44b7e92 100644
--- a/plugins/libkolab/lib/kolab_format_configuration.php
+++ b/plugins/libkolab/lib/kolab_format_configuration.php
@@ -24,16 +24,18 @@
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';
- protected $objclass = 'Configuration';
- protected $read_func = 'readConfiguration';
+ protected $objclass = 'Configuration';
+ protected $read_func = 'readConfiguration';
protected $write_func = 'writeConfiguration';
private $type_map = array(
+ 'category' => Configuration::TypeCategoryColor,
'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;
$this->obj = new Configuration($categories);
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:
return false;
}
@@ -90,8 +134,9 @@ class kolab_format_configuration extends kolab_format
public function to_array($data = array())
{
// return cached result
- if (!empty($this->data))
+ if (!empty($this->data)) {
return $this->data;
+ }
// read common object props into local data object
$object = parent::to_array($data);
@@ -111,11 +156,44 @@ class kolab_format_configuration extends kolab_format
case 'category':
// TODO: implement this
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
- if ($object['type'])
+ if ($object['type']) {
$this->CTYPE = $this->CTYPEv2 = 'application/x-vnd.kolab.configuration.' . $object['type'];
+ }
$this->data = $object;
return $this->data;
@@ -130,10 +208,10 @@ class kolab_format_configuration extends kolab_format
{
$tags = array();
- if ($this->data['type'] == 'dictionary')
+ if ($this->data['type'] == 'dictionary') {
$tags = array($this->data['language']);
+ }
return $tags;
}
-
}