Store task tags in relation objects (#3395)
This commit is contained in:
parent
419296757a
commit
1a46c1d897
2 changed files with 65 additions and 8 deletions
|
@ -558,7 +558,7 @@ class tasklist_kolab_driver extends tasklist_driver
|
||||||
*/
|
*/
|
||||||
public function get_task($prop)
|
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;
|
$list_id = is_array($prop) ? $prop['list'] : null;
|
||||||
$folders = $list_id ? array($list_id => $this->get_folder($list_id)) : $this->folders;
|
$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];
|
return $this->tasks[$id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -759,6 +764,27 @@ class tasklist_kolab_driver extends tasklist_driver
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Convert from Kolab_Format to internal representation
|
||||||
*/
|
*/
|
||||||
|
@ -768,9 +794,8 @@ class tasklist_kolab_driver extends tasklist_driver
|
||||||
'id' => $record['uid'],
|
'id' => $record['uid'],
|
||||||
'uid' => $record['uid'],
|
'uid' => $record['uid'],
|
||||||
'title' => $record['title'],
|
'title' => $record['title'],
|
||||||
# 'location' => $record['location'],
|
// 'location' => $record['location'],
|
||||||
'description' => $record['description'],
|
'description' => $record['description'],
|
||||||
'tags' => array_filter((array)$record['categories']),
|
|
||||||
'flagged' => $record['priority'] == 1,
|
'flagged' => $record['priority'] == 1,
|
||||||
'complete' => floatval($record['complete'] / 100),
|
'complete' => floatval($record['complete'] / 100),
|
||||||
'status' => $record['status'],
|
'status' => $record['status'],
|
||||||
|
@ -779,6 +804,11 @@ class tasklist_kolab_driver extends tasklist_driver
|
||||||
'attendees' => $record['attendees'],
|
'attendees' => $record['attendees'],
|
||||||
'organizer' => $record['organizer'],
|
'organizer' => $record['organizer'],
|
||||||
'sequence' => $record['sequence'],
|
'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
|
// 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())
|
private function _from_rcube_task($task, $old = array())
|
||||||
{
|
{
|
||||||
$object = $task;
|
$object = $task;
|
||||||
$object['categories'] = (array)$task['tags'];
|
|
||||||
|
|
||||||
if (!empty($task['date'])) {
|
if (!empty($task['date'])) {
|
||||||
$object['due'] = rcube_utils::anytodatetime($task['date'].' '.$task['time'], $this->plugin->timezone);
|
$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)))
|
if (!$list_id || !($folder = $this->get_folder($list_id)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// tags are stored separately
|
||||||
|
$tags = $task['tags'];
|
||||||
|
unset($task['tags']);
|
||||||
|
|
||||||
// moved from another folder
|
// moved from another folder
|
||||||
if ($task['_fromlist'] && ($fromfolder = $this->get_folder($task['_fromlist']))) {
|
if ($task['_fromlist'] && ($fromfolder = $this->get_folder($task['_fromlist']))) {
|
||||||
if (!$fromfolder->move($task['id'], $folder->name))
|
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
|
// generate new task object from RC input
|
||||||
$object = $this->_from_rcube_task($task, $old);
|
$object = $this->_from_rcube_task($task, $old);
|
||||||
$saved = $folder->save($object, 'task', $task['id']);
|
$saved = $folder->save($object, 'task', $task['id']);
|
||||||
|
|
||||||
if (!$saved) {
|
if (!$saved) {
|
||||||
raise_error(array(
|
raise_error(array(
|
||||||
|
@ -986,8 +1019,12 @@ class tasklist_kolab_driver extends tasklist_driver
|
||||||
$saved = false;
|
$saved = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// save tags in configuration.relation object
|
||||||
|
$this->save_tags($object['uid'], $tags);
|
||||||
|
|
||||||
$task = $this->_to_rcube_task($object);
|
$task = $this->_to_rcube_task($object);
|
||||||
$task['list'] = $list_id;
|
$task['list'] = $list_id;
|
||||||
|
$task['tags'] = (array) $tags;
|
||||||
$this->tasks[$task['id']] = $task;
|
$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)))
|
if (!$list_id || !($folder = $this->get_folder($list_id)))
|
||||||
return false;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -63,6 +63,7 @@ class tasklist extends rcube_plugin
|
||||||
private $collapsed_tasks = array();
|
private $collapsed_tasks = array();
|
||||||
private $itip;
|
private $itip;
|
||||||
private $ical;
|
private $ical;
|
||||||
|
private $driver_name;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,7 +175,7 @@ class tasklist extends rcube_plugin
|
||||||
if (is_object($this->driver))
|
if (is_object($this->driver))
|
||||||
return;
|
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';
|
$driver_class = 'tasklist_' . $driver_name . '_driver';
|
||||||
|
|
||||||
require_once($this->home . '/drivers/tasklist_driver.php');
|
require_once($this->home . '/drivers/tasklist_driver.php');
|
||||||
|
@ -188,6 +189,8 @@ class tasklist extends rcube_plugin
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->driver_name = $driver_name;
|
||||||
|
|
||||||
$this->rc->output->set_env('tasklist_driver', $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)
|
private function tasks_data($records, $f, &$tags)
|
||||||
{
|
{
|
||||||
$data = $tags = $this->task_tree = $this->task_titles = array();
|
$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) {
|
foreach ($records as $rec) {
|
||||||
if ($rec['parent_id']) {
|
if ($rec['parent_id']) {
|
||||||
$this->task_tree[$rec['id']] = $rec['parent_id'];
|
$this->task_tree[$rec['id']] = $rec['parent_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->encode_task($rec);
|
$this->encode_task($rec);
|
||||||
if (!empty($rec['tags']))
|
|
||||||
|
if ($this->driver_name != 'kolab' && !empty($rec['tags'])) {
|
||||||
$tags = array_merge($tags, (array)$rec['tags']);
|
$tags = array_merge($tags, (array)$rec['tags']);
|
||||||
|
}
|
||||||
|
|
||||||
// apply filter; don't trust the driver on this :-)
|
// apply filter; don't trust the driver on this :-)
|
||||||
if ((!$f && !$this->driver->is_complete($rec)) || ($rec['mask'] & $f))
|
if ((!$f && !$this->driver->is_complete($rec)) || ($rec['mask'] & $f))
|
||||||
|
|
Loading…
Add table
Reference in a new issue