plugins/libkolab
Aleksander Machniak
machniak at kolabsys.com
Sun May 18 14:45:41 CEST 2014
plugins/libkolab/lib/kolab_format.php | 2
plugins/libkolab/lib/kolab_format_configuration.php | 94 ++++++++++++++++++--
2 files changed, 87 insertions(+), 9 deletions(-)
New commits:
commit 39c2aee5b9820154cca3c9930db1268325498ba0
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Sun May 18 14:45:23 2014 +0200
Initial support for Snippets and Relations
diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php
index 7c34310..fefef1b 100644
--- a/plugins/libkolab/lib/kolab_format.php
+++ b/plugins/libkolab/lib/kolab_format.php
@@ -174,7 +174,7 @@ abstract class kolab_format
* Convert a libkolabxml vector to a PHP array
*
* @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)
{
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;
}
-
}
More information about the commits
mailing list