1 /* UIxCalMulticolumnDayView.h - 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/NSDictionary.h>
25 #import <Foundation/NSString.h>
26 #import <Foundation/NSUserDefaults.h>
27 #import <Foundation/NSValue.h>
29 #import <NGExtensions/NSCalendarDate+misc.h>
31 #import <SoObjects/SOGo/SOGoUser.h>
32 #import <SoObjects/SOGo/SOGoDateFormatter.h>
34 #import "UIxCalMulticolumnDayView.h"
36 @implementation UIxCalMulticolumnDayView : UIxCalDayView
40 if ((self = [super init]))
42 // allAppointments = nil;
43 subscriptionUsers = nil;
45 currentTableUser = nil;
46 currentTableHour = nil;
47 // dateFormatter = [[SOGoDateFormatter alloc]
48 // initWithLocale: [self locale]];
56 // [allAppointments release];
57 [subscriptionUsers release];
58 [hoursToDisplay release];
59 // [dateFormatter release];
63 - (void) setCSSClass: (NSString *) aCssClass
68 - (NSString *) cssClass
73 - (void) setCSSId: (NSString *) aCssId
83 - (NSArray *) hoursToDisplay
85 unsigned int currentHour, lastHour;
89 currentHour = [self dayStartHour];
90 lastHour = [self dayEndHour];
91 hoursToDisplay = [NSMutableArray new];
93 while (currentHour < lastHour)
96 addObject: [NSString stringWithFormat: @"%d", currentHour]];
100 addObject: [NSString stringWithFormat: @"%d", currentHour]];
103 return hoursToDisplay;
106 - (NSArray *) subscriptionUsers
108 SOGoUser *activeUser;
109 NSString *userList, *currentUserLogin;
112 if (!subscriptionUsers)
114 subscriptionUsers = [NSMutableArray new];
115 activeUser = [context activeUser];
116 userList = [[activeUser userDefaults] objectForKey: @"calendaruids"];
117 users = [[userList componentsSeparatedByString: @","] objectEnumerator];
118 currentUserLogin = [users nextObject];
119 while (currentUserLogin)
121 if (![currentUserLogin hasPrefix: @"-"])
122 [subscriptionUsers addObject: currentUserLogin];
123 currentUserLogin = [users nextObject];
127 return subscriptionUsers;
130 - (void) setCurrentTableUser: (NSString *) aTableUser;
132 currentTableUser = aTableUser;
135 - (NSString *) currentTableUser;
137 return currentTableUser;
140 - (void) setCurrentTableHour: (NSString *) aTableHour
142 currentTableHour = aTableHour;
145 - (NSString *) currentTableHour
147 return currentTableHour;
150 - (NSString *) currentAppointmentHour
152 return [NSString stringWithFormat: @"%.2d00", [currentTableHour intValue]];
155 - (NSDictionary *) _adjustedAppointment: (NSDictionary *) anAppointment
156 forStart: (NSCalendarDate *) start
157 andEnd: (NSCalendarDate *) end
159 NSMutableDictionary *newMutableAppointment;
160 NSDictionary *newAppointment;
161 BOOL startIsEarlier, endIsLater;
164 = ([[anAppointment objectForKey: @"startDate"] laterDate: start] == start);
166 = ([[anAppointment objectForKey: @"endDate"] earlierDate: end] == end);
168 if (startIsEarlier || endIsLater)
170 newMutableAppointment
171 = [NSMutableDictionary dictionaryWithDictionary: anAppointment];
174 [newMutableAppointment setObject: start
175 forKey: @"startDate"];
177 [newMutableAppointment setObject: end
180 newAppointment = newMutableAppointment;
183 newAppointment = anAppointment;
185 return newAppointment;
190 // - (NSCalendarDate *) startDate
192 // return [[self selectedDate] beginOfDay];
195 // - (NSCalendarDate *) endDate
197 // return [[self selectedDate] endOfDay];
200 // - (NSArray *) appointmentsForCurrentUser
202 // NSMutableArray *filteredAppointments;
203 // NSEnumerator *aptsEnumerator;
204 // NSDictionary *userAppointment;
205 // NSCalendarDate *start, *end;
208 // if (!allAppointments)
210 // allAppointments = [self fetchCoreAppointmentsInfos];
211 // [allAppointments retain];
214 // start = [[self selectedDate] hour: [self dayStartHour] minute: 0];
215 // endHour = [self dayEndHour];
217 // end = [[self selectedDate] hour: [self dayEndHour] minute: 59];
219 // end = [[[self selectedDate] tomorrow] hour: 0 minute: 0];
221 // filteredAppointments = [NSMutableArray new];
222 // [filteredAppointments autorelease];
224 // aptsEnumerator = [allAppointments objectEnumerator];
225 // userAppointment = [aptsEnumerator nextObject];
226 // while (userAppointment)
228 // if ([[userAppointment objectForKey: @"owner"]
229 // isEqualToString: currentTableUser])
230 // [filteredAppointments
231 // addObject: [self _adjustedAppointment: userAppointment
232 // forStart: start andEnd: end]];
233 // userAppointment = [aptsEnumerator nextObject];
236 // return filteredAppointments;
239 // - (void) setCurrentAppointment: (NSDictionary *) newCurrentAppointment
241 // currentAppointment = newCurrentAppointment;
244 // - (NSDictionary *) currentAppointment
246 // return currentAppointment;
249 // - (NSString *) appointmentsClasses
251 // return @"appointments appointmentsFor1Days";
254 - (NSString *) currentUserClasses
257 NSString *lastDayUser;
259 users = [self subscriptionUsers];
261 if (currentTableUser == [users lastObject])
262 lastDayUser = @" lastDayUser";
266 return [NSString stringWithFormat: @"day appointmentsOf%@%@",
267 currentTableUser, lastDayUser];
270 - (NSString *) clickableHourCellClass
272 return [NSString stringWithFormat: @"clickableHourCell clickableHourCell%@", currentTableHour];
275 - (NSNumber *) dayWidthPercentage
279 users = [self subscriptionUsers];
281 return [NSNumber numberWithFloat: (100.0 / [users count])];
284 - (NSNumber *) currentTableUserDayLeftPercentage
288 users = [self subscriptionUsers];
290 return [NSNumber numberWithFloat: ([users indexOfObject: currentTableUser]
291 * (100.0 / [users count]))];