2 Copyright (C) 2004-2005 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
22 #import <GDLContentStore/GCSFolder.h>
26 #import "SOGoContactGCSEntry.h"
27 #import "SOGoContactGCSFolder.h"
29 #define folderListingFields [NSArray arrayWithObjects: @"c_name", @"cn", \
30 @"givenname", @"screenname", \
31 @"o", @"mail", @"telephonenumber", \
34 @implementation SOGoContactGCSFolder
36 + (id <SOGoContactFolder>) contactFolderWithName: (NSString *) aName
37 andDisplayName: (NSString *) aDisplayName
38 inContainer: (SOGoObject *) aContainer
40 SOGoContactGCSFolder *folder;
42 folder = [[self alloc] initWithName: aName
43 andDisplayName: aDisplayName
44 inContainer: aContainer];
52 [displayName release];
56 - (id <SOGoContactFolder>) initWithName: (NSString *) newName
57 andDisplayName: (NSString *) newDisplayName
58 inContainer: (SOGoObject *) newContainer
60 if ((self = [self initWithName: newName
61 inContainer: newContainer]))
62 ASSIGN (displayName, newDisplayName);
67 - (NSString *) displayName
74 - (id <SOGoContactObject>) lookupContactWithId: (NSString *) recordId
76 SOGoContactGCSEntry *contact;
78 if ([recordId length] > 0)
79 contact = [SOGoContactGCSEntry objectWithName: recordId
87 - (id) lookupName: (NSString *) _key
88 inContext: (WOContext *) _ctx
95 /* first check attributes directly bound to the application */
96 obj = [super lookupName:_key inContext:_ctx acquire:NO];
99 if ([[[_ctx request] method] isEqualToString: @"PUT"])
101 if ([_key isEqualToString: @"PUT"])
104 obj = [SOGoContactGCSEntry objectWithName: _key
108 obj = [self lookupContactWithId: _key];
110 // if (!(obj || isPut))
111 // obj = [NSException exceptionWithHTTPStatus:404 /* Not Found */];
114 // if ([[self ocsFolder] versionOfContentWithName:_key])
116 // return [self contactWithName:_key inContext:_ctx];
119 /* return 404 to stop acquisition */
124 - (EOQualifier *) _qualifierForFilter: (NSString *) filter
127 EOQualifier *qualifier;
129 if (filter && [filter length] > 0)
131 qs = [NSString stringWithFormat:
132 @"(sn isCaseInsensitiveLike: '%@%%') OR "
133 @"(givenname isCaseInsensitiveLike: '%@%%') OR "
134 @"(mail isCaseInsensitiveLike: '%@%%') OR "
135 @"(telephonenumber isCaseInsensitiveLike: '%%%@%%')",
136 filter, filter, filter, filter];
137 qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
145 - (NSArray *) lookupContactsWithFilter: (NSString *) filter
146 sortBy: (NSString *) sortKey
147 ordering: (NSComparisonResult) sortOrdering
149 NSArray *fields, *records;
150 EOQualifier *qualifier;
151 EOSortOrdering *ordering;
153 // NSLog (@"fetching records matching '%@', sorted by '%@' in order %d",
154 // filter, sortKey, sortOrdering);
156 fields = folderListingFields;
157 qualifier = [self _qualifierForFilter: filter];
158 records = [[self ocsFolder] fetchFields: fields
159 matchingQualifier: qualifier];
160 if ([records count] > 1)
163 = [EOSortOrdering sortOrderingWithKey: sortKey
164 selector: ((sortOrdering == NSOrderedDescending)
165 ? EOCompareCaseInsensitiveDescending
166 : EOCompareCaseInsensitiveAscending)];
168 = [records sortedArrayUsingKeyOrderArray:
169 [NSArray arrayWithObject: ordering]];
172 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
174 //[self debugWithFormat:@"fetched %i records.", [records count]];
178 - (NSString *) groupDavResourceType
180 return @"vcard-collection";
183 - (NSException *) delete
185 return (([nameInContainer isEqualToString: @"personal"])
186 ? [NSException exceptionWithHTTPStatus: 403
187 reason: @"the 'personal' folder cannot be deleted"]
193 // - (id) GETAction: (id)_ctx
195 // // TODO: I guess this should really be done by SOPE (redirect to
196 // // default method)
200 // uri = [[_ctx request] uri];
201 // if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"];
202 // uri = [uri stringByAppendingString:@"view"];
204 // r = [_ctx response];
205 // [r setStatus:302 /* moved */];
206 // [r setHeader:uri forKey:@"location"];
212 - (NSString *) folderType
217 - (NSString *) outlookFolderClass
219 return @"IPF.Contact";
222 @end /* SOGoContactGCSFolder */