From 99e4b1fc22751dac61a340a25c00dd7bb6aaee2f Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 26 Mar 2007 13:41:04 +0000 Subject: [PATCH] Monotone-Parent: 6723ab8142f4a076f7663746dfb3f59de2190e55 Monotone-Revision: b2f8cfd95a5bbbd3129eea0cb28710e341ce22db Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-03-26T13:41:04 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 5 ++ UI/MainUI/SOGoUserHomePage.m | 119 +++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/ChangeLog b/ChangeLog index c1dad0c55..cc2e56f6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-03-26 Wolfgang Sourdeau + + * UI/MainUI/SOGoUserHomePage.m ([SOGoUserHomePage + -readFreeBusyAction]): restored method. + 2007-03-22 Wolfgang Sourdeau * UI/MainUI/SOGoUserHomePage.m ([SOGoUserHomePage diff --git a/UI/MainUI/SOGoUserHomePage.m b/UI/MainUI/SOGoUserHomePage.m index 4cd16e76e..559e4b3c6 100644 --- a/UI/MainUI/SOGoUserHomePage.m +++ b/UI/MainUI/SOGoUserHomePage.m @@ -20,7 +20,14 @@ * Boston, MA 02111-1307, USA. */ +#import +#import #import +#import +#import + +#import +#import #import @interface SOGoUserHomePage : UIxComponent @@ -39,4 +46,116 @@ return [self redirectToLocation: url]; } +- (void) _fillFreeBusyItems: (NSMutableArray *) items + withRecords: (NSEnumerator *) records + fromStartDate: (NSCalendarDate *) startDate + toEndDate: (NSCalendarDate *) endDate +{ + NSDictionary *record; + int count, startInterval, endInterval, value; + NSNumber *status; + NSCalendarDate *currentDate; + + record = [records nextObject]; + while (record) + { + status = [record objectForKey: @"status"]; + + value = [[record objectForKey: @"startdate"] intValue]; + currentDate = [NSCalendarDate dateWithTimeIntervalSince1970: value]; + if ([currentDate earlierDate: startDate] == currentDate) + startInterval = 0; + else + startInterval + = ([currentDate timeIntervalSinceDate: startDate] / 900); + + value = [[record objectForKey: @"enddate"] intValue]; + currentDate = [NSCalendarDate dateWithTimeIntervalSince1970: value]; + if ([currentDate earlierDate: endDate] == endDate) + endInterval = [items count] - 1; + else + endInterval = ([currentDate timeIntervalSinceDate: startDate] / 900); + + for (count = startInterval; count < endInterval; count++) + [items replaceObjectAtIndex: count withObject: status]; + + record = [records nextObject]; + } +} + +- (NSString *) _freeBusyAsTextFromStartDate: (NSCalendarDate *) startDate + toEndDate: (NSCalendarDate *) endDate + forFreeBusy: (SOGoFreeBusyObject *) fb +{ + NSEnumerator *records; + NSMutableArray *freeBusyItems; + NSTimeInterval interval; + int count, intervals; + + interval = [endDate timeIntervalSinceDate: startDate] + 60; + intervals = interval / 900; /* slices of 15 minutes */ + freeBusyItems = [NSMutableArray arrayWithCapacity: intervals]; + for (count = 1; count < intervals; count++) + [freeBusyItems addObject: @"0"]; + + records = [[fb fetchFreeBusyInfosFrom: startDate to: endDate] objectEnumerator]; + [self _fillFreeBusyItems: freeBusyItems withRecords: records + fromStartDate: startDate toEndDate: endDate]; + + return [freeBusyItems componentsJoinedByString: @","]; +} + +- (NSString *) _freeBusyAsText +{ + SOGoFreeBusyObject *co; + NSCalendarDate *startDate, *endDate; + NSString *queryDay, *additionalDays; + NSTimeZone *uTZ; + + co = [self clientObject]; + uTZ = [co userTimeZone]; + + queryDay = [self queryParameterForKey: @"sday"]; + if ([queryDay length]) + startDate = [NSCalendarDate dateFromShortDateString: queryDay + andShortTimeString: @"0000" + inTimeZone: uTZ]; + else + { + startDate = [NSCalendarDate calendarDate]; + [startDate setTimeZone: uTZ]; + startDate = [startDate hour: 0 minute: 0]; + } + + queryDay = [self queryParameterForKey: @"eday"]; + if ([queryDay length]) + endDate = [NSCalendarDate dateFromShortDateString: queryDay + andShortTimeString: @"2359" + inTimeZone: uTZ]; + else + endDate = [startDate hour: 23 minute: 59]; + + additionalDays = [self queryParameterForKey: @"additional"]; + if ([additionalDays length] > 0) + endDate = [endDate dateByAddingYears: 0 months: 0 + days: [additionalDays intValue] + hours: 0 minutes: 0 seconds: 0]; + + return [self _freeBusyAsTextFromStartDate: startDate toEndDate: endDate + forFreeBusy: co]; +} + +- (id ) readFreeBusyAction +{ + WOResponse *response; + + response = [context response]; + [response setStatus: 200]; + [response setHeader: @"text/plain; charset=iso-8859-1" + forKey: @"Content-Type"]; + [response appendContentString: [self _freeBusyAsText]]; + + return response; +} + @end