2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2012-01-12 21:01:34 +01:00
|
|
|
Copyright (C) 2007-2012 Inverse inc.
|
2006-06-15 21:34:10 +02:00
|
|
|
Copyright (C) 2000-2004 SKYRIX Software AG
|
|
|
|
|
2011-04-25 12:31:08 +02:00
|
|
|
This file is part of SOGo
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2011-04-25 12:31:08 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
2011-04-25 12:31:08 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2012-01-12 21:01:34 +01:00
|
|
|
#import <Foundation/NSData.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
|
2012-01-12 21:01:34 +01:00
|
|
|
#import <NGObjWeb/WOApplication.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
|
|
|
#import <NGCards/iCalFreeBusy.h>
|
2007-05-09 21:30:06 +02:00
|
|
|
#import <NGCards/iCalPerson.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2011-03-30 17:01:55 +02:00
|
|
|
#import <SOGo/SOGoBuild.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoDomainDefaults.h>
|
2012-01-12 21:01:34 +01:00
|
|
|
#import <SOGo/SOGoSource.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <SOGo/SOGoUser.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
|
|
|
#import <SOGo/SOGoUserManager.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
#import <SOGo/SOGoPermissions.h>
|
|
|
|
|
2007-09-15 00:49:49 +02:00
|
|
|
#import "SOGoAppointmentFolder.h"
|
2008-06-19 20:31:18 +02:00
|
|
|
#import "SOGoAppointmentFolders.h"
|
2007-09-15 00:49:49 +02:00
|
|
|
|
2012-01-12 21:01:34 +01:00
|
|
|
#import "MSExchangeFreeBusy.h"
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
#import "SOGoFreeBusyObject.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@interface SOGoFreeBusyObject (PrivateAPI)
|
2006-10-26 02:09:03 +02:00
|
|
|
- (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
|
|
|
|
from: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate;
|
2006-06-15 21:34:10 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFreeBusyObject
|
|
|
|
|
2008-06-27 16:49:28 +02:00
|
|
|
- (iCalPerson *) iCalPersonWithUID: (NSString *) uid
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2008-06-27 16:49:28 +02:00
|
|
|
iCalPerson *person;
|
2009-09-25 16:42:33 +02:00
|
|
|
SOGoUserManager *um;
|
2012-01-13 18:20:58 +01:00
|
|
|
NSString *domain;
|
2008-06-27 16:49:28 +02:00
|
|
|
NSDictionary *contactInfos;
|
2012-01-13 18:20:58 +01:00
|
|
|
NSArray *contacts;
|
2006-10-26 02:09:03 +02:00
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
um = [SOGoUserManager sharedUserManager];
|
2008-06-27 16:49:28 +02:00
|
|
|
contactInfos = [um contactInfosForUserWithUIDorEmail: uid];
|
2012-01-13 18:20:58 +01:00
|
|
|
if (contactInfos == nil)
|
|
|
|
{
|
|
|
|
domain = [[context activeUser] domain];
|
|
|
|
[um fetchContactsMatching: uid inDomain: domain];
|
|
|
|
contacts = [um fetchContactsMatching: uid inDomain: domain];
|
|
|
|
if ([contacts count] == 1)
|
|
|
|
contactInfos = [contacts lastObject];
|
|
|
|
}
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2009-07-20 20:49:56 +02:00
|
|
|
/* iCal.app compatibility:
|
|
|
|
- don't add "cn"; */
|
2008-06-27 16:49:28 +02:00
|
|
|
person = [iCalPerson new];
|
|
|
|
[person autorelease];
|
|
|
|
[person setEmail: [contactInfos objectForKey: @"c_email"]];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-27 16:49:28 +02:00
|
|
|
return person;
|
2007-11-07 16:58:43 +01:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* Private API */
|
2008-11-20 20:17:59 +01:00
|
|
|
- (iCalFreeBusyType) _fbTypeForEventStatus: (int) eventStatus
|
2006-10-26 02:09:03 +02:00
|
|
|
{
|
2008-11-20 20:17:59 +01:00
|
|
|
//unsigned int status;
|
2006-10-26 02:09:03 +02:00
|
|
|
iCalFreeBusyType fbType;
|
|
|
|
|
2008-11-20 20:17:59 +01:00
|
|
|
//status = [eventStatus unsignedIntValue];
|
|
|
|
if (eventStatus == 0)
|
2006-10-26 02:09:03 +02:00
|
|
|
fbType = iCalFBBusyTentative;
|
2008-11-20 20:17:59 +01:00
|
|
|
else if (eventStatus == 1)
|
2006-10-26 02:09:03 +02:00
|
|
|
fbType = iCalFBBusy;
|
|
|
|
else
|
|
|
|
fbType = iCalFBFree;
|
|
|
|
|
|
|
|
return fbType;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
- (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
|
2008-06-27 16:49:28 +02:00
|
|
|
withMethod: (NSString *) method
|
2009-06-09 22:43:53 +02:00
|
|
|
andUID: (NSString *) uid
|
2009-06-09 23:10:25 +02:00
|
|
|
andOrganizer: (iCalPerson *) organizer
|
2012-01-13 18:20:58 +01:00
|
|
|
andContact: (NSString *) contactID
|
2006-10-26 02:09:03 +02:00
|
|
|
from: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2008-11-20 20:17:59 +01:00
|
|
|
NSArray *emails, *partstates;
|
2006-10-26 02:09:03 +02:00
|
|
|
NSEnumerator *events;
|
|
|
|
iCalCalendar *calendar;
|
|
|
|
iCalFreeBusy *freebusy;
|
|
|
|
NSDictionary *info;
|
|
|
|
iCalFreeBusyType type;
|
2008-11-20 20:17:59 +01:00
|
|
|
SOGoUser *user;
|
2009-06-09 22:43:53 +02:00
|
|
|
NSString *login;
|
2008-11-20 20:17:59 +01:00
|
|
|
int i;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-06-09 22:43:53 +02:00
|
|
|
login = [container ownerInContext: context];
|
2009-08-25 23:28:24 +02:00
|
|
|
user = [SOGoUser userWithLogin: login];
|
2006-10-26 02:09:03 +02:00
|
|
|
|
|
|
|
calendar = [iCalCalendar groupWithTag: @"vcalendar"];
|
2011-03-30 17:01:55 +02:00
|
|
|
[calendar setProdID: [NSString stringWithFormat:
|
|
|
|
@"-//Inverse inc./SOGo %@//EN",
|
|
|
|
SOGoVersion]];
|
2006-10-26 02:09:03 +02:00
|
|
|
[calendar setVersion: @"2.0"];
|
2008-06-27 16:49:28 +02:00
|
|
|
if (method)
|
|
|
|
[calendar setMethod: method];
|
2006-10-26 02:09:03 +02:00
|
|
|
|
|
|
|
freebusy = [iCalFreeBusy groupWithTag: @"vfreebusy"];
|
2009-06-09 22:43:53 +02:00
|
|
|
if (uid)
|
|
|
|
[freebusy setUid: uid];
|
2009-06-09 23:10:25 +02:00
|
|
|
if (organizer)
|
|
|
|
[freebusy setOrganizer: organizer];
|
2012-01-13 18:20:58 +01:00
|
|
|
if (contactID)
|
|
|
|
[freebusy addToAttendees: [self iCalPersonWithUID: contactID]];
|
|
|
|
else
|
|
|
|
[freebusy addToAttendees: [self iCalPersonWithUID: login]];
|
2006-10-26 02:09:03 +02:00
|
|
|
[freebusy setTimeStampAsDate: [NSCalendarDate calendarDate]];
|
|
|
|
[freebusy setStartDate: _startDate];
|
|
|
|
[freebusy setEndDate: _endDate];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* ORGANIZER - strictly required but missing for now */
|
|
|
|
|
|
|
|
/* ATTENDEE */
|
2009-06-09 22:43:53 +02:00
|
|
|
// person = [self iCalPersonWithUid: login];
|
2006-10-26 02:09:03 +02:00
|
|
|
// [person setTag: @"ATTENDEE"];
|
|
|
|
// [ms appendString: [person versitString]];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
/* FREEBUSY */
|
|
|
|
events = [_infos objectEnumerator];
|
2008-06-19 20:31:18 +02:00
|
|
|
while ((info = [events nextObject]))
|
|
|
|
if ([[info objectForKey: @"c_isopaque"] boolValue])
|
|
|
|
{
|
2008-11-20 20:17:59 +01:00
|
|
|
type = iCalFBFree;
|
|
|
|
|
|
|
|
// If the event has NO organizer (which means it's the user that has created it) OR
|
|
|
|
// If we are the organizer of the event THEN we are automatically busy
|
|
|
|
if ([[info objectForKey: @"c_orgmail"] length] == 0 ||
|
|
|
|
[user hasEmail: [info objectForKey: @"c_orgmail"]])
|
|
|
|
{
|
|
|
|
type = iCalFBBusy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We check if the user has accepted/declined or needs action
|
|
|
|
// on the current event.
|
|
|
|
emails = [[info objectForKey: @"c_partmails"] componentsSeparatedByString: @"\n"];
|
|
|
|
|
|
|
|
for (i = 0; i < [emails count]; i++)
|
|
|
|
{
|
|
|
|
if ([user hasEmail: [emails objectAtIndex: i]])
|
|
|
|
{
|
|
|
|
// We now fetch the c_partstates array and get the participation
|
|
|
|
// status of the user for the event
|
|
|
|
partstates = [[info objectForKey: @"c_partstates"] componentsSeparatedByString: @"\n"];
|
|
|
|
|
|
|
|
if (i < [partstates count])
|
|
|
|
{
|
|
|
|
type = [self _fbTypeForEventStatus: [[partstates objectAtIndex: i] intValue]];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-09 22:14:45 +02:00
|
|
|
if (type == iCalFBBusy
|
|
|
|
|| type == iCalFBBusyTentative
|
|
|
|
|| type == iCalFBBusyUnavailable)
|
2008-11-20 20:17:59 +01:00
|
|
|
[freebusy addFreeBusyFrom: [info objectForKey: @"startDate"]
|
|
|
|
to: [info objectForKey: @"endDate"]
|
2009-06-09 22:14:45 +02:00
|
|
|
type: type];
|
2008-06-19 20:31:18 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
[calendar setUniqueChild: freebusy];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
return [calendar versitString];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-06-27 16:49:28 +02:00
|
|
|
- (NSString *) contentAsString
|
|
|
|
{
|
|
|
|
NSCalendarDate *today, *startDate, *endDate;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
SOGoDomainDefaults *dd;
|
|
|
|
NSArray *interval;
|
|
|
|
unsigned int start, end;
|
2008-06-27 16:49:28 +02:00
|
|
|
|
|
|
|
today = [[NSCalendarDate calendarDate] beginOfDay];
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
[today setTimeZone: [ud timeZone]];
|
|
|
|
|
|
|
|
dd = [[context activeUser] domainDefaults];
|
|
|
|
interval = [dd freeBusyDefaultInterval];
|
|
|
|
if ([interval count] > 1)
|
|
|
|
{
|
|
|
|
start = [[interval objectAtIndex: 0] unsignedIntValue];
|
|
|
|
end = [[interval objectAtIndex: 1] unsignedIntValue];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = 7;
|
|
|
|
end = 7;
|
|
|
|
}
|
2008-06-27 16:49:28 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
startDate = [today dateByAddingYears: 0 months: 0 days: -start
|
2008-06-27 16:49:28 +02:00
|
|
|
hours: 0 minutes: 0 seconds: 0];
|
2009-11-29 05:19:32 +01:00
|
|
|
endDate = [today dateByAddingYears: 0 months: 0 days: end
|
2008-06-27 16:49:28 +02:00
|
|
|
hours: 0 minutes: 0 seconds: 0];
|
|
|
|
|
|
|
|
return [self contentAsStringFrom: startDate to: endDate];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) contentAsStringWithMethod: (NSString *) method
|
2009-06-09 22:43:53 +02:00
|
|
|
andUID: (NSString *) UID
|
2009-06-09 23:10:25 +02:00
|
|
|
andOrganizer: (iCalPerson *) organizer
|
2012-01-13 18:20:58 +01:00
|
|
|
andContact: (NSString *) contactID
|
2008-06-27 16:49:28 +02:00
|
|
|
from: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate
|
|
|
|
{
|
|
|
|
NSArray *infos;
|
2009-06-09 22:43:53 +02:00
|
|
|
|
2012-01-13 18:20:58 +01:00
|
|
|
infos = [self fetchFreeBusyInfosFrom: _startDate to: _endDate
|
|
|
|
forContact: contactID];
|
2008-06-27 16:49:28 +02:00
|
|
|
|
2009-06-09 22:43:53 +02:00
|
|
|
return [self iCalStringForFreeBusyInfos: infos
|
2009-06-09 23:10:25 +02:00
|
|
|
withMethod: method
|
|
|
|
andUID: UID andOrganizer: organizer
|
2012-01-13 18:20:58 +01:00
|
|
|
andContact: contactID
|
2009-06-09 22:43:53 +02:00
|
|
|
from: _startDate to: _endDate];
|
2008-06-27 16:49:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) contentAsStringFrom: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate
|
|
|
|
{
|
2009-06-09 22:43:53 +02:00
|
|
|
return [self contentAsStringWithMethod: nil andUID: nil
|
2009-06-09 23:10:25 +02:00
|
|
|
andOrganizer: nil
|
2012-01-13 18:20:58 +01:00
|
|
|
andContact: nil
|
2009-06-09 22:43:53 +02:00
|
|
|
from: _startDate
|
|
|
|
to: _endDate];
|
2008-06-27 16:49:28 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 21:01:34 +01:00
|
|
|
/**
|
|
|
|
* Fetch freebusy information for a user that exists in a contact source
|
|
|
|
* (not an authentication source) for which freebusy information is available
|
|
|
|
* (currently limited to a Microsoft Exchange server with Web Services enabled).
|
|
|
|
* @param startDate the beginning of the covered period
|
|
|
|
* @param endDate the ending of the covered period
|
2012-01-13 18:20:58 +01:00
|
|
|
* @param uid the ID of the contact within the current domain
|
2012-01-12 21:01:34 +01:00
|
|
|
* @return an array of dictionaries containing the start and end dates of each busy period
|
|
|
|
* @see MSExchangeFreeBusy.m
|
|
|
|
*/
|
|
|
|
- (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) startDate
|
|
|
|
to: (NSCalendarDate *) endDate
|
2012-01-13 18:20:58 +01:00
|
|
|
forContact: (NSString *) uid
|
2012-01-12 21:01:34 +01:00
|
|
|
{
|
|
|
|
if ([uid length])
|
|
|
|
{
|
|
|
|
SOGoUserManager *um;
|
2012-01-13 18:20:58 +01:00
|
|
|
NSArray *contacts;
|
2012-01-12 21:01:34 +01:00
|
|
|
NSString *domain, *email;
|
2012-01-13 18:20:58 +01:00
|
|
|
NSDictionary *contact;
|
2012-01-12 21:01:34 +01:00
|
|
|
MSExchangeFreeBusy *exchangeFreeBusy;
|
|
|
|
NSObject <SOGoDNSource> *source;
|
|
|
|
|
|
|
|
um = [SOGoUserManager sharedUserManager];
|
|
|
|
domain = [[context activeUser] domain];
|
2012-01-13 18:20:58 +01:00
|
|
|
contacts = [um fetchContactsMatching: uid inDomain: domain];
|
|
|
|
if ([contacts count] == 1)
|
2012-01-12 21:01:34 +01:00
|
|
|
{
|
2012-01-13 18:20:58 +01:00
|
|
|
contact = [contacts lastObject];
|
|
|
|
email = [contact valueForKey: @"c_email"];
|
|
|
|
source = [contact objectForKey: @"source"];
|
2012-01-12 21:01:34 +01:00
|
|
|
if ([email length])
|
|
|
|
{
|
|
|
|
exchangeFreeBusy = [[MSExchangeFreeBusy alloc] init];
|
|
|
|
[exchangeFreeBusy autorelease];
|
|
|
|
|
|
|
|
return [exchangeFreeBusy fetchFreeBusyInfosFrom: startDate
|
|
|
|
to: endDate
|
|
|
|
forEmail: email
|
|
|
|
inSource: source
|
|
|
|
inContext: context];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return [self fetchFreeBusyInfosFrom: startDate to: endDate];
|
|
|
|
}
|
|
|
|
|
|
|
|
// No freebusy information found
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-27 16:49:28 +02:00
|
|
|
- (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) startDate
|
|
|
|
to: (NSCalendarDate *) endDate
|
|
|
|
{
|
|
|
|
SOGoAppointmentFolder *calFolder;
|
2011-09-27 17:43:46 +02:00
|
|
|
SOGoUser *user;
|
|
|
|
SOGoUserDefaults *ud;
|
2008-06-27 16:49:28 +02:00
|
|
|
NSArray *folders;
|
|
|
|
NSMutableArray *infos;
|
2011-09-27 17:43:46 +02:00
|
|
|
NSString *login;
|
2008-06-27 16:49:28 +02:00
|
|
|
unsigned int count, max;
|
|
|
|
|
|
|
|
infos = [NSMutableArray array];
|
|
|
|
|
|
|
|
folders = [[container lookupName: @"Calendar"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO] subFolders];
|
|
|
|
max = [folders count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
calFolder = [folders objectAtIndex: count];
|
2010-05-06 21:30:14 +02:00
|
|
|
if (![calFolder isSubscription] && [calFolder includeInFreeBusy])
|
2008-06-27 16:49:28 +02:00
|
|
|
[infos addObjectsFromArray: [calFolder fetchFreeBusyInfosFrom: startDate
|
2010-05-06 21:30:14 +02:00
|
|
|
to: endDate]];
|
2008-06-27 16:49:28 +02:00
|
|
|
}
|
|
|
|
|
2011-09-27 17:43:46 +02:00
|
|
|
login = [container ownerInContext: context];
|
|
|
|
user = [SOGoUser userWithLogin: login];
|
|
|
|
ud = [user userDefaults];
|
|
|
|
|
|
|
|
if ([ud busyOffHours])
|
|
|
|
{
|
|
|
|
NSCalendarDate *currentStartDate, *currentEndDate, *weekendStartDate, *weekendEndDate;
|
|
|
|
NSTimeZone *timeZone;
|
|
|
|
unsigned int dayStartHour, dayEndHour, intervalHours;
|
|
|
|
BOOL firstRange;
|
|
|
|
|
|
|
|
dayStartHour = [ud dayStartHour];
|
|
|
|
dayEndHour = [ud dayEndHour];
|
|
|
|
intervalHours = dayStartHour + 24 - dayEndHour;
|
|
|
|
timeZone = [ud timeZone];
|
|
|
|
firstRange = YES;
|
|
|
|
|
|
|
|
currentStartDate = [NSCalendarDate dateWithYear: [startDate yearOfCommonEra]
|
|
|
|
month: [startDate monthOfYear]
|
|
|
|
day: [startDate dayOfMonth]
|
|
|
|
hour: 0
|
|
|
|
minute: 0
|
|
|
|
second: 0
|
|
|
|
timeZone: timeZone];
|
|
|
|
currentEndDate = [NSCalendarDate dateWithYear: [startDate yearOfCommonEra]
|
|
|
|
month: [startDate monthOfYear]
|
|
|
|
day: [startDate dayOfMonth]
|
|
|
|
hour: dayStartHour
|
|
|
|
minute: 0
|
|
|
|
second: 0
|
|
|
|
timeZone: timeZone];
|
|
|
|
|
|
|
|
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
|
|
|
|
[currentStartDate compare: endDate] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
if ([endDate compare: currentEndDate] == NSOrderedAscending)
|
|
|
|
currentEndDate = endDate;
|
|
|
|
|
|
|
|
[infos addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithBool: YES], @"c_isopaque",
|
|
|
|
([currentStartDate compare: startDate] == NSOrderedAscending)? startDate : currentStartDate, @"startDate",
|
|
|
|
currentEndDate, @"endDate", nil]];
|
|
|
|
|
|
|
|
if (!firstRange
|
|
|
|
&& currentEndDate != endDate
|
|
|
|
&& ([currentEndDate dayOfWeek] == 6 || [currentEndDate dayOfWeek] == 0))
|
|
|
|
{
|
|
|
|
// Fill weekend days
|
|
|
|
weekendStartDate = currentEndDate;
|
|
|
|
weekendEndDate = [weekendStartDate addYear:0 month:0 day:0 hour:(-[weekendStartDate hourOfDay] + dayEndHour) minute:0 second:0];
|
|
|
|
[infos addObject: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool: YES], @"c_isopaque",
|
|
|
|
weekendStartDate, @"startDate",
|
|
|
|
weekendEndDate, @"endDate", nil]];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute next range
|
|
|
|
if (firstRange)
|
|
|
|
{
|
|
|
|
currentStartDate = [currentStartDate addYear:0 month:0 day:0 hour:dayEndHour minute:0 second:0];
|
|
|
|
firstRange = NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentStartDate = [currentStartDate addYear:0 month:0 day:1 hour:0 minute:0 second:0];
|
|
|
|
}
|
|
|
|
currentEndDate = [currentStartDate addYear:0 month:0 day:0 hour:intervalHours minute:0 second:0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-27 16:49:28 +02:00
|
|
|
return infos;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) iCalString
|
|
|
|
{
|
|
|
|
// for UI-X appointment viewer
|
|
|
|
return [self contentAsString];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* deliver content without need for view method */
|
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
- (id) GETAction: (id)_ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
WOResponse *r;
|
2009-11-29 05:19:32 +01:00
|
|
|
NSData *contentData;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-07 16:58:43 +01:00
|
|
|
contentData = [[self contentAsString]
|
|
|
|
dataUsingEncoding: NSUTF8StringEncoding];
|
2006-10-26 02:09:03 +02:00
|
|
|
|
|
|
|
r = [(WOContext *) _ctx response];
|
|
|
|
[r setHeader: @"text/calendar" forKey: @"content-type"];
|
|
|
|
[r setContent: contentData];
|
|
|
|
[r setStatus: 200];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-03-04 21:57:36 +01:00
|
|
|
- (BOOL) isFolderish
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2007-06-01 08:13:44 +02:00
|
|
|
- (NSString *) davContentType
|
|
|
|
{
|
|
|
|
return @"text/calendar";
|
|
|
|
}
|
|
|
|
|
2007-11-07 16:58:43 +01:00
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end
|