From 9aa7cfd03ffe0906c5f0fb7f59700b4d0be22b94 Mon Sep 17 00:00:00 2001 From: matt handler Date: Mon, 25 Apr 2011 18:07:54 -0400 Subject: nice steady state, gotto get the server up to speed then we golden boyee --- Classes/Topic.m | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'Classes/Topic.m') diff --git a/Classes/Topic.m b/Classes/Topic.m index 123df3f..1ed4420 100644 --- a/Classes/Topic.m +++ b/Classes/Topic.m @@ -12,7 +12,7 @@ @implementation Topic -@synthesize guid, title, iconUrl, description, releaseDate, category, picCount; +@synthesize guid, title, iconUrl, description, releaseDate, category, picCount, foreignId; + (Topic *) initFromDatabaseRow:(FMResultSet *)result { NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; @@ -26,9 +26,25 @@ topic.title = [result stringForColumn:@"title"]; topic.iconUrl = [result stringForColumn:@"iconUrl"]; topic.description = [result stringForColumn:@"description"]; - topic.releaseDate = [Topic stringToDate:[result stringForColumn:@"releaseDate"]]; + topic.releaseDate = [result dateForColumn:@"releaseDate"]; topic.category = [result stringForColumn:@"category"]; - topic.picCount = [result intForColumn:@"picCount"]; + topic.picCount = [NSNumber numberWithInt:[result intForColumn:@"picCount"]]; + + return topic; +} + ++ (Topic *) initFromJsonObject:(NSDictionary *)obj { + Topic *topic = [[[Topic alloc] init] autorelease]; + + NSDictionary *info = [obj objectForKey:@"fields"]; + + topic.title = [info objectForKey:@"title"]; + topic.foreignId = [obj objectForKey:@"pk"]; + topic.iconUrl = [info objectForKey:@"iconUrl"]; + topic.description = [info objectForKey:@"description"]; + topic.releaseDate = [self stringToDate:[info objectForKey:@"releaseDate"]]; + topic.category = [info objectForKey:@"category"]; + topic.picCount = [info objectForKey:@"picCount"]; return topic; } @@ -53,12 +69,12 @@ - (void)serializeToDatabase:(FMDatabase *)db { [db retain]; - NSLog(@"title: %@", title); + NSLog(@"title: %d", [releaseDate timeIntervalSince1970]); [db executeUpdate:@"INSERT INTO picCasts \ (foreignId, link, title, description, releaseDate, category, iconUrl, picCount) \ VALUES \ (?, ?, ?, ?, ?, ?, ?, ?)", - [NSNumber numberWithInt:12], guid, title, description, [Topic dateToString:releaseDate], category, iconUrl, [NSNumber numberWithInt:12]]; + [NSNumber numberWithInt:12], guid, title, description, releaseDate, category, iconUrl, picCount]; //NSLog(@"insert id:%d error: %@", [db lastInsertRowId], [db lastErrorMessage]); // [NSString stringWithFormat:@"number %d", i], -- cgit v1.2.3