summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2012-11-14 14:30:49 (GMT)
committerThomas Bruederli <thomas@roundcube.net>2012-11-14 14:30:49 (GMT)
commit92eb064f4ff5a5507b9f9b5c9e5351a53e08f27d (patch)
tree28a773f3b89d0da887914dd42db80a2fdc94efa8
parentb20c816e83481c7ed94ac34f0238b0da480ed7b7 (diff)
downloadroundcubemail-plugins-kolab-92eb064f4ff5a5507b9f9b5c9e5351a53e08f27d.tar.gz
Implement reading and writing task objects using Horde
-rw-r--r--plugins/libkolab/lib/kolab_format.php55
-rw-r--r--plugins/libkolab/lib/kolab_format_event.php32
-rw-r--r--plugins/libkolab/lib/kolab_format_task.php95
3 files changed, 148 insertions, 34 deletions
diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php
index afa43ce..97ac252 100644
--- a/plugins/libkolab/lib/kolab_format.php
+++ b/plugins/libkolab/lib/kolab_format.php
@@ -96,6 +96,61 @@ abstract class kolab_format
return preg_replace('/dictionary.[a-z.]+$/', 'dictionary', substr($x_kolab_type, strlen(self::KTYPE_PREFIX)));
}
+ /**
+ * Convert alarm time into internal ical-based format
+ *
+ * @param int Alarm value as saved in Kolab 2 format
+ * @return string iCal-style alarm value for internal use
+ */
+ public static function from_kolab2_alarm($alarm_value)
+ {
+ if (!$alarm_value)
+ return null;
+
+ $alarm_unit = 'M';
+ if ($rec['alarm'] % 1440 == 0) {
+ $alarm_value /= 1440;
+ $alarm_unit = 'D';
+ }
+ else if ($rec['alarm'] % 60 == 0) {
+ $alarm_value /= 60;
+ $alarm_unit = 'H';
+ }
+ $alarm_value *= -1;
+
+ return $alarm_value . $alarm_unit;
+ }
+
+ /**
+ * Utility function to convert from Roundcube's internal alarms format
+ * to an alarm offset in minutes used by the Kolab 2 format.
+ *
+ * @param string iCal-style alarm string
+ * @return int Alarm offset in minutes
+ */
+ public static function to_kolab2_alarm($alarms)
+ {
+ $ret = null;
+
+ if (!$alarms)
+ return $ret;
+
+ $alarmbase = explode(":", $alarms);
+ $avalue = intval(preg_replace('/[^0-9]/', '', $alarmbase[0]));
+
+ if (preg_match("/H/",$alarmbase[0])) {
+ $ret = $avalue*60;
+ }
+ else if (preg_match("/D/",$alarmbase[0])) {
+ $ret = $avalue*24*60;
+ }
+ else {
+ $ret = $avalue;
+ }
+
+ return $ret;
+ }
+
/**
* Default constructor of all kolab_format_* objects
diff --git a/plugins/libkolab/lib/kolab_format_event.php b/plugins/libkolab/lib/kolab_format_event.php
index 505b617..7aedecc 100644
--- a/plugins/libkolab/lib/kolab_format_event.php
+++ b/plugins/libkolab/lib/kolab_format_event.php
@@ -115,20 +115,7 @@ class kolab_format_event extends kolab_format
}
// handle alarms
- if ($object['alarms']) {
- $alarmbase = explode(":", $object['alarms']);
- $avalue = preg_replace('/[^0-9]/', '', $alarmbase[0]);
-
- if (preg_match("/H/",$alarmbase[0])) {
- $this->kolab_object['alarm'] = $avalue*60;
- }
- else if (preg_match("/D/",$alarmbase[0])) {
- $this->kolab_object['alarm'] = $avalue*24*60;
- }
- else {
- $this->kolab_object['alarm'] = $avalue;
- }
- }
+ $this->kolab_object['alarm'] = self::to_kolab2_alarm($object['alarms']);
// recurr object/array
if (count($object['recurrence']) > 1) {
@@ -297,21 +284,6 @@ class kolab_format_event extends kolab_format
$rec['end-date'] += 86400;
}
- // convert alarm time into internal format
- if ($rec['alarm']) {
- $alarm_value = $rec['alarm'];
- $alarm_unit = 'M';
- if ($rec['alarm'] % 1440 == 0) {
- $alarm_value /= 1440;
- $alarm_unit = 'D';
- }
- else if ($rec['alarm'] % 60 == 0) {
- $alarm_value /= 60;
- $alarm_unit = 'H';
- }
- $alarm_value *= -1;
- }
-
// convert recurrence rules into internal pseudo-vcalendar format
if ($recurrence = $rec['recurrence']) {
$rrule = array(
@@ -379,7 +351,7 @@ class kolab_format_event extends kolab_format
'end' => new DateTime('@'.$rec['end-date']),
'allday' => $allday,
'recurrence' => $rrule,
- 'alarms' => $alarm_value . $alarm_unit,
+ 'alarms' => self::from_kolab2_alarm($rec['alarm']),
'categories' => $rec['categories'],
'attendees' => $attendees,
'free_busy' => $rec['show-time-as'],
diff --git a/plugins/libkolab/lib/kolab_format_task.php b/plugins/libkolab/lib/kolab_format_task.php
index d1d29f4..eb0f2ee 100644
--- a/plugins/libkolab/lib/kolab_format_task.php
+++ b/plugins/libkolab/lib/kolab_format_task.php
@@ -30,6 +30,24 @@ class kolab_format_task extends kolab_format
public static $fulltext_cols = array('title', 'description', 'location', 'attendees:name', 'attendees:email', 'categories');
+ // Kolab 2 format field map
+ private $kolab2_fieldmap = array(
+ // kolab => roundcube
+ 'name' => 'title',
+ 'body' => 'description',
+ 'categories' => 'categories',
+ 'sensitivity' => 'sensitivity',
+ 'priority' => 'priority',
+ 'parent' => 'parent_id',
+ );
+ private $kolab2_statusmap = array(
+ 'none' => 'NEEDS-ACTION',
+ 'deferred' => 'NEEDS-ACTION',
+ 'not-started' => 'NEEDS-ACTION',
+ 'in-progress' => 'IN-PROCESS',
+ 'complete' => 'COMPLETED',
+ );
+
/**
* Set properties to the kolabformat object
@@ -40,7 +58,49 @@ class kolab_format_task extends kolab_format
{
$this->init();
- // TODO: implement this
+ if ($object['uid'])
+ $this->kolab_object['uid'] = $object['uid'];
+
+ $this->kolab_object['last-modification-date'] = time();
+
+ // map basic fields rcube => $kolab
+ foreach ($this->kolab2_fieldmap as $kolab => $rcube) {
+ $this->kolab_object[$kolab] = $object[$rcube];
+ }
+
+ $this->kolab_object['categories'] = join(',', (array)$object['categories']);
+
+ $status_map = array_flip($this->kolab2_statusmap);
+ if ($kolab_status = $status_map[$object['status']])
+ $this->kolab_object['status'] = $kolab_status;
+
+ $this->kolab_object['due'] = $this->kolab_object['start'] = 0;
+ if ($object['due']) {
+ $dtdue = clone $object['due'];
+ $dtdue->setTimezone(new DateTimeZone('UTC'));
+ if ($object['due']->_dateonly)
+ $dtdue->setTime(0,0,0);
+ $this->kolab_object['due'] = $dtdue->format('U');
+ }
+ if ($object['start']) {
+ $dtstart = clone $object['start'];
+ $dtstart->setTimezone(new DateTimeZone('UTC'));
+ if ($object['start']->_dateonly)
+ $dtstart->setTime(0,0,0);
+ $this->kolab_object['start'] = $dtstart->format('U');
+ }
+
+ // set 'completed-date' on transition
+ if (!$this->kolab_object['complete'] && $object['status'] == 'COMPLETED')
+ $this->kolab_object['completed-date'] = time();
+
+ if ($object['status'] == 'COMPLETED' || $object['complete'] == 100)
+ $this->kolab_object['completed'] = true;
+ else if ($object['status'] != 'COMPLETED' && $this->kolab_object['completed'])
+ $this->kolab_object['completed'] = 0;
+
+ // handle alarms
+ $this->kolab_object['alarm'] = self::to_kolab2_alarm($object['alarms']);
// cache this data
$this->data = $object;
@@ -52,7 +112,7 @@ class kolab_format_task extends kolab_format
*/
public function is_valid()
{
- return $this->data;
+ return !empty($this->data['uid']) && isset($this->data['title']);
}
/**
@@ -62,10 +122,37 @@ class kolab_format_task extends kolab_format
{
$object = array(
'uid' => $record['uid'],
- 'changed' => $record['last-modification-date'],
+ 'dtstamp' => $record['last-modification-date'],
+ 'complete' => 0,
);
- // TODO: implement this
+ // map basic fields rcube => $kolab
+ foreach ($this->kolab2_fieldmap as $kolab => $rcube) {
+ $object[$rcube] = $record[$kolab];
+ }
+
+ if ($record['completed']) {
+ $object['status'] = 'COMPLETED';
+ $object['complete'] = 100;
+ }
+
+ $object['categories'] = array_filter(explode(',', $record['categories']));
+
+ if ($record['due']) {
+ $object['due'] = new DateTime('@'.$record['due']);
+ if ($object['due']->format('H:i') == '00:00')
+ $object['due']->_dateonly = true;
+ $object['due']->setTimezone(self::$timezone);
+ }
+ if ($record['start']) {
+ $object['start'] = new DateTime('@'.$record['start']);
+ if ($object['start']->format('H:i') == '00:00')
+ $object['start']->_dateonly = true;
+ $object['start']->setTimezone(self::$timezone);
+ }
+
+ if ($record['alarm'])
+ $object['alarms'] = self::from_kolab2_alarm($record['alarm']);
$this->data = $object;
}