summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-08-19 08:06:45 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-08-19 08:06:45 (GMT)
commit1a46c1d89717725d910ce0f36327e9e406fae74e (patch)
tree5d3ec65f5aaffc6c80f8f29511d1f9bfd8df5fb6
parent419296757aad4da3499763a775d42688c3fced70 (diff)
downloadroundcubemail-plugins-kolab-1a46c1d89717725d910ce0f36327e9e406fae74e.tar.gz
Store task tags in relation objects (#3395)
-rw-r--r--plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php57
-rw-r--r--plugins/tasklist/tasklist.php16
2 files changed, 65 insertions, 8 deletions
diff --git a/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php b/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
index 9a37df0..1c8a8c7 100644
--- a/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
+++ b/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
@@ -558,7 +558,7 @@ class tasklist_kolab_driver extends tasklist_driver
*/
public function get_task($prop)
{
- $id = is_array($prop) ? ($prop['uid'] ?: $prop['id']) : $prop;
+ $id = is_array($prop) ? ($prop['uid'] ?: $prop['id']) : $prop;
$list_id = is_array($prop) ? $prop['list'] : null;
$folders = $list_id ? array($list_id => $this->get_folder($list_id)) : $this->folders;
@@ -573,6 +573,11 @@ class tasklist_kolab_driver extends tasklist_driver
}
}
+ // assign tags
+ if ($this->tasks[$id]) {
+ $this->tasks[$id]['tags'] = $this->get_tags($this->tasks[$id]['uid']);
+ }
+
return $this->tasks[$id];
}
@@ -760,6 +765,27 @@ class tasklist_kolab_driver extends tasklist_driver
}
/**
+ * Get task tags
+ */
+ private function get_tags($uid)
+ {
+ $config = kolab_storage_config::get_instance();
+ $tags = $config->get_tags($uid);
+ $tags = array_map(function($v) { return $v['name']; }, $tags);
+
+ return $tags;
+ }
+
+ /**
+ * Update task tags
+ */
+ private function save_tags($uid, $tags)
+ {
+ $config = kolab_storage_config::get_instance();
+ $config->save_tags($uid, $tags);
+ }
+
+ /**
* Convert from Kolab_Format to internal representation
*/
private function _to_rcube_task($record)
@@ -768,9 +794,8 @@ class tasklist_kolab_driver extends tasklist_driver
'id' => $record['uid'],
'uid' => $record['uid'],
'title' => $record['title'],
-# 'location' => $record['location'],
+// 'location' => $record['location'],
'description' => $record['description'],
- 'tags' => array_filter((array)$record['categories']),
'flagged' => $record['priority'] == 1,
'complete' => floatval($record['complete'] / 100),
'status' => $record['status'],
@@ -779,6 +804,11 @@ class tasklist_kolab_driver extends tasklist_driver
'attendees' => $record['attendees'],
'organizer' => $record['organizer'],
'sequence' => $record['sequence'],
+ // old categories will be replaced by tags
+ 'categories' => $record['categories'],
+ // keep mailbox which is needed to convert
+ // categories to tags in kolab_storage_config::apply_tags()
+ '_mailbox' => $record['_mailbox'],
);
// convert from DateTime to internal date format
@@ -842,7 +872,6 @@ class tasklist_kolab_driver extends tasklist_driver
private function _from_rcube_task($task, $old = array())
{
$object = $task;
- $object['categories'] = (array)$task['tags'];
if (!empty($task['date'])) {
$object['due'] = rcube_utils::anytodatetime($task['date'].' '.$task['time'], $this->plugin->timezone);
@@ -954,6 +983,10 @@ class tasklist_kolab_driver extends tasklist_driver
if (!$list_id || !($folder = $this->get_folder($list_id)))
return false;
+ // tags are stored separately
+ $tags = $task['tags'];
+ unset($task['tags']);
+
// moved from another folder
if ($task['_fromlist'] && ($fromfolder = $this->get_folder($task['_fromlist']))) {
if (!$fromfolder->move($task['id'], $folder->name))
@@ -975,7 +1008,7 @@ class tasklist_kolab_driver extends tasklist_driver
// generate new task object from RC input
$object = $this->_from_rcube_task($task, $old);
- $saved = $folder->save($object, 'task', $task['id']);
+ $saved = $folder->save($object, 'task', $task['id']);
if (!$saved) {
raise_error(array(
@@ -986,8 +1019,12 @@ class tasklist_kolab_driver extends tasklist_driver
$saved = false;
}
else {
+ // save tags in configuration.relation object
+ $this->save_tags($object['uid'], $tags);
+
$task = $this->_to_rcube_task($object);
$task['list'] = $list_id;
+ $task['tags'] = (array) $tags;
$this->tasks[$task['id']] = $task;
}
@@ -1029,7 +1066,15 @@ class tasklist_kolab_driver extends tasklist_driver
if (!$list_id || !($folder = $this->get_folder($list_id)))
return false;
- return $folder->delete($task['id']);
+ $status = $folder->delete($task['id']);
+
+ if ($status) {
+ // remove tag assignments
+ // @TODO: don't do this when undelete feature will be implemented
+ $this->save_tags($task['id'], null);
+ }
+
+ return $status;
}
/**
diff --git a/plugins/tasklist/tasklist.php b/plugins/tasklist/tasklist.php
index a573128..c943f54 100644
--- a/plugins/tasklist/tasklist.php
+++ b/plugins/tasklist/tasklist.php
@@ -63,6 +63,7 @@ class tasklist extends rcube_plugin
private $collapsed_tasks = array();
private $itip;
private $ical;
+ private $driver_name;
/**
@@ -174,7 +175,7 @@ class tasklist extends rcube_plugin
if (is_object($this->driver))
return;
- $driver_name = $this->rc->config->get('tasklist_driver', 'database');
+ $driver_name = $this->rc->config->get('tasklist_driver', 'database');
$driver_class = 'tasklist_' . $driver_name . '_driver';
require_once($this->home . '/drivers/tasklist_driver.php');
@@ -188,6 +189,8 @@ class tasklist extends rcube_plugin
break;
}
+ $this->driver_name = $driver_name;
+
$this->rc->output->set_env('tasklist_driver', $driver_name);
}
@@ -948,13 +951,22 @@ class tasklist extends rcube_plugin
private function tasks_data($records, $f, &$tags)
{
$data = $tags = $this->task_tree = $this->task_titles = array();
+
+ if ($this->driver_name == 'kolab') {
+ $config = kolab_storage_config::get_instance();
+ $tags = $config->apply_tags($records);
+ }
+
foreach ($records as $rec) {
if ($rec['parent_id']) {
$this->task_tree[$rec['id']] = $rec['parent_id'];
}
+
$this->encode_task($rec);
- if (!empty($rec['tags']))
+
+ if ($this->driver_name != 'kolab' && !empty($rec['tags'])) {
$tags = array_merge($tags, (array)$rec['tags']);
+ }
// apply filter; don't trust the driver on this :-)
if ((!$f && !$this->driver->is_complete($rec)) || ($rec['mask'] & $f))