// $Id$
#include "SOGoAppointmentFolder.h"
+#include <OGoContentStore/OCSFolder.h>
#include "common.h"
#include <unistd.h>
#include <stdlib.h>
/* fetching */
+- (NSMutableDictionary *)fixupRecord:(NSDictionary *)_record {
+ NSMutableDictionary *md;
+ id tmp;
+
+ md = [[_record mutableCopy] autorelease];
+
+ if ((tmp = [_record objectForKey:@"startdate"])) {
+ tmp = [[NSCalendarDate alloc] initWithTimeIntervalSince1970:
+ (NSTimeInterval)[tmp unsignedIntValue]];
+ if (tmp) [md setObject:tmp forKey:@"startDate"];
+ [tmp release];
+ }
+ else
+ [self logWithFormat:@"missing 'startdate' in record?"];
+
+ if ((tmp = [_record objectForKey:@"enddate"])) {
+ tmp = [[NSCalendarDate alloc] initWithTimeIntervalSince1970:
+ (NSTimeInterval)[tmp unsignedIntValue]];
+ if (tmp) [md setObject:tmp forKey:@"endDate"];
+ [tmp release];
+ }
+ else
+ [self logWithFormat:@"missing 'enddate' in record?"];
+
+ return md;
+}
+
+- (NSArray *)fixupRecords:(NSArray *)_records {
+ NSMutableArray *ma;
+ unsigned i, count;
+
+ if (_records == nil) return nil;
+ if ((count = [_records count]) == 0)
+ return _records;
+
+ ma = [NSMutableArray arrayWithCapacity:count];
+ for (i = 0; i < count; i++) {
+ id row;
+
+ row = [self fixupRecord:[_records objectAtIndex:i]];
+ if (row) [ma addObject:row];
+ }
+ return ma;
+}
+
- (NSArray *)fetchCoreInfosFrom:(NSCalendarDate *)_startDate
to:(NSCalendarDate *)_endDate
{
- id appointments;
+ OCSFolder *folder;
+ EOQualifier *qualifier;
+ NSArray *fields, *records;
+ NSString *sql;
+
+ if ((folder = [self ocsFolder]) == nil) {
+ [self logWithFormat:@"ERROR(%s): missing folder for fetch!",
+ __PRETTY_FUNCTION__];
+ return nil;
+ }
[self logWithFormat:@"should fetch (%@ => %@) ...", _startDate, _endDate];
-#warning TODO: IMPLEMENT!
+ sql = [NSString stringWithFormat:@"(startdate < %d) AND (enddate > %d)",
+ (unsigned int)[_endDate timeIntervalSince1970],
+ (unsigned int)[_startDate timeIntervalSince1970]];
+ qualifier = [EOQualifier qualifierWithQualifierFormat:sql];
+
+ fields = [NSArray arrayWithObjects:
+ @"uid", @"startdate", @"enddate",
+ @"title", @"participants", nil];
+
+ records = [folder fetchFields:fields matchingQualifier:qualifier];
+ if (records == nil) {
+ [self logWithFormat:@"ERROR(%s): fetch failed!", __PRETTY_FUNCTION__];
+ return nil;
+ }
- [self logWithFormat:@"fetched %i records.", [appointments count]];
- return appointments;
+ records = [self fixupRecords:records];
+ [self logWithFormat:@"fetched %i records: %@", [records count], records];
+ return records;
}
@end /* SOGoAppointmentFolder */
}
- (NSString *)shortTextForApt {
- UIxAppointmentFormatter *f;
-
- f = [UIxAppointmentFormatter formatterWithFormat:
+#if 1
+ NSCalendarDate *startDate;
+ NSString *ms;
+
+ startDate = [[self appointment] valueForKey:@"startDate"];
+ ms = [NSString stringWithFormat:@"%02i:%02i %@",
+ [startDate hourOfDay],
+ [startDate minuteOfHour],
+ [[self appointment] valueForKey:@"title"]];
+ return ms;
+#else
+ UIxAppointmentFormatter *f;
+
+ f = [UIxAppointmentFormatter formatterWithFormat:
@"%S - %E;\n%T;\n%L;\n%5P;\n%50R"];
- [f setRelationDate:[self referenceDateForFormatter]];
- [f setShowFullNames:[self showFullNames]];
- if([self showAMPMDates])
+ [f setRelationDate:[self referenceDateForFormatter]];
+ [f setShowFullNames:[self showFullNames]];
+ if([self showAMPMDates])
[f switchToAMPMTimes:YES];
- return [NSString stringWithFormat:@"%@:\n%@",
+ return [NSString stringWithFormat:@"%@:\n%@",
[self aptTypeLabel],
[f stringForObjectValue:self->appointment]];
+#endif
}
- (NSString *)shortTitleForApt {
}
- (NSArray *)fetchCoreInfos {
- return [[self clientObject] fetchCoreInfosFrom:[self startDate]
- to:[self endDate]];
+ if (self->appointments)
+ return self->appointments;
+
+ self->appointments =
+ [[[self clientObject] fetchCoreInfosFrom:[self startDate]
+ to:[self endDate]] retain];
+ return self->appointments;
}
/* date selection & conversion */