2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #import <NGCards/iCalCalendar.h>
24 #import <NGCards/iCalFreeBusy.h>
28 #import <SOGo/AgenorUserManager.h>
29 #import <SOGo/SOGoPermissions.h>
31 #import "SOGoFreeBusyObject.h"
33 @interface SOGoFreeBusyObject (PrivateAPI)
34 - (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
35 from: (NSCalendarDate *) _startDate
36 to: (NSCalendarDate *) _endDate;
39 @implementation SOGoFreeBusyObject
41 - (NSString *) iCalString
43 // for UI-X appointment viewer
44 return [self contentAsString];
47 - (NSString *) contentAsString
49 NSCalendarDate *startDate, *endDate;
51 startDate = [[[NSCalendarDate calendarDate] mondayOfWeek] beginOfDay];
52 endDate = [startDate dateByAddingYears: 0 months: 0 days: 7
53 hours: 23 minutes: 59 seconds: 59];
54 return [self contentAsStringFrom: startDate to: endDate];
57 - (NSString *) contentAsStringFrom: (NSCalendarDate *) _startDate
58 to: (NSCalendarDate *) _endDate
62 infos = [self fetchFreeBusyInfosFrom:_startDate to:_endDate];
63 return [self iCalStringForFreeBusyInfos:infos from:_startDate to:_endDate];
66 - (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) _startDate
67 to: (NSCalendarDate *) _endDate
70 SoSecurityManager *sm;
74 woApp = [WOApplication application];
76 calFolder = [container lookupName: @"Calendar" inContext: nil acquire: NO];
77 sm = [SoSecurityManager sharedSecurityManager];
78 if (![sm validatePermission: SOGoPerm_FreeBusyLookup
80 inContext: [woApp context]])
81 infos = [calFolder fetchFreeBusyInfosFrom: _startDate
85 infos = [NSArray new];
93 - (iCalFreeBusyType) _fbTypeForEventStatus: (NSNumber *) eventStatus
96 iCalFreeBusyType fbType;
98 status = [eventStatus unsignedIntValue];
100 fbType = iCalFBBusyTentative;
101 else if (status == 1)
109 - (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
110 from: (NSCalendarDate *) _startDate
111 to: (NSCalendarDate *) _endDate
113 AgenorUserManager *um;
115 NSEnumerator *events;
116 iCalCalendar *calendar;
117 iCalFreeBusy *freebusy;
119 iCalFreeBusyType type;
121 um = [AgenorUserManager sharedUserManager];
122 uid = [[self container] login];
124 calendar = [iCalCalendar groupWithTag: @"vcalendar"];
125 [calendar setProdID: @"//Inverse groupe conseil/SOGo 0.9"];
126 [calendar setVersion: @"2.0"];
128 freebusy = [iCalFreeBusy groupWithTag: @"vfreebusy"];
129 [freebusy addToAttendees: [um iCalPersonWithUid: uid]];
130 [freebusy setTimeStampAsDate: [NSCalendarDate calendarDate]];
131 [freebusy setStartDate: _startDate];
132 [freebusy setEndDate: _endDate];
134 /* ORGANIZER - strictly required but missing for now */
137 // person = [um iCalPersonWithUid: uid];
138 // [person setTag: @"ATTENDEE"];
139 // [ms appendString: [person versitString]];
142 events = [_infos objectEnumerator];
143 info = [events nextObject];
146 if ([[info objectForKey: @"isopaque"] boolValue])
148 type = [self _fbTypeForEventStatus: [info objectForKey: @"status"]];
149 [freebusy addFreeBusyFrom: [info objectForKey: @"startDate"]
150 to: [info objectForKey: @"endDate"]
153 info = [events nextObject];
156 [calendar setUniqueChild: freebusy];
158 return [calendar versitString];
161 /* deliver content without need for view method */
163 - (id) GETAction: (id)_ctx
168 contentData = [[self contentAsString] dataUsingEncoding: NSUTF8StringEncoding];
170 r = [(WOContext *) _ctx response];
171 [r setHeader: @"text/calendar" forKey: @"content-type"];
172 [r setContent: contentData];