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 {
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()) {
$appointment = new SyncAppointment();
$appointment->busystatus = 0;
$appointment->sensitivity = 0;
$appointment->alldayevent = 0;
$appointment->reminder = 0;
$appointment->meetingstatus = 0;
$appointment->responserequested = 0;
$appointment->flags = $message->flags;
// update category from SyncNote->Color
$message->SetCategoryFromColor();
$task = new SyncTask();
$task->complete = 0;
$task->sensitivity = 0;
$task->reminder = 0;
$task->flags = $message->flags;
if (isset($message->asbody))
$appointment->asbody = $message->asbody;
$task->asbody = $message->asbody;
if (isset($message->categories))
$appointment->categories = $message->categories;
$task->categories = $message->categories;
if (isset($message->subject))
$appointment->subject = $message->subject;
$task->subject = $message->subject;
if (isset($message->lastmodified))
$appointment->dtstamp = $message->lastmodified;
if (isset($message->Color))
$appointment->location = $message->Color;
$task->startdate = $message->lastmodified;
$appointment->starttime = time();
$appointment->endtime = $appointment->starttime + 1;
$message = $appointment;
$message = $task;
}
// prevent sending the same object twice in one request
......
......@@ -283,8 +283,8 @@ class Ping extends RequestProcessor {
*/
private function isClassValid($class, $spa) {
if ($class == $spa->GetContentClass() ||
// Acacia ZO-42: Notes are synched as Appointments
(self::$deviceManager->IsOutlookClient() && $class == "Calendar" && $spa->GetContentClass() == "Notes")
// Acacia ZO-42: Notes are synched as Tasks
(self::$deviceManager->IsOutlookClient() && $class == "Tasks" && $spa->GetContentClass() == "Notes")
) {
return true;
}
......
......@@ -453,10 +453,10 @@ class Sync extends RequestProcessor {
if(($el = self::$decoder->getElementStartTag(SYNC_DATA)) && ($el[EN_FLAGS] & EN_FLAGS_CONTENT)) {
$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()) {
ZLog::Write(LOGLEVEL_DEBUG, "HandleSync(): Outlook sends Notes as Appointments, read as SyncAppointment and convert it into a SyncNote object.");
$message = new SyncAppointment();
ZLog::Write(LOGLEVEL_DEBUG, "HandleSync(): Outlook sends Notes as Tasks, read as SyncTask and convert it into a SyncNote object.");
$message = new SyncTask();
$message->Decode(self::$decoder);
$note = new SyncNote();
......@@ -466,8 +466,9 @@ class Sync extends RequestProcessor {
$note->categories = $message->categories;
if (isset($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;
......
......@@ -47,6 +47,21 @@
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 $categories;
public $lastmodified;
......@@ -74,4 +89,52 @@ class SyncNote extends SyncObject {
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