lib/kolab_sync_data_calendar.php lib/kolab_sync_data.php
Aleksander Machniak
machniak at kolabsys.com
Thu Jan 10 18:42:43 CET 2013
lib/kolab_sync_data.php | 83 ++++++++++++++++++++++-----------------
lib/kolab_sync_data_calendar.php | 15 +++++--
2 files changed, 58 insertions(+), 40 deletions(-)
New commits:
commit af89e8c9add745bca15dd73aa780d742bb4f197b
Author: Aleksander Machniak <alec at alec.pl>
Date: Thu Jan 10 18:41:44 2013 +0100
Implemented partial support for event reccurence exceptions (Bug #1498)
diff --git a/lib/kolab_sync_data.php b/lib/kolab_sync_data.php
index 6bcbe54..4e7064b 100644
--- a/lib/kolab_sync_data.php
+++ b/lib/kolab_sync_data.php
@@ -1164,55 +1164,66 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
/**
* Convert Kolab event recurrence exceptions into ActiveSync
*/
- protected function exceptions_from_kolab($data)
+ protected function exceptions_from_kolab($data, $start_date)
{
-/*
- // handle exceptions of repeating events
- if($data->exdate && $data->exdate->count() > 0) {
- $exceptionsTag = $_domParent->appendChild(new DOMElement('Exceptions', null, 'uri:Calendar'));
+ if (empty($data['recurrence'])) {
+ return null;
+ }
+
+ $rex = (array) $data['recurrence']['EXDATE'];
+ $exceptions = array();
+
+ foreach ($rex as $ex_date) {
+ if (!($ex_date instanceof DateTime)) {
+ continue;
+ }
- foreach ($data->exdate as $exception) {
- $exceptionTag = $exceptionsTag->appendChild(new DOMElement('Exception', null, 'uri:Calendar'));
+ $start = clone $ex_date;
+ $end = clone $ex_date;
- $exceptionTag->appendChild(new DOMElement('Deleted', (int)$exception->is_deleted, 'uri:Calendar'));
- $exceptionTag->appendChild(new DOMElement('ExceptionStartTime', $exception->getOriginalDtStart()->format('Ymd\THis') . 'Z', 'uri:Calendar'));
+ $start->setTime(0, 0, 0);
+ $end->setTime(0, 0, 0);
+ $end->modify('+1 day');
- if ((int)$exception->is_deleted === 0) {
- $this->appendXML($exceptionTag, $_collectionData, $exception);
- }
- }
+ $ex = array(
+ 'exceptionStartTime' => $start_date,
+ 'startTime' => self::date_from_kolab($start),
+ 'endTime' => self::date_from_kolab($end),
+ 'deleted' => 1,
+ );
+
+ if ($data['allday']) {
+ $ex['allDayEvent'] = 1;
}
-*/
+
+ $exceptions[] = new Syncroton_Model_EventException($ex);
+ }
+
+ return $exceptions;
}
/**
* Convert ActiveSync event recurrence exceptions into Kolab
*/
- protected function exceptions_to_kolab($data, $timezone = null)
+ protected function exceptions_to_kolab($exceptions, $timezone = null)
{
-/*
- // handle exceptions from recurrence
- if (isset($xmlData->Exceptions)) {
- $exdates = new Tinebase_Record_RecordSet('Calendar_Model_Event');
-
- foreach ($xmlData->Exceptions->Exception as $exception) {
- $eventException = new Calendar_Model_Event(array(
- 'recurid' => new Tinebase_DateTime((string)$exception->ExceptionStartTime)
- ));
-
- if ((int)$exception->Deleted === 0) {
- $eventException->is_deleted = false;
- $this->toTineModel($exception, $eventException);
- } else {
- $eventException->is_deleted = true;
- }
-
- $exdates->addRecord($eventException);
+ $exdates = array();
+ // handle exceptions from recurrence
+ if (!empty($exceptions)) {
+ foreach ($exceptions as $exception) {
+ if ($exception->deleted && $exception->startTime) {
+ $date = clone $exception->startTime;
+ $date->setTimezone($timezone);
+ $date->setTime(0, 0, 0);
+ $exdates[] = $date;
+ }
+ else {
+ // @TODO: handle modification exceptions (that doesn't delete) ?
}
-
- $event->exdate = $exdates;
}
-*/
+ }
+
+ return $exdates;
}
/**
diff --git a/lib/kolab_sync_data_calendar.php b/lib/kolab_sync_data_calendar.php
index 5c66557..64f702d 100644
--- a/lib/kolab_sync_data_calendar.php
+++ b/lib/kolab_sync_data_calendar.php
@@ -206,15 +206,16 @@ class kolab_sync_data_calendar extends kolab_sync_data
// For all-day events Kolab uses different times
// At least Android doesn't display such event as all-day event
if ($value && $event['allday']) {
+ $date = clone $value;
if ($name == 'start') {
- $value->setTime(0, 0, 0);
+ $date->setTime(0, 0, 0);
}
else if ($name == 'end') {
- $value->setTime(0, 0, 0);
- $value->modify('+1 day');
+ $date->setTime(0, 0, 0);
+ $date->modify('+1 day');
}
}
- $value = self::date_from_kolab($value);
+ $value = self::date_from_kolab($date);
break;
@@ -306,6 +307,9 @@ class kolab_sync_data_calendar extends kolab_sync_data
// Recurrence
$result['recurrence'] = $this->recurrence_from_kolab($event);
+ // Recurrence exceptions
+ $result['exceptions'] = $this->exceptions_from_kolab($event, $result['startTime']);
+
return new Syncroton_Model_Event($result);
}
@@ -449,6 +453,9 @@ class kolab_sync_data_calendar extends kolab_sync_data
// recurrence
$event['recurrence'] = $this->recurrence_to_kolab($data->recurrence, $timezone);
+ // recurrence exceptions
+ $event['recurrence']['EXDATE'] = $this->exceptions_to_kolab($data->exceptions, $timezone);
+
return $event;
}
More information about the commits
mailing list