1 /* UIxCalDayTable.m - this file is part of SOGo
3 * Copyright (C) 2006 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSCalendarDate.h>
25 #import <Foundation/NSDictionary.h>
26 #import <Foundation/NSKeyValueCoding.h>
27 #import <Foundation/NSString.h>
29 #import <EOControl/EOQualifier.h>
31 #import <NGExtensions/NSCalendarDate+misc.h>
32 #import <SOGoUI/SOGoDateFormatter.h>
34 #import "UIxCalDayTable.h"
36 @class SOGoAppointment;
38 @implementation UIxCalDayTable
42 if ((self = [super init]))
44 // allAppointments = nil;
49 currentTableDay = nil;
50 currentTableHour = nil;
51 dateFormatter = [[SOGoDateFormatter alloc]
52 initWithLocale: [self locale]];
60 // if (allAppointments)
61 // [allAppointments release];
62 [daysToDisplay release];
63 [hoursToDisplay release];
64 [dateFormatter release];
68 - (void) setCSSClass: (NSString *) aCssClass
73 - (NSString *) cssClass
78 - (void) setCSSId: (NSString *) aCssId
88 - (void) setNumberOfDays: (NSString *) aNumber
90 numberOfDays = [aNumber intValue];
91 [daysToDisplay release];
95 - (NSString *) numberOfDays
97 return [NSString stringWithFormat: @"%d", numberOfDays];
100 - (void) setStartDate: (NSCalendarDate *) aStartDate
102 startDate = aStartDate;
103 [daysToDisplay release];
107 - (NSCalendarDate *) startDate
110 startDate = [super startDate];
112 return [startDate beginOfDay];
115 - (NSCalendarDate *) endDate
117 NSCalendarDate *endDate;
119 endDate = [[self startDate] dateByAddingYears: 0
121 days: numberOfDays - 1];
123 return [endDate endOfDay];
126 - (NSArray *) hoursToDisplay
128 unsigned int currentHour, lastHour;
132 currentHour = [self dayStartHour];
133 lastHour = [self dayEndHour];
134 hoursToDisplay = [NSMutableArray new];
136 while (currentHour < lastHour)
139 addObject: [NSString stringWithFormat: @"%d", currentHour]];
143 addObject: [NSString stringWithFormat: @"%d", currentHour]];
146 return hoursToDisplay;
149 - (NSArray *) daysToDisplay
151 NSCalendarDate *currentDate;
156 daysToDisplay = [NSMutableArray new];
157 currentDate = [[self startDate] hour: [self dayStartHour]
159 [daysToDisplay addObject: currentDate];
160 for (count = 1; count < numberOfDays; count++)
161 [daysToDisplay addObject: [currentDate dateByAddingYears: 0
167 return daysToDisplay;
170 - (void) setCurrentTableDay: (NSCalendarDate *) aTableDay
172 currentTableDay = aTableDay;
175 - (NSCalendarDate *) currentTableDay
177 return currentTableDay;
180 - (void) setCurrentTableHour: (NSString *) aTableHour
182 currentTableHour = aTableHour;
185 - (NSString *) currentTableHour
187 return currentTableHour;
190 - (NSString *) currentAppointmentHour
192 return [NSString stringWithFormat: @"%.2d00", [currentTableHour intValue]];
195 - (NSString *) labelForDay
197 return [dateFormatter shortDayOfWeek: [currentTableDay dayOfWeek]];
200 - (NSString *) labelForDate
202 return [dateFormatter stringForObjectValue: currentTableDay];
205 // - (NSDictionary *) _adjustedAppointment: (NSDictionary *) anAppointment
206 // forStart: (NSCalendarDate *) start
207 // andEnd: (NSCalendarDate *) end
209 // NSMutableDictionary *newMutableAppointment;
210 // NSDictionary *newAppointment;
211 // BOOL startIsEarlier, endIsLater;
214 // = ([[anAppointment objectForKey: @"startDate"] laterDate: start] == start);
216 // = ([[anAppointment objectForKey: @"endDate"] earlierDate: end] == end);
218 // if (startIsEarlier || endIsLater)
220 // newMutableAppointment
221 // = [NSMutableDictionary dictionaryWithDictionary: anAppointment];
223 // if (startIsEarlier)
224 // [newMutableAppointment setObject: start
225 // forKey: @"startDate"];
227 // [newMutableAppointment setObject: end
228 // forKey: @"endDate"];
230 // newAppointment = newMutableAppointment;
233 // newAppointment = anAppointment;
235 // return newAppointment;
238 // - (NSArray *) appointmentsForCurrentDay
240 // NSMutableArray *filteredAppointments;
241 // NSEnumerator *aptsEnumerator;
242 // NSDictionary *currentDayAppointment;
243 // NSCalendarDate *start, *end;
246 // if (!allAppointments)
248 // allAppointments = [self fetchCoreAppointmentsInfos];
249 // [allAppointments retain];
252 // filteredAppointments = [NSMutableArray new];
253 // [filteredAppointments autorelease];
255 // start = [currentTableDay hour: [self dayStartHour] minute: 0];
256 // endHour = [self dayEndHour];
258 // end = [currentTableDay hour: [self dayEndHour] minute: 59];
260 // end = [[currentTableDay tomorrow] hour: 0 minute: 0];
262 // aptsEnumerator = [allAppointments objectEnumerator];
263 // currentDayAppointment = [aptsEnumerator nextObject];
264 // while (currentDayAppointment)
266 // if (([end laterDate: [currentDayAppointment
267 // valueForKey: @"startDate"]] == end)
268 // && ([start earlierDate: [currentDayAppointment
269 // valueForKey: @"endDate"]] == start))
270 // [filteredAppointments
271 // addObject: [self _adjustedAppointment: currentDayAppointment
272 // forStart: start andEnd: end]];
273 // currentDayAppointment = [aptsEnumerator nextObject];
276 // return filteredAppointments;
279 // - (void) setCurrentAppointment: (NSDictionary *) newCurrentAppointment
281 // currentAppointment = newCurrentAppointment;
284 // - (NSDictionary *) currentAppointment
286 // return currentAppointment;
289 - (NSString *) appointmentsClasses
291 return [NSString stringWithFormat: @"appointments appointmentsFor%dDays",
295 - (NSString *) daysViewClasses
297 return [NSString stringWithFormat: @"daysView daysViewFor%dDays", numberOfDays];
300 - (NSString *) dayClasses
302 NSMutableString *classes;
305 classes = [NSMutableString new];
306 [classes autorelease];
307 [classes appendFormat: @"day day%d", [currentTableDay dayOfWeek]];
308 if (numberOfDays > 1)
310 dayOfWeek = [currentTableDay dayOfWeek];
311 if (dayOfWeek == 0 || dayOfWeek == 6)
312 [classes appendString: @" weekEndDay"];
313 if ([currentTableDay isToday])
314 [classes appendString: @" dayOfToday"];
315 if ([[self selectedDate] isDateOnSameDay: currentTableDay])
316 [classes appendString: @" selectedDay"];
322 - (NSString *) clickableHourCellClass
324 return [NSString stringWithFormat: @"clickableHourCell clickableHourCell%@", currentTableHour];