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/NSValue.h>
28 #import <NGExtensions/NSCalendarDate+misc.h>
30 #import <SOGo/SOGoUser.h>
31 #import <SOGoUI/SOGoDateFormatter.h>
33 #import "UIxCalMulticolumnDayView.h"
35 @implementation UIxCalMulticolumnDayView : UIxCalDayView
39 if ((self = [super init]))
41 allAppointments = nil;
42 subscriptionUsers = nil;
44 currentTableUser = nil;
45 currentTableHour = nil;
46 dateFormatter = [[SOGoDateFormatter alloc]
47 initWithLocale: [self locale]];
56 [allAppointments release];
57 if (subscriptionUsers)
58 [subscriptionUsers release];
60 [hoursToDisplay release];
61 [dateFormatter release];
65 - (void) setCSSClass: (NSString *) aCssClass
70 - (NSString *) cssClass
75 - (void) setCSSId: (NSString *) aCssId
85 - (NSArray *) hoursToDisplay
87 unsigned int currentHour, lastHour;
91 currentHour = [self dayStartHour];
92 lastHour = [self dayEndHour];
93 hoursToDisplay = [NSMutableArray new];
95 while (currentHour < lastHour)
98 addObject: [NSString stringWithFormat: @"%d", currentHour]];
102 addObject: [NSString stringWithFormat: @"%d", currentHour]];
105 return hoursToDisplay;
108 - (NSArray *) subscriptionUsers
110 SOGoUser *activeUser;
111 NSString *userList, *currentUserLogin;
114 if (!subscriptionUsers)
116 subscriptionUsers = [NSMutableArray new];
117 activeUser = [context activeUser];
118 userList = [[activeUser userDefaults] objectForKey: @"calendaruids"];
119 users = [[userList componentsSeparatedByString: @","] objectEnumerator];
120 currentUserLogin = [users nextObject];
121 while (currentUserLogin)
123 if (![currentUserLogin hasPrefix: @"-"])
124 [subscriptionUsers addObject: currentUserLogin];
125 currentUserLogin = [users nextObject];
129 return subscriptionUsers;
132 - (void) setCurrentTableUser: (NSString *) aTableUser;
134 currentTableUser = aTableUser;
137 - (NSString *) currentTableUser;
139 return currentTableUser;
142 - (void) setCurrentTableHour: (NSString *) aTableHour
144 currentTableHour = aTableHour;
147 - (NSString *) currentTableHour
149 return currentTableHour;
152 - (NSString *) currentAppointmentHour
154 return [NSString stringWithFormat: @"%.2d00", [currentTableHour intValue]];
157 - (NSDictionary *) _adjustedAppointment: (NSDictionary *) anAppointment
158 forStart: (NSCalendarDate *) start
159 andEnd: (NSCalendarDate *) end
161 NSMutableDictionary *newMutableAppointment;
162 NSDictionary *newAppointment;
163 BOOL startIsEarlier, endIsLater;
166 = ([[anAppointment objectForKey: @"startDate"] laterDate: start] == start);
168 = ([[anAppointment objectForKey: @"endDate"] earlierDate: end] == end);
170 if (startIsEarlier || endIsLater)
172 newMutableAppointment
173 = [NSMutableDictionary dictionaryWithDictionary: anAppointment];
176 [newMutableAppointment setObject: start
177 forKey: @"startDate"];
179 [newMutableAppointment setObject: end
182 newAppointment = newMutableAppointment;
185 newAppointment = anAppointment;
187 return newAppointment;
192 - (NSCalendarDate *) startDate
194 return [[self selectedDate] beginOfDay];
197 - (NSCalendarDate *) endDate
199 return [[self selectedDate] endOfDay];
202 - (NSArray *) appointmentsForCurrentUser
204 NSMutableArray *filteredAppointments;
205 NSEnumerator *aptsEnumerator;
206 NSDictionary *userAppointment;
207 NSCalendarDate *start, *end;
210 if (!allAppointments)
212 allAppointments = [self fetchCoreAppointmentsInfos];
213 [allAppointments retain];
216 start = [[self selectedDate] hour: [self dayStartHour] minute: 0];
217 endHour = [self dayEndHour];
219 end = [[self selectedDate] hour: [self dayEndHour] minute: 59];
221 end = [[[self selectedDate] tomorrow] hour: 0 minute: 0];
223 filteredAppointments = [NSMutableArray new];
224 [filteredAppointments autorelease];
226 aptsEnumerator = [allAppointments objectEnumerator];
227 userAppointment = [aptsEnumerator nextObject];
228 while (userAppointment)
230 if ([[userAppointment objectForKey: @"owner"]
231 isEqualToString: currentTableUser])
232 [filteredAppointments
233 addObject: [self _adjustedAppointment: userAppointment
234 forStart: start andEnd: end]];
235 userAppointment = [aptsEnumerator nextObject];
238 return filteredAppointments;
241 - (void) setCurrentAppointment: (NSDictionary *) newCurrentAppointment
243 currentAppointment = newCurrentAppointment;
246 - (NSDictionary *) currentAppointment
248 return currentAppointment;
251 - (NSString *) appointmentsClasses
253 return @"appointments appointmentsFor1Days";
256 - (NSString *) currentUserClasses
259 NSString *lastDayUser;
261 users = [self subscriptionUsers];
263 if (currentTableUser == [users lastObject])
264 lastDayUser = @" lastDayUser";
268 return [NSString stringWithFormat: @"day appointmentsOf%@%@",
269 currentTableUser, lastDayUser];
272 - (NSString *) clickableHourCellClass
274 return [NSString stringWithFormat: @"clickableHourCell clickableHourCell%@", currentTableHour];
277 - (NSNumber *) dayWidthPercentage
281 users = [self subscriptionUsers];
283 return [NSNumber numberWithFloat: (100.0 / [users count])];
286 - (NSNumber *) currentTableUserDayLeftPercentage
290 users = [self subscriptionUsers];
292 return [NSNumber numberWithFloat: ([users indexOfObject: currentTableUser]
293 * (100.0 / [users count]))];