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 {
114 - (NSString *)appointmentViewURL {
117 if ((pkey = [[self appointment] valueForKey:@"uid"]) == nil)
120 return [NSString stringWithFormat:@"%@/view", pkey];
126 /* resource URLs (TODO?) */
128 - (NSString *)resourcePath {
129 return @"/sogod.woa/WebServerResources/";
132 - (NSString *)favIconPath {
133 return [[self resourcePath] stringByAppendingPathComponent:@"favicon.ico"];
135 - (NSString *)cssPath {
138 // TODO: there should be reusable functionality for that!
139 #warning ZideStore specific?
140 path = @"ControlPanel/Products/ZideStoreUI/Resources/uix.css";
141 return [[self context] urlWithRequestHandlerKey:@"so"
146 - (NSString *)calCSSPath {
149 // TODO: there should be reusable functionality for that!
150 #warning ZideStore specific?
151 path = @"ControlPanel/Products/ZideStoreUI/Resources/calendar.css";
152 return [[self context] urlWithRequestHandlerKey:@"so"
159 - (NSCalendarDate *)startDate {
160 return [self selectedDate];
162 - (NSCalendarDate *)endDate {
163 return [[self startDate] tomorrow];
166 - (NSArray *)_fetchCoreInfosForUIDs:(NSArray *)_uids
167 uniqueWithSet:(NSMutableSet *)_uniquer
172 count = [_uids count];
173 ma = [NSMutableArray arrayWithCapacity:count * 10];
175 for (i = 0; i < count; i++) {
181 uid = [_uids objectAtIndex:i];
182 if ([uid length] == 0) continue;
184 path = [[@"/Users/" stringByAppendingString:uid]
185 stringByAppendingString:@"/Calendar"];
187 if ((folder = [[self clientObject] ocsFolderForPath:path]) == nil) {
188 [self logWithFormat:@"ERROR: did not find user: %@", uid];
192 res = [[self clientObject] fetchCoreInfosFromFolder:folder
193 from:[self startDate] to:[self endDate]];
195 [self logWithFormat:@"ERROR: fetch failed for user: %@", uid];
199 /* perform uniquing */
203 for (j = 0, rcount = [res count]; j < rcount; j++) {
204 NSDictionary *record;
206 record = [res objectAtIndex:j];
208 if ([_uniquer containsObject:[record valueForKey:@"uid"]])
211 [ma addObject:record];
212 [_uniquer addObject:[record valueForKey:@"uid"]];
219 - (NSArray *)fetchCoreInfos {
224 if (self->appointments)
225 return self->appointments;
227 aptFolder = [self clientObject];
229 [[aptFolder fetchCoreInfosFrom:[self startDate] to:[self endDate]] retain];
231 uids = [[[[self context] request] formValueForKey:@"uids"] stringValue];
232 uids = [uids length] > 0 ? [uids componentsSeparatedByString:@","] : nil;
233 if ([uids count] > 0) {
234 NSMutableSet *availUIDs;
237 /* make appointments unique, prefer the own "versions" */
238 tmp = [self->appointments valueForKey:@"uid"];
239 availUIDs = [[NSMutableSet alloc] initWithArray:tmp];
241 more = [self _fetchCoreInfosForUIDs:uids uniqueWithSet:availUIDs];
245 tmp = self->appointments;
246 self->appointments = [[tmp arrayByAddingObjectsFromArray:more] retain];
253 return self->appointments;
256 /* date selection & conversion */
259 - (NSDictionary *)todayQueryParameters {
260 NSCalendarDate *date;
262 date = [NSCalendarDate date]; /* today */
263 return [self queryParametersBySettingSelectedDate:date];
266 - (NSDictionary *)currentDayQueryParameters {
267 return [self queryParametersBySettingSelectedDate:self->currentDay];
270 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date {
271 NSMutableDictionary *qp;
273 qp = [[self queryParameters] mutableCopy];
274 [self setSelectedDateQueryParameter:_date inDictionary:qp];
275 return [qp autorelease];
278 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
279 inDictionary:(NSMutableDictionary *)_qp;
282 [_qp setObject:[self dateStringForDate:_newDate] forKey:@"day"];
284 [_qp removeObjectForKey:@"day"];
287 @end /* UIxCalView */