]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Scheduler/UIxCalView.m
more code for day overview and the usual fixes
[scalable-opengroupware.org] / SOGo / UI / Scheduler / UIxCalView.m
1 // $Id$
2
3 #include "UIxCalView.h"
4 #include "common.h"
5 #include "UIxAppointmentFormatter.h"
6 #include <OGoContentStore/OCSFolder.h>
7 #include "SoObjects/Appointments/SOGoAppointmentFolder.h"
8
9 @implementation UIxCalView
10
11 - (void)dealloc {
12   [self->appointment  release];
13   [self->appointments release];
14   [self->currentDay   release];
15   [super dealloc];
16 }
17
18 /* accessors */
19
20 - (void)setAppointments:(NSArray *)_apts {
21   ASSIGN(self->appointments, _apts);
22 }
23 - (NSArray *)appointments {
24   return self->appointments;
25 }
26
27 - (void)setAppointment:(id)_apt {
28   ASSIGN(self->appointment, _apt);
29 }
30 - (id)appointment {
31   return self->appointment;
32 }
33
34 - (NSDictionary *)aptTypeDict {
35     return nil;
36 }
37
38 - (NSString *)aptTypeLabel {
39     return @"aptLabel";
40 }
41
42 - (NSString *)aptTypeIcon {
43     return @"";
44 }
45
46 - (NSString *)shortTextForApt {
47   NSCalendarDate *startDate;
48   NSString *ms;
49   
50   startDate = [[self appointment] valueForKey:@"startDate"];
51   [startDate setTimeZone:[self viewTimeZone]];
52   ms = [NSString stringWithFormat:@"%02i:%02i %@",
53                  [startDate hourOfDay],
54                  [startDate minuteOfHour],
55                  [[self appointment] valueForKey:@"title"]];
56   return ms;
57 }
58
59 - (NSString *)shortTitleForApt {
60   NSString *title;
61     
62   title = [self->appointment valueForKey:@"title"];
63   if ([title length] > 12)
64     title = [[title substringToIndex:11] stringByAppendingString:@"..."];
65   
66   return title;
67 }
68
69 - (NSCalendarDate *)referenceDateForFormatter {
70   return [self selectedDate];
71 }
72
73 /* current day related */
74
75 - (void)setCurrentDay:(NSCalendarDate *)_day {
76   [_day setTimeZone:[self viewTimeZone]];
77   ASSIGN(self->currentDay, _day);
78 }
79 - (NSCalendarDate *)currentDay {
80   return self->currentDay;
81 }
82
83 - (NSString *)currentDayName {
84   return [self localizedNameForDayOfWeek:[self->currentDay dayOfWeek]];
85 }
86
87 - (BOOL)hasDayInfo {
88     return [self hasHoldidayInfo] || ([[self allDayApts] count] != 0);
89 }
90
91 - (BOOL)hasHoldidayInfo {
92     return NO;
93 }
94
95 - (NSArray *)allDayApts {
96     return [NSArray array];
97 }
98
99
100 /* defaults */
101
102
103 - (BOOL)showFullNames {
104     return YES;
105 }
106
107 - (BOOL)showAMPMDates {
108     return NO;
109 }
110
111 - (unsigned)dayStartHour {
112     return 8;
113 }
114
115 - (unsigned)dayEndHour {
116     return 19;
117 }
118
119 - (BOOL)shouldDisplayWeekend {
120     return NO;
121 }
122
123
124 /* URLs */
125
126 - (NSString *)appointmentViewURL {
127   id pkey;
128   
129   if ((pkey = [[self appointment] valueForKey:@"uid"]) == nil)
130     return nil;
131   
132   return [NSString stringWithFormat:@"%@/view", pkey];
133 }
134
135
136 /* backend */
137
138 /* resource URLs (TODO?) */
139
140 - (NSString *)resourcePath {
141   return @"/sogod.woa/WebServerResources/";
142 }
143
144 - (NSString *)favIconPath {
145   return [[self resourcePath] stringByAppendingPathComponent:@"favicon.ico"];
146 }
147 - (NSString *)cssPath {
148   NSString *path;
149   
150   // TODO: there should be reusable functionality for that!
151 #warning ZideStore specific?
152   path = @"ControlPanel/Products/ZideStoreUI/Resources/uix.css";
153   return [[self context] urlWithRequestHandlerKey:@"so"
154                          path:path
155                          queryString:nil];
156 }
157
158 - (NSString *)calCSSPath {
159   NSString *path;
160   
161   // TODO: there should be reusable functionality for that!
162 #warning ZideStore specific?
163   path = @"ControlPanel/Products/ZideStoreUI/Resources/calendar.css";
164   return [[self context] urlWithRequestHandlerKey:@"so"
165                          path:path
166                          queryString:nil];
167 }
168
169 /* fetching */
170
171 - (NSCalendarDate *)startDate {
172   return [self selectedDate];
173 }
174 - (NSCalendarDate *)endDate {
175   return [[self startDate] tomorrow];
176 }
177
178 - (NSArray *)_fetchCoreInfosForUIDs:(NSArray *)_uids 
179   uniqueWithSet:(NSMutableSet *)_uniquer 
180 {
181   NSMutableArray *ma;
182   unsigned i, count;
183   
184   count = [_uids count];
185   ma    = [NSMutableArray arrayWithCapacity:count * 10];
186   
187   for (i = 0; i < count; i++) {
188     OCSFolder *folder;
189     NSString *path;
190     NSString *uid;
191     NSArray  *res;
192         
193     uid = [_uids objectAtIndex:i];
194     if ([uid length] == 0) continue;
195
196     path = [[@"/Users/" stringByAppendingString:uid]
197                         stringByAppendingString:@"/Calendar"];
198     
199     if ((folder = [[self clientObject] ocsFolderForPath:path]) == nil) {
200       [self logWithFormat:@"ERROR: did not find user: %@", uid];
201       continue;
202     }
203     
204     res = [[self clientObject] fetchCoreInfosFromFolder:folder 
205                                from:[self startDate] to:[self endDate]];
206     if (res == nil) {
207       [self logWithFormat:@"ERROR: fetch failed for user: %@", uid];
208       continue;
209     }
210
211     /* perform uniquing */
212     {
213       int j, rcount;
214       
215       for (j = 0, rcount = [res count]; j < rcount; j++) {
216         NSDictionary *record;
217         
218         record = [res objectAtIndex:j];
219         
220         if ([_uniquer containsObject:[record valueForKey:@"uid"]])
221           continue;
222         
223         [ma addObject:record];
224         [_uniquer addObject:[record valueForKey:@"uid"]];
225       }
226     }
227   }
228   return ma;
229 }
230
231 - (NSArray *)fetchCoreInfos {
232   id      aptFolder;
233   NSArray *more;
234   id      uids;
235   
236   if (self->appointments)
237     return self->appointments;
238   
239   aptFolder = [self clientObject];
240   self->appointments =
241     [[aptFolder fetchCoreInfosFrom:[self startDate] to:[self endDate]] retain];
242   
243   uids = [[[[self context] request] formValueForKey:@"uids"] stringValue];
244   uids = [uids length] > 0 ? [uids componentsSeparatedByString:@","] : nil;
245   if ([uids count] > 0) {
246     NSMutableSet *availUIDs;
247     id tmp;
248     
249     /* make appointments unique, prefer the own "versions" */
250     tmp = [self->appointments valueForKey:@"uid"];
251     availUIDs = [[NSMutableSet alloc] initWithArray:tmp];
252     
253     more = [self _fetchCoreInfosForUIDs:uids uniqueWithSet:availUIDs];
254     if (more > 0) {
255       NSArray *tmp;
256       
257       tmp = self->appointments;
258       self->appointments = [[tmp arrayByAddingObjectsFromArray:more] retain];
259       [tmp release];
260     }
261     
262     [availUIDs release];
263   }
264   
265   return self->appointments;
266 }
267
268 /* date selection & conversion */
269
270
271 - (NSDictionary *)todayQueryParameters {
272   NSCalendarDate *date;
273     
274   date = [NSCalendarDate date]; /* today */
275   return [self queryParametersBySettingSelectedDate:date];
276 }
277
278 - (NSDictionary *)currentDayQueryParameters {
279   return [self queryParametersBySettingSelectedDate:self->currentDay];
280 }
281
282 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date {
283     NSMutableDictionary *qp;
284     
285     qp = [[self queryParameters] mutableCopy];
286     [self setSelectedDateQueryParameter:_date inDictionary:qp];
287     return [qp autorelease];
288 }
289
290 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
291   inDictionary:(NSMutableDictionary *)_qp;
292 {
293   if(_newDate != nil)
294     [_qp setObject:[self dateStringForDate:_newDate] forKey:@"day"];
295   else
296     [_qp removeObjectForKey:@"day"];
297 }
298
299 @end /* UIxCalView */