From 76dc1f341ada22a2c9118cdb7552de2543f54e4f Mon Sep 17 00:00:00 2001 From: Emile Baizel Date: Fri, 7 Feb 2014 17:10:11 -0800 Subject: [PATCH] menu items are now fetched from the server --- PLALaCarteItem.h | 1 - PLALaCarteViewController.m | 87 ++- PLAddOnItem.h | 1 - PLAddOnViewController.m | 58 +- PLBasketStore.m | 46 +- PLBasketViewController.m | 4 +- PLConnection.h | 1 + PLConnection.m | 6 + PLMenu.h | 6 +- PLMenu.m | 101 ++- PLMenuItem.h | 4 + PLMenuItem.m | 1 + PLPlate.h | 5 + PLPlateSize.h | 3 +- PLPlateSize.m | 5 +- PLPlateStore.h | 17 +- PLPlateStore.m | 365 ++++++---- PLPlateType.h | 10 +- PLPlateType.m | 20 +- PLPlateTypeSize.h | 24 + PLPlateTypeSize.m | 33 + PLPlatesTypesAndSizes.h | 21 + PLPlatesTypesAndSizes.m | 76 +++ PLSelectMainsViewController.m | 18 +- PLSelectPlateSizeViewController.h | 4 +- PLSelectPlateSizeViewController.m | 169 +++-- PLSelectSidesViewController.m | 43 +- Plate.xcodeproj/project.pbxproj | 24 +- .../xcdebugger/Breakpoints_v2.xcbkptlist | 624 ++++++++++++------ Plate/Plate-Prefix.pch | 12 +- 30 files changed, 1227 insertions(+), 562 deletions(-) create mode 100644 PLPlateTypeSize.h create mode 100644 PLPlateTypeSize.m create mode 100644 PLPlatesTypesAndSizes.h create mode 100644 PLPlatesTypesAndSizes.m diff --git a/PLALaCarteItem.h b/PLALaCarteItem.h index 420a879..4d000e8 100644 --- a/PLALaCarteItem.h +++ b/PLALaCarteItem.h @@ -10,5 +10,4 @@ @interface PLALaCarteItem : PLMenuItem -@property (nonatomic) int quantity; @end diff --git a/PLALaCarteViewController.m b/PLALaCarteViewController.m index 2a56fd3..0f1cda0 100644 --- a/PLALaCarteViewController.m +++ b/PLALaCarteViewController.m @@ -12,6 +12,7 @@ #import "PLMenuItemTableViewCell.h" #import "PLBasketStore.h" #import "Colours.h" +#import "PLPlateStore.h" @interface PLALaCarteViewController () @@ -174,37 +175,67 @@ - (void)viewDidLoad - (void)fetchALaCarteItems { - // This will be a call out to server - - NSMutableArray *mainItems = [[NSMutableArray alloc] init]; - NSMutableArray *sideItems = [[NSMutableArray alloc] init]; - - [mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Beef Stroganoff" itemType:MenuItemMain itemId:@"1"]]; - [mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Wild Salmon" itemType:MenuItemMain itemId:@"2"]]; - [mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Moo Goo Gai Pan" itemType:MenuItemMain itemId:@"3"]]; - - [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Eggplant" itemType:MenuItemSide itemId:@"4"]]; - [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Zucchini" itemType:MenuItemSide itemId:@"5"]]; - [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Broccoli" itemType:MenuItemSide itemId:@"6"]]; - [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Animal Crackers" itemType:MenuItemSide itemId:@"7"]]; - [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Fudge Ice Cream" itemType:MenuItemSide itemId:@"8"]]; - [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Spinach" itemType:MenuItemSide itemId:@"9"]]; - [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Artichokes" itemType:MenuItemSide itemId:@"10"]]; - [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Sardines" itemType:MenuItemSide itemId:@"11"]]; - - for (PLALaCarteItem *item in mainItems) { - item.price = 10.0; - } - - for (PLALaCarteItem *item in sideItems) { - item.price = 4.0; - } - - [self setMains:mainItems]; - [self setSides:sideItems]; + UIView *currentTitleView = [[self navigationItem] titleView]; + UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; + [[self navigationItem] setTitleView:aiView]; + [aiView startAnimating]; + + __weak PLALaCarteViewController *weakSelf = self; + + [[PLPlateStore sharedStore]getALaCarteMenu:^(PLMenu *menuResult, NSError *err) { + + [[weakSelf navigationItem] setTitleView:currentTitleView]; + + if (!err) { + _mains = [menuResult mains]; + _sides = [menuResult sides]; + [weakSelf reloadTableViewData]; + } else { + UIAlertView *av =[[UIAlertView alloc] + initWithTitle:@"Error" + message:[err localizedDescription] + delegate:nil + cancelButtonTitle:@"OK" + otherButtonTitles:nil]; + [av show]; + } + }]; } +//- (void)fetchALaCarteItems +//{ +// // This will be a call out to server +// +// NSMutableArray *mainItems = [[NSMutableArray alloc] init]; +// NSMutableArray *sideItems = [[NSMutableArray alloc] init]; +// +// [mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Beef Stroganoff" itemType:MenuItemMain itemId:@"1"]]; +// [mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Wild Salmon" itemType:MenuItemMain itemId:@"2"]]; +// [mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Moo Goo Gai Pan" itemType:MenuItemMain itemId:@"3"]]; +// +// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Eggplant" itemType:MenuItemSide itemId:@"4"]]; +// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Zucchini" itemType:MenuItemSide itemId:@"5"]]; +// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Broccoli" itemType:MenuItemSide itemId:@"6"]]; +// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Animal Crackers" itemType:MenuItemSide itemId:@"7"]]; +// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Fudge Ice Cream" itemType:MenuItemSide itemId:@"8"]]; +// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Spinach" itemType:MenuItemSide itemId:@"9"]]; +// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Artichokes" itemType:MenuItemSide itemId:@"10"]]; +// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Sardines" itemType:MenuItemSide itemId:@"11"]]; +// +// for (PLALaCarteItem *item in mainItems) { +// item.price = 10.0; +// } +// +// for (PLALaCarteItem *item in sideItems) { +// item.price = 4.0; +// } +// +// [self setMains:mainItems]; +// [self setSides:sideItems]; +// +//} + - (IBAction)actionContinue:(id)sender { [[self navigationController] pushViewController:[[PLALaCarteSummaryViewController alloc]init] animated:YES]; } diff --git a/PLAddOnItem.h b/PLAddOnItem.h index 2d54f23..e62c06e 100644 --- a/PLAddOnItem.h +++ b/PLAddOnItem.h @@ -10,5 +10,4 @@ @interface PLAddOnItem : PLMenuItem -@property (nonatomic) int quantity; @end diff --git a/PLAddOnViewController.m b/PLAddOnViewController.m index 5f06071..c81f357 100644 --- a/PLAddOnViewController.m +++ b/PLAddOnViewController.m @@ -13,6 +13,8 @@ #import "PLALaCarteSummaryViewController.h" #import "PLAddOnSummaryViewController.h" #import "Colours.h" +#import "PLPlateStore.h" +#import "PLMenu.h" @interface PLAddOnViewController () @@ -149,25 +151,55 @@ - (void)viewDidLoad // self.toolbarItems = [NSArray arrayWithObjects: flexibleSpaceLeft, barButton, nil]; } --(void)fetchAddOnItems +- (void)fetchAddOnItems { - NSMutableArray *addOnItems = [[NSMutableArray alloc]init]; - [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Coca Cola" itemType:MenuItemAddOn itemId:@"1"]]; - [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Cheez Whiz" itemType:MenuItemAddOn itemId:@"2"]]; - [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Faygo" itemType:MenuItemAddOn itemId:@"3"]]; - [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Frito Lays" itemType:MenuItemAddOn itemId:@"4"]]; - [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Chips Ahoy" itemType:MenuItemAddOn itemId:@"5"]]; - [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Saltines" itemType:MenuItemAddOn itemId:@"6"]]; - [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Vanilla Wafers" itemType:MenuItemAddOn itemId:@"7"]]; + UIView *currentTitleView = [[self navigationItem] titleView]; + UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; + [[self navigationItem] setTitleView:aiView]; + [aiView startAnimating]; - for (PLAddOnItem *item in addOnItems) { - item.price = 2.0; - } + __weak PLAddOnViewController *weakSelf = self; - [self setAddOns:addOnItems]; +// PLPlate *plate = [[PLBasketStore sharedStore] plateBuilder]; + [[PLPlateStore sharedStore]getAddOnMenu:^(PLMenu *menuResult, NSError *err) { + + [[weakSelf navigationItem] setTitleView:currentTitleView]; + + if (!err) { + _addOns = [menuResult addons]; + [[weakSelf addOnsTable] reloadData]; + } else { + UIAlertView *av =[[UIAlertView alloc] + initWithTitle:@"Error" + message:[err localizedDescription] + delegate:nil + cancelButtonTitle:@"OK" + otherButtonTitles:nil]; + [av show]; + } + }]; } +//-(void)fetchAddOnItems +//{ +// NSMutableArray *addOnItems = [[NSMutableArray alloc]init]; +// +// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Coca Cola" itemType:MenuItemAddOn itemId:@"1"]]; +// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Cheez Whiz" itemType:MenuItemAddOn itemId:@"2"]]; +// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Faygo" itemType:MenuItemAddOn itemId:@"3"]]; +// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Frito Lays" itemType:MenuItemAddOn itemId:@"4"]]; +// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Chips Ahoy" itemType:MenuItemAddOn itemId:@"5"]]; +// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Saltines" itemType:MenuItemAddOn itemId:@"6"]]; +// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Vanilla Wafers" itemType:MenuItemAddOn itemId:@"7"]]; +// +// for (PLAddOnItem *item in addOnItems) { +// item.price = 2.0; +// } +// +// [self setAddOns:addOnItems]; +//} + - (IBAction)actionContinue:(id)sender { [[self navigationController] pushViewController:[[PLAddOnSummaryViewController alloc]init] animated:YES]; } diff --git a/PLBasketStore.m b/PLBasketStore.m index 83b7324..2c1190c 100644 --- a/PLBasketStore.m +++ b/PLBasketStore.m @@ -10,6 +10,7 @@ #import "PLALaCarteItem.h" #import "PLPlate.h" #import "PLAddOnItem.h" +#import "PLPlateSize.h" @implementation PLBasketStore @@ -184,6 +185,17 @@ -(void)setPlateSize:(PlateSize)plateSize [[self plateBuilder] setSize:plateSize]; } +-(void)setPlateType2:(PlateType)plateType +{ + [[self plateBuilder] setType:plateType]; +} + +-(void)setPlateSize2:(PlateSize)plateSize +{ + [[self plateBuilder] setSize:plateSize]; +} + + -(void)setPlateMain:(PLMenuItem *)mainEntree { [[self plateBuilder] setMain:mainEntree]; @@ -194,9 +206,10 @@ -(void)addPlateSide:(PLMenuItem *)newSide // Make sure we do not exceed the allowed number of sides int numSides = 0; - if ([[self plateBuilder] type] == OneMain) { + NSString *slug = [[[[PLBasketStore sharedStore] plateBuilder] plateTypeSize] typeSlug]; + if ([slug isEqualToString:OneMainTwoSides]) { numSides = 2; - } else if ([[self plateBuilder] type] == FourSides) { + } else if ([slug isEqualToString:FourSides]) { numSides = 4; } @@ -305,25 +318,28 @@ -(float)totalCostOfItemsInBasket { float total = 0.0; for (PLPlate *plate in [self plates]) { - if ([plate size] == Ultra) { - total += 15.0; - } else if ([plate size] == Fit) { - total += 12.0; - } else if ([plate size] == Kids) { - total += 8.0; - } + total += [[plate plateSize] price]; +// if ([plate size] == Ultra) { +// total += 15.0; +// } else if ([plate size] == Fit) { +// total += 12.0; +// } else if ([plate size] == Kids) { +// total += 8.0; +// } } for (PLALaCarteItem *item in [self alaCarteItems]) { - if ([item itemType] == MenuItemMain) { - total += (10 * [item quantity]); - } else if ([item itemType] == MenuItemSide) { - total += (4 * [item quantity]); - } + total += [item price] * [item quantity]; +// if ([item itemType] == MenuItemMain) { +// total += (10 * [item quantity]); +// } else if ([item itemType] == MenuItemSide) { +// total += (4 * [item quantity]); +// } } for (PLAddOnItem *item in [self addOns]) { - total += (2 * [item quantity]); + total += [item price] * [item quantity]; +// total += (2 * [item quantity]); } return total; diff --git a/PLBasketViewController.m b/PLBasketViewController.m index 3d1b906..18af2b9 100644 --- a/PLBasketViewController.m +++ b/PLBasketViewController.m @@ -56,8 +56,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.side2Label.text = @""; } - if ([plate type] == FourSides) { - + NSString *slug = [[[[PLBasketStore sharedStore] plateBuilder] plateTypeSize] typeSlug]; + if ([slug isEqualToString:FourSides]) { side = [[plate sides] objectAtIndex:2]; cell.side3Label.text = [side name]; diff --git a/PLConnection.h b/PLConnection.h index 6ec0dea..3e53e55 100644 --- a/PLConnection.h +++ b/PLConnection.h @@ -13,6 +13,7 @@ { NSURLConnection *internalConnection; NSMutableData *container; + NSURLSessionDataTask *task; } @property (nonatomic, copy) NSURLRequest *request; diff --git a/PLConnection.m b/PLConnection.m index 0e61795..b7f49e5 100644 --- a/PLConnection.m +++ b/PLConnection.m @@ -29,6 +29,12 @@ - (void) start container = [[NSMutableData alloc]init]; internalConnection = [[NSURLConnection alloc] initWithRequest:[self request] delegate:self startImmediately:YES]; +// NSURLSession *session = [NSURLSession sharedSession]; +// task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { +// +// }]; +// [task resume]; + if (!sharedConnectionList) { sharedConnectionList = [[NSMutableArray alloc]init]; } diff --git a/PLMenu.h b/PLMenu.h index f0bf0fe..b24d81b 100644 --- a/PLMenu.h +++ b/PLMenu.h @@ -8,6 +8,8 @@ #import #import "JSONSerializable.h" +#import "PLPlateSize.h" +#import "PLPlateTypeSize.h" @interface PLMenu : NSObject @@ -16,6 +18,8 @@ @property (nonatomic, strong) NSMutableArray *addons; @property (nonatomic, strong) NSString *location; @property (nonatomic, strong) NSDate *menuDate; - +@property (nonatomic, strong) PLPlateSize *plateSize; +@property (nonatomic, strong) PLPlateTypeSize *plateTypeSize; +@property (nonatomic) MenuType menuType; @end diff --git a/PLMenu.m b/PLMenu.m index 36f7669..0b3722b 100644 --- a/PLMenu.m +++ b/PLMenu.m @@ -27,50 +27,79 @@ +(NSString *)generateRandomID -(void)readFromJSONDictionary:(NSDictionary *)d { - NSDictionary *response = [d objectForKey:@"response"]; - NSDictionary *mainModifiers = [response valueForKeyPath:@"3.modifiers"]; - if (mainModifiers) { - - if (!mains) { - mains = [[NSMutableArray alloc]init]; - } + + if ([self menuType] == MenuTypePlate) { + + NSString *sizeSlug = [[self plateSize] slug]; + NSString *mainKey = [sizeSlug stringByAppendingString:@"-main"]; + NSString *sideKey = [sizeSlug stringByAppendingString:@"-side"]; - for (NSString *key in mainModifiers) { - - NSDictionary *mainModifier = [mainModifiers objectForKey:key]; - NSDictionary *mainItem = [mainModifier objectForKey:@"meta"]; + NSDictionary *mainKeys = [d objectForKey:mainKey]; + if (mainKeys && [mainKeys count] > 0) { + NSMutableArray *modifiersArray = (NSMutableArray *)[mainKeys objectForKey:@"modifiers"]; + NSMutableArray *mainModifiers = [self parseModifiers:(modifiersArray)]; + [self setMains:mainModifiers]; + } - PLMenuItem *plmi = [[PLMenuItem alloc] init]; - [plmi setName:[mainModifier objectForKey:@"name"]]; - [plmi setPlateId:[PLMenu generateRandomID]]; // probably need to remove this -// ### UNCOMMENT BELOW WHEN META IS WORKING -// [plmi setName:[mainItem objectForKey:@"name"]]; -// [plmi setDescription:[mainItem objectForKey:@"description"]]; -// [plmi setAllergies:[mainItem objectForKey:@"alergies"]]; -// [plmi setIsGlutenFree:[[mainItem objectForKey:@"is_gluten_free"] boolValue]]; -// [plmi setIsVegan:[[mainItem objectForKey:@"is_vegan"] boolValue]]; -// [plmi setIsVegetarian:[[mainItem objectForKey:@"is_vegetarian"] boolValue]]; - - [mains addObject:plmi]; + NSDictionary *sideKeys = [d objectForKey:sideKey]; + if (sideKeys && [sideKeys count] > 0) { + NSMutableArray *modifiersArray = (NSMutableArray *)[sideKeys objectForKey:@"modifiers"]; + NSMutableArray *sideModifiers = [self parseModifiers:(modifiersArray)]; + [self setSides:sideModifiers]; + } + } else if ([self menuType] == MenuTypeALaCarte) { + NSArray *menus = [d objectForKey:@"menus"]; + for (NSDictionary * menuDict in menus) { + NSMutableArray *productsDicts = [menuDict objectForKey:@"products"]; + NSMutableArray *products = [self parseModifiers:productsDicts]; + NSString *slug = [menuDict objectForKey:@"slug"]; + if ([slug isEqualToString:@"main-entrees"]) { + for (PLMenuItem *menuItem in products) { + [menuItem setItemType:MenuItemMain]; + } + [self setMains:products]; + } else if ([slug isEqualToString:@"sides"]) { + for (PLMenuItem *menuItem in products) { + [menuItem setItemType:MenuItemSide]; + } + [self setSides:products]; + } + } + } else if ([self menuType] == MenuTypeAddOn) { + NSArray *menus = [d objectForKey:@"menus"]; + [self setAddons:[[NSMutableArray alloc]init]]; + for (NSDictionary * menuDict in menus) { + NSMutableArray *productsDicts = [menuDict objectForKey:@"products"]; + NSMutableArray *products = [self parseModifiers:productsDicts]; + [[self addons] addObjectsFromArray:products]; } } - NSDictionary *sideModifiers = [response valueForKeyPath:@"4.modifiers"]; - if (sideModifiers) { +} + +-(NSMutableArray *)parseModifiers:(NSMutableArray *)modifiersArray +{ + NSMutableArray *result = [[NSMutableArray alloc]init]; + for (NSDictionary *modifierDict in modifiersArray) { + PLMenuItem *plmi = [[PLMenuItem alloc] init]; + [plmi setName:[modifierDict objectForKey:@"name"]]; + [plmi setSlug:[modifierDict objectForKey:@"slug"]]; + [plmi setPrice:[[modifierDict objectForKey:@"price"] floatValue]]; - if (!sides) { - sides = [[NSMutableArray alloc]init]; - } + NSDictionary *metaDict = [modifierDict objectForKey:@"meta"]; + [plmi setName:[metaDict objectForKey:@"name"]]; + [plmi setDescription:[metaDict objectForKey:@"description"]]; + [plmi setAllergies:[metaDict objectForKey:@"alergies"]]; + [plmi setIsGlutenFree:[[metaDict objectForKey:@"is_gluten_free"] boolValue]]; + [plmi setIsVegan:[[metaDict objectForKey:@"is_vegan"] boolValue]]; + [plmi setIsVegetarian:[[metaDict objectForKey:@"is_vegetarian"] boolValue]]; + [plmi setIngredients:[metaDict objectForKey:@"ingredients"]]; + [plmi setPlateId:(NSString *)[metaDict objectForKey:@"id"]]; + [plmi setImageURL:[metaDict objectForKey:@"image"]]; - for (NSString *key in sideModifiers) { - NSDictionary *sideItem = [sideModifiers objectForKey:key]; - PLMenuItem *plmi = [[PLMenuItem alloc] init]; - [plmi setName:[sideItem objectForKey:@"name"]]; - [plmi setPlateId:[PLMenu generateRandomID]]; - [sides addObject:plmi]; - } + [result addObject:plmi]; } - + return result; } @end diff --git a/PLMenuItem.h b/PLMenuItem.h index f1b77e6..cf5791f 100644 --- a/PLMenuItem.h +++ b/PLMenuItem.h @@ -15,7 +15,11 @@ @property (nonatomic, strong) NSString *plateId; @property (nonatomic, strong) NSString *description; @property (nonatomic, strong) NSString *allergies; +@property (nonatomic, strong) NSString *ingredients; +@property (nonatomic, strong) NSString *imageURL; +@property (nonatomic, strong) NSString *slug; @property (nonatomic, assign) float price; +@property (nonatomic) int quantity; @property (nonatomic) MenuItemType itemType; @property (assign) BOOL isGlutenFree; @property (assign) BOOL isVegan; diff --git a/PLMenuItem.m b/PLMenuItem.m index cbd00ef..77bcd9f 100644 --- a/PLMenuItem.m +++ b/PLMenuItem.m @@ -41,6 +41,7 @@ -(id)copyWithZone:(NSZone *)zone another.isVegan = [self isVegan]; another.isVegetarian = [self isVegetarian]; another.price = [self price]; + another.quantity = [self quantity]; return another; } diff --git a/PLPlate.h b/PLPlate.h index 04f463b..3cdae53 100644 --- a/PLPlate.h +++ b/PLPlate.h @@ -10,11 +10,16 @@ #import "PLMenuItem.h" #import "PLPlateType.h" #import "PLPlateSize.h" +#import "PLPlateTypeSize.h" @interface PLPlate : NSObject @property (nonatomic, assign) PlateType type; //onemain, foursides @property (nonatomic, assign) PlateSize size; //fit, ultra + +@property (nonatomic, assign) PLPlateSize *plateSize; +@property (nonatomic, assign) PLPlateTypeSize *plateTypeSize; + //@property (nonatomic, strong) PLPlateType *type; //@property (nonatomic, strong) PLPlateSize *size; @property (nonatomic, strong) PLMenuItem *main; diff --git a/PLPlateSize.h b/PLPlateSize.h index 3535565..9b90092 100644 --- a/PLPlateSize.h +++ b/PLPlateSize.h @@ -13,5 +13,6 @@ @property (nonatomic, strong) NSString *name; //fit, ultra @property (nonatomic) float price; -@property (nonatomic) int id; +@property (nonatomic, strong) NSString *id; +@property (nonatomic, strong) NSString *slug; @end diff --git a/PLPlateSize.m b/PLPlateSize.m index 07b001a..8aa1666 100644 --- a/PLPlateSize.m +++ b/PLPlateSize.m @@ -12,9 +12,10 @@ @implementation PLPlateSize -(void)readFromJSONDictionary:(NSDictionary *)d { + self.slug = [d objectForKey:@"slug"]; + self.price = [[d objectForKey:@"price"] floatValue]; + self.id = [[d objectForKey:@"id"] stringValue]; self.name = [d objectForKey:@"name"]; - self.price = [[d objectForKey:@"price"]floatValue]; - self.id = [[d objectForKey:@"id"] intValue]; } @end diff --git a/PLPlateStore.h b/PLPlateStore.h index e11ccee..e6fc339 100644 --- a/PLPlateStore.h +++ b/PLPlateStore.h @@ -8,20 +8,25 @@ #import #import "PLMenu.h" +#import "PLMenuItem.h" +#import "PLPlatesTypesAndSizes.h" +#import "PLPlateSize.h" @interface PLPlateStore : NSObject { - PLMenu *menu; - NSMutableArray *plates; + PLPlatesTypesAndSizes *plateTypesSizes; + NSMutableArray *plateMenus; + PLMenu *aLaCarteMenu; + PLMenu *addOnsMenu; } + (PLPlateStore *)sharedStore; - (void)clearCache; -- (void)getMenu:(void (^)(PLMenu *menuResult, NSError *err))block; -- (void)getPlateMenu:(int)sizeTypeId forBlock:(void (^)(PLMenu *menuResult, NSError *))block; + +- (void)getPlateMenu:(PLPlateSize *)plateSize plateType:(PLPlateTypeSize *)plateTypeSize forBlock:(void (^)(PLMenu *menuResult, NSError *))block; - (void)getAddOnMenu:(void (^)(PLMenu *menuResult, NSError *err))block; - (void)getALaCarteMenu:(void (^)(PLMenu *menuResult, NSError *))block; -- (void)getPlateSizesAndTypes:(void (^)(NSMutableArray *plates, NSError *err))block; -- (int)getPlateSizeTypeId:(int)typeId sizeId:(int)sizeId; +- (void)getPlateSizesAndTypes:(void (^)(PLPlatesTypesAndSizes *plateTypesSizes, NSError *err))block; +//- (void)getProductDetail:(PLMenuItem *)menuItem forBlock:(void (^)(PLMenuItem)) @end diff --git a/PLPlateStore.m b/PLPlateStore.m index 1bd431f..221615f 100644 --- a/PLPlateStore.m +++ b/PLPlateStore.m @@ -10,62 +10,128 @@ #import "PLMenuItem.h" #import "PLConnection.h" #import "PLMenu.h" -#import "PLPlateType.h" -#import "PLPlateSize.h" +#import "PLPlatesTypesAndSizes.h" +#import "PLPlateTypeSize.h" + +#ifdef DEBUG + #define BASEURL @"http://ep2.gulosolutions.com/" +#else + #define BASEURL @"http://ep2.gulosolutions.com/" +#endif @implementation PLPlateStore -- (int)getPlateSizeTypeId:(int)typeId sizeId:(int)sizeId +//- (int)getPlateSizeTypeId:(int)typeId sizeId:(int)sizeId +//{ +// if (!plates) { return 0; } +// int result = 0; +// for (PLPlateType *plateType in plates) { +// if (plateType.id == typeId) { +// for (PLPlateSize *plateSize in plateType.sizes) { +// if (plateSize.id == sizeId) { +// result = plateSize.id; +// break; +// } +// } +// } +// } +// return result; +//} + +- (void)getALaCarteMenu:(void (^)(PLMenu *, NSError *))block { - if (!plates) { return 0; } - int result = 0; - for (PLPlateType *plateType in plates) { - if (plateType.id == typeId) { - for (PLPlateSize *plateSize in plateType.sizes) { - if (plateSize.id == sizeId) { - result = plateSize.id; - break; - } + if (aLaCarteMenu) { + block(aLaCarteMenu, nil); + } else { + NSString *urlString = [NSString stringWithFormat:@"%@%@", BASEURL, @"api/menus/a-la-carte"]; + NSURL *url = [NSURL URLWithString:urlString]; + NSURLRequest *request = [NSURLRequest requestWithURL:url]; + PLMenu *menuRootObject = [[PLMenu alloc]init]; + [menuRootObject setMenuType:MenuTypeALaCarte]; + PLConnection *connect = [[PLConnection alloc]initWithRequest:request]; + [connect setJsonRootObject:menuRootObject]; + + [connect setCompletionBlock:^(PLMenu *menuConnectResult, NSError *err) { + if (!err) { + aLaCarteMenu = menuConnectResult; + block(menuConnectResult, nil); + } else { + block(nil, err); } - } + }]; + [connect start]; } - return result; } -- (void)getPlateMenu:(int)sizeTypeId forBlock:(void (^)(PLMenu *menuResult, NSError *))block +- (void)getAddOnMenu:(void (^)(PLMenu *, NSError *))block { - if (menu) { - block(menu, nil); + if (addOnsMenu) { + block(addOnsMenu, nil); } else { + NSString *urlString = [NSString stringWithFormat:@"%@%@", BASEURL, @"api/menus/add-ons"]; + NSURL *url = [NSURL URLWithString:urlString]; + NSURLRequest *request = [NSURLRequest requestWithURL:url]; + PLMenu *menuRootObject = [[PLMenu alloc]init]; + [menuRootObject setMenuType:MenuTypeAddOn]; + PLConnection *connect = [[PLConnection alloc]initWithRequest:request]; + [connect setJsonRootObject:menuRootObject]; -// NSString *urlString = [NSString stringWithFormat:@"http://ep2.gulosolutions.com/menus/get_modifiers/%d", sizeTypeId]; -// NSURL *url = [NSURL URLWithString:urlString]; -// NSURLRequest *req = [NSURLRequest requestWithURL:url]; -// -// PLMenu *menuRootObject = [[PLMenu alloc]init]; -// PLConnection *connect = [[PLConnection alloc]initWithRequest:req]; -// [connect setJsonRootObject:menuRootObject]; -// -// [connect setCompletionBlock:^(PLMenu *menuConnectResult, NSError *err) { -// if (!err) { -// menu = menuConnectResult; -// block(menuConnectResult, nil); -// } else { -// block(nil, err); -// } -// }]; -// [connect start]; - menu = [self buildFakeMenu]; - block(menu, nil); + [connect setCompletionBlock:^(PLMenu *menuConnectResult, NSError *err) { + if (!err) { + addOnsMenu = menuConnectResult; + block(menuConnectResult, nil); + } else { + block(nil, err); + } + }]; + [connect start]; } } -- (void) getMenu:(void (^)(PLMenu *menuResult, NSError *err))block +- (void)getPlateMenu:(PLPlateSize *)plateSize plateType:(PLPlateTypeSize *)plateTypeSize forBlock:(void (^)(PLMenu *menuResult, NSError *))block { - if (menu) { - block(menu, nil); - } else { + BOOL exists = false; + if ([plateMenus count] >0) { + for (PLMenu *menu in plateMenus) { + if (([menu plateSize] == plateSize) && ([menu plateTypeSize] == plateTypeSize)) { + block(menu, nil); + exists = true; + break; + } + } + } + + if (!exists) { + NSString *urlString = [NSString stringWithFormat:@"%@%@%@", BASEURL, @"api/modifiers/", [plateSize id]]; + NSURL *url = [NSURL URLWithString:urlString]; + NSURLRequest *request = [NSURLRequest requestWithURL:url]; + PLMenu *menuRootObject = [[PLMenu alloc]init]; + [menuRootObject setMenuType:MenuTypePlate]; + [menuRootObject setPlateTypeSize:plateTypeSize]; + [menuRootObject setPlateSize:plateSize]; + PLConnection *connect = [[PLConnection alloc]initWithRequest:request]; + [connect setJsonRootObject:menuRootObject]; + [connect setCompletionBlock:^(PLMenu *menuConnectResult, NSError *err) { + if (!err) { + [menuConnectResult setPlateSize:plateSize]; + [menuConnectResult setPlateTypeSize:plateTypeSize]; + [plateMenus addObject:menuConnectResult]; + block(menuConnectResult, nil); + } else { + block(nil, err); + } + }]; + [connect start]; + } +} + +//- (void) getMenu:(void (^)(PLMenu *menuResult, NSError *err))block +//{ +// if (menu) { +// block(menu, nil); +// } else { + // NSURL *url = [NSURL URLWithString:@"http://ep2.gulosolutions.com/menus/get_modifiers/1"]; // NSURLRequest *req = [NSURLRequest requestWithURL:url]; // @@ -82,125 +148,148 @@ - (void) getMenu:(void (^)(PLMenu *menuResult, NSError *err))block // } // }]; // [connect start]; - menu = [self buildFakeMenu]; - block(menu, nil); - } -} - -- (PLMenu *)buildFakeMenu -{ - PLMenu *fakeMenu = [[PLMenu alloc]init]; - - NSMutableArray *mainItems = [[NSMutableArray alloc] init]; - NSMutableArray *sideItems = [[NSMutableArray alloc] init]; - - [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Beef Stroganoff" itemType:MenuItemMain itemId:@"31"]]; - [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Wild Salmon" itemType:MenuItemMain itemId:@"32"]]; - [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Moo Goo Gai Pan" itemType:MenuItemMain itemId:@"33"]]; - [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Braised Pork Loin" itemType:MenuItemMain itemId:@"34"]]; - [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Tofu Enchiladas" itemType:MenuItemMain itemId:@"35"]]; - - for (PLMenuItem *item in mainItems) { - item.price = 10.0; - } - - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Miso Eggplant" itemType:MenuItemSide itemId:@"4"]]; - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Zucchini" itemType:MenuItemSide itemId:@"5"]]; - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Broccoli" itemType:MenuItemSide itemId:@"6"]]; - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Animal Crackers" itemType:MenuItemSide itemId:@"7"]]; - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Fudge Ice Cream" itemType:MenuItemSide itemId:@"8"]]; - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Spinach" itemType:MenuItemSide itemId:@"9"]]; - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Artichokes" itemType:MenuItemSide itemId:@"10"]]; - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Sardines" itemType:MenuItemSide itemId:@"11"]]; - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Macaroni and Cheese" itemType:MenuItemSide itemId:@"12"]]; - [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Moroccan Cauliflower" itemType:MenuItemSide itemId:@"13"]]; - - for (PLMenuItem *item in sideItems) { - item.price = 4.0; - } - - [fakeMenu setMains:mainItems]; - [fakeMenu setSides:sideItems]; - return fakeMenu; -} +// menu = [self buildFakeMenu]; +// block(menu, nil); +// } +//} +// +//- (PLMenu *)buildFakeMenu +//{ +// PLMenu *fakeMenu = [[PLMenu alloc]init]; +// +// NSMutableArray *mainItems = [[NSMutableArray alloc] init]; +// NSMutableArray *sideItems = [[NSMutableArray alloc] init]; +// +// [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Beef Stroganoff" itemType:MenuItemMain itemId:@"31"]]; +// [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Wild Salmon" itemType:MenuItemMain itemId:@"32"]]; +// [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Moo Goo Gai Pan" itemType:MenuItemMain itemId:@"33"]]; +// [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Braised Pork Loin" itemType:MenuItemMain itemId:@"34"]]; +// [mainItems addObject:[[PLMenuItem alloc] initWithName:@"Tofu Enchiladas" itemType:MenuItemMain itemId:@"35"]]; +// +// for (PLMenuItem *item in mainItems) { +// item.price = 10.0; +// } +// +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Miso Eggplant" itemType:MenuItemSide itemId:@"4"]]; +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Zucchini" itemType:MenuItemSide itemId:@"5"]]; +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Broccoli" itemType:MenuItemSide itemId:@"6"]]; +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Animal Crackers" itemType:MenuItemSide itemId:@"7"]]; +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Fudge Ice Cream" itemType:MenuItemSide itemId:@"8"]]; +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Spinach" itemType:MenuItemSide itemId:@"9"]]; +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Artichokes" itemType:MenuItemSide itemId:@"10"]]; +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Sardines" itemType:MenuItemSide itemId:@"11"]]; +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Macaroni and Cheese" itemType:MenuItemSide itemId:@"12"]]; +// [sideItems addObject:[[PLMenuItem alloc] initWithName:@"Moroccan Cauliflower" itemType:MenuItemSide itemId:@"13"]]; +// +// for (PLMenuItem *item in sideItems) { +// item.price = 4.0; +// } +// +// [fakeMenu setMains:mainItems]; +// [fakeMenu setSides:sideItems]; +// return fakeMenu; +//} -- (void) getPlateSizesAndTypes:(void (^)(NSMutableArray *, NSError *))block +- (void) getPlateSizesAndTypes:(void (^)(PLPlatesTypesAndSizes *, NSError *))block { - if (plates) { - block(plates, nil); + if (plateTypesSizes) { + block(plateTypesSizes, nil); } else { - // Make a request - - // For now hard code 2 Plate Types - - // 1 Main and 2 Sides - PLPlateType *plateType1Main2Sides = [[PLPlateType alloc]init]; - [plateType1Main2Sides setName:@"1 Main 2 Sides"]; - [plateType1Main2Sides setId:1]; - [plateType1Main2Sides setSizes:[[NSMutableArray alloc]init]]; - - PLPlateSize *plateType1SizeFit = [[PLPlateSize alloc]init]; - [plateType1SizeFit setName:@"Fit"]; - [plateType1SizeFit setPrice:10.00]; - [plateType1SizeFit setId:90]; - - PLPlateSize *plateType1SizeUltra = [[PLPlateSize alloc]init]; - [plateType1SizeUltra setName:@"Ultra"]; - [plateType1SizeUltra setPrice:12.00]; - [plateType1SizeUltra setId:91]; - - PLPlateSize *plateType1SizeKids = [[PLPlateSize alloc]init]; - [plateType1SizeKids setName:@"Kids"]; - [plateType1SizeKids setPrice:8.00]; - [plateType1SizeKids setId:92]; - - [[plateType1Main2Sides sizes] addObject:plateType1SizeFit]; - [[plateType1Main2Sides sizes] addObject:plateType1SizeUltra]; - [[plateType1Main2Sides sizes] addObject:plateType1SizeKids]; + NSString *urlString = [NSString stringWithFormat:@"%@%@", BASEURL, @"api/plates"]; + NSURL *url = [NSURL URLWithString:urlString]; + NSURLRequest *request = [NSURLRequest requestWithURL:url]; - [plates addObject:plateType1Main2Sides]; + PLPlatesTypesAndSizes *plates = [[PLPlatesTypesAndSizes alloc]init]; + PLConnection *connect = [[PLConnection alloc]initWithRequest:request]; + [connect setJsonRootObject:plates]; - // 4 Sides - PLPlateType *plateType4Sides = [[PLPlateType alloc]init]; - [plateType4Sides setName:@"4 Sides"]; - [plateType4Sides setId:2]; - [plateType4Sides setSizes:[[NSMutableArray alloc]init]]; - - PLPlateSize *plateType2SizeFit = [[PLPlateSize alloc]init]; - [plateType2SizeFit setName:@"Fit"]; - [plateType2SizeFit setPrice:10.00]; - [plateType2SizeFit setId:80]; + [connect setCompletionBlock:^(PLPlatesTypesAndSizes *platesResult, NSError *err) { + if (!err) { + plateTypesSizes = platesResult; + block(platesResult, nil); + } else { + block(nil, err); + } + }]; + [connect start]; - PLPlateSize *plateType2SizeUltra = [[PLPlateSize alloc]init]; - [plateType2SizeUltra setName:@"Ultra"]; - [plateType2SizeUltra setPrice:12.00]; - [plateType2SizeUltra setId:81]; - PLPlateSize *plateType2SizeKids = [[PLPlateSize alloc]init]; - [plateType2SizeKids setName:@"Kids"]; - [plateType2SizeKids setPrice:8.00]; - [plateType2SizeKids setId:82]; + // Make a request - [[plateType4Sides sizes] addObject:plateType2SizeFit]; - [[plateType4Sides sizes] addObject:plateType2SizeUltra]; - [[plateType4Sides sizes] addObject:plateType2SizeKids]; + // For now hard code 2 Plate Types - [plates addObject:plateType4Sides]; + // 1 Main and 2 Sides +// PLPlateType *plateType1Main2Sides = [[PLPlateType alloc]init]; +// [plateType1Main2Sides setName:@"1 Main 2 Sides"]; +// [plateType1Main2Sides setId:1]; +// [plateType1Main2Sides setSizes:[[NSMutableArray alloc]init]]; +// +// PLPlateSize *plateType1SizeFit = [[PLPlateSize alloc]init]; +// [plateType1SizeFit setName:@"Fit"]; +// [plateType1SizeFit setPrice:10.00]; +// [plateType1SizeFit setId:90]; +// +// PLPlateSize *plateType1SizeUltra = [[PLPlateSize alloc]init]; +// [plateType1SizeUltra setName:@"Ultra"]; +// [plateType1SizeUltra setPrice:12.00]; +// [plateType1SizeUltra setId:91]; +// +// PLPlateSize *plateType1SizeKids = [[PLPlateSize alloc]init]; +// [plateType1SizeKids setName:@"Kids"]; +// [plateType1SizeKids setPrice:8.00]; +// [plateType1SizeKids setId:92]; +// +// [[plateType1Main2Sides sizes] addObject:plateType1SizeFit]; +// [[plateType1Main2Sides sizes] addObject:plateType1SizeUltra]; +// [[plateType1Main2Sides sizes] addObject:plateType1SizeKids]; +// +// [plates addObject:plateType1Main2Sides]; +// +// // 4 Sides +// PLPlateType *plateType4Sides = [[PLPlateType alloc]init]; +// [plateType4Sides setName:@"4 Sides"]; +// [plateType4Sides setId:2]; +// [plateType4Sides setSizes:[[NSMutableArray alloc]init]]; +// +// PLPlateSize *plateType2SizeFit = [[PLPlateSize alloc]init]; +// [plateType2SizeFit setName:@"Fit"]; +// [plateType2SizeFit setPrice:10.00]; +// [plateType2SizeFit setId:80]; +// +// PLPlateSize *plateType2SizeUltra = [[PLPlateSize alloc]init]; +// [plateType2SizeUltra setName:@"Ultra"]; +// [plateType2SizeUltra setPrice:12.00]; +// [plateType2SizeUltra setId:81]; +// +// PLPlateSize *plateType2SizeKids = [[PLPlateSize alloc]init]; +// [plateType2SizeKids setName:@"Kids"]; +// [plateType2SizeKids setPrice:8.00]; +// [plateType2SizeKids setId:82]; +// +// [[plateType4Sides sizes] addObject:plateType2SizeFit]; +// [[plateType4Sides sizes] addObject:plateType2SizeUltra]; +// [[plateType4Sides sizes] addObject:plateType2SizeKids]; +// +// [plates addObject:plateType4Sides]; } } - (void)clearCache { - menu = nil; + plateTypesSizes = nil; + plateMenus = nil; + aLaCarteMenu = nil; + addOnsMenu = nil; } + (PLPlateStore *)sharedStore { static PLPlateStore *sharedStore = nil; - if (!sharedStore) + if (!sharedStore) { sharedStore = [[super allocWithZone:nil] init]; - + [sharedStore clearCache]; + } return sharedStore; } diff --git a/PLPlateType.h b/PLPlateType.h index fb232ff..5034158 100644 --- a/PLPlateType.h +++ b/PLPlateType.h @@ -2,18 +2,16 @@ // PLPlateType.h // Plate // -// Created by emileleon on 1/24/14. +// Created by emileleon on 2/6/14. // Copyright (c) 2014 Plate SF. All rights reserved. // #import -#import "JSONSerializable.h" -@class PLPlateSize; -@interface PLPlateType : NSObject +@interface PLPlateType : NSObject @property (nonatomic, strong) NSString *name; -@property (nonatomic) int id; +@property (nonatomic, strong) NSString *slug; +@property (nonatomic, strong) NSString *id; @property (nonatomic, strong) NSMutableArray *sizes; - @end diff --git a/PLPlateType.m b/PLPlateType.m index b2d9196..089e3a9 100644 --- a/PLPlateType.m +++ b/PLPlateType.m @@ -2,30 +2,12 @@ // PLPlateType.m // Plate // -// Created by emileleon on 1/24/14. +// Created by emileleon on 2/6/14. // Copyright (c) 2014 Plate SF. All rights reserved. // #import "PLPlateType.h" -#import "PLPlateSize.h" @implementation PLPlateType --(void)readFromJSONDictionary:(NSDictionary *)d -{ - self.name = [d objectForKey:@"name"]; - self.id = [[d objectForKey:@"id"] intValue]; - - - if (self.sizes == nil) { - self.sizes = [[NSMutableArray alloc]init]; - } - - NSDictionary *sizesDict = [d objectForKey:@"sizes"]; - for (NSDictionary *sizeDict in sizesDict) { - PLPlateSize *size = [[PLPlateSize alloc]init]; - [size readFromJSONDictionary:sizeDict]; - [[self sizes] addObject:size]; - } -} @end diff --git a/PLPlateTypeSize.h b/PLPlateTypeSize.h new file mode 100644 index 0000000..fbc4c40 --- /dev/null +++ b/PLPlateTypeSize.h @@ -0,0 +1,24 @@ +// +// PLPlateTypeSize.h +// Plate +// +// Created by emileleon on 2/6/14. +// Copyright (c) 2014 Plate SF. All rights reserved. +// + +#import +#import "JSONSerializable.h" + +@interface PLPlateTypeSize : NSObject + +@property (nonatomic, strong) NSString *typeName; +@property (nonatomic, strong) NSString *typeSlug; +@property (nonatomic, strong) NSString *typeId; +@property (nonatomic, strong) NSMutableArray *sizes; // array of PLPlateSize + +//@property (nonatomic, strong) NSString *sizeName; +//@property (nonatomic, strong) NSString *sizeSlug; +//@property (nonatomic, strong) NSString *typeId; +//@property (nonatomic, strong) NSString *modifierId; +//@property (nonatomic, assign) float price; +@end diff --git a/PLPlateTypeSize.m b/PLPlateTypeSize.m new file mode 100644 index 0000000..d8abe98 --- /dev/null +++ b/PLPlateTypeSize.m @@ -0,0 +1,33 @@ +// +// PLPlateTypeSize.m +// Plate +// +// Created by emileleon on 2/6/14. +// Copyright (c) 2014 Plate SF. All rights reserved. +// + +#import "PLPlateTypeSize.h" +#import "PLPlateSize.h" + +@implementation PLPlateTypeSize + +- (void)readFromJSONDictionary:(NSDictionary *)d +{ + self.typeName = [d objectForKey:@"name"]; + self.typeSlug = [d objectForKey:@"slug"]; + self.typeId = [[d objectForKey:@"id"] stringValue]; + + NSDictionary *sizesDict = [d objectForKey:@"sizes"]; + + if (!self.sizes) { + self.sizes = [[NSMutableArray alloc]init]; + } + + for (NSDictionary *sizeDict in sizesDict) { + PLPlateSize *size = [[PLPlateSize alloc]init]; + [size readFromJSONDictionary:sizeDict]; + [self.sizes addObject:size]; + } +} + +@end diff --git a/PLPlatesTypesAndSizes.h b/PLPlatesTypesAndSizes.h new file mode 100644 index 0000000..b3611fc --- /dev/null +++ b/PLPlatesTypesAndSizes.h @@ -0,0 +1,21 @@ +// +// PLPlateType.h +// Plate +// +// Created by emileleon on 1/24/14. +// Copyright (c) 2014 Plate SF. All rights reserved. +// + +#import +#import "JSONSerializable.h" +#import "PLPlateSize.h" + +@interface PLPlatesTypesAndSizes : NSObject +{ + NSMutableArray *plates; //array of PLPlateTypeSize +} + +- (NSMutableArray *)getSizes; +- (NSMutableArray *)getTypes; +//- (NSString *)getModifierIDForSize:(int)size type:(int)type; +@end diff --git a/PLPlatesTypesAndSizes.m b/PLPlatesTypesAndSizes.m new file mode 100644 index 0000000..234a209 --- /dev/null +++ b/PLPlatesTypesAndSizes.m @@ -0,0 +1,76 @@ +// +// PLPlateType.m +// Plate +// +// Created by emileleon on 1/24/14. +// Copyright (c) 2014 Plate SF. All rights reserved. +// + +#import "PLPlatesTypesAndSizes.h" +#import "PLPlateTypeSize.h" + +@implementation PLPlatesTypesAndSizes + +-(void)readFromJSONDictionary:(NSDictionary *)d +{ + if (plates == nil) { + plates = [[NSMutableArray alloc]init]; + } + + NSDictionary *platesDict = [d objectForKey:@"plates"]; + for (NSDictionary *plateDict in platesDict) { + PLPlateTypeSize *plate = [[PLPlateTypeSize alloc]init]; + [plate readFromJSONDictionary:plateDict]; + [plates addObject:plate]; + } +} + +- (NSMutableArray *)getSizes +{ + NSMutableArray *result = [[NSMutableArray alloc]init]; + + for (PLPlateTypeSize *plateType in plates) { + for (PLPlateSize *size in plateType.sizes) { + BOOL exists = false; + for (PLPlateSize *resultSize in result) { + if ([resultSize.slug isEqualToString:size.slug]) { + exists = true; + break; + } + } + if (!exists) { + [result addObject:size]; + } + } + } + + return result; +} + +- (NSMutableArray *)getTypes +{ + return plates; +} + +//-(NSString *)getModifierIDForSize:(int)size type:(int)type +//{ +// if (type == OneMain) { +// if (size == Fit) { +// return @"1"; +// } else if (size == Ultra) { +// return @"71"; +// } else if (size == Kids) { +// return @"73"; +// } +// } else if (type == FourSides) { +// if (size == Fit) { +// return @"2"; +// } else if (size == Ultra) { +// return @"72"; +// } else if (size == Kids) { +// return @"74"; +// } +// } +// return nil; +//} +@end diff --git a/PLSelectMainsViewController.m b/PLSelectMainsViewController.m index 8ff662f..33bb336 100644 --- a/PLSelectMainsViewController.m +++ b/PLSelectMainsViewController.m @@ -13,6 +13,8 @@ #import "PLBasketStore.h" #import "PLPlate.h" #import "Colours.h" +#import "PLPlateTypeSize.h" +#import "PLPlateSize.h" @interface PLSelectMainsViewController () @@ -58,14 +60,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [[PLBasketStore sharedStore] setPlateMain:[mains objectAtIndex:[indexPath row]]]; - [tableView reloadData]; - -// if([tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark){ -// [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone; -// }else{ -// [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; -// } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section @@ -88,10 +83,8 @@ - (void)fetchMains __weak PLSelectMainsViewController *weakSelf = self; - // Determine the sizeTypeId -// [[Pla]] - - [[PLPlateStore sharedStore] getPlateMenu:2 forBlock:^(PLMenu *menuResult, NSError *err) { + PLPlate *plate = [[PLBasketStore sharedStore] plateBuilder]; + [[PLPlateStore sharedStore] getPlateMenu:[plate plateSize] plateType:[plate plateTypeSize] forBlock:^(PLMenu *menuResult, NSError *err) { [[weakSelf navigationItem] setTitleView:currentTitleView]; @@ -135,9 +128,6 @@ - (void)viewDidLoad [self setTitle:@"Mains"]; [[self tableMains] setTableHeaderView:nil]; [self fetchMains]; - - // self.automaticallyAdjustsScrollViewInsets = NO; - // self.edgesForExtendedLayout=UIRectEdgeNone; } diff --git a/PLSelectPlateSizeViewController.h b/PLSelectPlateSizeViewController.h index 4d99f71..471d742 100644 --- a/PLSelectPlateSizeViewController.h +++ b/PLSelectPlateSizeViewController.h @@ -14,8 +14,8 @@ @interface PLSelectPlateSizeViewController : PLBaseOrderViewController { - NSArray *plateType; // main with two sides, or 4 sides - NSArray *plateSize; // ultra, fit, kids + NSArray *plateTypes; // main with two sides, or 4 sides + NSArray *plateSizes; // ultra, fit, kids } @property (weak, nonatomic) IBOutlet UITableView *plateTypeTable; @property (weak, nonatomic) IBOutlet UITableView *plateSizeTable; diff --git a/PLSelectPlateSizeViewController.m b/PLSelectPlateSizeViewController.m index a154c39..d34df03 100644 --- a/PLSelectPlateSizeViewController.m +++ b/PLSelectPlateSizeViewController.m @@ -10,8 +10,10 @@ #import "PLSelectMainsViewController.h" #import "PLSelectSidesViewController.h" #import "PLBasketStore.h" +#import "PLPlateStore.h" #import "PLPlate.h" #import "Colours.h" +#import "PLPlatesTypesAndSizes.h" @interface PLSelectPlateSizeViewController () @@ -21,33 +23,67 @@ @implementation PLSelectPlateSizeViewController @synthesize mainsViewController; +//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +//{ +// if (tableView == [self plateTypeTable]) { // Plate Type +// if ([indexPath row] == 0) { +// [[[PLBasketStore sharedStore] plateBuilder] setType:OneMain]; +// } else { +// [[[PLBasketStore sharedStore] plateBuilder] setType:FourSides]; +// } +// } else { // Plate Size +// if ([indexPath row] == 0) { +// [[[PLBasketStore sharedStore] plateBuilder] setSize:Fit]; +// } else if ([indexPath row] == 1) { +// [[[PLBasketStore sharedStore] plateBuilder] setSize:Ultra]; +// } else if ([indexPath row] == 2) { +// [[[PLBasketStore sharedStore] plateBuilder] setSize:Kids]; +// } +// } +// +// [self reloadTableViewData]; +//} + - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == [self plateTypeTable]) { // Plate Type - if ([indexPath row] == 0) { - [[[PLBasketStore sharedStore] plateBuilder] setType:OneMain]; - } else { - [[[PLBasketStore sharedStore] plateBuilder] setType:FourSides]; - } + PLPlateTypeSize *selectedPlateTypeSize = (PLPlateTypeSize *)[plateTypes objectAtIndex:[indexPath row]]; + [[[PLBasketStore sharedStore] plateBuilder] setPlateTypeSize:selectedPlateTypeSize]; } else { // Plate Size - if ([indexPath row] == 0) { - [[[PLBasketStore sharedStore] plateBuilder] setSize:Fit]; - } else if ([indexPath row] == 1) { - [[[PLBasketStore sharedStore] plateBuilder] setSize:Ultra]; - } else if ([indexPath row] == 2) { - [[[PLBasketStore sharedStore] plateBuilder] setSize:Kids]; - } + PLPlateSize *selectedSize = (PLPlateSize *)[plateSizes objectAtIndex:[indexPath row]]; + [[[PLBasketStore sharedStore] plateBuilder] setPlateSize:selectedSize]; } - [self reloadTableViewData]; } +- (void)fetchPlateTypesAndSides +{ + __weak PLSelectPlateSizeViewController *weakSelf = self; + + [[PLPlateStore sharedStore] getPlateSizesAndTypes:^(PLPlatesTypesAndSizes *plateTypesSize, NSError *err) { + + if (!err) { + plateTypes = [plateTypesSize getTypes]; + plateSizes = [plateTypesSize getSizes]; + [weakSelf reloadTableViewData]; + } else { + UIAlertView *av =[[UIAlertView alloc] + initWithTitle:@"Error" + message:[err localizedDescription] + delegate:nil + cancelButtonTitle:@"OK" + otherButtonTitles:nil]; + [av show]; + } + }]; +} + - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if ([self plateSizeTable] == tableView) { - return [plateSize count]; + return [plateSizes count]; } else { - return [plateType count]; + return [plateTypes count]; } } @@ -71,39 +107,78 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.layer.backgroundColor = [[UIColor grayColor] CGColor]; cell.accessoryType = UITableViewCellAccessoryNone; cell.textLabel.textColor = [UIColor moneyGreenColor]; - - if (tableView == [self plateTypeTable]) { // Plate Type - - [[cell textLabel] setText:[plateType objectAtIndex:[indexPath row]]]; + if (tableView == [self plateTypeTable]) { // Plate Type + PLPlateTypeSize *plateTypeSize = (PLPlateTypeSize *)[plateTypes objectAtIndex:[indexPath row]]; + [[cell textLabel] setText:[plateTypeSize typeName]]; + // Add the checkmark if a type has been set - PlateType currentType = [[[PLBasketStore sharedStore] plateBuilder] type]; - if (([indexPath row] == 0) && (currentType == OneMain)) { - cell.accessoryType = UITableViewCellAccessoryCheckmark; - } else if (([indexPath row] == 1) && (currentType == FourSides)) { + PLPlateTypeSize *currentType = [[[PLBasketStore sharedStore] plateBuilder] plateTypeSize]; + if ([currentType.typeId isEqualToString:[plateTypeSize typeId]]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } - } else { // Plate Size - - [[cell textLabel] setText:[plateSize objectAtIndex:[indexPath row]]]; + PLPlateSize *plateSize = (PLPlateSize *)[plateSizes objectAtIndex:[indexPath row]]; + [[cell textLabel] setText:[plateSize name]]; // Add the checkmark if a size has been set - PlateSize currentSize = [[[PLBasketStore sharedStore] plateBuilder] size]; - if (([indexPath row] == 0) && (currentSize == Fit)) { - cell.accessoryType = UITableViewCellAccessoryCheckmark; - } else if (([indexPath row] == 1) && (currentSize == Ultra)) { - cell.accessoryType = UITableViewCellAccessoryCheckmark; - } else if (([indexPath row] == 2) && (currentSize == Kids)) { + PLPlateSize *currentSize = [[[PLBasketStore sharedStore] plateBuilder] plateSize]; + if ([currentSize.id isEqualToString:plateSize.id]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } - } return cell; } +//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +//{ +// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; +// if (cell == nil) { +// cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UITableViewCell"]; +// } +// +// cell.layer.borderWidth = 1.0f; +// cell.layer.borderColor = [[UIColor blackColor] CGColor]; +// cell.layer.masksToBounds = YES; +// cell.layer.cornerRadius = 12.0f; +// cell.layer.backgroundColor = [[UIColor grayColor] CGColor]; +// cell.accessoryType = UITableViewCellAccessoryNone; +// cell.textLabel.textColor = [UIColor moneyGreenColor]; +// +// if (tableView == [self plateTypeTable]) { // Plate Type +// +// [[cell textLabel] setText:[plateType objectAtIndex:[indexPath row]]]; +// +// // Add the checkmark if a type has been set +// PlateType currentType = [[[PLBasketStore sharedStore] plateBuilder] type]; +// if (([indexPath row] == 0) && (currentType == OneMain)) { +// cell.accessoryType = UITableViewCellAccessoryCheckmark; +// } else if (([indexPath row] == 1) && (currentType == FourSides)) { +// cell.accessoryType = UITableViewCellAccessoryCheckmark; +// } +// +// } else { // Plate Size +// +// [[cell textLabel] setText:[plateSize objectAtIndex:[indexPath row]]]; +// +// // Add the checkmark if a size has been set +// PlateSize currentSize = [[[PLBasketStore sharedStore] plateBuilder] size]; +// if (([indexPath row] == 0) && (currentSize == Fit)) { +// cell.accessoryType = UITableViewCellAccessoryCheckmark; +// } else if (([indexPath row] == 1) && (currentSize == Ultra)) { +// cell.accessoryType = UITableViewCellAccessoryCheckmark; +// } else if (([indexPath row] == 2) && (currentSize == Kids)) { +// cell.accessoryType = UITableViewCellAccessoryCheckmark; +// } +// +// } +// +// return cell; +// +//} + #pragma INITIALIZERS - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil @@ -124,18 +199,16 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view from its nib. - - if (!plateType) { - plateType = [[NSArray alloc]initWithObjects:@"1 Main with 2 Sides", @"4 Sides", nil]; - } - - if (!plateSize) { - plateSize = [[NSArray alloc]initWithObjects:@"Fit", @"Ultra", @"Kids", nil]; - } - + [self fetchPlateTypesAndSides]; [self setTitle:@"Sizes"]; - +// if (!plateTypes) { +// plateTypes = [[NSArray alloc]initWithObjects:@"1 Main with 2 Sides", @"4 Sides", nil]; +// } +// +// if (!plateSizes) { +// plateSizes = [[NSArray alloc]initWithObjects:@"Fit", @"Ultra", @"Kids", nil]; +// } + } - (void)didReceiveMemoryWarning @@ -147,7 +220,8 @@ - (void)didReceiveMemoryWarning - (IBAction)actionContinue:(id)sender { PLPlate *plate = [[PLBasketStore sharedStore] plateBuilder]; - if (([plate size] == UndefinedSize) || ([plate type] == UndefinedType)) { +// if (([plate size] == UndefinedSize) || ([plate type] == UndefinedType)) { + if (([plate plateSize] == nil) || ([plate plateTypeSize] == nil)) { NSString *msg = [NSString stringWithFormat:@"Select a type and size"]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:msg message:@"Please select your Plate's size and type" @@ -162,9 +236,10 @@ - (IBAction)actionContinue:(id)sender { [plate setMain:nil]; [plate setSides:[[NSMutableArray alloc]init]]; - if ([plate type] == OneMain) { + NSString *slug = [[[[PLBasketStore sharedStore] plateBuilder] plateTypeSize] typeSlug]; + if ([slug isEqualToString:OneMainTwoSides]) { [[self navigationController] pushViewController:[self mainsViewController] animated:YES]; - } else if ([plate type] == FourSides) { + } else if ([slug isEqualToString:FourSides]) { [[self navigationController] pushViewController:[self sidesViewController] animated:YES]; } } diff --git a/PLSelectSidesViewController.m b/PLSelectSidesViewController.m index 072ef26..a2a8b62 100644 --- a/PLSelectSidesViewController.m +++ b/PLSelectSidesViewController.m @@ -35,7 +35,8 @@ - (void)fetchSides __weak PLSelectSidesViewController *weakSelf = self; - [[PLPlateStore sharedStore] getMenu:^(PLMenu *menuResult, NSError *err) { + PLPlate *plate = [[PLBasketStore sharedStore] plateBuilder]; + [[PLPlateStore sharedStore] getPlateMenu:[plate plateSize] plateType:[plate plateTypeSize] forBlock:^(PLMenu *menuResult, NSError *err) { [[weakSelf navigationItem] setTitleView:currentTitleView]; @@ -94,23 +95,42 @@ - (void)viewDidLoad [super viewDidLoad]; self.title = @"Sides"; self.orderSummaryController = [[PLOrderSummaryViewController alloc]init]; - + UINib *nib = [UINib nibWithNibName:@"PLMenuItemTableViewCell" bundle:nil]; [[self tableSides] registerNib:nib forCellReuseIdentifier:@"PLMenuItemTableViewCell"]; [self fetchSides]; - + int numSides = 0; - if ([[[PLBasketStore sharedStore] plateBuilder] type] == OneMain) { + NSString *slug = [[[[PLBasketStore sharedStore] plateBuilder] plateTypeSize] typeSlug]; + if ([slug isEqualToString:OneMainTwoSides]) { numSides = 2; - } else if ([[[PLBasketStore sharedStore] plateBuilder] type] == FourSides) { + } else if ([slug isEqualToString:FourSides]) { numSides = 4; } self.labelSelectSides.text = [NSString stringWithFormat:@"Select %d sides", numSides]; - - } +//- (void)viewDidLoad +//{ +// [super viewDidLoad]; +// self.title = @"Sides"; +// self.orderSummaryController = [[PLOrderSummaryViewController alloc]init]; +// +// UINib *nib = [UINib nibWithNibName:@"PLMenuItemTableViewCell" bundle:nil]; +// [[self tableSides] registerNib:nib forCellReuseIdentifier:@"PLMenuItemTableViewCell"]; +// +// [self fetchSides]; +// +// int numSides = 0; +// if ([[[PLBasketStore sharedStore] plateBuilder] type] == OneMain) { +// numSides = 2; +// } else if ([[[PLBasketStore sharedStore] plateBuilder] type] == FourSides) { +// numSides = 4; +// } +// self.labelSelectSides.text = [NSString stringWithFormat:@"Select %d sides", numSides]; +//} + -(int)addItemWithCell:(PLMenuItemTableViewCell *)cell { PLMenuItem *item = nil; @@ -162,13 +182,14 @@ - (IBAction)actionContinue:(id)sender { PLPlate *plate = [[PLBasketStore sharedStore] plateBuilder]; int numSidesNeeded = 0; - - if ([plate type] == OneMain) { + + NSString *slug = [[[[PLBasketStore sharedStore] plateBuilder] plateTypeSize] typeSlug]; + if ([slug isEqualToString:OneMainTwoSides]) { numSidesNeeded = 2; - } else if ([plate type] == FourSides) { + } else if ([slug isEqualToString:FourSides]) { numSidesNeeded = 4; } - + int numSidesAdded = [[plate sides] count]; if (numSidesNeeded != numSidesAdded) { diff --git a/Plate.xcodeproj/project.pbxproj b/Plate.xcodeproj/project.pbxproj index b9abf3b..b31d752 100644 --- a/Plate.xcodeproj/project.pbxproj +++ b/Plate.xcodeproj/project.pbxproj @@ -41,7 +41,7 @@ 0A5FC5411886199800F69BA5 /* PLMenuItemTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A5FC5401886199800F69BA5 /* PLMenuItemTableViewCell.m */; }; 0A5FC58B188865EA00F69BA5 /* Plate.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 0A5FC589188865EA00F69BA5 /* Plate.xcdatamodeld */; }; 0A5FC58E18886C4900F69BA5 /* PLAddOnItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A5FC58D18886C4900F69BA5 /* PLAddOnItem.m */; }; - 0A6D138C189310D100C8F977 /* PLPlateType.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A6D138B189310D100C8F977 /* PLPlateType.m */; }; + 0A6D138C189310D100C8F977 /* PLPlatesTypesAndSizes.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A6D138B189310D100C8F977 /* PLPlatesTypesAndSizes.m */; }; 0A6D138F189310E000C8F977 /* PLPlateSize.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A6D138E189310E000C8F977 /* PLPlateSize.m */; }; 0A6D13931893286F00C8F977 /* PLBasketViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A6D13911893286F00C8F977 /* PLBasketViewController.m */; }; 0A6D13941893286F00C8F977 /* PLBasketViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0A6D13921893286F00C8F977 /* PLBasketViewController.xib */; }; @@ -60,6 +60,8 @@ 0A9D7E07184D602500BAE38D /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 0A9D7E01184D602500BAE38D /* README.md */; }; 0A9D7E08184D602500BAE38D /* release_notes.md in Resources */ = {isa = PBXBuildFile; fileRef = 0A9D7E02184D602500BAE38D /* release_notes.md */; }; 0A9D7E0A184D606200BAE38D /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A9D7E09184D606200BAE38D /* libz.dylib */; }; + 0AB66E0B18A4137B00441562 /* PLPlateTypeSize.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AB66E0A18A4137B00441562 /* PLPlateTypeSize.m */; }; + 0AB66E0E18A41AAD00441562 /* PLPlateType.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AB66E0D18A41AAD00441562 /* PLPlateType.m */; }; 0ABBE3F41843D0390031D3E2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0ABBE3F31843D0390031D3E2 /* Foundation.framework */; }; 0ABBE3F61843D0390031D3E2 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0ABBE3F51843D0390031D3E2 /* CoreGraphics.framework */; }; 0ABBE3F81843D0390031D3E2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0ABBE3F71843D0390031D3E2 /* UIKit.framework */; }; @@ -144,8 +146,8 @@ 0A5FC58A188865EA00F69BA5 /* Plate.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Plate.xcdatamodel; sourceTree = ""; }; 0A5FC58C18886C4900F69BA5 /* PLAddOnItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLAddOnItem.h; sourceTree = ""; }; 0A5FC58D18886C4900F69BA5 /* PLAddOnItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLAddOnItem.m; sourceTree = ""; }; - 0A6D138A189310D100C8F977 /* PLPlateType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLPlateType.h; sourceTree = ""; }; - 0A6D138B189310D100C8F977 /* PLPlateType.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLPlateType.m; sourceTree = ""; }; + 0A6D138A189310D100C8F977 /* PLPlatesTypesAndSizes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLPlatesTypesAndSizes.h; sourceTree = ""; }; + 0A6D138B189310D100C8F977 /* PLPlatesTypesAndSizes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLPlatesTypesAndSizes.m; sourceTree = ""; }; 0A6D138D189310E000C8F977 /* PLPlateSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLPlateSize.h; sourceTree = ""; }; 0A6D138E189310E000C8F977 /* PLPlateSize.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLPlateSize.m; sourceTree = ""; }; 0A6D13901893286F00C8F977 /* PLBasketViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLBasketViewController.h; sourceTree = ""; }; @@ -173,6 +175,10 @@ 0A9D7E04184D602500BAE38D /* TestFlight+ManualSessions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TestFlight+ManualSessions.h"; sourceTree = ""; }; 0A9D7E05184D602500BAE38D /* TestFlight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestFlight.h; sourceTree = ""; }; 0A9D7E09184D606200BAE38D /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; + 0AB66E0918A4137B00441562 /* PLPlateTypeSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLPlateTypeSize.h; sourceTree = ""; }; + 0AB66E0A18A4137B00441562 /* PLPlateTypeSize.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLPlateTypeSize.m; sourceTree = ""; }; + 0AB66E0C18A41AAD00441562 /* PLPlateType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLPlateType.h; sourceTree = ""; }; + 0AB66E0D18A41AAD00441562 /* PLPlateType.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLPlateType.m; sourceTree = ""; }; 0ABBE3F01843D0390031D3E2 /* Plate.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Plate.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0ABBE3F31843D0390031D3E2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 0ABBE3F51843D0390031D3E2 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -348,6 +354,8 @@ 0A9D7DE1184BA6E800BAE38D /* Stash Bin */ = { isa = PBXGroup; children = ( + 0AB66E0C18A41AAD00441562 /* PLPlateType.h */, + 0AB66E0D18A41AAD00441562 /* PLPlateType.m */, ); name = "Stash Bin"; sourceTree = ""; @@ -468,8 +476,10 @@ 0A5FC53B18860B9D00F69BA5 /* PLALaCarteItem.m */, 0A5FC58C18886C4900F69BA5 /* PLAddOnItem.h */, 0A5FC58D18886C4900F69BA5 /* PLAddOnItem.m */, - 0A6D138A189310D100C8F977 /* PLPlateType.h */, - 0A6D138B189310D100C8F977 /* PLPlateType.m */, + 0A6D138A189310D100C8F977 /* PLPlatesTypesAndSizes.h */, + 0A6D138B189310D100C8F977 /* PLPlatesTypesAndSizes.m */, + 0AB66E0918A4137B00441562 /* PLPlateTypeSize.h */, + 0AB66E0A18A4137B00441562 /* PLPlateTypeSize.m */, 0A6D138D189310E000C8F977 /* PLPlateSize.h */, 0A6D138E189310E000C8F977 /* PLPlateSize.m */, ); @@ -622,6 +632,7 @@ 0ADC53301856738400258E1E /* PLPlateStore.m in Sources */, 0A0D16931850FC9E0057F538 /* PLMenuViewController.m in Sources */, 0ABBE4041843D0390031D3E2 /* PLAppDelegate.m in Sources */, + 0AB66E0B18A4137B00441562 /* PLPlateTypeSize.m in Sources */, 0A21869D1896E00E00F79E4A /* Colours.m in Sources */, 0ADC53331856808F00258E1E /* PLConnection.m in Sources */, 0A318C63184532250023FFF5 /* PLStartOrderViewController.m in Sources */, @@ -644,10 +655,11 @@ 0A9D7DCE18470F5F00BAE38D /* PLSelectPlateSizeViewController.m in Sources */, 0A5FC53C18860B9D00F69BA5 /* PLALaCarteItem.m in Sources */, 0A5FC5271868CE5600F69BA5 /* PLBasketStore.m in Sources */, - 0A6D138C189310D100C8F977 /* PLPlateType.m in Sources */, + 0A6D138C189310D100C8F977 /* PLPlatesTypesAndSizes.m in Sources */, 0A5FC58E18886C4900F69BA5 /* PLAddOnItem.m in Sources */, 0A6D13931893286F00C8F977 /* PLBasketViewController.m in Sources */, 0A5FC52C1868D06B00F69BA5 /* PLALaCarteViewController.m in Sources */, + 0AB66E0E18A41AAD00441562 /* PLPlateType.m in Sources */, 0A495EF61852925D00C14B03 /* PLBaseRewardsViewController.m in Sources */, 0AC187F3185F872D00A0DD9F /* PLPlate.m in Sources */, ); diff --git a/Plate.xcodeproj/xcuserdata/emileleon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Plate.xcodeproj/xcuserdata/emileleon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index ad06399..4ac9ec1 100644 --- a/Plate.xcodeproj/xcuserdata/emileleon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Plate.xcodeproj/xcuserdata/emileleon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -250,11 +250,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLMenu.m" - timestampString = "411946333.160836" + timestampString = "413509505.834373" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "30" - endingLineNumber = "30" + startingLineNumber = "33" + endingLineNumber = "33" landmarkName = "-readFromJSONDictionary:" landmarkType = "5"> @@ -291,22 +291,6 @@ landmarkType = "5"> - - - - + landmarkName = "@implementation PLSelectMainsViewController" + landmarkType = "3"> - - - - @@ -458,11 +426,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLALaCarteViewController.m" - timestampString = "412560495.983315" + timestampString = "413513217.116828" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "34" - endingLineNumber = "34" + startingLineNumber = "35" + endingLineNumber = "35" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -474,11 +442,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLALaCarteViewController.m" - timestampString = "412560495.983315" + timestampString = "413513217.116828" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "31" - endingLineNumber = "31" + startingLineNumber = "32" + endingLineNumber = "32" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -568,11 +536,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLALaCarteViewController.m" - timestampString = "412560495.983315" + timestampString = "413513217.116828" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "51" - endingLineNumber = "51" + startingLineNumber = "52" + endingLineNumber = "52" landmarkName = "-addItemWithCell:" landmarkType = "5"> @@ -584,11 +552,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLALaCarteViewController.m" - timestampString = "412560495.983315" + timestampString = "413513217.116828" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "68" - endingLineNumber = "68" + startingLineNumber = "69" + endingLineNumber = "69" landmarkName = "-addItemWithCell:" landmarkType = "5"> @@ -600,11 +568,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLALaCarteViewController.m" - timestampString = "412560495.983315" + timestampString = "413513217.116828" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "148" - endingLineNumber = "148" + startingLineNumber = "149" + endingLineNumber = "149" landmarkName = "-viewDidLoad" landmarkType = "5"> @@ -616,11 +584,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLALaCarteViewController.m" - timestampString = "412560495.983315" + timestampString = "413513217.116828" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "132" - endingLineNumber = "132" + startingLineNumber = "133" + endingLineNumber = "133" landmarkName = "-viewDidAppear:" landmarkType = "5"> @@ -648,11 +616,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLALaCarteViewController.m" - timestampString = "412560495.983315" + timestampString = "413513217.116828" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "25" - endingLineNumber = "25" + startingLineNumber = "26" + endingLineNumber = "26" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -728,31 +696,15 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLALaCarteViewController.m" - timestampString = "412560495.983315" + timestampString = "413513217.116828" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "69" - endingLineNumber = "69" + startingLineNumber = "70" + endingLineNumber = "70" landmarkName = "-addItemWithCell:" landmarkType = "5"> - - - - + landmarkName = "@implementation PLSelectPlateSizeViewController" + landmarkType = "3"> - - - - - - - - - - - - @@ -904,11 +808,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLALaCarteViewController.m" - timestampString = "412560495.983315" + timestampString = "413513217.116828" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "27" - endingLineNumber = "27" + startingLineNumber = "28" + endingLineNumber = "28" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -945,22 +849,6 @@ landmarkType = "5"> - - - - + landmarkName = "@implementation PLBasketStore" + landmarkType = "3"> + landmarkName = "@implementation PLSelectPlateSizeViewController" + landmarkType = "3"> @@ -1079,7 +967,7 @@ symbolName = "-[PLALaCarteSummaryViewController viewDidLoad]" moduleName = "Plate" urlString = "file:///Users/emileleon/Documents/workspace/ios/Plate/PLALaCarteSummaryViewController.m" - timestampString = "411958402.634066" + timestampString = "413513911.773339" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "35" @@ -1093,7 +981,7 @@ symbolName = "-[PLALaCarteSummaryViewController viewDidLoad]" moduleName = "Plate" urlString = "file:///Users/emileleon/Documents/workspace/ios/Plate/PLALaCarteSummaryViewController.m" - timestampString = "411958402.634562" + timestampString = "413513911.773711" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "35" @@ -1238,11 +1126,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLAddOnViewController.m" - timestampString = "412559675.410612" + timestampString = "413511588.471462" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "26" - endingLineNumber = "26" + startingLineNumber = "28" + endingLineNumber = "28" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -1254,11 +1142,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLAddOnViewController.m" - timestampString = "412559675.410612" + timestampString = "413511588.471462" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "31" - endingLineNumber = "31" + startingLineNumber = "33" + endingLineNumber = "33" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -1609,23 +1497,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "123" endingLineNumber = "123" - landmarkName = "-buildFakeMenu" - landmarkType = "5"> - - - - @@ -1641,7 +1513,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "118" endingLineNumber = "118" - landmarkName = "-buildFakeMenu" + landmarkName = "-getPlateMenu:plateType:forBlock:" landmarkType = "5"> @@ -1697,14 +1569,44 @@ shouldBeEnabled = "No" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "PLAddOnViewController.m" - timestampString = "412569505.331929" + filePath = "PLBasketStore.m" + timestampString = "412570353.2294" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "154" - endingLineNumber = "154" - landmarkName = "-fetchAddOnItems" + startingLineNumber = "307" + endingLineNumber = "307" + landmarkName = "-printContentsOfBasket" landmarkType = "5"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1746,41 +1870,119 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "PLBasketStore.m" - timestampString = "412570353.2294" + timestampString = "413512544.107216" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "307" - endingLineNumber = "307" - landmarkName = "-totalCostOfItemsInBasket" + startingLineNumber = "28" + endingLineNumber = "28" + landmarkName = "-addAddOnItem:" + landmarkType = "5"> + + + + + startingLineNumber = "146" + endingLineNumber = "146" + offsetFromSymbolStart = "54"> + startingLineNumber = "146" + endingLineNumber = "146" + offsetFromSymbolStart = "1427"> + + + + + + + + + + + + + + diff --git a/Plate/Plate-Prefix.pch b/Plate/Plate-Prefix.pch index 2dd6226..2f50a28 100644 --- a/Plate/Plate-Prefix.pch +++ b/Plate/Plate-Prefix.pch @@ -17,6 +17,8 @@ #endif #define AppDelegate (PLAppDelegate *)[[UIApplication sharedApplication] delegate] +#define OneMainTwoSides @"1-main-2-sides" +#define FourSides @"4-sides" typedef enum { MenuItemMain, @@ -27,7 +29,7 @@ typedef enum { typedef enum { UndefinedType, OneMain, - FourSides + FourSidesX } PlateType; typedef enum { @@ -41,4 +43,10 @@ typedef enum { Plate, ALaCarte, AddOn -} BasketItemType; \ No newline at end of file +} BasketItemType; + +typedef enum { + MenuTypePlate, + MenuTypeALaCarte, + MenuTypeAddOn +} MenuType; \ No newline at end of file