diff --git a/ChangeLog b/ChangeLog index 568645278..d0699f642 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-03-18 Wolfgang Sourdeau + + * SoObjects/Appointments/SOGoCalendarComponent.m + ([SOGoCalendarComponent -isOrganizer:emailorOwner:login]): new + method. + ([SOGoCalendarComponent -isParticipant:email]): new method. + ([SOGoCalendarComponent -calendar:create]): takes one parameter + "create" which is a boolean indicating whether we want to create + the calendar if it does not exist. + 2007-03-12 Wolfgang Sourdeau * UI/Scheduler/UIxCalMonthView.m: changed view to use divs instead diff --git a/SoObjects/Appointments/SOGoCalendarComponent.h b/SoObjects/Appointments/SOGoCalendarComponent.h index 589b7dbb6..80230884c 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.h +++ b/SoObjects/Appointments/SOGoCalendarComponent.h @@ -35,11 +35,13 @@ { iCalCalendar *calendar; NSString *calContent; + BOOL isNew; } - (NSString *) componentTag; -- (iCalCalendar *) calendar; -- (iCalRepeatableEntityObject *) component; +- (iCalCalendar *) calendar: (BOOL) create; +- (iCalRepeatableEntityObject *) component: (BOOL) create; +- (BOOL) isNew; - (NSException *) primarySaveContentString: (NSString *) _iCalString; - (NSException *) primaryDelete; @@ -53,6 +55,10 @@ andNewObject: (iCalRepeatableEntityObject *) _newObject toAttendees: (NSArray *) _attendees; +- (BOOL) isOrganizer: (NSString *) email + orOwner: (NSString *) login; +- (BOOL) isParticipant: (NSString *) email; + @end #endif /* SOGOCALENDARCOMPONENT_H */ diff --git a/SoObjects/Appointments/SOGoCalendarComponent.m b/SoObjects/Appointments/SOGoCalendarComponent.m index c79091a72..11a3178a1 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.m +++ b/SoObjects/Appointments/SOGoCalendarComponent.m @@ -69,6 +69,7 @@ static BOOL sendEMailNotifications = NO; { calendar = nil; calContent = nil; + isNew = NO; } return self; @@ -158,30 +159,49 @@ static BOOL sendEMailNotifications = NO; return result; } -- (iCalCalendar *) calendar +- (iCalCalendar *) calendar: (BOOL) create { - NSString *iCalString; + NSString *iCalString, *componentTag; + CardGroup *newComponent; if (!calendar) { iCalString = [self contentAsString]; - if (iCalString) + if ([iCalString length] > 0) + calendar = [iCalCalendar parseSingleFromSource: iCalString]; + else { - calendar = [iCalCalendar parseSingleFromSource: iCalString]; - [calendar retain]; + if (create) + { + calendar = [iCalCalendar groupWithTag: @"vcalendar"]; + [calendar setVersion: @"2.0"]; + [calendar setProdID: @"-//Inverse groupe conseil//SOGo 0.9//EN"]; + componentTag = [[self componentTag] uppercaseString]; + newComponent = [[calendar classForTag: componentTag] + groupWithTag: componentTag]; + [calendar addChild: newComponent]; + isNew = YES; + } } + if (calendar) + [calendar retain]; } return calendar; } -- (iCalRepeatableEntityObject *) component +- (iCalRepeatableEntityObject *) component: (BOOL) create { return (iCalRepeatableEntityObject *) - [[self calendar] + [[self calendar: create] firstChildWithTag: [self componentTag]]; } +- (BOOL) isNew +{ + return isNew; +} + /* raw saving */ - (NSException *) primarySaveContentString: (NSString *) _iCalString @@ -376,7 +396,7 @@ static BOOL sendEMailNotifications = NO; um = [AgenorUserManager sharedUserManager]; email = [um getEmailForUID: login]; - component = [self component]; + component = [self component: NO]; if (component) { if ([component isOrganizer: email]) @@ -397,4 +417,36 @@ static BOOL sendEMailNotifications = NO; return sogoRoles; } +- (BOOL) isOrganizer: (NSString *) email + orOwner: (NSString *) login +{ + BOOL isOrganizerOrOwner; + iCalRepeatableEntityObject *component; + + component = [self component: NO]; + if (component) + isOrganizerOrOwner + = ([component isOrganizer: email] + || [[container ownerInContext: nil] isEqualToString: login]); + else + isOrganizerOrOwner + = [[container ownerInContext: nil] isEqualToString: login]; + + return isOrganizerOrOwner; +} + +- (BOOL) isParticipant: (NSString *) email +{ + BOOL isParticipant; + iCalRepeatableEntityObject *component; + + component = [self component: NO]; + if (component) + isParticipant = [component isParticipant: email]; + else + isParticipant = NO; + + return isParticipant; +} + @end