2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include <SOGoUI/UIxComponent.h>
24 @class NSMutableArray;
26 @interface UIxCalScheduleOverview : UIxComponent
28 NSMutableArray *userApts;
29 NSMutableArray *foreignApts;
33 unsigned participantIndex;
36 - (NSCalendarDate *)startDate;
37 - (NSCalendarDate *)endDate;
39 - (NSArray *)userAppointments;
40 - (NSArray *)foreignAppointments;
42 - (BOOL)hasUserAppointments;
43 - (BOOL)hasForeignAppointments;
44 - (BOOL)hasAnyAppointments;
48 - (NSString *)appointmentBaseURL;
50 - (unsigned)participantsCount;
51 - (unsigned)maxRenderedParticipantsCount;
52 - (unsigned)renderedParticipantsCount;
53 - (unsigned)truncatedParticipantsCount;
54 - (BOOL)didTruncateParticipants;
58 #include <NGObjWeb/SoComponent.h>
59 #include "UIxComponent+Agenor.h"
60 #include "SoObjects/Appointments/SOGoAppointmentFolder.h"
63 @implementation UIxCalScheduleOverview
66 [self->userApts release];
67 [self->foreignApts release];
68 [self->partNames release];
69 [self->partStates release];
77 - (void)setItem:(id)_item {
80 ASSIGN(self->item, _item);
82 [self->partNames release];
83 [self->partStates release];
84 ps = [self->item valueForKey:@"participants"];
85 self->partNames = [[ps componentsSeparatedByString:@"\n"] retain];
86 ps = [self->item valueForKey:@"partstates"];
87 self->partStates = [[ps componentsSeparatedByString:@"\n"] retain];
93 - (void)setParticipantIndex:(unsigned)_participantIndex {
94 self->participantIndex = _participantIndex;
96 - (unsigned)participantIndex {
97 return self->participantIndex;
100 - (BOOL)isFirstParticipant {
101 return self->participantIndex == 0 ? YES : NO;
104 - (BOOL)hasUserAppointments {
105 return [[self userAppointments] count] > 0;
107 - (BOOL)hasForeignAppointments {
108 return [[self foreignAppointments] count] > 0;
110 - (BOOL)hasAnyAppointments {
111 return ([self hasUserAppointments] ||
112 [self hasForeignAppointments]) ? YES : NO;
115 - (unsigned)participantsCount {
116 return [self->partNames count];
119 - (NSString *)participant {
120 return [self->partNames objectAtIndex:self->participantIndex];
123 - (NSString *)participationStatus {
124 return [self->partStates objectAtIndex:self->participantIndex];
127 - (unsigned)maxRenderedParticipantsCount {
131 - (unsigned)renderedParticipantsCount {
132 if ([self didTruncateParticipants])
133 return [self maxRenderedParticipantsCount];
134 return [self participantsCount];
137 - (unsigned)truncatedParticipantsCount {
138 return [self participantsCount] - [self renderedParticipantsCount];
141 - (BOOL)didTruncateParticipants {
142 return [self participantsCount] >
143 ([self maxRenderedParticipantsCount] + 1) ? YES : NO;
146 - (unsigned)rowspan {
149 count = [self renderedParticipantsCount];
150 if ([self didTruncateParticipants])
155 - (NSString *)userParticipationStatus {
160 pms = [self->item valueForKey:@"partmails"];
161 partmails = [pms componentsSeparatedByString:@"\n"];
162 idx = [partmails indexOfObject:[self emailForUser]];
163 if (idx == NSNotFound)
165 return [self->partStates objectAtIndex:idx];
171 - (NSCalendarDate *)startDate {
172 return [[NSCalendarDate date] beginOfDay];
175 /* ZNeK: is a month ok? */
176 - (NSCalendarDate *)endDate {
177 NSCalendarDate *date;
179 date = [NSCalendarDate date];
180 date = [date dateByAddingYears:0 months:1 days:0
181 hours:0 minutes:0 seconds:0];
182 date = [date endOfDay];
186 - (NSArray *)userAppointments {
187 if (!self->userApts) {
190 return self->userApts;
193 - (NSArray *)foreignAppointments {
194 if (!self->foreignApts) {
197 return self->foreignApts;
201 static NSArray *orders = nil;
209 so = [EOSortOrdering sortOrderingWithKey:@"startDate"
210 selector:EOCompareAscending];
211 orders = [[NSArray alloc] initWithObjects:so, nil];
214 aptFolder = [self clientObject];
215 apts = [aptFolder fetchCoreInfosFrom:[self startDate]
217 userEmail = [self emailForUser];
218 count = [apts count];
220 self->userApts = [[NSMutableArray alloc] initWithCapacity:count];
221 self->foreignApts = [[NSMutableArray alloc] initWithCapacity:count];
223 for (i = 0; i < count; i++) {
227 apt = [apts objectAtIndex:i];
228 orgEmail = [apt objectForKey:@"orgmail"];
229 if (orgEmail && [orgEmail isEqualToString:userEmail])
230 [self->userApts addObject:apt];
232 [self->foreignApts addObject:apt];
234 [self->userApts sortUsingKeyOrderArray:orders];
235 [self->foreignApts sortUsingKeyOrderArray:orders];
241 - (NSString *)appointmentBaseURL {
244 if (![(pkey = [self->item valueForKey:@"uid"]) isNotNull])
247 return [[self clientObject] baseURLForAptWithUID:[pkey stringValue]
248 inContext:[self context]];
250 - (NSString *)appointmentViewURL {
251 return [[self appointmentBaseURL] stringByAppendingPathComponent:@"view"];
253 - (NSString *)acceptAppointmentURL {
254 return [[self appointmentBaseURL] stringByAppendingPathComponent:@"accept"];
256 - (NSString *)declineAppointmentURL {
257 return [[self appointmentBaseURL] stringByAppendingPathComponent:@"decline"];
261 /* access protection */
266 owner = [[self clientObject] ownerInContext:[self context]];
269 return [[[[self context] activeUser] login] isEqualToString:owner];