return self;
}
-- (void) setCurrentTask: (NSDictionary *) task
+- (void) _updatePrivacyInObjects: (NSArray *) objectInfos
+ fromFolder: (SOGoAppointmentFolder *) folder
{
- currentTask = task;
+ int hideDetails[] = {-1, -1, -1};
+ NSMutableDictionary *currentRecord;
+ int privacyFlag;
+ NSString *roleString, *userLogin;
+ NSEnumerator *infos;
+
+ userLogin = [[context activeUser] login];
+ infos = [objectInfos objectEnumerator];
+ currentRecord = [infos nextObject];
+ while (currentRecord)
+ {
+ privacyFlag = [[currentRecord objectForKey: @"classification"] intValue];
+ if (hideDetails[privacyFlag] == -1)
+ {
+ roleString = [folder roleForComponentsWithAccessClass: privacyFlag
+ forUser: userLogin];
+ hideDetails[privacyFlag] = ([roleString isEqualToString: @"ComponentDAndTViewer"]
+ ? 1 : 0);
+ }
+ if (hideDetails[privacyFlag])
+ {
+ [currentRecord setObject: [self labelForKey: @"(Private Event)"]
+ forKey: @"title"];
+ [currentRecord setObject: @"" forKey: @"location"];
+ }
+ currentRecord = [infos nextObject];
+ }
}
-- (NSDictionary *) currentTask
+- (NSArray *) _fetchCoreInfosForComponent: (NSString *) component
{
- return currentTask;
-}
+ NSArray *currentInfos;
+ NSMutableArray *infos;
+ NSEnumerator *folders;
+ SOGoAppointmentFolder *currentFolder;
-- (NSCalendarDate *) startDate
-{
- return nil;
+ infos = [componentsData objectForKey: component];
+ if (!infos)
+ {
+ infos = [NSMutableArray array];
+ folders = [[self _activeCalendarFolders] objectEnumerator];
+ currentFolder = [folders nextObject];
+ while (currentFolder)
+ {
+ currentInfos = [currentFolder fetchCoreInfosFrom: [[self startDate] beginOfDay]
+ to: [[self endDate] endOfDay]
+ component: component];
+ [currentInfos makeObjectsPerform: @selector (setObject:forKey:)
+ withObject: [currentFolder ownerInContext: nil]
+ withObject: @"owner"];
+ [self _updatePrivacyInObjects: currentInfos
+ fromFolder: currentFolder];
+ [infos addObjectsFromArray: currentInfos];
+ currentFolder = [folders nextObject];
+ }
+ [componentsData setObject: infos forKey: component];
+ }
+
+ return infos;
}
-- (NSCalendarDate *) endDate
+- (NSArray *) fetchCoreAppointmentsInfos
{
- return nil;
+ if (!appointments)
+ [self setAppointments: [self _fetchCoreInfosForComponent: @"vevent"]];
+
+ return appointments;
}
-- (NSString *) currentStatusClass
+- (WOResponse *) tasksListAction
{
- NSCalendarDate *taskDate, *now;
- NSString *statusClass, *allClasses;
- NSNumber *taskDueStamp;
-
- if ([[currentTask objectForKey: @"status"] intValue] == 1)
- statusClass = @"completed";
- else
- {
- taskDueStamp = [currentTask objectForKey: @"enddate"];
- if ([taskDueStamp intValue])
- {
- now = [NSCalendarDate calendarDate];
- taskDate = [NSCalendarDate dateWithTimeIntervalSince1970:
- [taskDueStamp intValue]];
- if ([taskDate earlierDate: now] == taskDate)
- statusClass = @"overdue";
- else
- {
- if ([taskDate isToday])
- statusClass = @"duetoday";
- else
- statusClass = @"duelater";
- }
- }
- else
- statusClass = @"duelater";
+ WOResponse *response;
+ NSDictionary *tasks;
+ NSMutableArray *filteredTasks;
+ BOOL showCompleted;
+ unsigned i, count;
+
+ response = [context response];
+ filteredTasks = [NSMutableArray new];
+ [filteredTasks autorelease];
+ tasks = [self _fetchCoreInfosForComponent: @"vtodo"];
+ showCompleted = [[self queryParameterForKey: @"show-completed"] intValue];
+
+ count = [tasks count];
+ for (i = 0; i < count; i++) {
+ NSDictionary *task;
+ NSArray *filteredTask;
+
+ task = [tasks objectAtIndex: i];
+
+ if ([[task objectForKey: @"status"] intValue] != 1
+ || showCompleted)
+ {
+ filteredTask = [NSArray arrayWithObjects:
+ [task objectForKey: @"c_name"],
+ [task objectForKey: @"owner"],
+ [task objectForKey: @"status"],
+ [task objectForKey: @"title"],
+ [self getStatusClassForTask: task],
+ nil];
+ [filteredTasks addObject: filteredTask];
}
+ }
+
+ [response setStatus: 200];
+ [response appendContentString: [filteredTasks jsonRepresentation]];
- allClasses = [NSString stringWithFormat: @"%@ ownerIs%@",
- statusClass,
- [currentTask objectForKey: @"owner"]];
-
- return allClasses;
+ return response;
}
- (BOOL) shouldDisplayCurrentTask
return showCompleted;
}
-- (BOOL) isCurrentTaskCompleted
-{
- return ([[currentTask objectForKey: @"status"] intValue] == 1);
-}
-
@end