3 #include "UIxCalView.h"
5 #include "UIxAppointmentFormatter.h"
6 #include <OGoContentStore/OCSFolder.h>
7 #include "SoObjects/Appointments/SOGoAppointmentFolder.h"
9 @implementation UIxCalView
12 [self->appointment release];
13 [self->appointments release];
14 [self->currentDay release];
20 - (void)setAppointments:(NSArray *)_apts {
21 ASSIGN(self->appointments, _apts);
23 - (NSArray *)appointments {
24 return self->appointments;
27 - (void)setAppointment:(id)_apt {
28 ASSIGN(self->appointment, _apt);
31 return self->appointment;
34 - (NSDictionary *)aptTypeDict {
38 - (NSString *)aptTypeLabel {
42 - (NSString *)aptTypeIcon {
46 - (NSString *)shortTextForApt {
47 NSCalendarDate *startDate;
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"]];
59 - (NSString *)shortTitleForApt {
62 title = [self->appointment valueForKey:@"title"];
63 if ([title length] > 12)
64 title = [[title substringToIndex:11] stringByAppendingString:@"..."];
69 - (NSCalendarDate *)referenceDateForFormatter {
70 return [self selectedDate];
73 /* current day related */
75 - (void)setCurrentDay:(NSCalendarDate *)_day {
76 ASSIGN(self->currentDay, _day);
78 - (NSCalendarDate *)currentDay {
79 return self->currentDay;
82 - (NSString *)currentDayName {
83 // TODO: this is slow, use locale dictionary to speed this up
84 [self->currentDay setTimeZone:[self viewTimeZone]];
85 return [self->currentDay descriptionWithCalendarFormat:@"%A"];
89 return [self hasHoldidayInfo] || ([[self allDayApts] count] != 0);
92 - (BOOL)hasHoldidayInfo {
96 - (NSArray *)allDayApts {
97 return [NSArray array];
104 - (BOOL)showFullNames {
108 - (BOOL)showAMPMDates {
115 - (NSString *)appointmentViewURL {
118 if ((pkey = [[self appointment] valueForKey:@"uid"]) == nil)
121 return [NSString stringWithFormat:@"%@/view", pkey];
127 /* resource URLs (TODO?) */
129 - (NSString *)resourcePath {
130 return @"/sogod.woa/WebServerResources/";
133 - (NSString *)favIconPath {
134 return [[self resourcePath] stringByAppendingPathComponent:@"favicon.ico"];
136 - (NSString *)cssPath {
139 // TODO: there should be reusable functionality for that!
140 #warning ZideStore specific?
141 path = @"ControlPanel/Products/ZideStoreUI/Resources/zidestoreui.css";
142 return [[self context] urlWithRequestHandlerKey:@"so"
147 - (NSString *)calCSSPath {
150 // TODO: there should be reusable functionality for that!
151 #warning ZideStore specific?
152 path = @"ControlPanel/Products/ZideStoreUI/Resources/calendar.css";
153 return [[self context] urlWithRequestHandlerKey:@"so"
160 - (NSCalendarDate *)startDate {
161 return [self selectedDate];
163 - (NSCalendarDate *)endDate {
164 return [[self startDate] tomorrow];
167 - (NSArray *)_fetchCoreInfosForUIDs:(NSArray *)_uids
168 uniqueWithSet:(NSMutableSet *)_uniquer
173 count = [_uids count];
174 ma = [NSMutableArray arrayWithCapacity:count * 10];
176 for (i = 0; i < count; i++) {
182 uid = [_uids objectAtIndex:i];
183 if ([uid length] == 0) continue;
185 path = [[@"/Users/" stringByAppendingString:uid]
186 stringByAppendingString:@"/Calendar"];
188 if ((folder = [[self clientObject] ocsFolderForPath:path]) == nil) {
189 [self logWithFormat:@"ERROR: did not find user: %@", uid];
193 res = [[self clientObject] fetchCoreInfosFromFolder:folder
194 from:[self startDate] to:[self endDate]];
196 [self logWithFormat:@"ERROR: fetch failed for user: %@", uid];
200 /* perform uniquing */
204 for (j = 0, rcount = [res count]; j < rcount; j++) {
205 NSDictionary *record;
207 record = [res objectAtIndex:j];
209 if ([_uniquer containsObject:[record valueForKey:@"uid"]])
212 [ma addObject:record];
213 [_uniquer addObject:[record valueForKey:@"uid"]];
220 - (NSArray *)fetchCoreInfos {
225 if (self->appointments)
226 return self->appointments;
228 aptFolder = [self clientObject];
230 [[aptFolder fetchCoreInfosFrom:[self startDate] to:[self endDate]] retain];
232 uids = [[[[self context] request] formValueForKey:@"uids"] stringValue];
233 uids = [uids length] > 0 ? [uids componentsSeparatedByString:@","] : nil;
234 if ([uids count] > 0) {
235 NSMutableSet *availUIDs;
238 /* make appointments unique, prefer the own "versions" */
239 tmp = [self->appointments valueForKey:@"uid"];
240 availUIDs = [[NSMutableSet alloc] initWithArray:tmp];
242 more = [self _fetchCoreInfosForUIDs:uids uniqueWithSet:availUIDs];
246 tmp = self->appointments;
247 self->appointments = [[tmp arrayByAddingObjectsFromArray:more] retain];
254 return self->appointments;
257 /* date selection & conversion */
260 - (NSDictionary *)todayQueryParameters {
261 NSCalendarDate *date;
263 date = [NSCalendarDate date]; /* today */
264 return [self queryParametersBySettingSelectedDate:date];
267 - (NSDictionary *)currentDayQueryParameters {
268 return [self queryParametersBySettingSelectedDate:self->currentDay];
271 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date {
272 NSMutableDictionary *qp;
274 qp = [[self queryParameters] mutableCopy];
275 [self setSelectedDateQueryParameter:_date inDictionary:qp];
276 return [qp autorelease];
279 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
280 inDictionary:(NSMutableDictionary *)_qp;
283 [_qp setObject:[self dateStringForDate:_newDate] forKey:@"day"];
285 [_qp removeObjectForKey:@"day"];
288 @end /* UIxCalView */