-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConference.m
252 lines (220 loc) · 8.22 KB
/
Conference.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//
// Conference.m
// AnyXML
//
// Created by Helge Städtler on 17.01.11.
// Copyright 2011 staedtler development. All rights reserved.
//
#import "Conference.h"
#import "Day.h"
#import "Event.h"
@implementation Conference
@synthesize title;
@synthesize subtitle;
@synthesize venue;
@synthesize city;
@synthesize startDate;
@synthesize endDate;
@synthesize release;
@synthesize dayChange;
@synthesize timeslotDuration;
@synthesize days;
@synthesize cachedAvailableTracks;
@synthesize cachedAvailableTypes;
@synthesize cachedAvailableLanguages;
@synthesize cachedAvailableRooms;
@synthesize cachedAvailableSlugs;
@synthesize cachedAvailablePersons;
@synthesize cachedAvailableLinks;
- (void) dealloc {
[title release];
[subtitle release];
[venue release];
[city release];
[startDate release];
[endDate release];
[release release];
[days release];
self.cachedAvailableTracks = nil;
self.cachedAvailableTypes = nil;
self.cachedAvailableLanguages = nil;
self.cachedAvailableRooms = nil;
self.cachedAvailableSlugs = nil;
self.cachedAvailablePersons = nil;
self.cachedAvailableLinks = nil;
[super dealloc];
}
- (id)init {
if (self = [super init]) {
// Initialization code
self.days = [NSMutableArray array];
}
return self;
}
- (NSString*) description {
NSMutableString *stringRepresentation = [NSMutableString string];
[stringRepresentation appendFormat:@"\nTitle = %@\n", title == nil ? @"[NIL]" : title];
[stringRepresentation appendFormat:@"Subtitle = %@\n", subtitle == nil ? @"[NIL]" : subtitle];
[stringRepresentation appendFormat:@"Venue = %@\n", venue == nil ? @"[NIL]" : venue];
[stringRepresentation appendFormat:@"City = %@\n", city == nil ? @"[NIL]" : city];
[stringRepresentation appendFormat:@"Release = %@\n", release == nil ? @"[NIL]" : release];
[stringRepresentation appendFormat:@"Start = %@\n", startDate == nil ? @"[NIL]" : [self stringForDate:startDate]];
[stringRepresentation appendFormat:@"End = %@\n", endDate == nil ? @"[NIL]" : [self stringForDate:endDate]];
return stringRepresentation;
}
- (NSString*) stringForDate:(NSDate*)date {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [NSLocale currentLocale];
dateFormatter.timeZone = [NSTimeZone localTimeZone];
dateFormatter.dateStyle = NSDateFormatterMediumStyle;
dateFormatter.timeStyle = NSDateFormatterNoStyle;
return [dateFormatter stringFromDate:date];
}
- (void) addDay:(Day*)dayToAdd {
[days addObject:dayToAdd];
}
#pragma mark - Post Processing for convenient Access to Stuff
- (BOOL) array:(NSMutableArray*)array containsString:(NSString*)string {
for( NSString* currentString in array ) {
if( [currentString isEqualToString:string] ) {
return YES;
}
}
return NO;
}
- (void) addKey:(NSString*)key toArray:(NSMutableArray*)array {
key = [key stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSArray *keys = [key componentsSeparatedByString:@","];
for( NSString* currentKey in keys ) {
key = [key normalizedString];
if( !key || [key length] == 0 ) {
break;
}
else {
if( [self array:array containsString:key] ) {
break;
}
else {
[array addObject:key];
}
}
}
}
- (UIColor*) colorForTrack:(NSString*)trackName {
NSArray *availableColors = [NSArray arrayWithObjects:kCOLOR_CYAN,kCOLOR_GREEN,kCOLOR_ORANGE,kCOLOR_RED,kCOLOR_VIOLET,[UIColor yellowColor],[UIColor blueColor], [UIColor brownColor],kCOLOR_WHITE, nil];
if( !trackName ) return kCOLOR_CLEAR;
NSInteger index = 0;
for( NSString* currentTrack in cachedAvailableTracks ) {
if( [[currentTrack lowercaseString] isEqualToString:[trackName lowercaseString]] ) {
if( index < [availableColors count]-1 ) {
return [availableColors objectAtIndex:index];
}
else {
return [UIColor randomColor];
}
}
index++;
}
return [UIColor randomColor];
}
- (NSArray*) allEvents {
NSMutableArray *allEvents = [NSMutableArray array];
for( Day* currentDay in days ) {
[allEvents addObjectsFromArray:currentDay.events];
}
return [NSArray arrayWithArray:allEvents];
}
- (NSArray*) allPersons {
NSMutableArray *allPersons = [NSMutableArray array];
NSArray *events = [self allEvents];
for( Event* currentEvent in events ) {
[allPersons addObjectsFromArray:currentEvent.persons];
}
NSMutableDictionary *personsUniqueDictionary = [NSMutableDictionary dictionary];
for( Person* currentPerson in allPersons ) {
[personsUniqueDictionary setObject:currentPerson forKey:currentPerson.personIdKey];
}
return [NSArray arrayWithArray:[personsUniqueDictionary allValues]];
}
- (NSArray*) allLinks {
NSMutableArray *allLinks = [NSMutableArray array];
NSArray *events = [self allEvents];
for( Event* currentEvent in events ) {
[allLinks addObjectsFromArray:currentEvent.links];
}
NSMutableDictionary *linksUniqueDictionary = [NSMutableDictionary dictionary];
for( Link* currentLink in allLinks ) {
if( currentLink.href && [currentLink.href length] > 0 ) {
[linksUniqueDictionary setObject:currentLink forKey:currentLink.href];
}
}
return [NSArray arrayWithArray:[linksUniqueDictionary allValues]];
}
- (void) computeCachedProperties {
self.cachedAvailableTracks = [NSMutableArray array];
self.cachedAvailableTypes = [NSMutableArray array];
self.cachedAvailableLanguages = [NSMutableArray array];
self.cachedAvailableRooms = [NSMutableArray array];
self.cachedAvailableSlugs = [NSMutableArray array];
self.cachedAvailablePersons = [NSMutableArray array];
self.cachedAvailableLinks = [NSMutableArray array];
NSMutableArray *allEvents = [NSMutableArray arrayWithArray:[self allEvents]];
// COMPUTE LIST OF USED TRACKS
for( Event *currentEvent in allEvents ) {
[self addKey:currentEvent.track toArray:cachedAvailableTracks];
[self addKey:currentEvent.type toArray:cachedAvailableTypes];
[self addKey:currentEvent.language toArray:cachedAvailableLanguages];
[self addKey:currentEvent.room toArray:cachedAvailableRooms];
[self addKey:currentEvent.slug toArray:cachedAvailableSlugs];
}
if( DEBUG ) {
NSLog( @"tracks = %@", cachedAvailableTracks );
NSLog( @"types = %@", cachedAvailableTypes );
NSLog( @"languages = %@", cachedAvailableLanguages );
NSLog( @"rooms = %@", cachedAvailableRooms );
NSLog( @"slugs = %@", cachedAvailableSlugs );
NSLog( @"events in room 'saal 1': %@", [self eventsForRoom:@"saal 1"] );
}
}
- (NSArray*) eventsWithProperty:(NSString*)propertyName matchingValue:(NSString*)value {
NSMutableArray *eventsMatching = [NSMutableArray array];
NSArray *allEvents = [self allEvents];
for( Event* currentEvent in allEvents ) {
SEL selector = NSSelectorFromString(propertyName);
id result = [currentEvent performSelector:selector];
if( [result isKindOfClass:[NSString class]] ) {
NSString *resultNormalized = [(NSString*)result normalizedString];
if( [resultNormalized isEqualToString:value] ) {
[eventsMatching addObject:currentEvent];
}
}
else {
NSLog( @"No NSString Property: %@", propertyName );
}
}
return [NSArray arrayWithArray:eventsMatching];
}
- (NSArray*) eventsForTrack:(NSString*)track {
return [self eventsWithProperty:@"track" matchingValue:track];
}
- (NSArray*) eventsForType:(NSString*)type {
return [self eventsWithProperty:@"type" matchingValue:type];
}
- (NSArray*) eventsForLanguage:(NSString*)language {
return [self eventsWithProperty:@"language" matchingValue:language];
}
- (NSArray*) eventsForRoom:(NSString*)room {
return [self eventsWithProperty:@"room" matchingValue:room];
}
- (NSArray*) eventsForSlug:(NSString*)slug {
return [self eventsWithProperty:@"slug" matchingValue:slug];
}
- (NSArray*) eventsForPerson:(Person*)person {
// TODO: implement
return nil;
}
- (NSArray*) eventsForLink:(Link*)link {
// TODO: implement
return nil;
}
@end