Changeset View
Changeset View
Standalone View
Standalone View
plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
Show First 20 Lines • Show All 647 Lines • ▼ Show 20 Lines | public function list_tasks($filter, $lists = null) | ||||
// full text search (only works with cache enabled) | // full text search (only works with cache enabled) | ||||
if ($filter['search']) { | if ($filter['search']) { | ||||
$search = mb_strtolower($filter['search']); | $search = mb_strtolower($filter['search']); | ||||
foreach (rcube_utils::normalize_string($search, true) as $word) { | foreach (rcube_utils::normalize_string($search, true) as $word) { | ||||
$query[] = array('words', '~', $word); | $query[] = array('words', '~', $word); | ||||
} | } | ||||
} | } | ||||
if ($filter['since']) { | if ($filter['since'] ?? false) { | ||||
$query[] = array('changed', '>=', $filter['since']); | $query[] = array('changed', '>=', $filter['since']); | ||||
} | } | ||||
if ($filter['uid']) { | if ($filter['uid'] ?? false) { | ||||
$query[] = array('uid', '=', (array) $filter['uid']); | $query[] = array('uid', '=', (array) $filter['uid']); | ||||
} | } | ||||
foreach ($lists as $list_id) { | foreach ($lists as $list_id) { | ||||
if (!$folder = $this->get_folder($list_id)) { | if (!$folder = $this->get_folder($list_id)) { | ||||
continue; | continue; | ||||
} | } | ||||
Show All 35 Lines | public function get_task($prop, $filter = 0) | ||||
$folders = $list_id ? array($list_id => $this->get_folder($list_id)) : $this->get_lists($filter); | $folders = $list_id ? array($list_id => $this->get_folder($list_id)) : $this->get_lists($filter); | ||||
// find task in the available folders | // find task in the available folders | ||||
foreach ($folders as $list_id => $folder) { | foreach ($folders as $list_id => $folder) { | ||||
if (is_array($folder)) | if (is_array($folder)) | ||||
$folder = $this->folders[$list_id]; | $folder = $this->folders[$list_id]; | ||||
if (is_numeric($list_id) || !$folder) | if (is_numeric($list_id) || !$folder) | ||||
continue; | continue; | ||||
if (!$this->tasks[$id] && ($object = $folder->get_object($id))) { | if (!($this->tasks[$id] ?? false) && ($object = $folder->get_object($id))) { | ||||
$this->load_tags($object); | $this->load_tags($object); | ||||
$this->tasks[$id] = $this->_to_rcube_task($object, $list_id); | $this->tasks[$id] = $this->_to_rcube_task($object, $list_id); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return $this->tasks[$id]; | return $this->tasks[$id]; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 532 Lines • ▼ Show 20 Lines | */ | ||||
* Convert from Kolab_Format to internal representation | * Convert from Kolab_Format to internal representation | ||||
*/ | */ | ||||
private function _to_rcube_task($record, $list_id, $all = true) | private function _to_rcube_task($record, $list_id, $all = true) | ||||
{ | { | ||||
$id_prefix = $list_id . ':'; | $id_prefix = $list_id . ':'; | ||||
$task = array( | $task = array( | ||||
'id' => $id_prefix . $record['uid'], | 'id' => $id_prefix . $record['uid'], | ||||
'uid' => $record['uid'], | 'uid' => $record['uid'], | ||||
'title' => $record['title'], | 'title' => $record['title'] ?? null, | ||||
// 'location' => $record['location'], | // 'location' => $record['location'], | ||||
'description' => $record['description'], | 'description' => $record['description'] ?? null, | ||||
'flagged' => $record['priority'] == 1, | 'flagged' => ($record['priority'] ?? null) == 1, | ||||
'complete' => floatval($record['complete'] / 100), | 'complete' => floatval(($record['complete'] ?? null) / 100), | ||||
'status' => $record['status'], | 'status' => $record['status'] ?? null, | ||||
'parent_id' => $record['parent_id'] ? $id_prefix . $record['parent_id'] : null, | 'parent_id' => ($record['parent_id'] ?? null) ? $id_prefix . $record['parent_id'] : null, | ||||
'recurrence' => $record['recurrence'], | 'recurrence' => $record['recurrence'] ?? null, | ||||
'attendees' => $record['attendees'], | 'attendees' => $record['attendees'] ?? null, | ||||
'organizer' => $record['organizer'], | 'organizer' => $record['organizer'] ?? null, | ||||
'sequence' => $record['sequence'], | 'sequence' => $record['sequence'] ?? null, | ||||
'tags' => $record['tags'], | 'tags' => $record['tags'] ?? null, | ||||
'list' => $list_id, | 'list' => $list_id, | ||||
'links' => $record['links'], | 'links' => $record['links'] ?? null, | ||||
); | ); | ||||
// we can sometimes skip this expensive operation | // we can sometimes skip this expensive operation | ||||
if ($all && !array_key_exists('links', $task)) { | if ($all && !array_key_exists('links', $task)) { | ||||
$task['links'] = $this->get_links($task['uid']); | $task['links'] = $this->get_links($task['uid']); | ||||
} | } | ||||
// convert from DateTime to internal date format | // convert from DateTime to internal date format | ||||
if ($record['due'] instanceof DateTimeInterface) { | if (($record['due'] ?? null) instanceof DateTimeInterface) { | ||||
$due = $this->plugin->lib->adjust_timezone($record['due']); | $due = $this->plugin->lib->adjust_timezone($record['due']); | ||||
$task['date'] = $due->format('Y-m-d'); | $task['date'] = $due->format('Y-m-d'); | ||||
if (empty($record['due']->_dateonly)) { | if (empty($record['due']->_dateonly)) { | ||||
$task['time'] = $due->format('H:i'); | $task['time'] = $due->format('H:i'); | ||||
} | } | ||||
} | } | ||||
// convert from DateTime to internal date format | // convert from DateTime to internal date format | ||||
if ($record['start'] instanceof DateTimeInterface) { | if (($record['start'] ?? null) instanceof DateTimeInterface) { | ||||
$start = $this->plugin->lib->adjust_timezone($record['start']); | $start = $this->plugin->lib->adjust_timezone($record['start']); | ||||
$task['startdate'] = $start->format('Y-m-d'); | $task['startdate'] = $start->format('Y-m-d'); | ||||
if (empty($record['start']->_dateonly)) { | if (empty($record['start']->_dateonly)) { | ||||
$task['starttime'] = $start->format('H:i'); | $task['starttime'] = $start->format('H:i'); | ||||
} | } | ||||
} | } | ||||
if ($record['changed'] instanceof DateTimeInterface) { | if (($record['changed'] ?? null) instanceof DateTimeInterface) { | ||||
$task['changed'] = $record['changed']; | $task['changed'] = $record['changed']; | ||||
} | } | ||||
if ($record['created'] instanceof DateTimeInterface) { | if (($record['created'] ?? null) instanceof DateTimeInterface) { | ||||
$task['created'] = $record['created']; | $task['created'] = $record['created']; | ||||
} | } | ||||
if ($record['valarms']) { | if ($record['valarms'] ?? false) { | ||||
$task['valarms'] = $record['valarms']; | $task['valarms'] = $record['valarms']; | ||||
} | } | ||||
else if ($record['alarms']) { | else if ($record['alarms'] ?? false) { | ||||
$task['alarms'] = $record['alarms']; | $task['alarms'] = $record['alarms']; | ||||
} | } | ||||
if (!empty($task['attendees'])) { | if (!empty($task['attendees'])) { | ||||
foreach ((array)$task['attendees'] as $i => $attendee) { | foreach ((array)$task['attendees'] as $i => $attendee) { | ||||
if (isset($attendee['delegated-from']) && is_array($attendee['delegated-from'])) { | if (isset($attendee['delegated-from']) && is_array($attendee['delegated-from'])) { | ||||
$task['attendees'][$i]['delegated-from'] = join(', ', $attendee['delegated-from']); | $task['attendees'][$i]['delegated-from'] = join(', ', $attendee['delegated-from']); | ||||
} | } | ||||
if (isset($attendee['delegated-to']) && is_array($attendee['delegated-to'])) { | if (isset($attendee['delegated-to']) && is_array($attendee['delegated-to'])) { | ||||
$task['attendees'][$i]['delegated-to'] = join(', ', $attendee['delegated-to']); | $task['attendees'][$i]['delegated-to'] = join(', ', $attendee['delegated-to']); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (!empty($record['_attachments'])) { | if (!empty($record['_attachments'] ?? [])) { | ||||
foreach ($record['_attachments'] as $key => $attachment) { | foreach ($record['_attachments'] as $key => $attachment) { | ||||
if ($attachment !== false) { | if ($attachment !== false) { | ||||
if (empty($attachment['name'])) { | if (empty($attachment['name'])) { | ||||
$attachment['name'] = $key; | $attachment['name'] = $key; | ||||
} | } | ||||
$attachments[] = $attachment; | $attachments[] = $attachment; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | private function _from_rcube_task($task, $old = []) | ||||
$object['start']->_dateonly = true; | $object['start']->_dateonly = true; | ||||
$object['due']->_dateonly = true; | $object['due']->_dateonly = true; | ||||
} | } | ||||
$object['complete'] = $task['complete'] * 100; | $object['complete'] = $task['complete'] * 100; | ||||
if ($task['complete'] == 1.0 && empty($task['complete'])) | if ($task['complete'] == 1.0 && empty($task['complete'])) | ||||
$object['status'] = 'COMPLETED'; | $object['status'] = 'COMPLETED'; | ||||
if ($task['flagged']) | if ($task['flagged'] ?? false) | ||||
$object['priority'] = 1; | $object['priority'] = 1; | ||||
else | else | ||||
$object['priority'] = $old['priority'] > 1 ? $old['priority'] : 0; | $object['priority'] = ($old['priority'] ?? 0) > 1 ? $old['priority'] : 0; | ||||
// remove list: prefix from parent_id | // remove list: prefix from parent_id | ||||
if (!empty($task['parent_id']) && strpos($task['parent_id'], $id_prefix) === 0) { | if (!empty($task['parent_id']) && strpos($task['parent_id'], $id_prefix) === 0) { | ||||
$object['parent_id'] = substr($task['parent_id'], strlen($id_prefix)); | $object['parent_id'] = substr($task['parent_id'], strlen($id_prefix)); | ||||
} | } | ||||
// copy meta data (starting with _) from old object | // copy meta data (starting with _) from old object | ||||
foreach ((array)$old as $key => $val) { | foreach ((array)$old as $key => $val) { | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public function edit_task($task) | ||||
'code' => 600, 'type' => 'php', | 'code' => 600, 'type' => 'php', | ||||
'file' => __FILE__, 'line' => __LINE__, | 'file' => __FILE__, 'line' => __LINE__, | ||||
'message' => "Invalid list identifer to save task: " . print_r($list_id, true)), | 'message' => "Invalid list identifer to save task: " . print_r($list_id, true)), | ||||
true, false); | true, false); | ||||
return false; | return false; | ||||
} | } | ||||
// email links and tags are stored separately | // email links and tags are stored separately | ||||
$links = $task['links']; | $links = $task['links'] ?? null; | ||||
$tags = $task['tags']; | $tags = $task['tags'] ?? null; | ||||
unset($task['tags'], $task['links']); | unset($task['tags'], $task['links']); | ||||
// moved from another folder | // moved from another folder | ||||
if ($task['_fromlist'] && ($fromfolder = $this->get_folder($task['_fromlist']))) { | if (($task['_fromlist'] ?? false) && ($fromfolder = $this->get_folder($task['_fromlist']))) { | ||||
if (!$fromfolder->move($task['uid'], $folder)) | if (!$fromfolder->move($task['uid'], $folder)) | ||||
return false; | return false; | ||||
unset($task['_fromlist']); | unset($task['_fromlist']); | ||||
} | } | ||||
// load previous version of this task to merge | // load previous version of this task to merge | ||||
if ($task['id']) { | $old = null; | ||||
if ($task['id'] ?? null) { | |||||
$old = $folder->get_object($task['uid']); | $old = $folder->get_object($task['uid']); | ||||
if (!$old || PEAR::isError($old)) | if (!$old || PEAR::isError($old)) | ||||
return false; | return false; | ||||
// merge existing properties if the update isn't complete | // merge existing properties if the update isn't complete | ||||
if (!isset($task['title']) || !isset($task['complete'])) | if (!isset($task['title']) || !isset($task['complete'])) | ||||
$task += $this->_to_rcube_task($old, $list_id); | $task += $this->_to_rcube_task($old, $list_id); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines |