diff options
Diffstat (limited to 'Classes/Topic.m')
| -rw-r--r-- | Classes/Topic.m | 58 | 
1 files changed, 55 insertions, 3 deletions
diff --git a/Classes/Topic.m b/Classes/Topic.m index 712519b..65ea506 100644 --- a/Classes/Topic.m +++ b/Classes/Topic.m @@ -7,17 +7,69 @@  //  #import "Topic.h" - +#import "FMDatabase.h" +#import "FMResultSet.h"  @implementation Topic -@synthesize title, guid, creator, iconUrl, description, releaseDate, category, picCount; +@synthesize guid, title, iconUrl, description, releaseDate, category, picCount; + ++ (Topic *) initFromDatabaseRow:(FMResultSet *)result { +	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; +    [dateFormatter setDateStyle:NSDateFormatterLongStyle]; +    [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; +    [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]]; +	 +	Topic *topic = [[[Topic alloc] init] autorelease]; +	 +	topic.guid = [result stringForColumn:@"link"]; +	topic.title = [result stringForColumn:@"title"]; +	topic.iconUrl = [result stringForColumn:@"iconUrl"]; +	topic.description = [result stringForColumn:@"description"]; +	topic.releaseDate = [Topic stringToDate:[result stringForColumn:@"releaseDate"]]; +	topic.category = [result stringForColumn:@"category"]; +	topic.picCount = [result intForColumn:@"picCount"]; +	 +	return topic; +} + ++ (NSString *) dateToString:(NSDate *)date { +	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; +    [dateFormatter setDateStyle:NSDateFormatterLongStyle]; +    [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; +    [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]]; +	 +	return [dateFormatter stringFromDate:date]; +} + ++ (NSDate *) stringToDate:(NSString *)string { +	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; +    [dateFormatter setDateStyle:NSDateFormatterLongStyle]; +    [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; +    [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]]; +	 +	return [dateFormatter dateFromString:string]; +} + +- (void)serializeToDatabase:(FMDatabase *)db { +	//NSLog(@"title: %@", title); +	[db executeUpdate:@"INSERT INTO picCasts \ +	 (foreignId, link, title, description, releaseDate, category, iconUrl, picCount) \ +	 VALUES \ +	 (?, ?, ?, ?, ?, ?, ?, ?)", +	 12, guid, title, description, [Topic dateToString:releaseDate], category, picCount]; +	//NSLog(@"insert id:%d error: %@", [db lastInsertRowId], [db lastErrorMessage]); + +	//	 [NSString stringWithFormat:@"number %d", i], +	//	 [NSNumber numberWithInt:i], +	//	 [NSDate date], +	//	 [NSNumber numberWithFloat:2.2f]]; +}  - (void)dealloc {  	[picCount release];  	[guid release];      [title release]; -    [creator release];      [description release];      [releaseDate release];      [category release];  | 
