return md;
}
+- (void)_flattenCycleRecord:(NSDictionary *)row
+ forRange:(NGCalendarDateRange *)_r
+ intoArray:(NSMutableArray *)ma
+{
+ NSString *uid;
+ id aptObject;
+ iCalEvent *apt;
+ NSArray *ranges;
+ unsigned k, rCount;
+
+ uid = [row valueForKey:@"uid"];
+
+#warning FIXME: lookup done by name, not by UID
+ // TODO: this is wrong, we need to lookup the appointment by UID, not name
+ aptObject = [self appointmentWithName:uid inContext:nil];
+
+ apt = [aptObject event];
+ ranges = [apt recurrenceRangesWithinCalendarDateRange:_r];
+ rCount = [ranges count];
+ for (k = 0; k < rCount; k++) {
+ NGCalendarDateRange *rRange;
+ id fixedRow;
+
+ rRange = [ranges objectAtIndex:k];
+ fixedRow = [self fixupRecord:row fetchRange:rRange];
+ if (fixedRow != nil) [ma addObject:fixedRow];
+ }
+}
+
- (NSArray *)fixupRecords:(NSArray *)_records
fetchRange:(NGCalendarDateRange *)_r
{
+ // TODO: is the result supposed to be sorted by date?
+ // TODO: move cycle handling out of fixup
NSMutableArray *ma;
unsigned i, count;
if ((count = [_records count]) == 0)
return _records;
+ // TODO: inefficient, does a lot of fetches for cycles, separate cycle
+ // handling from fixup!
ma = [NSMutableArray arrayWithCapacity:count];
for (i = 0; i < count; i++) {
- id row;
-
+ id row; // TODO: what is the type of the record?
+
row = [_records objectAtIndex:i];
if ([[row valueForKey:@"iscycle"] intValue] != 0) {
- NSString *uid;
- id aptObject;
- iCalEvent *apt;
- NSArray *ranges;
- unsigned k, rCount;
-
- uid = [row valueForKey:@"uid"];
- aptObject = [self appointmentWithName:uid inContext:nil];
- apt = [aptObject event];
- ranges = [apt recurrenceRangesWithinCalendarDateRange:_r];
- rCount = [ranges count];
- for (k = 0; k < rCount; k++) {
- NGCalendarDateRange *rRange;
- id fixedRow;
-
- rRange = [ranges objectAtIndex:k];
- fixedRow = [self fixupRecord:row fetchRange:rRange];
- if (fixedRow) [ma addObject:fixedRow];
- }
+ [self _flattenCycleRecord:row forRange:_r intoArray:ma];
}
else {
row = [self fixupRecord:row fetchRange:_r];
- if (row) [ma addObject:row];
+ if (row != nil) [ma addObject:row];
}
}
return ma;
__PRETTY_FUNCTION__];
return nil;
}
- return [self fetchFields:_fields
- fromFolder:folder
- from:_startDate
- to:_endDate];
+ return [self fetchFields:_fields fromFolder:folder
+ from:_startDate to:_endDate];
}
- (NSArray *)fetchFreebusyInfosFrom:(NSCalendarDate *)_startDate
to:(NSCalendarDate *)_endDate
{
- static NSArray *infos = nil;
- if(!infos) {
- infos = [[NSArray arrayWithObjects:@"uid", @"startdate", @"enddate",
- nil] retain];
+ static NSArray *infos = nil; // TODO: move to a plist file
+ if (infos == nil) {
+ infos = [[NSArray alloc] initWithObjects:@"uid", @"startdate", @"enddate",
+ nil];
}
- return [self fetchFields:infos
- from:_startDate
- to:_endDate];
+ return [self fetchFields:infos from:_startDate to:_endDate];
}
- (NSArray *)fetchOverviewInfosFrom:(NSCalendarDate *)_startDate
to:(NSCalendarDate *)_endDate
{
- static NSArray *infos = nil;
- if(!infos) {
- infos = [[NSArray arrayWithObjects:@"uid", @"startdate", @"enddate",
- @"title", @"location", @"orgmail",
- @"status", @"ispublic", @"iscycle",
- @"isallday",
- nil] retain];
+ static NSArray *infos = nil; // TODO: move to a plist file
+ if (infos == nil) {
+ infos = [[NSArray alloc] initWithObjects:
+ @"uid", @"startdate", @"enddate", @"title",
+ @"location", @"orgmail", @"status", @"ispublic",
+ @"iscycle", @"isallday", nil];
}
return [self fetchFields:infos
from:_startDate
- (NSArray *)fetchCoreInfosFrom:(NSCalendarDate *)_startDate
to:(NSCalendarDate *)_endDate
{
- static NSArray *infos = nil;
- if(!infos) {
- infos = [[NSArray arrayWithObjects:@"uid", @"startdate", @"enddate",
- @"title", @"location", @"orgmail",
- @"status", @"ispublic", @"iscycle",
- @"isallday", @"isopaque",
- @"participants", @"partmails",
- @"partstates", @"sequence",
- nil] retain];
+ static NSArray *infos = nil; // TODO: move to a plist file
+ if (infos == nil) {
+ infos = [[NSArray alloc] initWithObjects:@"uid", @"startdate", @"enddate",
+ @"title", @"location", @"orgmail",
+ @"status", @"ispublic", @"iscycle",
+ @"isallday", @"isopaque",
+ @"participants", @"partmails",
+ @"partstates", @"sequence",
+ nil];
}
return [self fetchFields:infos
from:_startDate