2007-06-07 22:49:06 +02:00
|
|
|
/* UIxCalListingActions.m - this file is part of SOGo
|
|
|
|
*
|
2009-04-21 17:20:52 +02:00
|
|
|
* Copyright (C) 2006-2009 Inverse inc.
|
2007-06-07 22:49:06 +02:00
|
|
|
*
|
|
|
|
* 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/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
#import <Foundation/NSNull.h>
|
|
|
|
#import <Foundation/NSString.h>
|
2007-10-30 22:51:31 +01:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2009-08-17 22:07:54 +02:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-06-07 22:49:06 +02:00
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2009-06-08 19:48:46 +02:00
|
|
|
|
2007-12-12 18:48:19 +01:00
|
|
|
#import <NGCards/iCalPerson.h>
|
2009-06-08 19:48:46 +02:00
|
|
|
|
2009-03-16 22:21:43 +01:00
|
|
|
#import <NGExtensions/NGCalendarDateRange.h>
|
2009-06-08 19:48:46 +02:00
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
2009-07-03 21:46:01 +02:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2007-06-07 22:49:06 +02:00
|
|
|
|
2007-06-19 20:08:16 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoDateFormatter.h>
|
2009-06-08 19:48:46 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoUserFolder.h>
|
2007-06-07 22:49:06 +02:00
|
|
|
#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
|
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SoObjects/SOGo/NSObject+Utilities.h>
|
|
|
|
#import <SoObjects/Appointments/SOGoAppointmentFolder.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <SoObjects/Appointments/SOGoAppointmentFolders.h>
|
2009-04-22 23:02:11 +02:00
|
|
|
#import <SoObjects/Appointments/SOGoAppointmentObject.h>
|
2009-06-04 16:57:50 +02:00
|
|
|
#import <Appointments/SOGoFreeBusyObject.h>
|
2007-06-07 22:49:06 +02:00
|
|
|
|
2007-09-11 21:36:40 +02:00
|
|
|
#import <UI/Common/WODirectAction+SOGo.h>
|
|
|
|
|
2007-06-13 21:33:31 +02:00
|
|
|
#import "NSArray+Scheduler.h"
|
2007-06-11 23:28:28 +02:00
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
#import "UIxCalListingActions.h"
|
|
|
|
|
2008-07-16 04:12:18 +02:00
|
|
|
static NSArray *eventsFields = nil;
|
|
|
|
static NSArray *tasksFields = nil;
|
|
|
|
|
|
|
|
#define dayLength 86400
|
|
|
|
#define quarterLength 900
|
|
|
|
|
2009-06-04 16:57:50 +02:00
|
|
|
#define intervalSeconds 900
|
|
|
|
#define offsetHours 24 * 5
|
|
|
|
#define offsetSeconds offsetHours * 60 * 60
|
|
|
|
#define offsetBlocks offsetHours * 4
|
|
|
|
#define maxBlocks offsetBlocks * 2
|
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
@implementation UIxCalListingActions
|
|
|
|
|
2008-07-16 04:12:18 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (!eventsFields)
|
|
|
|
{
|
|
|
|
eventsFields = [NSArray arrayWithObjects: @"c_name", @"c_folder",
|
|
|
|
@"c_status", @"c_title", @"c_startdate",
|
|
|
|
@"c_enddate", @"c_location", @"c_isallday",
|
|
|
|
@"c_classification", @"c_partmails",
|
2009-04-24 21:19:43 +02:00
|
|
|
@"c_partstates", @"c_owner", @"c_iscycle", @"c_nextalarm",
|
2009-06-15 23:19:36 +02:00
|
|
|
@"c_recurrence_id", @"isException", nil];
|
2008-07-16 04:12:18 +02:00
|
|
|
[eventsFields retain];
|
|
|
|
}
|
|
|
|
if (!tasksFields)
|
|
|
|
{
|
|
|
|
tasksFields = [NSArray arrayWithObjects: @"c_name", @"c_folder",
|
|
|
|
@"c_status", @"c_title", @"c_enddate",
|
2009-07-31 21:48:25 +02:00
|
|
|
@"c_classification", @"editable", @"c_priority", nil];
|
2008-07-16 04:12:18 +02:00
|
|
|
[tasksFields retain];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-11 23:43:37 +02:00
|
|
|
- (id) initWithRequest: (WORequest *) newRequest
|
2007-06-07 22:49:06 +02:00
|
|
|
{
|
2007-06-19 20:08:16 +02:00
|
|
|
SOGoUser *user;
|
2007-06-11 23:28:28 +02:00
|
|
|
|
2007-06-11 23:43:37 +02:00
|
|
|
if ((self = [super initWithRequest: newRequest]))
|
2007-06-07 22:49:06 +02:00
|
|
|
{
|
|
|
|
componentsData = [NSMutableDictionary new];
|
|
|
|
startDate = nil;
|
|
|
|
endDate = nil;
|
2007-06-11 23:43:37 +02:00
|
|
|
ASSIGN (request, newRequest);
|
2007-06-19 20:08:16 +02:00
|
|
|
user = [[self context] activeUser];
|
2009-03-24 14:47:11 +01:00
|
|
|
ASSIGN (dateFormatter, [user dateFormatterInContext: context]);
|
2007-06-19 20:08:16 +02:00
|
|
|
ASSIGN (userTimeZone, [user timeZone]);
|
2008-07-16 04:12:18 +02:00
|
|
|
dayBasedView = NO;
|
2007-06-11 23:43:37 +02:00
|
|
|
}
|
2007-06-07 22:49:06 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-06-11 23:28:28 +02:00
|
|
|
[dateFormatter release];
|
2007-06-11 23:43:37 +02:00
|
|
|
[request release];
|
2007-06-07 22:49:06 +02:00
|
|
|
[componentsData release];
|
2007-06-19 20:08:16 +02:00
|
|
|
[userTimeZone release];
|
2007-06-07 22:49:06 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-06-08 01:22:14 +02:00
|
|
|
- (void) _setupDatesWithPopup: (NSString *) popupValue
|
|
|
|
andUserTZ: (NSTimeZone *) userTZ
|
|
|
|
{
|
|
|
|
NSCalendarDate *newDate;
|
|
|
|
NSString *param;
|
|
|
|
|
|
|
|
if ([popupValue isEqualToString: @"view_today"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
endDate = [newDate endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_all"])
|
|
|
|
{
|
|
|
|
startDate = nil;
|
|
|
|
endDate = nil;
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_next7"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
endDate = [[startDate dateByAddingYears: 0 months: 0 days: 6] endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_next14"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
endDate = [[startDate dateByAddingYears: 0 months: 0 days: 13] endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_next31"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
endDate = [[startDate dateByAddingYears: 0 months: 0 days: 30] endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_thismonth"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [[newDate firstDayOfMonth] beginOfDay];
|
|
|
|
endDate = [[newDate lastDayOfMonth] endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_future"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
2008-11-07 19:56:03 +01:00
|
|
|
endDate = nil;
|
2007-06-08 01:22:14 +02:00
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_selectedday"])
|
|
|
|
{
|
|
|
|
param = [request formValueForKey: @"day"];
|
|
|
|
if ([param length] > 0)
|
|
|
|
startDate = [[NSCalendarDate dateFromShortDateString: param
|
|
|
|
andShortTimeString: nil
|
|
|
|
inTimeZone: userTZ] beginOfDay];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
}
|
|
|
|
endDate = [startDate endOfDay];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
- (void) _setupContext
|
|
|
|
{
|
|
|
|
SOGoUser *user;
|
|
|
|
NSTimeZone *userTZ;
|
|
|
|
NSString *param;
|
|
|
|
|
|
|
|
user = [context activeUser];
|
|
|
|
userLogin = [user login];
|
|
|
|
userTZ = [user timeZone];
|
|
|
|
|
2007-06-08 01:22:14 +02:00
|
|
|
param = [request formValueForKey: @"filterpopup"];
|
2008-07-16 04:12:18 +02:00
|
|
|
if ([param length])
|
2007-11-21 18:23:51 +01:00
|
|
|
{
|
|
|
|
[self _setupDatesWithPopup: param andUserTZ: userTZ];
|
|
|
|
title = [request formValueForKey: @"search"];
|
|
|
|
}
|
2007-06-07 22:49:06 +02:00
|
|
|
else
|
2007-06-08 01:22:14 +02:00
|
|
|
{
|
|
|
|
param = [request formValueForKey: @"sd"];
|
|
|
|
if ([param length] > 0)
|
|
|
|
startDate = [[NSCalendarDate dateFromShortDateString: param
|
|
|
|
andShortTimeString: nil
|
|
|
|
inTimeZone: userTZ] beginOfDay];
|
|
|
|
else
|
|
|
|
startDate = nil;
|
2008-07-16 04:12:18 +02:00
|
|
|
|
2007-06-11 23:28:28 +02:00
|
|
|
param = [request formValueForKey: @"ed"];
|
2007-06-08 01:22:14 +02:00
|
|
|
if ([param length] > 0)
|
|
|
|
endDate = [[NSCalendarDate dateFromShortDateString: param
|
|
|
|
andShortTimeString: nil
|
|
|
|
inTimeZone: userTZ] endOfDay];
|
|
|
|
else
|
|
|
|
endDate = nil;
|
2008-07-16 04:12:18 +02:00
|
|
|
|
|
|
|
param = [request formValueForKey: @"view"];
|
|
|
|
dayBasedView = ![param isEqualToString: @"monthview"];
|
2007-06-08 01:22:14 +02:00
|
|
|
}
|
2007-06-07 22:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (SOGoAppointmentFolder *) _aptFolder: (NSString *) folder
|
|
|
|
withClientObject: (SOGoAppointmentFolder *) clientObject
|
|
|
|
{
|
|
|
|
SOGoAppointmentFolder *aptFolder;
|
|
|
|
NSArray *folderParts;
|
|
|
|
|
|
|
|
if ([folder isEqualToString: @"/"])
|
|
|
|
aptFolder = clientObject;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
folderParts = [folder componentsSeparatedByString: @":"];
|
|
|
|
aptFolder
|
|
|
|
= [clientObject lookupCalendarFolderForUID:
|
|
|
|
[folderParts objectAtIndex: 0]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return aptFolder;
|
|
|
|
}
|
|
|
|
|
2007-11-26 18:40:44 +01:00
|
|
|
- (void) _fixComponentTitle: (NSMutableDictionary *) component
|
|
|
|
withType: (NSString *) type
|
|
|
|
{
|
|
|
|
NSString *labelKey;
|
|
|
|
|
|
|
|
labelKey = [NSString stringWithFormat: @"%@_class%@",
|
|
|
|
type, [component objectForKey: @"c_classification"]];
|
|
|
|
[component setObject: [self labelForKey: labelKey]
|
|
|
|
forKey: @"c_title"];
|
|
|
|
}
|
|
|
|
|
2009-03-16 22:21:43 +01:00
|
|
|
- (void) _fixDates: (NSMutableDictionary *) aRecord
|
|
|
|
{
|
|
|
|
NSCalendarDate *aDate, *aStartDate;
|
|
|
|
NSNumber *aDateValue;
|
|
|
|
NSString *aDateField;
|
|
|
|
signed int daylightOffset;
|
|
|
|
unsigned int count;
|
|
|
|
static NSString *fields[] = { @"startDate", @"c_startdate",
|
|
|
|
@"endDate", @"c_enddate" };
|
|
|
|
|
|
|
|
for (count = 0; count < 2; count++)
|
|
|
|
{
|
|
|
|
aDateField = fields[count * 2];
|
|
|
|
aDate = [aRecord objectForKey: aDateField];
|
|
|
|
if ([userTimeZone isDaylightSavingTimeForDate: aDate] !=
|
|
|
|
[userTimeZone isDaylightSavingTimeForDate: startDate])
|
|
|
|
{
|
|
|
|
daylightOffset = (signed int)[userTimeZone secondsFromGMTForDate: aDate]
|
|
|
|
- (signed int)[userTimeZone secondsFromGMTForDate: startDate];
|
|
|
|
aDate = [aDate dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:daylightOffset];
|
|
|
|
[aRecord setObject: aDate forKey: aDateField];
|
|
|
|
aDateValue = [NSNumber numberWithInt: [aDate timeIntervalSince1970]];
|
|
|
|
[aRecord setObject: aDateValue forKey: fields[count * 2 + 1]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aDateValue = [aRecord objectForKey: @"c_recurrence_id"];
|
|
|
|
aDate = [aRecord objectForKey: @"cycleStartDate"];
|
|
|
|
aStartDate = [aRecord objectForKey: @"startDate"];
|
|
|
|
if (aDateValue && aDate)
|
|
|
|
{
|
|
|
|
if ([userTimeZone isDaylightSavingTimeForDate: aStartDate] !=
|
|
|
|
[userTimeZone isDaylightSavingTimeForDate: aDate])
|
|
|
|
{
|
|
|
|
// For the event's recurrence id, compute the daylight saving time
|
|
|
|
// offset with respect to the first occurrence of the recurring event.
|
|
|
|
daylightOffset = (signed int)[userTimeZone secondsFromGMTForDate: aStartDate]
|
|
|
|
- (signed int)[userTimeZone secondsFromGMTForDate: aDate];
|
|
|
|
aDateValue = [NSNumber numberWithInt: [aDateValue intValue] + daylightOffset];
|
|
|
|
[aRecord setObject: aDateValue forKey: @"c_recurrence_id"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
- (NSArray *) _fetchFields: (NSArray *) fields
|
|
|
|
forComponentOfType: (NSString *) component
|
|
|
|
{
|
|
|
|
NSEnumerator *folders, *currentInfos;
|
|
|
|
SOGoAppointmentFolder *currentFolder;
|
2007-10-09 19:19:20 +02:00
|
|
|
NSMutableDictionary *newInfo;
|
|
|
|
NSMutableArray *infos;
|
2007-06-07 22:49:06 +02:00
|
|
|
NSNull *marker;
|
2007-09-15 00:01:02 +02:00
|
|
|
SOGoAppointmentFolders *clientObject;
|
2009-07-22 21:35:37 +02:00
|
|
|
NSString *role;
|
2007-06-07 22:49:06 +02:00
|
|
|
|
2008-12-31 18:43:20 +01:00
|
|
|
infos = [NSMutableArray array];
|
2007-06-07 22:49:06 +02:00
|
|
|
marker = [NSNull null];
|
2007-11-26 18:40:44 +01:00
|
|
|
clientObject = [self clientObject];
|
2007-09-15 00:01:02 +02:00
|
|
|
|
|
|
|
folders = [[clientObject subFolders] objectEnumerator];
|
2008-12-31 18:43:20 +01:00
|
|
|
while ((currentFolder = [folders nextObject]))
|
2007-06-07 22:49:06 +02:00
|
|
|
{
|
2009-08-18 18:22:20 +02:00
|
|
|
if ([currentFolder isActive]
|
|
|
|
&& (![component isEqualToString: @"vtodo"] || [currentFolder showCalendarTasks]))
|
2009-07-21 20:06:55 +02:00
|
|
|
{
|
2009-08-18 18:22:20 +02:00
|
|
|
currentInfos
|
|
|
|
= [[currentFolder fetchCoreInfosFrom: startDate
|
|
|
|
to: endDate
|
|
|
|
title: title
|
|
|
|
component: component] objectEnumerator];
|
2009-07-22 20:47:27 +02:00
|
|
|
|
2009-08-18 18:22:20 +02:00
|
|
|
while ((newInfo = [currentInfos nextObject]))
|
|
|
|
{
|
|
|
|
if ([fields containsObject: @"editable"])
|
2009-07-22 20:47:27 +02:00
|
|
|
{
|
2009-08-18 18:22:20 +02:00
|
|
|
role =
|
|
|
|
[currentFolder roleForComponentsWithAccessClass:
|
|
|
|
[[newInfo objectForKey: @"c_classification"] intValue]
|
|
|
|
forUser: userLogin];
|
|
|
|
if ([role isEqualToString: @"ComponentModifier"]
|
|
|
|
|| [role length] == 0)
|
|
|
|
[newInfo setObject: [NSNumber numberWithInt: 1]
|
|
|
|
forKey: @"editable"];
|
|
|
|
else
|
|
|
|
[newInfo setObject: [NSNumber numberWithInt: 0]
|
|
|
|
forKey: @"editable"];
|
2009-07-22 20:47:27 +02:00
|
|
|
}
|
2009-08-18 18:22:20 +02:00
|
|
|
[newInfo setObject: [currentFolder nameInContainer]
|
|
|
|
forKey: @"c_folder"];
|
|
|
|
[newInfo setObject: [currentFolder ownerInContext: context]
|
|
|
|
forKey: @"c_owner"];
|
|
|
|
if (![[newInfo objectForKey: @"c_title"] length])
|
|
|
|
[self _fixComponentTitle: newInfo withType: component];
|
|
|
|
// Possible improvement: only call _fixDates if event is recurrent
|
|
|
|
// or the view range span a daylight saving time change
|
|
|
|
[self _fixDates: newInfo];
|
|
|
|
[infos addObject: [newInfo objectsForKeys: fields
|
|
|
|
notFoundMarker: marker]];
|
2009-07-22 20:47:27 +02:00
|
|
|
}
|
2009-07-21 20:06:55 +02:00
|
|
|
}
|
2007-06-07 22:49:06 +02:00
|
|
|
}
|
|
|
|
|
2007-10-09 19:19:20 +02:00
|
|
|
return infos;
|
2007-06-07 22:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) _responseWithData: (NSArray *) data
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
2007-09-11 21:36:40 +02:00
|
|
|
response = [self responseWithStatus: 200];
|
2007-06-07 22:49:06 +02:00
|
|
|
[response appendContentString: [data jsonRepresentation]];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-06-19 20:08:16 +02:00
|
|
|
- (NSString *) _formattedDateForSeconds: (unsigned int) seconds
|
|
|
|
forAllDay: (BOOL) forAllDay
|
|
|
|
{
|
|
|
|
NSCalendarDate *date;
|
|
|
|
NSString *formattedDate;
|
|
|
|
|
|
|
|
date = [NSCalendarDate dateWithTimeIntervalSince1970: seconds];
|
2008-11-07 19:56:03 +01:00
|
|
|
// Adjust for daylight saving time? (wrt to startDate)
|
2007-06-19 20:08:16 +02:00
|
|
|
[date setTimeZone: userTimeZone];
|
|
|
|
if (forAllDay)
|
|
|
|
formattedDate = [dateFormatter formattedDate: date];
|
|
|
|
else
|
|
|
|
formattedDate = [dateFormatter formattedDateAndTime: date];
|
|
|
|
|
|
|
|
return formattedDate;
|
|
|
|
}
|
|
|
|
|
2009-04-21 17:20:52 +02:00
|
|
|
//
|
|
|
|
// We return:
|
|
|
|
//
|
2009-04-22 23:02:11 +02:00
|
|
|
// [[calendar name (full path), complete Event ID (full path), Fire date (UTC)], ..]
|
2009-04-21 17:20:52 +02:00
|
|
|
//
|
|
|
|
// Called when each module is loaded or whenever a calendar component is created, modified, deleted
|
|
|
|
// or whenever there's a {un}subscribe to a calendar.
|
|
|
|
//
|
|
|
|
// Workflow :
|
|
|
|
//
|
|
|
|
// - for ALL subscribed and ACTIVE calendars
|
2009-04-22 23:02:11 +02:00
|
|
|
// - returns alarms that will occur in the next 48 hours or the non-triggered alarms
|
|
|
|
// for non-completed events
|
|
|
|
// - recurring events are currently ignored
|
2009-04-21 17:20:52 +02:00
|
|
|
//
|
|
|
|
- (WOResponse *) alarmsListAction
|
|
|
|
{
|
|
|
|
SOGoAppointmentFolder *currentFolder;
|
|
|
|
SOGoAppointmentFolders *clientObject;
|
|
|
|
NSMutableArray *allAlarms;
|
|
|
|
NSEnumerator *folders;
|
|
|
|
WOResponse *response;
|
2009-04-22 23:02:11 +02:00
|
|
|
unsigned int browserTime, laterTime;
|
2009-04-21 17:20:52 +02:00
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
// We look for alarms in the next 48 hours
|
2009-04-21 17:20:52 +02:00
|
|
|
browserTime = [[[context request] formValueForKey: @"browserTime"] intValue];
|
2009-04-22 23:02:11 +02:00
|
|
|
laterTime = browserTime + 60*60*48;
|
2009-04-21 17:20:52 +02:00
|
|
|
clientObject = [self clientObject];
|
|
|
|
allAlarms = [NSMutableArray array];
|
|
|
|
|
|
|
|
folders = [[clientObject subFolders] objectEnumerator];
|
|
|
|
while ((currentFolder = [folders nextObject]))
|
|
|
|
{
|
2009-07-21 20:06:55 +02:00
|
|
|
if ([currentFolder isActive] && [currentFolder showCalendarAlarms])
|
2009-04-21 17:20:52 +02:00
|
|
|
{
|
2009-04-22 23:02:11 +02:00
|
|
|
NSDictionary *entry;
|
2009-04-21 17:20:52 +02:00
|
|
|
NSArray *alarms;
|
2009-04-22 23:02:11 +02:00
|
|
|
BOOL isCycle;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
alarms = [currentFolder fetchAlarmInfosFrom: [NSNumber numberWithInt: browserTime]
|
|
|
|
to: [NSNumber numberWithInt: laterTime]];
|
|
|
|
|
2009-04-21 17:20:52 +02:00
|
|
|
for (i = 0; i < [alarms count]; i++)
|
|
|
|
{
|
|
|
|
entry = [alarms objectAtIndex: i];
|
2009-04-22 23:02:11 +02:00
|
|
|
isCycle = [[entry objectForKey: @"c_iscycle"] boolValue];
|
|
|
|
|
|
|
|
if (!isCycle)
|
2009-04-21 17:20:52 +02:00
|
|
|
{
|
2009-04-22 23:02:11 +02:00
|
|
|
[allAlarms addObject: [NSArray arrayWithObjects:
|
|
|
|
[currentFolder nameInContainer],
|
|
|
|
[entry objectForKey: @"c_name"],
|
|
|
|
[entry objectForKey: @"c_nextalarm"],
|
|
|
|
nil]];
|
2009-04-21 17:20:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-22 23:02:11 +02:00
|
|
|
|
|
|
|
|
2009-04-21 17:20:52 +02:00
|
|
|
response = [self responseWithStatus: 200];
|
|
|
|
[response appendContentString: [allAlarms jsonRepresentation]];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
- (WOResponse *) eventsListAction
|
|
|
|
{
|
2008-07-16 23:48:54 +02:00
|
|
|
NSArray *oldEvent;
|
2007-06-11 23:28:28 +02:00
|
|
|
NSEnumerator *events;
|
|
|
|
NSMutableArray *newEvents, *newEvent;
|
2008-07-16 23:48:54 +02:00
|
|
|
unsigned int interval;
|
2007-06-19 20:08:16 +02:00
|
|
|
BOOL isAllDay;
|
2008-07-16 23:48:54 +02:00
|
|
|
NSString *sort, *ascending;
|
2007-06-07 22:49:06 +02:00
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
|
2007-06-11 23:28:28 +02:00
|
|
|
newEvents = [NSMutableArray array];
|
2008-07-16 04:12:18 +02:00
|
|
|
events = [[self _fetchFields: eventsFields
|
2007-06-11 23:28:28 +02:00
|
|
|
forComponentOfType: @"vevent"] objectEnumerator];
|
2008-07-16 04:12:18 +02:00
|
|
|
while ((oldEvent = [events nextObject]))
|
2007-06-11 23:28:28 +02:00
|
|
|
{
|
|
|
|
newEvent = [NSMutableArray arrayWithArray: oldEvent];
|
2007-06-19 20:08:16 +02:00
|
|
|
isAllDay = [[oldEvent objectAtIndex: 7] boolValue];
|
2007-06-11 23:28:28 +02:00
|
|
|
interval = [[oldEvent objectAtIndex: 4] intValue];
|
2007-06-19 20:08:16 +02:00
|
|
|
[newEvent addObject: [self _formattedDateForSeconds: interval
|
|
|
|
forAllDay: isAllDay]];
|
2007-06-11 23:28:28 +02:00
|
|
|
interval = [[oldEvent objectAtIndex: 5] intValue];
|
2007-06-19 20:08:16 +02:00
|
|
|
[newEvent addObject: [self _formattedDateForSeconds: interval
|
|
|
|
forAllDay: isAllDay]];
|
2007-06-11 23:28:28 +02:00
|
|
|
[newEvents addObject: newEvent];
|
|
|
|
}
|
2007-12-06 18:29:32 +01:00
|
|
|
|
|
|
|
sort = [[context request] formValueForKey: @"sort"];
|
|
|
|
if ([sort isEqualToString: @"title"])
|
|
|
|
[newEvents sortUsingSelector: @selector (compareEventsTitleAscending:)];
|
|
|
|
else if ([sort isEqualToString: @"end"])
|
|
|
|
[newEvents sortUsingSelector: @selector (compareEventsEndDateAscending:)];
|
|
|
|
else if ([sort isEqualToString: @"location"])
|
|
|
|
[newEvents sortUsingSelector: @selector (compareEventsLocationAscending:)];
|
|
|
|
else
|
|
|
|
[newEvents sortUsingSelector: @selector (compareEventsStartDateAscending:)];
|
2008-07-16 04:12:18 +02:00
|
|
|
|
2007-12-06 18:29:32 +01:00
|
|
|
ascending = [[context request] formValueForKey: @"asc"];
|
|
|
|
if (![ascending boolValue])
|
2007-12-17 16:29:06 +01:00
|
|
|
[newEvents reverseArray];
|
2007-06-07 22:49:06 +02:00
|
|
|
|
2007-06-11 23:28:28 +02:00
|
|
|
return [self _responseWithData: newEvents];
|
2007-06-07 22:49:06 +02:00
|
|
|
}
|
|
|
|
|
2008-07-16 04:12:18 +02:00
|
|
|
static inline void
|
|
|
|
_feedBlockWithDayBasedData(NSMutableDictionary *block, unsigned int start,
|
|
|
|
unsigned int end, unsigned int dayStart)
|
|
|
|
{
|
2008-12-30 21:20:41 +01:00
|
|
|
unsigned int delta, quarterStart, length, swap;
|
|
|
|
|
|
|
|
if (start > end)
|
|
|
|
{
|
|
|
|
swap = end;
|
|
|
|
end = start;
|
|
|
|
start = swap;
|
|
|
|
}
|
2008-07-16 04:12:18 +02:00
|
|
|
quarterStart = (start - dayStart) / quarterLength;
|
|
|
|
delta = end - dayStart;
|
|
|
|
if ((delta % quarterLength))
|
|
|
|
delta += quarterLength;
|
|
|
|
length = (delta / quarterLength) - quarterStart;
|
|
|
|
if (!length)
|
|
|
|
length = 1;
|
|
|
|
[block setObject: [NSNumber numberWithUnsignedInt: quarterStart]
|
|
|
|
forKey: @"start"];
|
|
|
|
[block setObject: [NSNumber numberWithUnsignedInt: length]
|
|
|
|
forKey: @"length"];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
_feedBlockWithMonthBasedData(NSMutableDictionary *block, unsigned int start,
|
|
|
|
NSTimeZone *userTimeZone,
|
|
|
|
SOGoDateFormatter *dateFormatter)
|
|
|
|
{
|
|
|
|
NSCalendarDate *eventStartDate;
|
|
|
|
NSString *startHour;
|
|
|
|
|
|
|
|
eventStartDate = [NSCalendarDate dateWithTimeIntervalSince1970: start];
|
|
|
|
[eventStartDate setTimeZone: userTimeZone];
|
|
|
|
startHour = [dateFormatter formattedTime: eventStartDate];
|
|
|
|
[block setObject: startHour forKey: @"starthour"];
|
|
|
|
[block setObject: [NSNumber numberWithUnsignedInt: start]
|
|
|
|
forKey: @"start"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableDictionary *) _eventBlockWithStart: (unsigned int) start
|
|
|
|
end: (unsigned int) end
|
2008-07-29 18:35:49 +02:00
|
|
|
number: (NSNumber *) number
|
2008-07-16 04:12:18 +02:00
|
|
|
onDay: (unsigned int) dayStart
|
2008-07-17 23:12:43 +02:00
|
|
|
recurrenceTime: (unsigned int) recurrenceTime
|
2008-07-16 23:48:54 +02:00
|
|
|
userState: (iCalPersonPartStat) userState
|
2008-07-16 04:12:18 +02:00
|
|
|
{
|
|
|
|
NSMutableDictionary *block;
|
|
|
|
|
|
|
|
block = [NSMutableDictionary dictionary];
|
|
|
|
|
|
|
|
if (dayBasedView)
|
|
|
|
_feedBlockWithDayBasedData (block, start, end, dayStart);
|
|
|
|
else
|
|
|
|
_feedBlockWithMonthBasedData (block, start, userTimeZone, dateFormatter);
|
2008-07-29 18:35:49 +02:00
|
|
|
[block setObject: number forKey: @"nbr"];
|
2008-07-17 23:12:43 +02:00
|
|
|
if (recurrenceTime)
|
|
|
|
[block setObject: [NSNumber numberWithInt: recurrenceTime]
|
|
|
|
forKey: @"recurrenceTime"];
|
2008-07-16 23:48:54 +02:00
|
|
|
if (userState != iCalPersonPartStatOther)
|
|
|
|
[block setObject: [NSNumber numberWithInt: userState]
|
|
|
|
forKey: @"userState"];
|
2008-07-16 04:12:18 +02:00
|
|
|
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
2008-07-16 23:48:54 +02:00
|
|
|
static inline iCalPersonPartStat
|
|
|
|
_userStateInEvent (NSArray *event)
|
|
|
|
{
|
|
|
|
unsigned int count, max;
|
|
|
|
iCalPersonPartStat state;
|
|
|
|
NSString *partList, *stateList;
|
|
|
|
NSArray *participants, *states;
|
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
participants = nil;
|
|
|
|
state = iCalPersonPartStatOther;
|
|
|
|
|
|
|
|
partList = [event objectAtIndex: 9];
|
|
|
|
stateList = [event objectAtIndex: 10];
|
|
|
|
if ([partList length] && [stateList length])
|
|
|
|
{
|
|
|
|
participants = [partList componentsSeparatedByString: @"\n"];
|
|
|
|
states = [stateList componentsSeparatedByString: @"\n"];
|
|
|
|
count = 0;
|
|
|
|
max = [participants count];
|
|
|
|
while (state == iCalPersonPartStatOther && count < max)
|
|
|
|
{
|
|
|
|
user = [SOGoUser userWithLogin: [event objectAtIndex: 11]
|
|
|
|
roles: nil];
|
|
|
|
if ([user hasEmail: [participants objectAtIndex: count]])
|
|
|
|
state = [[states objectAtIndex: count] intValue];
|
|
|
|
else
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2008-07-16 04:12:18 +02:00
|
|
|
- (void) _fillBlocks: (NSArray *) blocks
|
|
|
|
withEvent: (NSArray *) event
|
2008-07-29 18:35:49 +02:00
|
|
|
withNumber: (NSNumber *) number
|
2008-07-16 04:12:18 +02:00
|
|
|
{
|
2009-07-03 21:46:01 +02:00
|
|
|
int currentDayStart, startSecs, endsSecs, currentStart, eventStart,
|
2008-07-17 23:12:43 +02:00
|
|
|
eventEnd, offset, recurrenceTime;
|
2008-07-16 04:12:18 +02:00
|
|
|
NSMutableArray *currentDay;
|
|
|
|
NSMutableDictionary *eventBlock;
|
2008-07-16 23:48:54 +02:00
|
|
|
iCalPersonPartStat userState;
|
2008-07-16 04:12:18 +02:00
|
|
|
|
2009-07-03 21:46:01 +02:00
|
|
|
eventStart = [[event objectAtIndex: 4] intValue];
|
|
|
|
if (eventStart < 0)
|
|
|
|
[self errorWithFormat: @"event '%@' has negative start: %d (skipped)",
|
|
|
|
[event objectAtIndex: 0], eventStart];
|
2008-07-16 04:12:18 +02:00
|
|
|
else
|
|
|
|
{
|
2009-07-03 21:46:01 +02:00
|
|
|
eventEnd = [[event objectAtIndex: 5] intValue];
|
|
|
|
if (eventEnd < 0)
|
|
|
|
[self errorWithFormat: @"event '%@' has negative end: %d (skipped)",
|
|
|
|
[event objectAtIndex: 0], eventEnd];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (eventEnd < eventStart)
|
|
|
|
[self warnWithFormat: @"event '%@' has end < start: %d < %d",
|
|
|
|
[event objectAtIndex: 0], eventEnd, eventStart];
|
|
|
|
|
|
|
|
startSecs = (unsigned int) [startDate timeIntervalSince1970];
|
|
|
|
endsSecs = (unsigned int) [endDate timeIntervalSince1970];
|
|
|
|
|
|
|
|
if ([[event objectAtIndex: 12] boolValue]) // c_iscycle
|
|
|
|
recurrenceTime = [[event objectAtIndex: 14] unsignedIntValue]; // c_recurrence_id
|
|
|
|
else
|
|
|
|
recurrenceTime = 0;
|
|
|
|
|
|
|
|
currentStart = eventStart;
|
|
|
|
if (currentStart < startSecs)
|
|
|
|
{
|
|
|
|
currentStart = startSecs;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
offset = ((currentStart - startSecs)
|
|
|
|
/ dayLength);
|
|
|
|
if (offset >= [blocks count])
|
|
|
|
[self errorWithFormat: "event '%@' has a computed offset that"
|
|
|
|
@" overflows the amount of blocks (skipped)",
|
|
|
|
[event objectAtIndex: 0]];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentDay = [blocks objectAtIndex: offset];
|
|
|
|
currentDayStart = startSecs + dayLength * offset;
|
|
|
|
|
|
|
|
if (eventEnd > endsSecs)
|
|
|
|
eventEnd = endsSecs;
|
|
|
|
|
|
|
|
userState = _userStateInEvent (event);
|
|
|
|
while (currentDayStart + dayLength < eventEnd)
|
|
|
|
{
|
|
|
|
eventBlock = [self _eventBlockWithStart: currentStart
|
|
|
|
end: currentDayStart + dayLength - 1
|
|
|
|
number: number
|
|
|
|
onDay: currentDayStart
|
|
|
|
recurrenceTime: recurrenceTime
|
|
|
|
userState: userState];
|
|
|
|
[currentDay addObject: eventBlock];
|
|
|
|
currentDayStart += dayLength;
|
|
|
|
currentStart = currentDayStart;
|
|
|
|
offset++;
|
|
|
|
currentDay = [blocks objectAtIndex: offset];
|
|
|
|
}
|
|
|
|
eventBlock = [self _eventBlockWithStart: currentStart
|
|
|
|
end: eventEnd
|
|
|
|
number: number
|
|
|
|
onDay: currentDayStart
|
|
|
|
recurrenceTime: recurrenceTime
|
|
|
|
userState: userState];
|
|
|
|
[currentDay addObject: eventBlock];
|
|
|
|
}
|
|
|
|
}
|
2008-07-16 04:12:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _prepareEventBlocks: (NSMutableArray **) blocks
|
|
|
|
withAllDays: (NSMutableArray **) allDayBlocks
|
|
|
|
{
|
|
|
|
unsigned int count, nbrDays;
|
|
|
|
int seconds;
|
|
|
|
|
|
|
|
seconds = [endDate timeIntervalSinceDate: startDate];
|
|
|
|
if (seconds > 0)
|
|
|
|
{
|
|
|
|
nbrDays = 1 + (unsigned int) (seconds / dayLength);
|
|
|
|
*blocks = [NSMutableArray arrayWithCapacity: nbrDays];
|
|
|
|
*allDayBlocks = [NSMutableArray arrayWithCapacity: nbrDays];
|
|
|
|
for (count = 0; count < nbrDays; count++)
|
|
|
|
{
|
|
|
|
[*blocks addObject: [NSMutableArray array]];
|
|
|
|
[*allDayBlocks addObject: [NSMutableArray array]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*blocks = nil;
|
|
|
|
*allDayBlocks = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _horizontalBlocks: (NSMutableArray *) day
|
|
|
|
{
|
|
|
|
NSMutableArray *quarters[96];
|
|
|
|
NSMutableArray *currentBlock, *blocks;
|
|
|
|
NSDictionary *currentEvent;
|
|
|
|
unsigned int count, max, qCount, qMax, qOffset;
|
|
|
|
|
|
|
|
blocks = [NSMutableArray array];
|
|
|
|
|
|
|
|
bzero (quarters, 96 * sizeof (NSMutableArray *));
|
|
|
|
|
|
|
|
max = [day count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
currentEvent = [day objectAtIndex: count];
|
|
|
|
qMax = [[currentEvent objectForKey: @"length"] unsignedIntValue];
|
|
|
|
qOffset = [[currentEvent objectForKey: @"start"] unsignedIntValue];
|
|
|
|
for (qCount = 0; qCount < qMax; qCount++)
|
|
|
|
{
|
|
|
|
currentBlock = quarters[qCount + qOffset];
|
|
|
|
if (!currentBlock)
|
|
|
|
{
|
|
|
|
currentBlock = [NSMutableArray array];
|
|
|
|
quarters[qCount + qOffset] = currentBlock;
|
|
|
|
[blocks addObject: currentBlock];
|
|
|
|
}
|
|
|
|
[currentBlock addObject: currentEvent];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return blocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
_computeMaxBlockSiblings (NSArray *block)
|
|
|
|
{
|
|
|
|
unsigned int count, max, maxSiblings, siblings;
|
|
|
|
NSNumber *nbrEvents;
|
|
|
|
|
|
|
|
max = [block count];
|
|
|
|
maxSiblings = max;
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
nbrEvents = [[block objectAtIndex: count] objectForKey: @"siblings"];
|
|
|
|
if (nbrEvents)
|
|
|
|
{
|
|
|
|
siblings = [nbrEvents unsignedIntValue];
|
|
|
|
if (siblings > maxSiblings)
|
|
|
|
maxSiblings = siblings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return maxSiblings;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
_propagateBlockSiblings (NSArray *block, NSNumber *maxSiblings)
|
|
|
|
{
|
|
|
|
unsigned int count, max;
|
|
|
|
NSMutableDictionary *event;
|
|
|
|
NSNumber *realSiblings;
|
|
|
|
|
|
|
|
max = [block count];
|
|
|
|
realSiblings = [NSNumber numberWithUnsignedInt: max];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
event = [block objectAtIndex: count];
|
|
|
|
[event setObject: maxSiblings forKey: @"siblings"];
|
|
|
|
[event setObject: realSiblings forKey: @"realSiblings"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this requires two vertical passes */
|
|
|
|
static inline void
|
|
|
|
_computeBlocksSiblings (NSArray *blocks)
|
|
|
|
{
|
|
|
|
NSArray *currentBlock;
|
|
|
|
unsigned int count, max, maxSiblings;
|
|
|
|
|
|
|
|
max = [blocks count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
currentBlock = [blocks objectAtIndex: count];
|
|
|
|
maxSiblings = _computeMaxBlockSiblings (currentBlock);
|
|
|
|
_propagateBlockSiblings (currentBlock,
|
|
|
|
[NSNumber numberWithUnsignedInt: maxSiblings]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
_computeBlockPosition (NSArray *block)
|
|
|
|
{
|
|
|
|
unsigned int count, max, j, siblings;
|
|
|
|
NSNumber *position;
|
|
|
|
NSMutableDictionary *event;
|
|
|
|
NSMutableDictionary **positions;
|
|
|
|
|
|
|
|
max = [block count];
|
|
|
|
event = [block objectAtIndex: 0];
|
|
|
|
siblings = [[event objectForKey: @"siblings"] unsignedIntValue];
|
2009-06-04 01:06:52 +02:00
|
|
|
positions = NSZoneCalloc (NULL, siblings, sizeof (NSMutableDictionary *));
|
2008-07-16 04:12:18 +02:00
|
|
|
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
event = [block objectAtIndex: count];
|
|
|
|
position = [event objectForKey: @"position"];
|
|
|
|
if (position)
|
|
|
|
*(positions + [position unsignedIntValue]) = event;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
j = 0;
|
|
|
|
while (j < max && *(positions + j))
|
|
|
|
j++;
|
|
|
|
*(positions + j) = event;
|
|
|
|
[event setObject: [NSNumber numberWithUnsignedInt: j]
|
|
|
|
forKey: @"position"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-04 01:06:52 +02:00
|
|
|
NSZoneFree (NULL, positions);
|
2008-07-16 04:12:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static inline void
|
|
|
|
// _addBlockMultipliers (NSArray *block, NSMutableDictionary **positions)
|
|
|
|
// {
|
|
|
|
// unsigned int count, max, limit, multiplier;
|
|
|
|
// NSMutableDictionary *currentEvent, *event;
|
|
|
|
|
|
|
|
// max = [block count];
|
|
|
|
// event = [block objectAtIndex: 0];
|
|
|
|
// limit = [[event objectForKey: @"siblings"] unsignedIntValue];
|
|
|
|
|
|
|
|
// if (max < limit)
|
|
|
|
// {
|
|
|
|
// currentEvent = nil;
|
|
|
|
// for (count = 0; count < limit; count++)
|
|
|
|
// {
|
|
|
|
// multiplier = 1;
|
|
|
|
// event = positions[count];
|
|
|
|
// if ([[event objectForKey: @"realSiblings"] unsignedIntValue]
|
|
|
|
// < limit)
|
|
|
|
// {
|
|
|
|
// if (event)
|
|
|
|
// {
|
|
|
|
// if (currentEvent && multiplier > 1)
|
|
|
|
// [currentEvent setObject: [NSNumber numberWithUnsignedInt: multiplier]
|
|
|
|
// forKey: @"multiplier"];
|
|
|
|
// currentEvent = event;
|
|
|
|
// multiplier = 1;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// multiplier++;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
_computeBlocksPosition (NSArray *blocks)
|
|
|
|
{
|
|
|
|
NSArray *block;
|
|
|
|
unsigned int count, max;
|
|
|
|
// NSMutableDictionary **positions;
|
|
|
|
|
|
|
|
max = [blocks count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
block = [blocks objectAtIndex: count];
|
|
|
|
_computeBlockPosition (block);
|
|
|
|
// _addBlockMultipliers (block, positions);
|
2009-06-04 01:06:52 +02:00
|
|
|
// NSZoneFree (NULL, positions);
|
2008-07-16 04:12:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _addBlocksWidth: (NSMutableArray *) day
|
|
|
|
{
|
|
|
|
NSArray *blocks;
|
|
|
|
|
|
|
|
blocks = [self _horizontalBlocks: day];
|
|
|
|
_computeBlocksSiblings (blocks);
|
|
|
|
_computeBlocksSiblings (blocks);
|
|
|
|
_computeBlocksPosition (blocks);
|
|
|
|
/* ... _computeBlocksMultiplier() ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) eventsBlocksAction
|
|
|
|
{
|
|
|
|
int count, max;
|
|
|
|
NSArray *events, *event, *eventsBlocks;
|
|
|
|
NSMutableArray *allDayBlocks, *blocks, *currentDay;
|
2008-07-29 18:35:49 +02:00
|
|
|
NSNumber *eventNbr;
|
2008-07-16 04:12:18 +02:00
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
|
|
|
|
[self _prepareEventBlocks: &blocks withAllDays: &allDayBlocks];
|
|
|
|
events = [self _fetchFields: eventsFields
|
|
|
|
forComponentOfType: @"vevent"];
|
|
|
|
eventsBlocks
|
|
|
|
= [NSArray arrayWithObjects: events, allDayBlocks, blocks, nil];
|
|
|
|
max = [events count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
event = [events objectAtIndex: count];
|
2008-07-29 18:35:49 +02:00
|
|
|
eventNbr = [NSNumber numberWithUnsignedInt: count];
|
2008-07-16 04:12:18 +02:00
|
|
|
if (dayBasedView && [[event objectAtIndex: 7] boolValue])
|
2009-03-19 17:49:36 +01:00
|
|
|
[self _fillBlocks: allDayBlocks withEvent: event withNumber: eventNbr];
|
2008-07-16 04:12:18 +02:00
|
|
|
else
|
2008-07-29 18:35:49 +02:00
|
|
|
[self _fillBlocks: blocks withEvent: event withNumber: eventNbr];
|
2008-07-16 04:12:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
max = [blocks count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
currentDay = [blocks objectAtIndex: count];
|
|
|
|
[currentDay sortUsingSelector: @selector (compareEventByStart:)];
|
|
|
|
[self _addBlocksWidth: currentDay];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self _responseWithData: eventsBlocks];
|
|
|
|
// timeIntervalSinceDate:
|
|
|
|
}
|
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
- (NSString *) _getStatusClassForStatusCode: (int) statusCode
|
|
|
|
andEndDateStamp: (unsigned int) endDateStamp
|
|
|
|
{
|
|
|
|
NSCalendarDate *taskDate, *now;
|
|
|
|
NSString *statusClass;
|
|
|
|
|
|
|
|
if (statusCode == 1)
|
|
|
|
statusClass = @"completed";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (endDateStamp)
|
|
|
|
{
|
|
|
|
now = [NSCalendarDate calendarDate];
|
|
|
|
taskDate
|
|
|
|
= [NSCalendarDate dateWithTimeIntervalSince1970: endDateStamp];
|
|
|
|
if ([taskDate earlierDate: now] == taskDate)
|
|
|
|
statusClass = @"overdue";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([taskDate isToday])
|
|
|
|
statusClass = @"duetoday";
|
|
|
|
else
|
|
|
|
statusClass = @"duelater";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
statusClass = @"duelater";
|
|
|
|
}
|
|
|
|
|
|
|
|
return statusClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) tasksListAction
|
|
|
|
{
|
2009-08-17 22:07:54 +02:00
|
|
|
NSUserDefaults *ud;
|
2007-06-07 22:49:06 +02:00
|
|
|
NSEnumerator *tasks;
|
|
|
|
NSMutableArray *filteredTasks, *filteredTask;
|
2009-08-17 22:07:54 +02:00
|
|
|
BOOL showCompleted, setUserDefault;
|
2008-07-16 04:12:18 +02:00
|
|
|
NSArray *task;
|
2007-06-07 22:49:06 +02:00
|
|
|
int statusCode;
|
|
|
|
unsigned int endDateStamp;
|
|
|
|
NSString *statusFlag;
|
|
|
|
|
|
|
|
filteredTasks = [NSMutableArray array];
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
|
2008-07-16 04:12:18 +02:00
|
|
|
tasks = [[self _fetchFields: tasksFields
|
2007-06-07 22:49:06 +02:00
|
|
|
forComponentOfType: @"vtodo"] objectEnumerator];
|
|
|
|
showCompleted = [[request formValueForKey: @"show-completed"] intValue];
|
2009-08-17 22:07:54 +02:00
|
|
|
setUserDefault = [[request formValueForKey: @"setud"] intValue];
|
|
|
|
if (setUserDefault)
|
|
|
|
{
|
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
[ud setObject: [NSNumber numberWithInt: showCompleted]
|
|
|
|
forKey: @"ShowCompletedTasks"];
|
|
|
|
[ud synchronize];
|
|
|
|
}
|
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
|
2009-08-18 18:22:20 +02:00
|
|
|
while ((task = [tasks nextObject]))
|
2007-06-07 22:49:06 +02:00
|
|
|
{
|
|
|
|
statusCode = [[task objectAtIndex: 2] intValue];
|
|
|
|
if (statusCode != 1 || showCompleted)
|
|
|
|
{
|
|
|
|
filteredTask = [NSMutableArray arrayWithArray: task];
|
|
|
|
endDateStamp = [[task objectAtIndex: 4] intValue];
|
|
|
|
statusFlag = [self _getStatusClassForStatusCode: statusCode
|
|
|
|
andEndDateStamp: endDateStamp];
|
|
|
|
[filteredTask addObject: statusFlag];
|
|
|
|
[filteredTasks addObject: filteredTask];
|
|
|
|
}
|
|
|
|
}
|
2007-06-13 21:33:31 +02:00
|
|
|
[filteredTasks sortUsingSelector: @selector (compareTasksAscending:)];
|
2007-06-07 22:49:06 +02:00
|
|
|
|
|
|
|
return [self _responseWithData: filteredTasks];
|
|
|
|
}
|
|
|
|
|
2009-06-04 16:57:50 +02:00
|
|
|
|
|
|
|
- (void) _fillFreeBusy: (unsigned int *) fb
|
|
|
|
forUid: (NSString *) uid
|
|
|
|
fromDate: (NSCalendarDate *) start
|
|
|
|
{
|
|
|
|
SOGoUser *user;
|
|
|
|
SOGoFreeBusyObject *fbObject;
|
|
|
|
NSCalendarDate *end;
|
|
|
|
NSTimeInterval interval;
|
|
|
|
NSArray *records;
|
|
|
|
NSDictionary *record;
|
|
|
|
NSArray *emails, *partstates;
|
|
|
|
NSCalendarDate *currentDate;
|
|
|
|
unsigned int intervals, recordCount, recordMax;
|
|
|
|
int count, startInterval, endInterval, i, type;
|
|
|
|
int itemCount = (offsetBlocks + maxBlocks) * 15 * 60;
|
|
|
|
|
|
|
|
user = [SOGoUser userWithLogin: uid roles: nil];
|
|
|
|
fbObject = [[user homeFolderInContext: context]
|
|
|
|
freeBusyObject: @"freebusy.ifb"
|
|
|
|
inContext: context];
|
|
|
|
|
|
|
|
end = [start addTimeInterval: itemCount];
|
|
|
|
|
|
|
|
interval = [end timeIntervalSinceDate: start];// + 60;
|
|
|
|
intervals = interval / intervalSeconds; /* slices of 15 minutes */
|
|
|
|
|
|
|
|
records = [fbObject fetchFreeBusyInfosFrom: start to: end];
|
|
|
|
recordMax = [records count];
|
|
|
|
|
|
|
|
for (recordCount = 0; recordCount < recordMax; recordCount++)
|
|
|
|
{
|
|
|
|
record = [records objectAtIndex: recordCount];
|
|
|
|
if ([[record objectForKey: @"c_isopaque"] boolValue])
|
|
|
|
{
|
|
|
|
type = 0;
|
|
|
|
|
|
|
|
// 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 ([[record objectForKey: @"c_orgmail"] length] == 0 ||
|
|
|
|
[user hasEmail: [record objectForKey: @"c_orgmail"]])
|
|
|
|
{
|
|
|
|
type = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We check if the user has accepted/declined or needs action
|
|
|
|
// on the current event.
|
|
|
|
emails = [[record 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 = [[record objectForKey: @"c_partstates"] componentsSeparatedByString: @"\n"];
|
|
|
|
|
|
|
|
if (i < [partstates count])
|
|
|
|
{
|
|
|
|
type = ([[partstates objectAtIndex: i] intValue] < 2 ? 1 : 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentDate = [record objectForKey: @"startDate"];
|
|
|
|
if ([currentDate earlierDate: start] == currentDate)
|
|
|
|
startInterval = 0;
|
|
|
|
else
|
|
|
|
startInterval = ([currentDate timeIntervalSinceDate: start]
|
|
|
|
/ intervalSeconds);
|
|
|
|
|
|
|
|
currentDate = [record objectForKey: @"endDate"];
|
|
|
|
if ([currentDate earlierDate: end] == end)
|
|
|
|
endInterval = itemCount - 1;
|
|
|
|
else
|
|
|
|
endInterval = ([currentDate timeIntervalSinceDate: start]
|
|
|
|
/ intervalSeconds);
|
|
|
|
|
|
|
|
if (type == 1)
|
|
|
|
for (count = startInterval; count < endInterval; count++)
|
|
|
|
*(fb + count) = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int **) _loadFreeBusyForUsers: (NSArray *) uids
|
|
|
|
fromDate: (NSCalendarDate *) start
|
|
|
|
{
|
|
|
|
unsigned int **fbData, **node, count;
|
|
|
|
|
|
|
|
fbData = calloc ([uids count], sizeof (unsigned int *));
|
|
|
|
for (count = 0; count < [uids count]; count++)
|
|
|
|
{
|
|
|
|
fbData[count] = calloc (offsetBlocks + maxBlocks, sizeof (unsigned int *));
|
|
|
|
node = fbData + count;
|
|
|
|
[self _fillFreeBusy: *node
|
|
|
|
forUid: [uids objectAtIndex: count]
|
|
|
|
fromDate: start];
|
|
|
|
}
|
|
|
|
|
|
|
|
return fbData;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) _possibleBlock: (int) block
|
|
|
|
forUsers: (int) users
|
|
|
|
freeBusy: (unsigned int **) fbData
|
|
|
|
interval: (int) blocks
|
|
|
|
{
|
|
|
|
unsigned int *node;
|
|
|
|
int bCount, uCount;
|
|
|
|
BOOL rc = YES;
|
|
|
|
|
|
|
|
for (uCount = 0; uCount < users; uCount++)
|
|
|
|
{
|
|
|
|
node = *(fbData + uCount);
|
|
|
|
for (bCount = block; bCount < block + blocks; bCount++)
|
|
|
|
{
|
|
|
|
if (*(node+bCount) != 0)
|
|
|
|
{
|
|
|
|
rc = NO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) _parseDateField: (NSString *) dateF
|
|
|
|
timeField: (NSString *) timeF
|
|
|
|
{
|
|
|
|
NSString *buffer;
|
|
|
|
NSCalendarDate *rc;
|
|
|
|
|
|
|
|
buffer = [NSString stringWithFormat: @"%@ %@",
|
|
|
|
[[context request] formValueForKey: dateF],
|
|
|
|
[[context request] formValueForKey: timeF]];
|
|
|
|
rc = [NSCalendarDate dateWithString: buffer
|
|
|
|
calendarFormat: @"%Y%m%d %H:%M"];
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableDictionary *) _makeValidResponseFrom: (NSCalendarDate *) nStart
|
|
|
|
to: (NSCalendarDate *) nEnd
|
|
|
|
{
|
|
|
|
NSMutableDictionary *rc;
|
|
|
|
|
|
|
|
rc = [NSMutableDictionary dictionaryWithCapacity: 512];
|
|
|
|
[rc setObject: [nStart descriptionWithCalendarFormat: @"%Y%m%d"]
|
|
|
|
forKey: @"startDate"];
|
|
|
|
[rc setObject: [nStart descriptionWithCalendarFormat: @"%H"]
|
|
|
|
forKey: @"startHour"];
|
|
|
|
[rc setObject: [nStart descriptionWithCalendarFormat: @"%M"]
|
|
|
|
forKey: @"startMinute"];
|
|
|
|
|
|
|
|
[rc setObject: [nEnd descriptionWithCalendarFormat: @"%Y%m%d"]
|
|
|
|
forKey: @"endDate"];
|
|
|
|
[rc setObject: [nEnd descriptionWithCalendarFormat: @"%H"]
|
|
|
|
forKey: @"endHour"];
|
|
|
|
[rc setObject: [nEnd descriptionWithCalendarFormat: @"%M"]
|
|
|
|
forKey: @"endMinute"];
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) _validateStart: (NSCalendarDate *) start
|
|
|
|
andEnd: (NSCalendarDate *) end
|
|
|
|
against: (NSArray *) limits
|
|
|
|
{
|
2009-06-04 20:50:23 +02:00
|
|
|
NSCalendarDate *sFrom, *sTo, *eFrom, *eTo;
|
2009-06-04 16:57:50 +02:00
|
|
|
BOOL rc = YES;
|
|
|
|
|
2009-06-04 20:50:23 +02:00
|
|
|
sFrom = [NSCalendarDate dateWithYear: [start yearOfCommonEra]
|
|
|
|
month: [start monthOfYear]
|
|
|
|
day: [start dayOfMonth]
|
|
|
|
hour: [[limits objectAtIndex: 0] hourOfDay]
|
|
|
|
minute: [[limits objectAtIndex: 0] minuteOfHour]
|
|
|
|
second: 0
|
|
|
|
timeZone: [start timeZone]];
|
|
|
|
sTo = [NSCalendarDate dateWithYear: [start yearOfCommonEra]
|
|
|
|
month: [start monthOfYear]
|
|
|
|
day: [start dayOfMonth]
|
|
|
|
hour: [[limits objectAtIndex: 1] hourOfDay]
|
|
|
|
minute: [[limits objectAtIndex: 1] minuteOfHour]
|
|
|
|
second: 0
|
|
|
|
timeZone: [start timeZone]];
|
|
|
|
|
|
|
|
eFrom = [NSCalendarDate dateWithYear: [end yearOfCommonEra]
|
|
|
|
month: [end monthOfYear]
|
|
|
|
day: [end dayOfMonth]
|
|
|
|
hour: [[limits objectAtIndex: 0] hourOfDay]
|
|
|
|
minute: [[limits objectAtIndex: 0] minuteOfHour]
|
|
|
|
second: 0
|
|
|
|
timeZone: [end timeZone]];
|
|
|
|
eTo = [NSCalendarDate dateWithYear: [end yearOfCommonEra]
|
|
|
|
month: [end monthOfYear]
|
|
|
|
day: [end dayOfMonth]
|
|
|
|
hour: [[limits objectAtIndex: 1] hourOfDay]
|
|
|
|
minute: [[limits objectAtIndex: 1] minuteOfHour]
|
|
|
|
second: 0
|
|
|
|
timeZone: [end timeZone]];
|
|
|
|
|
|
|
|
// start < sFrom
|
|
|
|
if ([sFrom compare: start] == NSOrderedDescending)
|
|
|
|
rc = NO;
|
|
|
|
// start > sTo
|
|
|
|
if ([sTo compare: start] == NSOrderedAscending)
|
|
|
|
rc = NO;
|
|
|
|
|
|
|
|
// end > eTo
|
|
|
|
if ([eTo compare: end] == NSOrderedAscending)
|
2009-06-04 16:57:50 +02:00
|
|
|
rc = NO;
|
2009-06-04 20:50:23 +02:00
|
|
|
// end < eFrom
|
|
|
|
if ([eFrom compare: end] == NSOrderedDescending)
|
2009-06-04 16:57:50 +02:00
|
|
|
rc = NO;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _loadScheduleLimitsForUsers: (NSArray *) users
|
|
|
|
{
|
2009-06-08 19:48:46 +02:00
|
|
|
NSUserDefaults *ud;
|
2009-06-04 16:57:50 +02:00
|
|
|
NSCalendarDate *from, *to, *maxFrom, *maxTo;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
maxFrom = [NSCalendarDate dateWithString: @"00:01"
|
|
|
|
calendarFormat: @"%H:%M"];
|
|
|
|
maxTo = [NSCalendarDate dateWithString: @"23:59"
|
|
|
|
calendarFormat: @"%H:%M"];
|
|
|
|
|
|
|
|
for (count = 0; count < [users count]; count++)
|
|
|
|
{
|
|
|
|
ud = [[SOGoUser userWithLogin: [users objectAtIndex: count]
|
2009-06-08 19:48:46 +02:00
|
|
|
roles: nil] userDefaults];
|
2009-06-04 16:57:50 +02:00
|
|
|
from = [NSCalendarDate dateWithString: [ud objectForKey: @"DayStartTime"]
|
|
|
|
calendarFormat: @"%H:%M"];
|
|
|
|
to = [NSCalendarDate dateWithString: [ud objectForKey: @"DayEndTime"]
|
|
|
|
calendarFormat: @"%H:%M"];
|
|
|
|
maxFrom = (NSCalendarDate *)[from laterDate: maxFrom];
|
|
|
|
maxTo = (NSCalendarDate *)[to earlierDate: maxTo];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [NSArray arrayWithObjects: maxFrom, maxTo, nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) findPossibleSlotAction
|
|
|
|
{
|
|
|
|
WORequest *r;
|
|
|
|
NSCalendarDate *nStart, *nEnd;
|
|
|
|
NSArray *uids, *limits;
|
|
|
|
NSMutableDictionary *rc;
|
2009-06-04 20:50:23 +02:00
|
|
|
int direction, count, blockDuration, step;
|
2009-06-04 16:57:50 +02:00
|
|
|
unsigned int **fbData;
|
2009-06-05 18:55:26 +02:00
|
|
|
BOOL isAllDay = NO, onlyOfficeHours = YES;
|
2009-06-04 16:57:50 +02:00
|
|
|
|
|
|
|
r = [context request];
|
|
|
|
rc = nil;
|
|
|
|
|
|
|
|
uids = [[r formValueForKey: @"uids"] componentsSeparatedByString: @","];
|
|
|
|
if ([uids count] > 0)
|
|
|
|
{
|
2009-06-04 20:50:23 +02:00
|
|
|
isAllDay = [[r formValueForKey: @"isAllDay"] boolValue];
|
2009-06-05 18:55:26 +02:00
|
|
|
onlyOfficeHours = [[r formValueForKey: @"onlyOfficeHours"] boolValue];
|
2009-06-04 20:50:23 +02:00
|
|
|
direction = [[r formValueForKey: @"direction"] intValue];
|
2009-06-04 16:57:50 +02:00
|
|
|
limits = [self _loadScheduleLimitsForUsers: uids];
|
|
|
|
|
2009-06-04 20:50:23 +02:00
|
|
|
if (isAllDay)
|
|
|
|
step = direction * 96;
|
|
|
|
else
|
|
|
|
step = direction;
|
|
|
|
|
2009-06-04 16:57:50 +02:00
|
|
|
nStart = [[self _parseDateField: @"startDate"
|
|
|
|
timeField: @"startTime"]
|
2009-06-04 20:50:23 +02:00
|
|
|
addTimeInterval: intervalSeconds * step];
|
2009-06-04 16:57:50 +02:00
|
|
|
nEnd = [[self _parseDateField: @"endDate"
|
|
|
|
timeField: @"endTime"]
|
2009-06-04 20:50:23 +02:00
|
|
|
addTimeInterval: intervalSeconds * step];
|
2009-06-04 16:57:50 +02:00
|
|
|
blockDuration = [nEnd timeIntervalSinceDate: nStart] / intervalSeconds;
|
|
|
|
|
|
|
|
fbData = [self _loadFreeBusyForUsers: uids
|
|
|
|
fromDate: [nStart addTimeInterval: -offsetSeconds]];
|
|
|
|
|
|
|
|
for (count = offsetBlocks;
|
|
|
|
(count < offsetBlocks + maxBlocks) && count >= 0;
|
2009-06-04 20:50:23 +02:00
|
|
|
count += step)
|
2009-06-04 16:57:50 +02:00
|
|
|
{
|
2009-06-04 20:50:23 +02:00
|
|
|
//NSLog (@"Trying %@ -> %@", nStart, nEnd);
|
2009-06-05 18:55:26 +02:00
|
|
|
if ((onlyOfficeHours && [self _validateStart: nStart
|
|
|
|
andEnd: nEnd
|
|
|
|
against: limits])
|
|
|
|
|| !onlyOfficeHours)
|
2009-06-04 16:57:50 +02:00
|
|
|
{
|
2009-06-04 20:50:23 +02:00
|
|
|
//NSLog (@"valid");
|
2009-06-04 16:57:50 +02:00
|
|
|
if ([self _possibleBlock: count
|
|
|
|
forUsers: [uids count]
|
|
|
|
freeBusy: fbData
|
|
|
|
interval: blockDuration])
|
|
|
|
{
|
2009-06-04 20:50:23 +02:00
|
|
|
//NSLog (@"possible");
|
2009-06-04 16:57:50 +02:00
|
|
|
rc = [self _makeValidResponseFrom: nStart
|
|
|
|
to: nEnd];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-06-04 20:50:23 +02:00
|
|
|
nStart = [nStart addTimeInterval: intervalSeconds * step];
|
|
|
|
nEnd = [nEnd addTimeInterval: intervalSeconds * step];
|
2009-06-04 16:57:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (count = 0; count < [uids count]; count++)
|
|
|
|
free (*(fbData+count));
|
|
|
|
free (fbData);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self _responseWithData: [NSArray arrayWithObjects: rc, nil]];
|
|
|
|
}
|
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
@end
|