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 <SoObjects/SOGo/SOGoUser.h>
31 #import <SoObjects/SOGo/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]];
55 // [allAppointments release];
56 [subscriptionUsers release];
57 [hoursToDisplay release];
58 // [dateFormatter release];
62 - (void) setCSSClass: (NSString *) aCssClass
67 - (NSString *) cssClass
72 - (void) setCSSId: (NSString *) aCssId
82 - (NSArray *) hoursToDisplay
84 unsigned int currentHour, lastHour;
88 currentHour = [self dayStartHour];
89 lastHour = [self dayEndHour];
90 hoursToDisplay = [NSMutableArray new];
92 while (currentHour < lastHour)
95 addObject: [NSString stringWithFormat: @"%d", currentHour]];
99 addObject: [NSString stringWithFormat: @"%d", currentHour]];
102 return hoursToDisplay;
105 - (NSArray *) subscriptionUsers
107 SOGoUser *activeUser;
108 NSString *userList, *currentUserLogin;
111 if (!subscriptionUsers)
113 subscriptionUsers = [NSMutableArray new];
114 activeUser = [context activeUser];
115 userList = [[activeUser userDefaults] objectForKey: @"calendaruids"];
116 users = [[userList componentsSeparatedByString: @","] objectEnumerator];
117 currentUserLogin = [users nextObject];
118 while (currentUserLogin)
120 if (![currentUserLogin hasPrefix: @"-"])
121 [subscriptionUsers addObject: currentUserLogin];
122 currentUserLogin = [users nextObject];
126 return subscriptionUsers;
129 - (void) setCurrentTableUser: (NSString *) aTableUser;
131 currentTableUser = aTableUser;
134 - (NSString *) currentTableUser;
136 return currentTableUser;
139 - (void) setCurrentTableHour: (NSString *) aTableHour
141 currentTableHour = aTableHour;
144 - (NSString *) currentTableHour
146 return currentTableHour;
149 - (NSString *) currentAppointmentHour
151 return [NSString stringWithFormat: @"%.2d00", [currentTableHour intValue]];
154 - (NSDictionary *) _adjustedAppointment: (NSDictionary *) anAppointment
155 forStart: (NSCalendarDate *) start
156 andEnd: (NSCalendarDate *) end
158 NSMutableDictionary *newMutableAppointment;
159 NSDictionary *newAppointment;
160 BOOL startIsEarlier, endIsLater;
163 = ([[anAppointment objectForKey: @"startDate"] laterDate: start] == start);
165 = ([[anAppointment objectForKey: @"endDate"] earlierDate: end] == end);
167 if (startIsEarlier || endIsLater)
169 newMutableAppointment
170 = [NSMutableDictionary dictionaryWithDictionary: anAppointment];
173 [newMutableAppointment setObject: start
174 forKey: @"startDate"];
176 [newMutableAppointment setObject: end
179 newAppointment = newMutableAppointment;
182 newAppointment = anAppointment;
184 return newAppointment;
189 // - (NSCalendarDate *) startDate
191 // return [[self selectedDate] beginOfDay];
194 // - (NSCalendarDate *) endDate
196 // return [[self selectedDate] endOfDay];
199 // - (NSArray *) appointmentsForCurrentUser
201 // NSMutableArray *filteredAppointments;
202 // NSEnumerator *aptsEnumerator;
203 // NSDictionary *userAppointment;
204 // NSCalendarDate *start, *end;
207 // if (!allAppointments)
209 // allAppointments = [self fetchCoreAppointmentsInfos];
210 // [allAppointments retain];
213 // start = [[self selectedDate] hour: [self dayStartHour] minute: 0];
214 // endHour = [self dayEndHour];
216 // end = [[self selectedDate] hour: [self dayEndHour] minute: 59];
218 // end = [[[self selectedDate] tomorrow] hour: 0 minute: 0];
220 // filteredAppointments = [NSMutableArray new];
221 // [filteredAppointments autorelease];
223 // aptsEnumerator = [allAppointments objectEnumerator];
224 // userAppointment = [aptsEnumerator nextObject];
225 // while (userAppointment)
227 // if ([[userAppointment objectForKey: @"owner"]
228 // isEqualToString: currentTableUser])
229 // [filteredAppointments
230 // addObject: [self _adjustedAppointment: userAppointment
231 // forStart: start andEnd: end]];
232 // userAppointment = [aptsEnumerator nextObject];
235 // return filteredAppointments;
238 // - (void) setCurrentAppointment: (NSDictionary *) newCurrentAppointment
240 // currentAppointment = newCurrentAppointment;
243 // - (NSDictionary *) currentAppointment
245 // return currentAppointment;
248 // - (NSString *) appointmentsClasses
250 // return @"appointments appointmentsFor1Days";
253 - (NSString *) currentUserClasses
256 NSString *lastDayUser;
258 users = [self subscriptionUsers];
260 if (currentTableUser == [users lastObject])
261 lastDayUser = @" lastDayUser";
265 return [NSString stringWithFormat: @"day appointmentsOf%@%@",
266 currentTableUser, lastDayUser];
269 - (NSString *) clickableHourCellClass
271 return [NSString stringWithFormat: @"clickableHourCell clickableHourCell%@", currentTableHour];
274 - (NSNumber *) dayWidthPercentage
278 users = [self subscriptionUsers];
280 return [NSNumber numberWithFloat: (100.0 / [users count])];
283 - (NSNumber *) currentTableUserDayLeftPercentage
287 users = [self subscriptionUsers];
289 return [NSNumber numberWithFloat: ([users indexOfObject: currentTableUser]
290 * (100.0 / [users count]))];