2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "SOGoAppointmentFolder.h"
24 #include <OGoContentStore/OCSFolder.h>
30 @implementation SOGoAppointmentFolder
32 static BOOL debugOn = NO;
34 + (NSString *)globallyUniqueObjectId {
36 4C08AE1A-A808-11D8-AC5A-000393BBAFF6
37 SOGo-Web-28273-18283-288182
38 printf( "%x", *(int *) &f);
41 static int sequence = 0;
42 static float rndm = 0;
50 f = [[NSDate date] timeIntervalSince1970];
51 return [NSString stringWithFormat:@"%0X-%0X-%0X-%0X",
64 - (BOOL)isValidAppointmentName:(NSString *)_key {
65 if ([_key length] == 0)
71 - (id)appointmentWithName:(NSString *)_key inContext:(id)_ctx {
72 static Class aptClass = Nil;
76 aptClass = NSClassFromString(@"SOGoAppointmentObject");
77 if (aptClass == Nil) {
78 [self logWithFormat:@"ERROR: missing SOGoAppointmentObject class!"];
82 apt = [[aptClass alloc] initWithName:_key inContainer:self];
83 return [apt autorelease];
86 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
89 /* first check attributes directly bound to the application */
90 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
93 if ([self isValidAppointmentName:_key])
94 return [self appointmentWithName:_key inContext:_ctx];
96 /* return 404 to stop acquisition */
97 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
102 - (NSMutableDictionary *)fixupRecord:(NSDictionary *)_record {
103 NSMutableDictionary *md;
106 md = [[_record mutableCopy] autorelease];
108 if ((tmp = [_record objectForKey:@"startdate"])) {
109 tmp = [[NSCalendarDate alloc] initWithTimeIntervalSince1970:
110 (NSTimeInterval)[tmp unsignedIntValue]];
111 if (tmp) [md setObject:tmp forKey:@"startDate"];
115 [self logWithFormat:@"missing 'startdate' in record?"];
117 if ((tmp = [_record objectForKey:@"enddate"])) {
118 tmp = [[NSCalendarDate alloc] initWithTimeIntervalSince1970:
119 (NSTimeInterval)[tmp unsignedIntValue]];
120 if (tmp) [md setObject:tmp forKey:@"endDate"];
124 [self logWithFormat:@"missing 'enddate' in record?"];
129 - (NSArray *)fixupRecords:(NSArray *)_records {
133 if (_records == nil) return nil;
134 if ((count = [_records count]) == 0)
137 ma = [NSMutableArray arrayWithCapacity:count];
138 for (i = 0; i < count; i++) {
141 row = [self fixupRecord:[_records objectAtIndex:i]];
142 if (row) [ma addObject:row];
147 - (NSArray *)fetchCoreInfosFrom:(NSCalendarDate *)_startDate
148 to:(NSCalendarDate *)_endDate
151 EOQualifier *qualifier;
152 NSArray *fields, *records;
155 if ((folder = [self ocsFolder]) == nil) {
156 [self logWithFormat:@"ERROR(%s): missing folder for fetch!",
157 __PRETTY_FUNCTION__];
161 [self logWithFormat:@"should fetch (%@ => %@) ...", _startDate, _endDate];
163 sql = [NSString stringWithFormat:@"(startdate < %d) AND (enddate > %d)",
164 (unsigned int)[_endDate timeIntervalSince1970],
165 (unsigned int)[_startDate timeIntervalSince1970]];
166 qualifier = [EOQualifier qualifierWithQualifierFormat:sql];
168 fields = [NSArray arrayWithObjects:
169 @"uid", @"startdate", @"enddate",
170 @"title", @"participants", nil];
172 records = [folder fetchFields:fields matchingQualifier:qualifier];
173 if (records == nil) {
174 [self logWithFormat:@"ERROR(%s): fetch failed!", __PRETTY_FUNCTION__];
178 records = [self fixupRecords:records];
180 [self logWithFormat:@"fetched %i records: %@", [records count], records];
186 - (id)GETAction:(WOContext *)_ctx {
187 // TODO: I guess this should really be done by SOPE (redirect to
192 uri = [[_ctx request] uri];
193 if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"];
194 uri = [uri stringByAppendingString:@"weekoverview"];
197 [r setStatus:302 /* moved */];
198 [r setHeader:uri forKey:@"location"];
202 @end /* SOGoAppointmentFolder */