NSArray *participants; /* array of iCalPerson's */
NSArray *resources; /* array of iCalPerson's */
id duration;
+
+ NSArray *blockedRanges;
}
@end
+#include <SoObjects/Appointments/SOGoAppointmentFolder.h>
+#include <NGExtensions/NGCalendarDateRange.h>
#include "common.h"
@implementation UIxAppointmentProposal
- (void)dealloc {
+ [self->blockedRanges release];
+
[self->startDateHour release];
[self->startDateMinute release];
[self->startDateDay release];
/* 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 {
}
- (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;
}