2007-06-01 06:10:03 +02:00
|
|
|
/* iCalEntityObject+SOGo.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSString.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
2007-09-04 17:42:13 +02:00
|
|
|
#import <NGCards/iCalPerson.h>
|
|
|
|
|
2007-08-15 22:17:11 +02:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
2007-06-01 06:10:03 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
#import "iCalPerson+SOGo.h"
|
|
|
|
|
2007-06-01 06:10:03 +02:00
|
|
|
#import "iCalEntityObject+SOGo.h"
|
|
|
|
|
|
|
|
@implementation iCalEntityObject (SOGoExtensions)
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
+ (void) initializeSOGoExtensions;
|
|
|
|
{
|
|
|
|
if (!iCalDistantFuture)
|
|
|
|
{
|
|
|
|
iCalDistantFuture = [[NSCalendarDate distantFuture] retain];
|
|
|
|
/* INT_MAX due to Postgres constraint */
|
|
|
|
iCalDistantFutureNumber = [[NSNumber numberWithUnsignedInt: INT_MAX] retain];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-01 06:10:03 +02:00
|
|
|
- (BOOL) userIsParticipant: (SOGoUser *) user
|
|
|
|
{
|
2007-09-04 17:42:13 +02:00
|
|
|
NSEnumerator *participants;
|
|
|
|
iCalPerson *currentParticipant;
|
|
|
|
BOOL isParticipant;
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2007-09-04 17:42:13 +02:00
|
|
|
isParticipant = NO;
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2007-09-04 17:42:13 +02:00
|
|
|
participants = [[self participants] objectEnumerator];
|
|
|
|
currentParticipant = [participants nextObject];
|
|
|
|
while (!isParticipant
|
|
|
|
&& currentParticipant)
|
|
|
|
if ([user hasEmail: [currentParticipant rfc822Email]])
|
|
|
|
isParticipant = YES;
|
2007-06-01 06:10:03 +02:00
|
|
|
else
|
2007-09-04 17:42:13 +02:00
|
|
|
currentParticipant = [participants nextObject];
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2007-09-04 17:42:13 +02:00
|
|
|
return isParticipant;
|
2007-06-01 06:10:03 +02:00
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
#warning user could be a delegate, we will need to handle that someday
|
2007-06-01 06:10:03 +02:00
|
|
|
- (BOOL) userIsOrganizer: (SOGoUser *) user
|
|
|
|
{
|
2007-09-04 17:42:13 +02:00
|
|
|
NSString *orgMail;
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2007-09-04 17:42:13 +02:00
|
|
|
orgMail = [[self organizer] rfc822Email];
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2007-09-04 17:42:13 +02:00
|
|
|
return [user hasEmail: orgMail];
|
2007-06-01 06:10:03 +02:00
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (NSArray *) attendeeUIDs
|
|
|
|
{
|
|
|
|
NSEnumerator *attendees;
|
|
|
|
NSString *uid;
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
NSMutableArray *uids;
|
|
|
|
|
|
|
|
uids = [NSMutableArray array];
|
|
|
|
|
|
|
|
attendees = [[self attendees] objectEnumerator];
|
|
|
|
while ((currentAttendee = [attendees nextObject]))
|
|
|
|
{
|
|
|
|
uid = [currentAttendee uid];
|
|
|
|
if (uid)
|
|
|
|
[uids addObject: uid];
|
|
|
|
}
|
|
|
|
|
|
|
|
return uids;
|
|
|
|
}
|
|
|
|
|
|
|
|
#warning this method should be implemented in a category of iCalToDo
|
|
|
|
- (BOOL) isStillRelevant
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) itipEntryWithMethod: (NSString *) method
|
|
|
|
{
|
|
|
|
iCalCalendar *newCalendar;
|
|
|
|
iCalEntityObject *newEntry;
|
|
|
|
|
|
|
|
newCalendar = [parent mutableCopy];
|
|
|
|
[newCalendar autorelease];
|
|
|
|
[newCalendar setMethod: method];
|
|
|
|
newEntry = (iCalEntityObject *) [newCalendar firstChildWithTag: tag];
|
|
|
|
|
|
|
|
return newEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) attendeesWithoutUser: (SOGoUser *) user
|
|
|
|
{
|
|
|
|
NSMutableArray *newAttendees;
|
|
|
|
NSArray *oldAttendees;
|
|
|
|
unsigned int count, max;
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
NSString *userID;
|
|
|
|
|
|
|
|
userID = [user login];
|
|
|
|
oldAttendees = [self attendees];
|
|
|
|
max = [oldAttendees count];
|
|
|
|
newAttendees = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
currentAttendee = [oldAttendees objectAtIndex: count];
|
|
|
|
if (![[currentAttendee uid] isEqualToString: userID])
|
|
|
|
[newAttendees addObject: currentAttendee];
|
|
|
|
}
|
|
|
|
|
|
|
|
return newAttendees;
|
|
|
|
}
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
- (NSNumber *) quickRecordDateAsNumber: (NSCalendarDate *) _date
|
|
|
|
{
|
|
|
|
return ((_date == iCalDistantFuture)
|
|
|
|
? iCalDistantFutureNumber
|
|
|
|
: [NSNumber numberWithUnsignedInt: [_date timeIntervalSince1970]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableDictionary *) quickRecord
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) priorityNumber
|
|
|
|
{
|
|
|
|
NSString *prio;
|
|
|
|
NSRange r;
|
|
|
|
int priorityNumber;
|
|
|
|
|
|
|
|
prio = [self priority];
|
|
|
|
if (prio)
|
|
|
|
{
|
|
|
|
r = [prio rangeOfString: @";"];
|
|
|
|
if (r.length)
|
|
|
|
prio = [prio substringToIndex:r.location];
|
|
|
|
priorityNumber = [prio intValue];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
priorityNumber = 0;
|
|
|
|
|
|
|
|
return priorityNumber;
|
|
|
|
}
|
|
|
|
|
2007-06-01 06:10:03 +02:00
|
|
|
@end
|