Commit bacdd6b7 authored by Sebastian Kummer's avatar Sebastian Kummer

ZO-81 Use Task as Note transport, set category from color when streaming

to Outlook, set color from category when saving from Outlook.
parent 0d9553ed
...@@ -88,31 +88,27 @@ class ImportChangesStream implements IImportChanges { ...@@ -88,31 +88,27 @@ class ImportChangesStream implements IImportChanges {
return false; return false;
} }
// Acacia ZO-42: to sync Notes to Outlook we sync them as Appointments // Acacia ZO-42: to sync Notes to Outlook we sync them as Tasks
if ($this->classAsString == "SyncNote" && ZPush::GetDeviceManager()->IsOutlookClient()) { if ($this->classAsString == "SyncNote" && ZPush::GetDeviceManager()->IsOutlookClient()) {
$appointment = new SyncAppointment(); // update category from SyncNote->Color
$appointment->busystatus = 0; $message->SetCategoryFromColor();
$appointment->sensitivity = 0;
$appointment->alldayevent = 0; $task = new SyncTask();
$appointment->reminder = 0; $task->complete = 0;
$appointment->meetingstatus = 0; $task->sensitivity = 0;
$appointment->responserequested = 0; $task->reminder = 0;
$appointment->flags = $message->flags; $task->flags = $message->flags;
if (isset($message->asbody)) if (isset($message->asbody))
$appointment->asbody = $message->asbody; $task->asbody = $message->asbody;
if (isset($message->categories)) if (isset($message->categories))
$appointment->categories = $message->categories; $task->categories = $message->categories;
if (isset($message->subject)) if (isset($message->subject))
$appointment->subject = $message->subject; $task->subject = $message->subject;
if (isset($message->lastmodified)) if (isset($message->lastmodified))
$appointment->dtstamp = $message->lastmodified; $task->startdate = $message->lastmodified;
if (isset($message->Color))
$appointment->location = $message->Color;
$appointment->starttime = time(); $message = $task;
$appointment->endtime = $appointment->starttime + 1;
$message = $appointment;
} }
// prevent sending the same object twice in one request // prevent sending the same object twice in one request
......
...@@ -283,8 +283,8 @@ class Ping extends RequestProcessor { ...@@ -283,8 +283,8 @@ class Ping extends RequestProcessor {
*/ */
private function isClassValid($class, $spa) { private function isClassValid($class, $spa) {
if ($class == $spa->GetContentClass() || if ($class == $spa->GetContentClass() ||
// Acacia ZO-42: Notes are synched as Appointments // Acacia ZO-42: Notes are synched as Tasks
(self::$deviceManager->IsOutlookClient() && $class == "Calendar" && $spa->GetContentClass() == "Notes") (self::$deviceManager->IsOutlookClient() && $class == "Tasks" && $spa->GetContentClass() == "Notes")
) { ) {
return true; return true;
} }
......
...@@ -453,10 +453,10 @@ class Sync extends RequestProcessor { ...@@ -453,10 +453,10 @@ class Sync extends RequestProcessor {
if(($el = self::$decoder->getElementStartTag(SYNC_DATA)) && ($el[EN_FLAGS] & EN_FLAGS_CONTENT)) { if(($el = self::$decoder->getElementStartTag(SYNC_DATA)) && ($el[EN_FLAGS] & EN_FLAGS_CONTENT)) {
$message = ZPush::getSyncObjectFromFolderClass($spa->GetContentClass()); $message = ZPush::getSyncObjectFromFolderClass($spa->GetContentClass());
// Acacia ZO-42: OL sends Notes as Appointments // Acacia ZO-42: OL sends Notes as Tasks
if ($spa->GetContentClass() == "Notes" && self::$deviceManager->IsOutlookClient()) { if ($spa->GetContentClass() == "Notes" && self::$deviceManager->IsOutlookClient()) {
ZLog::Write(LOGLEVEL_DEBUG, "HandleSync(): Outlook sends Notes as Appointments, read as SyncAppointment and convert it into a SyncNote object."); ZLog::Write(LOGLEVEL_DEBUG, "HandleSync(): Outlook sends Notes as Tasks, read as SyncTask and convert it into a SyncNote object.");
$message = new SyncAppointment(); $message = new SyncTask();
$message->Decode(self::$decoder); $message->Decode(self::$decoder);
$note = new SyncNote(); $note = new SyncNote();
...@@ -466,8 +466,9 @@ class Sync extends RequestProcessor { ...@@ -466,8 +466,9 @@ class Sync extends RequestProcessor {
$note->categories = $message->categories; $note->categories = $message->categories;
if (isset($message->subject)) if (isset($message->subject))
$note->subject = $message->subject; $note->subject = $message->subject;
if (isset($message->location))
$note->Color = $message->location; // set SyncNote->Color from a color category
$note->SetColorFromCategory();
$message = $note; $message = $note;
......
...@@ -47,6 +47,21 @@ ...@@ -47,6 +47,21 @@
class SyncNote extends SyncObject { class SyncNote extends SyncObject {
// Outlook transports note colors as categories
static private $colors = array(
0 => "Blue Category",
1 => "Green Category",
2 => "Red Category",
3 => "Yellow Category",
4 => "White Category",
);
// Purple and orange are not supported in PidLidNoteColor
static private $unsupportedColors = array(
"Purple Category",
"Orange Category",
);
public $asbody; public $asbody;
public $categories; public $categories;
public $lastmodified; public $lastmodified;
...@@ -74,4 +89,52 @@ class SyncNote extends SyncObject { ...@@ -74,4 +89,52 @@ class SyncNote extends SyncObject {
parent::SyncObject($mapping); parent::SyncObject($mapping);
} }
/**
* Sets the color index from a known category.
*
* @access public
* @return void
*/
public function SetColorFromCategory() {
if (is_array($this->categories)) {
$result = array_intersect($this->categories, array_values(self::$colors));
if (empty($result)) {
$result = array_intersect($this->categories, array_values(self::$unsupportedColors));
if (!empty($result)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncNote->SetColorFromCategory(): unsupported color '%s', setting to color white", $result[0]));
$result = array("White Category");
}
}
if (!empty($result)) {
$this->Color = array_search($result[0], $this->categories);
}
}
}
/**
* Sets the category for a Color if color categories are not yet set.
*
* @access public
* @return boolean
*/
public function SetCategoryFromColor() {
// is a color other than white set
if (isset($this->Color) && $this->Color != 3 && $this->Color > -1 && $this->Color < 5) {
// check existing categories - do not rewrite category if the category is already a supported or unsupported color
if (isset($this->categories) && !empty($this->categories) &&
(!empty(array_intersect($this->categories, array_values(self::$unsupportedColors))) ||
!empty(array_intersect($this->categories, array_values(self::$colors))) )) {
return false;
}
if(!isset($this->category)) {
$this->category = array();
}
$this->category[] = self::$colors[$this->Color];
return true;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment