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 @"sn", @"givenname", @"l", \
31 @"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];
50 - (id <SOGoContactFolder>) initWithName: (NSString *) aName
51 andDisplayName: (NSString *) aDisplayName
52 inContainer: (SOGoObject *) aContainer
54 if ((self = [self initWithName: aName
55 inContainer: aContainer]))
56 [self setDisplayName: aDisplayName];
61 - (void) setDisplayName: (NSString *) aDisplayName
64 [displayName release];
65 displayName = aDisplayName;
70 - (NSString *) displayName
77 - (id <SOGoContactObject>) lookupContactWithId: (NSString *) recordId
79 SOGoContactGCSEntry *contact;
81 if ([recordId length] > 0)
82 contact = [SOGoContactGCSEntry objectWithName: recordId
90 - (id) lookupName: (NSString *) _key
91 inContext: (WOContext *) _ctx
96 /* first check attributes directly bound to the application */
97 obj = [super lookupName:_key inContext:_ctx acquire:NO];
100 if ([[[_ctx request] method] isEqualToString: @"PUT"])
102 obj = [[SOGoContactGCSEntry alloc] initWithName: _key
107 obj = [self lookupContactWithId: _key];
110 obj = [NSException exceptionWithHTTPStatus:404 /* Not Found */];
113 // if ([[self ocsFolder] versionOfContentWithName:_key])
115 // return [self contactWithName:_key inContext:_ctx];
118 /* return 404 to stop acquisition */
123 - (EOQualifier *) _qualifierForFilter: (NSString *) filter
126 EOQualifier *qualifier;
128 if (filter && [filter length] > 0)
130 qs = [NSString stringWithFormat:
131 @"(sn isCaseInsensitiveLike: '%@%%') OR "
132 @"(givenname isCaseInsensitiveLike: '%@%%') OR "
133 @"(mail isCaseInsensitiveLike: '%@%%') OR "
134 @"(telephonenumber isCaseInsensitiveLike: '%%%@%%')",
135 filter, filter, filter, filter];
136 qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
144 - (NSArray *) lookupContactsWithFilter: (NSString *) filter
145 sortBy: (NSString *) sortKey
146 ordering: (NSComparisonResult) sortOrdering
148 NSArray *fields, *records;
149 EOQualifier *qualifier;
150 EOSortOrdering *ordering;
152 NSLog (@"fetching records matching '*%@*', sorted by '%@' in order %d",
153 filter, sortKey, sortOrdering);
155 fields = folderListingFields;
156 qualifier = [self _qualifierForFilter: filter];
157 records = [[self ocsFolder] fetchFields: fields
158 matchingQualifier: qualifier];
162 = [EOSortOrdering sortOrderingWithKey: sortKey
163 selector: ((sortOrdering == NSOrderedDescending)
164 ? EOCompareCaseInsensitiveDescending
165 : EOCompareCaseInsensitiveAscending)];
167 = [records sortedArrayUsingKeyOrderArray:
168 [NSArray arrayWithObject: ordering]];
171 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
173 //[self debugWithFormat:@"fetched %i records.", [records count]];
177 - (NSString *) groupDavResourceType
179 return @"vcard-collection";
184 // - (id) GETAction: (id)_ctx
186 // // TODO: I guess this should really be done by SOPE (redirect to
187 // // default method)
191 // uri = [[_ctx request] uri];
192 // if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"];
193 // uri = [uri stringByAppendingString:@"view"];
195 // r = [_ctx response];
196 // [r setStatus:302 /* moved */];
197 // [r setHeader:uri forKey:@"location"];
203 - (NSString *)outlookFolderClass {
204 return @"IPF.Contact";
207 @end /* SOGoContactGCSFolder */