// $Id$ #include "UIxCalView.h" #include "common.h" #include "UIxAppointmentFormatter.h" #include #include "SoObjects/Appointments/SOGoAppointmentFolder.h" @implementation UIxCalView - (void)dealloc { [self->appointments release]; [self->allDayApts release]; [self->appointment release]; [self->currentDay release]; [super dealloc]; } /* accessors */ - (void)setAppointments:(NSArray *)_apts { ASSIGN(self->appointments, _apts); } - (NSArray *)appointments { return self->appointments; } - (void)setAppointment:(id)_apt { ASSIGN(self->appointment, _apt); } - (id)appointment { return self->appointment; } - (NSDictionary *)aptTypeDict { return nil; } - (NSString *)aptTypeLabel { return @"aptLabel"; } - (NSString *)aptTypeIcon { return @""; } - (NSString *)shortTextForApt { NSCalendarDate *startDate; NSString *ms; startDate = [[self appointment] valueForKey:@"startDate"]; [startDate setTimeZone:[self viewTimeZone]]; ms = [NSString stringWithFormat:@"%02i:%02i %@", [startDate hourOfDay], [startDate minuteOfHour], [[self appointment] valueForKey:@"title"]]; return ms; } - (NSString *)shortTitleForApt { NSString *title; title = [self->appointment valueForKey:@"title"]; if ([title length] > 12) title = [[title substringToIndex:11] stringByAppendingString:@"..."]; return title; } - (NSString *)tooltipForApt { NSCalendarDate *startDate, *endDate; NSMutableString *aptDescr; NSString *s; BOOL spansRange; id apt; apt = [self appointment]; spansRange = NO; startDate = [apt valueForKey:@"startDate"]; [startDate setTimeZone:[self viewTimeZone]]; endDate = [apt valueForKey:@"endDate"]; if(endDate != nil) { [endDate setTimeZone:[self viewTimeZone]]; spansRange = ![endDate isEqualToDate:startDate]; } aptDescr = [[NSMutableString alloc] init]; [aptDescr appendString:[self labelForKey:@"appointment"]]; [aptDescr appendFormat:@"\n%02i:%02i", [startDate hourOfDay], [startDate minuteOfHour]]; if(spansRange) { [aptDescr appendFormat:@" - %02i:%02i", [endDate hourOfDay], [endDate minuteOfHour]]; } s = [apt valueForKey:@"title"]; if(s) { [aptDescr appendFormat:@"\n%@", s]; } s = [apt valueForKey:@"location"]; if(s) { [aptDescr appendFormat:@"\n%@", s]; } return [aptDescr autorelease]; } - (NSCalendarDate *)referenceDateForFormatter { return [self selectedDate]; } - (NSCalendarDate *)thisMonth { return [self selectedDate]; } - (NSCalendarDate *)nextMonth { NSCalendarDate *date = [self thisMonth]; return [date dateByAddingYears:0 months:0 days:[date numberOfDaysInMonth] hours:0 minutes:0 seconds:0]; } /* current day related */ - (void)setCurrentDay:(NSCalendarDate *)_day { [_day setTimeZone:[self viewTimeZone]]; ASSIGN(self->currentDay, _day); } - (NSCalendarDate *)currentDay { return self->currentDay; } - (NSString *)currentDayName { return [self localizedNameForDayOfWeek:[self->currentDay dayOfWeek]]; } - (id)holidayInfo { return nil; } - (NSArray *)allDayApts { NSArray *apts; NSMutableArray *filtered; unsigned i, count; if(self->allDayApts) return self->allDayApts; apts = [self appointments]; count = [apts count]; filtered = [[NSMutableArray alloc] initWithCapacity:3]; for(i = 0; i < count; i++) { id apt; NSNumber *bv; apt = [apts objectAtIndex:i]; #warning !! check if isAllDay is correct bv = [apt valueForKey:@"isAllDay"]; if([bv boolValue]) { [filtered addObject:apt]; } } ASSIGN(self->allDayApts, filtered); [filtered release]; return self->allDayApts; } /* special appointments */ - (BOOL)hasDayInfo { return [self hasHoldidayInfo] || [self hasAllDayApts]; } - (BOOL)hasHoldidayInfo { return [self holidayInfo] != nil; } - (BOOL)hasAllDayApts { return [[self allDayApts] count] != 0; } /* defaults */ - (BOOL)showFullNames { return YES; } - (BOOL)showAMPMDates { return NO; } - (unsigned)dayStartHour { return 8; } - (unsigned)dayEndHour { return 18; } - (BOOL)shouldDisplayWeekend { return NO; } /* URLs */ - (NSString *)appointmentViewURL { id pkey; if ((pkey = [[self appointment] valueForKey:@"uid"]) == nil) return nil; return [NSString stringWithFormat:@"%@/view", pkey]; } /* backend */ /* resource URLs (TODO?) */ - (NSString *)resourcePath { return @"/sogod.woa/WebServerResources/"; } - (NSString *)favIconPath { return [[self resourcePath] stringByAppendingPathComponent:@"favicon.ico"]; } - (NSString *)cssPath { NSString *path; // TODO: there should be reusable functionality for that! #warning ZideStore specific? path = @"ControlPanel/Products/ZideStoreUI/Resources/uix.css"; return [[self context] urlWithRequestHandlerKey:@"so" path:path queryString:nil]; } - (NSString *)calCSSPath { NSString *path; // TODO: there should be reusable functionality for that! #warning ZideStore specific? path = @"ControlPanel/Products/ZideStoreUI/Resources/calendar.css"; return [[self context] urlWithRequestHandlerKey:@"so" path:path queryString:nil]; } /* fetching */ - (NSCalendarDate *)startDate { return [self selectedDate]; } - (NSCalendarDate *)endDate { return [[self startDate] tomorrow]; } - (NSArray *)_fetchCoreInfosForUIDs:(NSArray *)_uids uniqueWithSet:(NSMutableSet *)_uniquer { NSMutableArray *ma; unsigned i, count; count = [_uids count]; ma = [NSMutableArray arrayWithCapacity:count * 10]; for (i = 0; i < count; i++) { OCSFolder *folder; NSString *path; NSString *uid; NSArray *res; uid = [_uids objectAtIndex:i]; if ([uid length] == 0) continue; path = [[@"/Users/" stringByAppendingString:uid] stringByAppendingString:@"/Calendar"]; if ((folder = [[self clientObject] ocsFolderForPath:path]) == nil) { [self logWithFormat:@"ERROR: did not find user: %@", uid]; continue; } res = [[self clientObject] fetchCoreInfosFromFolder:folder from:[self startDate] to:[self endDate]]; if (res == nil) { [self logWithFormat:@"ERROR: fetch failed for user: %@", uid]; continue; } /* perform uniquing */ { int j, rcount; for (j = 0, rcount = [res count]; j < rcount; j++) { NSDictionary *record; record = [res objectAtIndex:j]; if ([_uniquer containsObject:[record valueForKey:@"uid"]]) continue; [ma addObject:record]; [_uniquer addObject:[record valueForKey:@"uid"]]; } } } return ma; } - (NSArray *)fetchCoreInfos { id aptFolder; NSArray *more; id uids; if (self->appointments) return self->appointments; aptFolder = [self clientObject]; self->appointments = [[aptFolder fetchCoreInfosFrom:[self startDate] to:[self endDate]] retain]; uids = [[[[self context] request] formValueForKey:@"uids"] stringValue]; uids = [uids length] > 0 ? [uids componentsSeparatedByString:@","] : nil; if ([uids count] > 0) { NSMutableSet *availUIDs; id tmp; /* make appointments unique, prefer the own "versions" */ tmp = [self->appointments valueForKey:@"uid"]; availUIDs = [[NSMutableSet alloc] initWithArray:tmp]; more = [self _fetchCoreInfosForUIDs:uids uniqueWithSet:availUIDs]; if (more > 0) { NSArray *tmp; tmp = self->appointments; self->appointments = [[tmp arrayByAddingObjectsFromArray:more] retain]; [tmp release]; } [availUIDs release]; } return self->appointments; } /* date selection & conversion */ - (NSDictionary *)todayQueryParameters { NSCalendarDate *date; date = [NSCalendarDate date]; /* today */ return [self queryParametersBySettingSelectedDate:date]; } - (NSDictionary *)currentDayQueryParameters { return [self queryParametersBySettingSelectedDate:self->currentDay]; } - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date { NSMutableDictionary *qp; qp = [[self queryParameters] mutableCopy]; [self setSelectedDateQueryParameter:_date inDictionary:qp]; return [qp autorelease]; } - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate inDictionary:(NSMutableDictionary *)_qp; { if(_newDate != nil) [_qp setObject:[self dateStringForDate:_newDate] forKey:@"day"]; else [_qp removeObjectForKey:@"day"]; } @end /* UIxCalView */