summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_data_calendar.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kolab_sync_data_calendar.php')
-rw-r--r--lib/kolab_sync_data_calendar.php50
1 files changed, 35 insertions, 15 deletions
diff --git a/lib/kolab_sync_data_calendar.php b/lib/kolab_sync_data_calendar.php
index 359821b..785c9d0 100644
--- a/lib/kolab_sync_data_calendar.php
+++ b/lib/kolab_sync_data_calendar.php
@@ -254,7 +254,7 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
}
// Event reminder time
- if ($config['ALARMS'] && ($minutes = $this->from_kolab_alarm($event['alarms']))) {
+ if ($config['ALARMS'] && ($minutes = $this->from_kolab_alarm($event))) {
$result['reminder'] = $minutes;
}
@@ -426,7 +426,7 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
// Reminder
// @TODO: should alarms be used when importing event from phone?
if ($config['ALARMS']) {
- $event['alarms'] = $this->to_kolab_alarm($data->reminder, $event);
+ $event['valarms'] = $this->to_kolab_alarm($data->reminder, $event);
}
$event['attendees'] = array();
@@ -530,13 +530,20 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
}
/**
- * Converts libkolab alarms string into number of minutes
+ * Converts libkolab alarms spec. into a number of minutes
*/
- protected function from_kolab_alarm($value)
+ protected function from_kolab_alarm($event)
{
- // e.g. '-15M:DISPLAY'
- // Ignore EMAIL alarms
- if (preg_match('/^-([0-9]+)([WDHMS]):(DISPLAY|AUDIO)$/', $value, $matches)) {
+ if (isset($event['valarms'])) {
+ foreach ($event['valarms'] as $alarm) {
+ if (in_array($alarm['action'], array('DISPLAY', 'AUDIO'))) {
+ $value = $alarm['trigger'];
+ break;
+ }
+ }
+ }
+
+ if ($value && preg_match('/^-[PT]*([0-9]+)([WDHMS])$/', $value, $matches)) {
$value = intval($matches[1]);
switch ($matches[2]) {
@@ -551,24 +558,37 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
}
/**
- * Converts ActiveSync libkolab alarms string into number of minutes
+ * Converts ActiveSync reminder into libkolab alarms spec.
*/
protected function to_kolab_alarm($value, $event)
{
- // Get alarm type from old event object if exists
- if (!empty($event['alarms']) && preg_match('/:(.*)$/', $event['alarms'], $matches)) {
- $type = $matches[1];
+ $valarms = array();
+ $unsupported = array();
+
+ if (!empty($event['valarms'])) {
+ foreach ($event['valarms'] as $alarm) {
+ if (!$current && in_array($alarm['action'], array('DISPLAY', 'AUDIO'))) {
+ $current = $alarm;
+ }
+ else {
+ $unsupported[] = $alarm;
+ }
+ }
}
if ($value) {
- return sprintf('-%dM:%s', $value, $type ? $type : 'DISPLAY');
+ $valarms[] = array(
+ 'action' => $current['action'] ?: 'DISPLAY',
+ 'description' => $current['description'] ?: '',
+ 'trigger' => sprintf('-PT%dM', $value),
+ );
}
- if ($type == 'DISPLAY' || $type == 'AUDIO') {
- return null;
+ if (!empty($unsupported)) {
+ $valarms = array_merge($valarms, $unsupported);
}
- return $event['alarms'];
+ return $valarms;
}
}