From c664b4d54dc702e5c6f15fd060bcd4c2775096ef Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 16 Aug 2004 12:56:48 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@258 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/UI/Scheduler/ChangeLog | 2 + SOGo/UI/Scheduler/UIxAppointmentProposal.m | 95 ++++++++++++++++++++-- SOGo/UI/Scheduler/Version | 3 +- 3 files changed, 93 insertions(+), 7 deletions(-) diff --git a/SOGo/UI/Scheduler/ChangeLog b/SOGo/UI/Scheduler/ChangeLog index 17d41229..8de44a1b 100644 --- a/SOGo/UI/Scheduler/ChangeLog +++ b/SOGo/UI/Scheduler/ChangeLog @@ -1,5 +1,7 @@ 2004-08-16 Helge Hess + * UIxAppointmentProposal.m: first working version of proposal (v0.9.62) + * UIxAppointmentProposal: proper vertical/horizontal row generation (v0.9.61) diff --git a/SOGo/UI/Scheduler/UIxAppointmentProposal.m b/SOGo/UI/Scheduler/UIxAppointmentProposal.m index 4ea4faef..85e15b5b 100644 --- a/SOGo/UI/Scheduler/UIxAppointmentProposal.m +++ b/SOGo/UI/Scheduler/UIxAppointmentProposal.m @@ -43,15 +43,21 @@ NSArray *participants; /* array of iCalPerson's */ NSArray *resources; /* array of iCalPerson's */ id duration; + + NSArray *blockedRanges; } @end +#include +#include #include "common.h" @implementation UIxAppointmentProposal - (void)dealloc { + [self->blockedRanges release]; + [self->startDateHour release]; [self->startDateMinute release]; [self->startDateDay release]; @@ -290,13 +296,57 @@ /* slots */ +- (BOOL)isRangeGreen:(NGCalendarDateRange *)_range { + unsigned idx; + + idx = [self->blockedRanges indexOfFirstIntersectingDateRange:_range]; + if (idx != NSNotFound) + return NO; + + return YES; +} + +- (BOOL)isSlotRangeGreen:(NGCalendarDateRange *)_slotRange { + NGCalendarDateRange *aptRange; + NSCalendarDate *aptStartDate, *aptEndDate; + + if (_slotRange == nil) + return NO; + + /* calculate the interval requested by the user (can be larger) */ + + aptStartDate = [_slotRange startDate]; + aptEndDate = [[NSCalendarDate alloc] initWithTimeIntervalSince1970: + [aptStartDate timeIntervalSince1970] + + [self durationAsTimeInterval]]; + [aptStartDate setTimeZone:[self viewTimeZone]]; + [aptEndDate setTimeZone:[self viewTimeZone]]; + aptRange = [NGCalendarDateRange calendarDateRangeWithStartDate:aptStartDate + endDate:aptEndDate]; + [aptEndDate release]; aptEndDate = nil; + + return [self isRangeGreen:aptRange]; +} + - (BOOL)isFirstHalfGreen { - [self logWithFormat:@"is first green: %@ %@", self->currentDay, self->item]; - return NO; + /* currentday is the date, self->item the hour */ + NSCalendarDate *from, *to; + NGCalendarDateRange *range; + + from = [self->currentDay hour:[[self item] intValue] minute:0]; + to = [self->currentDay hour:[[self item] intValue] minute:30]; + range = [NGCalendarDateRange calendarDateRangeWithStartDate:from endDate:to]; + return [self isSlotRangeGreen:range]; } - (BOOL)isSecondHalfGreen { - [self logWithFormat:@"is second green: %@ %@", self->currentDay, self->item]; - return YES; + /* currentday is the date, self->item the hour */ + NSCalendarDate *from, *to; + NGCalendarDateRange *range; + + from = [self->currentDay hour:[[self item] intValue] minute:30]; + to = [self->currentDay hour:[[self item] intValue] minute:59]; + range = [NGCalendarDateRange calendarDateRangeWithStartDate:from endDate:to]; + return [self isSlotRangeGreen:range]; } - (BOOL)isFirstHalfBlocked { @@ -325,10 +375,43 @@ } - (id)proposalSearchAction { + NSArray *attendees, *uids; + SOGoAppointmentFolder *groupCalendar; + NSArray *coreInfos; + NSArray *ranges; + [self logWithFormat:@"search from %@ to %@", [self startDate], [self endDate]]; - [self logWithFormat:@" participants: %@", [self participants]]; - [self logWithFormat:@" resources: %@", [self resources]]; + + attendees = [self attendees]; + uids = [[self clientObject] uidsFromICalPersons:attendees]; + if ([uids count] == 0) { + [self logWithFormat:@"Note: no UIDs selected."]; + return self; + } + + groupCalendar = [[self clientObject] lookupGroupCalendarFolderForUIDs:uids + inContext:[self context]]; + [self debugWithFormat:@"group calendar: %@", groupCalendar]; + + if (![groupCalendar respondsToSelector:@selector(fetchCoreInfosFrom:to:)]) { + return [NSException exceptionWithHTTPStatus:500 /* Internal Error */ + reason:@"invalid folder to run proposal query on!"]; + } + + // TODO: just query startdate and enddate ... (freebusy) + coreInfos = [groupCalendar fetchCoreInfosFrom:[self startDate] + to:[self endDate]]; + [self debugWithFormat:@" process: %d events", [coreInfos count]]; + + ranges = [coreInfos arrayByCreatingDateRangesFromObjectsWithStartDateKey: + @"startDate" + andEndDateKey:@"endDate"]; + ranges = [ranges arrayByCompactingContainedDateRanges]; + [self debugWithFormat:@" ranges: %@", ranges]; + + ASSIGNCOPY(self->blockedRanges, ranges); + return self; } diff --git a/SOGo/UI/Scheduler/Version b/SOGo/UI/Scheduler/Version index 491c7813..4b7ecabd 100644 --- a/SOGo/UI/Scheduler/Version +++ b/SOGo/UI/Scheduler/Version @@ -1,7 +1,8 @@ # $Id$ -SUBMINOR_VERSION:=60 +SUBMINOR_VERSION:=61 +# v0.9.61 requires libNGExtensions v4.2.102 # v0.9.41 requires libNGObjWeb v4.2.431 # v0.9.31 requires libWEExtensions v4.2.52 # v0.9.29 requires libWEExtensions v4.2.51 -- 2.39.2