From 92660c34b18f4f7caa543bc313cc08308dc75d02 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Mon, 5 Dec 2016 18:47:21 +0100 Subject: [PATCH] Import and export of free/busy state --- .idea/workspace.xml | 130 +++++++++++++++++++++++++++++++++------- php/module.calendar.php | 42 +++++++++++-- 2 files changed, 147 insertions(+), 25 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7379bc3..a0be335 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,6 @@ - @@ -27,16 +26,39 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -196,6 +218,46 @@ - @@ -397,6 +477,9 @@ + + + @@ -677,13 +760,6 @@ - - - - - - - @@ -736,13 +812,6 @@ - - - - - - - @@ -750,13 +819,32 @@ + + + + + + + + + + + + + + + + - - + + + + + diff --git a/php/module.calendar.php b/php/module.calendar.php index 53e9b94..4f5fbe1 100644 --- a/php/module.calendar.php +++ b/php/module.calendar.php @@ -58,6 +58,13 @@ class CalendarModule extends Module "OOF" ); + $this->freeBusyStates = array( // http://www.kanzaki.com/docs/ical/fbtype.html + "FREE", + "BUSY-TENTATIVE", + "BUSY", + "BUSY-UNAVAILABLE" + ); + $this->labels = array( "NONE", "IMPORTANT", @@ -270,17 +277,20 @@ class CalendarModule extends Module 'DTEND' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "duedate")), 'CREATED' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "creation_time")), 'LAST-MODIFIED' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "last_modification_time")), - 'PRIORITY' => $this->getProp($messageProps, "importance"), + 'PRIORITY' => intval($this->getProp($messageProps, "importance")), 'X-MICROSOFT-CDO-INTENDEDSTATUS' => $this->busyStates[intval($this->getProp($messageProps, "busystatus"))], // both seem to be valid... 'X-MICROSOFT-CDO-BUSYSTATUS' => $this->busyStates[intval($this->getProp($messageProps, "busystatus"))], // both seem to be valid... + 'FBTYPE' => $this->freeBusyStates[intval($this->getProp($messageProps, "busystatus"))], 'X-ZARAFA-LABEL' => $this->labels[intval($this->getProp($messageProps, "label"))], 'CLASS' => $this->getProp($messageProps, "private") ? "PRIVATE" : "PUBLIC", 'COMMENT' => "eid:" . $records[$index] ]); // Add organizer - $vEvent->add('ORGANIZER', 'mailto:' . $this->getProp($messageProps, "sender_email_address")); - $vEvent->ORGANIZER['CN'] = $this->getProp($messageProps, "sender_name"); + if(!empty( $this->getProp($messageProps, "sender_email_address"))) { + $vEvent->add('ORGANIZER', 'mailto:' . $this->getProp($messageProps, "sender_email_address")); + $vEvent->ORGANIZER['CN'] = $this->getProp($messageProps, "sender_name"); + } // Add Attendees if (isset($messageProps["recipients"]) && count($messageProps["recipients"]["item"]) > 0) { @@ -318,6 +328,13 @@ class CalendarModule extends Module if (!empty($body)) { $vEvent->add('DESCRIPTION', $body); } + + // Add categories + if (!empty($this->getProp($messageProps, "categories"))) { + $categories = array_map('trim', explode(';', trim($this->getProp($messageProps, "categories"), " ;"))); + + $vEvent->add('CATEGORIES', $categories); + } } // write combined ics file @@ -672,7 +689,15 @@ class CalendarModule extends Module $properties["comment"] = (string)$vEvent->COMMENT; $properties["timezone"] = (string)$vEvent->DTSTART["TZID"]; $properties["organizer"] = (string)$vEvent->ORGANIZER; - $properties["busystatus"] = array_search((string)$vEvent->{'X-MICROSOFT-CDO-INTENDEDSTATUS'}, $this->busyStates); // X-MICROSOFT-CDO-BUSYSTATUS + if(!empty((string)$vEvent->FBTYPE)) { + $properties["busystatus"] = array_search((string)$vEvent->FBTYPE, $this->freeBusyStates); + } else if(!empty((string)$vEvent->{'X-MICROSOFT-CDO-INTENDEDSTATUS'})) { + $properties["busystatus"] = array_search((string)$vEvent->{'X-MICROSOFT-CDO-INTENDEDSTATUS'}, $this->busyStates); + } else if(!empty((string)$vEvent->{'X-MICROSOFT-CDO-BUSYSTATUS'})) { + $properties["busystatus"] = array_search((string)$vEvent->{'X-MICROSOFT-CDO-BUSYSTATUS'}, $this->busyStates); + } else { + $properties["busystatus"] = array_search("BUSY", $this->busyStates); + } $properties["transp"] = (string)$vEvent->TRANSP; //$properties["trigger"] = (string)$vEvent->COMMENT; $properties["priority"] = (string)$vEvent->PRIORITY; @@ -692,6 +717,15 @@ class CalendarModule extends Module } $properties["rrule"] = (string)$vEvent->RRULE; + if (isset($vEvent->CATEGORIES) && count($vEvent->CATEGORIES) > 0) { + $categories = array(); + foreach ($vEvent->CATEGORIES as $category) { + $categories[] = (string) $category; + } + + $properties["categories"] = $categories; + } + // Attendees $properties["attendees"] = array(); if (isset($vEvent->ATTENDEE) && count($vEvent->ATTENDEE) > 0) {