set iCal colors in Tine 2.0 containers
[tine20] / tine20 / Calendar / Import / CalDav / Decorator / MacOSX.php
1 <?php
2
3 class Calendar_Import_CalDav_Decorator_MacOSX extends Calendar_Import_CalDav_Decorator_Abstract
4 {
5     public function preparefindAllCalendarsRequest($request)
6     {
7         $doc = new DOMDocument();
8         $doc->loadXML($request);
9         //$bulk = $doc->createElementNS('http://me.com/_namespace/', 'osxme:bulk-requests');
10         $color = $doc->createElementNS('http://apple.com/ns/ical/', 'osxical:calendar-color');
11         $prop = $doc->getElementsByTagNameNS('DAV:', 'prop')->item(0);
12         //$prop->appendChild($bulk);
13         $prop->appendChild($color);
14         return $doc->saveXML();
15     }
16     
17     public function processAdditionalCalendarProperties(array &$calendar, array $response)
18     {
19         if (isset($response['{http://apple.com/ns/ical/}calendar-color'])) {
20             $calendar['color'] = $response['{http://apple.com/ns/ical/}calendar-color'];
21             // cut off last two digits as this contains the alpha channel
22             if (strlen($calendar['color']) == 9) {
23                 $calendar['color'] = substr($calendar['color'], 0, 7);
24             }
25         }
26     }
27     
28     public function initCalendarImport()
29     {
30         $_SERVER['HTTP_USER_AGENT'] = 'Mac_OS_X/10.9 (13A603) CalendarAgent/174';
31     }
32 }