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 [_day setTimeZone:[self viewTimeZone]];
77 ASSIGN(self->currentDay, _day);
79 - (NSCalendarDate *)currentDay {
80 return self->currentDay;
83 - (NSString *)currentDayName {
84 return [self localizedNameForDayOfWeek:[self->currentDay dayOfWeek]];
88 return [self hasHoldidayInfo] || ([[self allDayApts] count] != 0);
91 - (BOOL)hasHoldidayInfo {
95 - (NSArray *)allDayApts {
96 return [NSArray array];
103 - (BOOL)showFullNames {
107 - (BOOL)showAMPMDates {
111 - (unsigned)dayStartHour {
115 - (unsigned)dayEndHour {
119 - (BOOL)shouldDisplayWeekend {
126 - (NSString *)appointmentViewURL {
129 if ((pkey = [[self appointment] valueForKey:@"uid"]) == nil)
132 return [NSString stringWithFormat:@"%@/view", pkey];
138 /* resource URLs (TODO?) */
140 - (NSString *)resourcePath {
141 return @"/sogod.woa/WebServerResources/";
144 - (NSString *)favIconPath {
145 return [[self resourcePath] stringByAppendingPathComponent:@"favicon.ico"];
147 - (NSString *)cssPath {
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"
158 - (NSString *)calCSSPath {
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"
171 - (NSCalendarDate *)startDate {
172 return [self selectedDate];
174 - (NSCalendarDate *)endDate {
175 return [[self startDate] tomorrow];
178 - (NSArray *)_fetchCoreInfosForUIDs:(NSArray *)_uids
179 uniqueWithSet:(NSMutableSet *)_uniquer
184 count = [_uids count];
185 ma = [NSMutableArray arrayWithCapacity:count * 10];
187 for (i = 0; i < count; i++) {
193 uid = [_uids objectAtIndex:i];
194 if ([uid length] == 0) continue;
196 path = [[@"/Users/" stringByAppendingString:uid]
197 stringByAppendingString:@"/Calendar"];
199 if ((folder = [[self clientObject] ocsFolderForPath:path]) == nil) {
200 [self logWithFormat:@"ERROR: did not find user: %@", uid];
204 res = [[self clientObject] fetchCoreInfosFromFolder:folder
205 from:[self startDate] to:[self endDate]];
207 [self logWithFormat:@"ERROR: fetch failed for user: %@", uid];
211 /* perform uniquing */
215 for (j = 0, rcount = [res count]; j < rcount; j++) {
216 NSDictionary *record;
218 record = [res objectAtIndex:j];
220 if ([_uniquer containsObject:[record valueForKey:@"uid"]])
223 [ma addObject:record];
224 [_uniquer addObject:[record valueForKey:@"uid"]];
231 - (NSArray *)fetchCoreInfos {
236 if (self->appointments)
237 return self->appointments;
239 aptFolder = [self clientObject];
241 [[aptFolder fetchCoreInfosFrom:[self startDate] to:[self endDate]] retain];
243 uids = [[[[self context] request] formValueForKey:@"uids"] stringValue];
244 uids = [uids length] > 0 ? [uids componentsSeparatedByString:@","] : nil;
245 if ([uids count] > 0) {
246 NSMutableSet *availUIDs;
249 /* make appointments unique, prefer the own "versions" */
250 tmp = [self->appointments valueForKey:@"uid"];
251 availUIDs = [[NSMutableSet alloc] initWithArray:tmp];
253 more = [self _fetchCoreInfosForUIDs:uids uniqueWithSet:availUIDs];
257 tmp = self->appointments;
258 self->appointments = [[tmp arrayByAddingObjectsFromArray:more] retain];
265 return self->appointments;
268 /* date selection & conversion */
271 - (NSDictionary *)todayQueryParameters {
272 NSCalendarDate *date;
274 date = [NSCalendarDate date]; /* today */
275 return [self queryParametersBySettingSelectedDate:date];
278 - (NSDictionary *)currentDayQueryParameters {
279 return [self queryParametersBySettingSelectedDate:self->currentDay];
282 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date {
283 NSMutableDictionary *qp;
285 qp = [[self queryParameters] mutableCopy];
286 [self setSelectedDateQueryParameter:_date inDictionary:qp];
287 return [qp autorelease];
290 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
291 inDictionary:(NSMutableDictionary *)_qp;
294 [_qp setObject:[self dateStringForDate:_newDate] forKey:@"day"];
296 [_qp removeObjectForKey:@"day"];
299 @end /* UIxCalView */