#import <Foundation/NSDictionary.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSString.h>
+#import <Foundation/NSUserDefaults.h>
+#import <NGExtensions/NSCalendarDate+misc.h>
#import <EOControl/EOQualifier.h>
-#import <NGExtensions/NSCalendarDate+misc.h>
-#import <SOGoUI/SOGoDateFormatter.h>
+#import <SoObjects/SOGo/SOGoDateFormatter.h>
+#import <SoObjects/SOGo/SOGoUser.h>
#import "UIxCalDayTable.h"
{
if ((self = [super init]))
{
- allAppointments = nil;
daysToDisplay = nil;
hoursToDisplay = nil;
numberOfDays = 1;
startDate = nil;
currentTableDay = nil;
currentTableHour = nil;
- dateFormatter = [[SOGoDateFormatter alloc]
- initWithLocale: [self locale]];
+ weekDays = [[context valueForKey: @"locale"] objectForKey: NSShortWeekDayNameArray];
+ [weekDays retain];
+ dateFormatter = [[context activeUser] dateFormatterInContext: context];
}
return self;
- (void) dealloc
{
- if (allAppointments)
- [allAppointments release];
- if (daysToDisplay)
- [daysToDisplay release];
- if (hoursToDisplay)
- [hoursToDisplay release];
- [dateFormatter release];
+// if (allAppointments)
+// [allAppointments release];
+ [weekDays release];
+ [daysToDisplay release];
+ [hoursToDisplay release];
[super dealloc];
}
-- (void) setCSSClass: (NSString *) aCssClass
-{
- cssClass = aCssClass;
-}
-
-- (NSString *) cssClass
-{
- return cssClass;
-}
-
-- (void) setCSSId: (NSString *) aCssId
-{
- cssId = aCssId;
-}
-
-- (NSString *) cssId
-{
- return cssId;
-}
-
- (void) setNumberOfDays: (NSString *) aNumber
{
numberOfDays = [aNumber intValue];
- if (daysToDisplay)
- {
- [daysToDisplay release];
- daysToDisplay = nil;
- }
+ [daysToDisplay release];
+ daysToDisplay = nil;
}
- (NSString *) numberOfDays
- (void) setStartDate: (NSCalendarDate *) aStartDate
{
startDate = aStartDate;
- if (daysToDisplay)
- {
- [daysToDisplay release];
- daysToDisplay = nil;
- }
+ [daysToDisplay release];
+ daysToDisplay = nil;
}
- (NSCalendarDate *) startDate
addObject: [NSString stringWithFormat: @"%d", currentHour]];
currentHour++;
}
+ [hoursToDisplay
+ addObject: [NSString stringWithFormat: @"%d", currentHour]];
}
return hoursToDisplay;
[daysToDisplay addObject: [currentDate dateByAddingYears: 0
months: 0
days: count]];
+
}
return daysToDisplay;
- (NSString *) labelForDay
{
- return [NSString stringWithFormat: @"%@ %@",
- [dateFormatter shortDayOfWeek: [currentTableDay dayOfWeek]],
- [dateFormatter stringForObjectValue: currentTableDay]];
-}
-
-- (NSDictionary *) _adjustedAppointment: (NSDictionary *) anAppointment
- forStart: (NSCalendarDate *) start
- andEnd: (NSCalendarDate *) end
-{
- NSMutableDictionary *newMutableAppointment;
- NSDictionary *newAppointment;
- BOOL startIsEarlier, endIsLater;
-
- startIsEarlier
- = ([[anAppointment objectForKey: @"startDate"] laterDate: start] == start);
- endIsLater
- = ([[anAppointment objectForKey: @"endDate"] earlierDate: end] == end);
-
- if (startIsEarlier || endIsLater)
- {
- newMutableAppointment
- = [NSMutableDictionary dictionaryWithDictionary: anAppointment];
-
- if (startIsEarlier)
- [newMutableAppointment setObject: start
- forKey: @"startDate"];
- if (endIsLater)
- [newMutableAppointment setObject: end
- forKey: @"endDate"];
-
- newAppointment = newMutableAppointment;
- }
- else
- newAppointment = anAppointment;
-
- return newAppointment;
+ return [weekDays objectAtIndex: [currentTableDay dayOfWeek]];
}
-- (NSArray *) appointmentsForCurrentDay
+- (NSString *) labelForDate
{
- NSMutableArray *filteredAppointments;
- NSEnumerator *aptsEnumerator;
- NSDictionary *currentDayAppointment;
- NSCalendarDate *start, *end;
-
- if (!allAppointments)
- {
- allAppointments = [self fetchCoreAppointmentsInfos];
- [allAppointments retain];
- }
-
- filteredAppointments = [NSMutableArray new];
- [filteredAppointments autorelease];
-
- start = [currentTableDay hour: [self dayStartHour] minute: 0];
- end = [currentTableDay hour: [self dayEndHour] minute: 0];
-
- aptsEnumerator = [allAppointments objectEnumerator];
- currentDayAppointment = [aptsEnumerator nextObject];
- while (currentDayAppointment)
- {
- if (([end laterDate: [currentDayAppointment
- valueForKey: @"startDate"]] == end)
- && ([start earlierDate: [currentDayAppointment
- valueForKey: @"endDate"]] == start))
- [filteredAppointments
- addObject: [self _adjustedAppointment: currentDayAppointment
- forStart: start andEnd: end]];
- currentDayAppointment = [aptsEnumerator nextObject];
- }
-
- return filteredAppointments;
+ return [dateFormatter shortFormattedDate: currentTableDay];
}
-- (void) setCurrentAppointment: (NSDictionary *) newCurrentAppointment
-{
- currentAppointment = newCurrentAppointment;
-}
-
-- (NSDictionary *) currentAppointment
-{
- return currentAppointment;
-}
-
-- (NSArray *) appointmentsClasses
+// - (NSDictionary *) _adjustedAppointment: (NSDictionary *) anAppointment
+// forStart: (NSCalendarDate *) start
+// andEnd: (NSCalendarDate *) end
+// {
+// NSMutableDictionary *newMutableAppointment;
+// NSDictionary *newAppointment;
+// BOOL startIsEarlier, endIsLater;
+
+// startIsEarlier
+// = ([[anAppointment objectForKey: @"startDate"] laterDate: start] == start);
+// endIsLater
+// = ([[anAppointment objectForKey: @"endDate"] earlierDate: end] == end);
+
+// if (startIsEarlier || endIsLater)
+// {
+// newMutableAppointment
+// = [NSMutableDictionary dictionaryWithDictionary: anAppointment];
+
+// if (startIsEarlier)
+// [newMutableAppointment setObject: start
+// forKey: @"startDate"];
+// if (endIsLater)
+// [newMutableAppointment setObject: end
+// forKey: @"endDate"];
+
+// newAppointment = newMutableAppointment;
+// }
+// else
+// newAppointment = anAppointment;
+
+// return newAppointment;
+// }
+
+// - (NSArray *) appointmentsForCurrentDay
+// {
+// NSMutableArray *filteredAppointments;
+// NSEnumerator *aptsEnumerator;
+// NSDictionary *currentDayAppointment;
+// NSCalendarDate *start, *end;
+// int endHour;
+
+// if (!allAppointments)
+// {
+// allAppointments = [self fetchCoreAppointmentsInfos];
+// [allAppointments retain];
+// }
+
+// filteredAppointments = [NSMutableArray new];
+// [filteredAppointments autorelease];
+
+// start = [currentTableDay hour: [self dayStartHour] minute: 0];
+// endHour = [self dayEndHour];
+// if (endHour < 24)
+// end = [currentTableDay hour: [self dayEndHour] minute: 59];
+// else
+// end = [[currentTableDay tomorrow] hour: 0 minute: 0];
+
+// aptsEnumerator = [allAppointments objectEnumerator];
+// currentDayAppointment = [aptsEnumerator nextObject];
+// while (currentDayAppointment)
+// {
+// if (([end laterDate: [currentDayAppointment
+// valueForKey: @"startDate"]] == end)
+// && ([start earlierDate: [currentDayAppointment
+// valueForKey: @"endDate"]] == start))
+// [filteredAppointments
+// addObject: [self _adjustedAppointment: currentDayAppointment
+// forStart: start andEnd: end]];
+// currentDayAppointment = [aptsEnumerator nextObject];
+// }
+
+// return filteredAppointments;
+// }
+
+// - (void) setCurrentAppointment: (NSDictionary *) newCurrentAppointment
+// {
+// currentAppointment = newCurrentAppointment;
+// }
+
+// - (NSDictionary *) currentAppointment
+// {
+// return currentAppointment;
+// }
+
+- (NSString *) appointmentsClasses
{
return [NSString stringWithFormat: @"appointments appointmentsFor%dDays",
numberOfDays];