diff options
Diffstat (limited to 'Classes/Topic.m')
-rw-r--r-- | Classes/Topic.m | 26 |
1 files changed, 21 insertions, 5 deletions
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], |