]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalMulticolumnDayView.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1172 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Scheduler / UIxCalMulticolumnDayView.m
1 /* UIxCalMulticolumnDayView.h - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSString.h>
26 #import <Foundation/NSValue.h>
27
28 #import <NGExtensions/NSCalendarDate+misc.h>
29
30 #import <SoObjects/SOGo/SOGoUser.h>
31 #import <SoObjects/SOGo/SOGoDateFormatter.h>
32
33 #import "UIxCalMulticolumnDayView.h"
34
35 @implementation UIxCalMulticolumnDayView : UIxCalDayView
36
37 - (id) init
38 {
39   if ((self = [super init]))
40     {
41 //       allAppointments = nil;
42       subscriptionUsers = nil;
43       hoursToDisplay = nil;
44       currentTableUser = nil;
45       currentTableHour = nil;
46 //       dateFormatter = [[SOGoDateFormatter alloc]
47 //                         initWithLocale: [self locale]];
48     }
49
50   return self;
51 }
52
53 - (void) dealloc
54 {
55 //   [allAppointments release];
56   [subscriptionUsers release];
57   [hoursToDisplay release];
58 //   [dateFormatter release];
59   [super dealloc];
60 }
61
62 - (void) setCSSClass: (NSString *) aCssClass
63 {
64   cssClass = aCssClass;
65 }
66
67 - (NSString *) cssClass
68 {
69   return cssClass;
70 }
71
72 - (void) setCSSId: (NSString *) aCssId
73 {
74   cssId = aCssId;
75 }
76
77 - (NSString *) cssId
78 {
79   return cssId;
80 }
81
82 - (NSArray *) hoursToDisplay
83 {
84   unsigned int currentHour, lastHour;
85
86   if (!hoursToDisplay)
87     {
88       currentHour = [self dayStartHour];
89       lastHour = [self dayEndHour];
90       hoursToDisplay = [NSMutableArray new];
91
92       while (currentHour < lastHour)
93         {
94           [hoursToDisplay
95             addObject: [NSString stringWithFormat: @"%d", currentHour]];
96           currentHour++;
97         }
98       [hoursToDisplay
99         addObject: [NSString stringWithFormat: @"%d", currentHour]];
100     }
101
102   return hoursToDisplay;
103 }
104
105 - (NSArray *) subscriptionUsers
106 {
107   SOGoUser *activeUser;
108   NSString *userList, *currentUserLogin;
109   NSEnumerator *users;
110
111   if (!subscriptionUsers)
112     {
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)
119         {
120           if (![currentUserLogin hasPrefix: @"-"])
121             [subscriptionUsers addObject: currentUserLogin];
122           currentUserLogin = [users nextObject];
123         }
124     }
125
126   return subscriptionUsers;
127 }
128
129 - (void) setCurrentTableUser: (NSString *) aTableUser;
130 {
131   currentTableUser = aTableUser;
132 }
133
134 - (NSString *) currentTableUser;
135 {
136   return currentTableUser;
137 }
138
139 - (void) setCurrentTableHour: (NSString *) aTableHour
140 {
141   currentTableHour = aTableHour;
142 }
143
144 - (NSString *) currentTableHour
145 {
146   return currentTableHour;
147 }
148
149 - (NSString *) currentAppointmentHour
150 {
151   return [NSString stringWithFormat: @"%.2d00", [currentTableHour intValue]];
152 }
153
154 - (NSDictionary *) _adjustedAppointment: (NSDictionary *) anAppointment
155                                forStart: (NSCalendarDate *) start
156                                  andEnd: (NSCalendarDate *) end
157 {
158   NSMutableDictionary *newMutableAppointment;
159   NSDictionary *newAppointment;
160   BOOL startIsEarlier, endIsLater;
161
162   startIsEarlier
163     = ([[anAppointment objectForKey: @"startDate"] laterDate: start] == start);
164   endIsLater
165     = ([[anAppointment objectForKey: @"endDate"] earlierDate: end] == end);
166
167   if (startIsEarlier || endIsLater)
168     {
169       newMutableAppointment
170         = [NSMutableDictionary dictionaryWithDictionary: anAppointment];
171       
172       if (startIsEarlier)
173         [newMutableAppointment setObject: start
174                                forKey: @"startDate"];
175       if (endIsLater)
176         [newMutableAppointment setObject: end
177                                forKey: @"endDate"];
178
179       newAppointment = newMutableAppointment;
180     }
181   else
182     newAppointment = anAppointment;
183
184   return newAppointment;
185 }
186
187 /* fetching */
188
189 // - (NSCalendarDate *) startDate
190 // {
191 //   return [[self selectedDate] beginOfDay];
192 // }
193
194 // - (NSCalendarDate *) endDate
195 // {
196 //   return [[self selectedDate] endOfDay];
197 // }
198
199 // - (NSArray *) appointmentsForCurrentUser
200 // {
201 //   NSMutableArray *filteredAppointments;
202 //   NSEnumerator *aptsEnumerator;
203 //   NSDictionary *userAppointment;
204 //   NSCalendarDate *start, *end;
205 //   int endHour;
206
207 //   if (!allAppointments)
208 //     {
209 //       allAppointments = [self fetchCoreAppointmentsInfos];
210 //       [allAppointments retain];
211 //     }
212
213 //   start = [[self selectedDate] hour: [self dayStartHour] minute: 0];
214 //   endHour = [self dayEndHour];
215 //   if (endHour < 24)
216 //     end = [[self selectedDate] hour: [self dayEndHour] minute: 59];
217 //   else
218 //     end = [[[self selectedDate] tomorrow] hour: 0 minute: 0];
219
220 //   filteredAppointments = [NSMutableArray new];
221 //   [filteredAppointments autorelease];
222
223 //   aptsEnumerator = [allAppointments objectEnumerator];
224 //   userAppointment = [aptsEnumerator nextObject];
225 //   while (userAppointment)
226 //     {
227 //       if ([[userAppointment objectForKey: @"owner"]
228 //             isEqualToString: currentTableUser])
229 //         [filteredAppointments
230 //           addObject: [self _adjustedAppointment: userAppointment
231 //                            forStart: start andEnd: end]];
232 //       userAppointment = [aptsEnumerator nextObject];
233 //     }
234
235 //   return filteredAppointments;
236 // }
237
238 // - (void) setCurrentAppointment: (NSDictionary *) newCurrentAppointment
239 // {
240 //   currentAppointment = newCurrentAppointment;
241 // }
242
243 // - (NSDictionary *) currentAppointment
244 // {
245 //   return currentAppointment;
246 // }
247
248 // - (NSString *) appointmentsClasses
249 // {
250 //   return @"appointments appointmentsFor1Days";
251 // }
252
253 - (NSString *) currentUserClasses
254 {
255   NSArray *users;
256   NSString *lastDayUser;
257
258   users = [self subscriptionUsers];
259
260   if (currentTableUser == [users lastObject])
261     lastDayUser = @" lastDayUser";
262   else
263     lastDayUser = @"";
264     
265   return [NSString stringWithFormat: @"day appointmentsOf%@%@",
266                    currentTableUser, lastDayUser];
267 }
268
269 - (NSString *) clickableHourCellClass
270 {
271   return [NSString stringWithFormat: @"clickableHourCell clickableHourCell%@", currentTableHour];
272 }
273
274 - (NSNumber *) dayWidthPercentage
275 {
276   NSArray *users;
277
278   users = [self subscriptionUsers];
279
280   return [NSNumber numberWithFloat: (100.0 / [users count])];
281 }
282
283 - (NSNumber *) currentTableUserDayLeftPercentage
284 {
285   NSArray *users;
286
287   users = [self subscriptionUsers];
288
289   return [NSNumber numberWithFloat: ([users indexOfObject: currentTableUser]
290                                      * (100.0 / [users count]))];
291 }
292
293 @end