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 *today, *startDate, *endDate;
51 today = [[NSCalendarDate calendarDate] beginOfDay];
52 [today setTimeZone: [self userTimeZone]];
54 startDate = [today dateByAddingYears: 0 months: 0 days: -14
55 hours: 0 minutes: 0 seconds: 0];
56 endDate = [startDate dateByAddingYears: 0 months: 1 days: 0
57 hours: 0 minutes: 0 seconds: 0];
58 return [self contentAsStringFrom: startDate to: endDate];
61 - (NSString *) contentAsStringFrom: (NSCalendarDate *) _startDate
62 to: (NSCalendarDate *) _endDate
66 infos = [self fetchFreeBusyInfosFrom:_startDate to:_endDate];
67 return [self iCalStringForFreeBusyInfos:infos from:_startDate to:_endDate];
70 - (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) _startDate
71 to: (NSCalendarDate *) _endDate
74 SoSecurityManager *sm;
78 woApp = [WOApplication application];
80 calFolder = [container lookupName: @"Calendar" inContext: nil acquire: NO];
81 sm = [SoSecurityManager sharedSecurityManager];
82 if (![sm validatePermission: SOGoPerm_FreeBusyLookup
84 inContext: [woApp context]])
85 infos = [calFolder fetchFreeBusyInfosFrom: _startDate
89 infos = [NSArray new];
97 - (iCalFreeBusyType) _fbTypeForEventStatus: (NSNumber *) eventStatus
100 iCalFreeBusyType fbType;
102 status = [eventStatus unsignedIntValue];
104 fbType = iCalFBBusyTentative;
105 else if (status == 1)
113 - (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
114 from: (NSCalendarDate *) _startDate
115 to: (NSCalendarDate *) _endDate
117 AgenorUserManager *um;
119 NSEnumerator *events;
120 iCalCalendar *calendar;
121 iCalFreeBusy *freebusy;
123 iCalFreeBusyType type;
125 um = [AgenorUserManager sharedUserManager];
126 uid = [[self container] login];
128 calendar = [iCalCalendar groupWithTag: @"vcalendar"];
129 [calendar setProdID: @"//Inverse groupe conseil/SOGo 0.9"];
130 [calendar setVersion: @"2.0"];
132 freebusy = [iCalFreeBusy groupWithTag: @"vfreebusy"];
133 [freebusy addToAttendees: [um iCalPersonWithUid: uid]];
134 [freebusy setTimeStampAsDate: [NSCalendarDate calendarDate]];
135 [freebusy setStartDate: _startDate];
136 [freebusy setEndDate: _endDate];
138 /* ORGANIZER - strictly required but missing for now */
141 // person = [um iCalPersonWithUid: uid];
142 // [person setTag: @"ATTENDEE"];
143 // [ms appendString: [person versitString]];
146 events = [_infos objectEnumerator];
147 info = [events nextObject];
150 if ([[info objectForKey: @"isopaque"] boolValue])
152 type = [self _fbTypeForEventStatus: [info objectForKey: @"status"]];
153 [freebusy addFreeBusyFrom: [info objectForKey: @"startDate"]
154 to: [info objectForKey: @"endDate"]
157 info = [events nextObject];
160 [calendar setUniqueChild: freebusy];
162 return [calendar versitString];
165 /* deliver content without need for view method */
167 - (id) GETAction: (id)_ctx
172 contentData = [[self contentAsString] dataUsingEncoding: NSUTF8StringEncoding];
174 r = [(WOContext *) _ctx response];
175 [r setHeader: @"text/calendar" forKey: @"content-type"];
176 [r setContent: contentData];