Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Added in a session survey.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangrimm committed Apr 6, 2012
1 parent 29ff9c6 commit aeb680a
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Controllers/MLWSessionDetailController.m
Expand Up @@ -11,6 +11,7 @@
#import "MLWSpeaker.h"
#import "MLWMySchedule.h"
#import "MLWAppDelegate.h"
#import "MLWSessionSurveyViewController.h"

@interface MLWSessionDetailController ()
@property (nonatomic, retain) UITableView *tableView;
Expand All @@ -19,6 +20,7 @@ @interface MLWSessionDetailController ()
@property (nonatomic, retain) UIBarButtonItem *removeFromScheduleButton;
- (void)addToSchedule:(UIBarButtonItem *)sender;
- (void)removeFromSchedule:(UIBarButtonItem *)sender;
- (void)takeSurvey:(UIBarButtonItem *)sender;
@end

@implementation MLWSessionDetailController
Expand All @@ -44,6 +46,8 @@ - (id)initWithSession:(MLWSession *)session {
self.navigationItem.rightBarButtonItem = self.addToScheduleButton;
}

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Survey" style:UIBarButtonItemStylePlain target:self action:@selector(takeSurvey:)] autorelease];

nameHeight = 50;
titleHeight = 44;
contactHeight = 25;
Expand Down Expand Up @@ -353,6 +357,12 @@ - (void)removeFromSchedule:(UIBarButtonItem *)sender {
self.navigationItem.rightBarButtonItem = self.addToScheduleButton;
}

- (void)takeSurvey:(UIBarButtonItem *)sender {
MLWSessionSurveyViewController *surveyController = [[MLWSessionSurveyViewController alloc] initWithSession:self.session];
[self.navigationController pushViewController:surveyController animated:YES];
[surveyController release];
}

- (void)viewDidUnload {
self.view = nil;
self.tableView = nil;
Expand Down
15 changes: 15 additions & 0 deletions Controllers/MLWSessionSurveyViewController.h
@@ -0,0 +1,15 @@
//
// MLWSessionSurveyViewController.h
// MarkLogic World
//
// Created by Ryan Grimm on 4/6/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MLWSession.h"

@interface MLWSessionSurveyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

- (id)initWithSession:(MLWSession *)session;

@end
212 changes: 212 additions & 0 deletions Controllers/MLWSessionSurveyViewController.m
@@ -0,0 +1,212 @@
//
// MLWSessionSurveyViewController.m
// MarkLogic World
//
// Created by Ryan Grimm on 4/6/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MLWSessionSurveyViewController.h"
#import "MLWSessionSurvey.h"
#import "UITableView+helpers.h"

@interface MLWSessionSurveyViewController ()
@property (nonatomic, retain) UIView *loadingView;
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) MLWSession *session;
@property (nonatomic, retain) UISegmentedControl *speakerTabs;
@property (nonatomic, retain) UISegmentedControl *qualityTabs;
@property (nonatomic, retain) UITextView *comments;
- (void)submit:(UIBarButtonItem *)sender;
@end

@implementation MLWSessionSurveyViewController

@synthesize loadingView = _loadingView;
@synthesize tableView = _tableView;
@synthesize session = _session;
@synthesize speakerTabs = _speakerTabs;
@synthesize qualityTabs = _qualityTabs;
@synthesize comments = _comments;

- (id)initWithSession:(MLWSession *)session {
self = [super init];
if(self) {
self.session = session;
self.navigationItem.title = session.title;
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Submit" style:UIBarButtonItemStyleDone target:self action:@selector(submit:)] autorelease];
}
return self;
}

- (void)loadView {
self.view = [[[UIView alloc] init] autorelease];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

self.tableView = [[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped] autorelease];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView applyBackground];
[self.view addSubview:self.tableView];

self.speakerTabs = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Poor", @"Fair", @"Avg", @"Good", @"Great", nil]] autorelease];
self.speakerTabs.tintColor = [UIColor colorWithWhite:0.5 alpha:1];
self.speakerTabs.segmentedControlStyle = UISegmentedControlStyleBar;

self.qualityTabs = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Poor", @"Fair", @"Avg", @"Good", @"Great", nil]] autorelease];
self.qualityTabs.tintColor = [UIColor colorWithWhite:0.5 alpha:1];
self.qualityTabs.segmentedControlStyle = UISegmentedControlStyleBar;

self.comments = [[[UITextView alloc] init] autorelease];

self.loadingView = [[[UIView alloc] initWithFrame:self.view.frame] autorelease];
self.loadingView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.loadingView.backgroundColor = [UIColor blackColor];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = self.loadingView.center;
spinner.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[spinner startAnimating];
[self.loadingView addSubview:spinner];
[spinner release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

return YES;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *) tableView {
return 3;
}

- (NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger) section {
return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section == 0) {
return @"Effectiveness of speaker";
}
if(section == 1) {
return @"Quality of content";
}
if(section == 2) {
return @"Comments";
}
return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if(sectionTitle == nil) {
return nil;
}

UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 6, 300, 30);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.shadowColor = [UIColor blackColor];
label.shadowOffset = CGSizeMake(0.0, 2.0);
label.font = [UIFont boldSystemFontOfSize:16];
label.text = sectionTitle;

UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)] autorelease];
[view addSubview:label];
[label release];

return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 2) {
return 200;
}
return 44;
}

- (UITableViewCell *)tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
CGRect frame = cell.contentView.bounds;
frame.size.height = frame.size.height + 2;

if(indexPath.section == 0) {
self.speakerTabs.frame = frame;
[cell.contentView addSubview:self.speakerTabs];
}
else if(indexPath.section == 1) {
self.qualityTabs.frame = frame;
[cell.contentView addSubview:self.qualityTabs];
}
else if(indexPath.section == 2) {
self.comments.frame = CGRectInset(frame, 5, 5);
[cell.contentView addSubview:self.comments];
}
}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}

- (void)submit:(UIBarButtonItem *)sender {
self.loadingView.frame = self.view.frame;
[self.view addSubview:self.loadingView];

MLWSessionSurvey *survey = [[MLWSessionSurvey alloc] initWithSession:self.session];
if(self.speakerTabs.selectedSegmentIndex != UISegmentedControlNoSegment) {
survey.speakerRating = self.speakerTabs.selectedSegmentIndex + 1;
}
if(self.qualityTabs.selectedSegmentIndex != UISegmentedControlNoSegment) {
survey.contentRating = self.qualityTabs.selectedSegmentIndex + 1;
}
survey.comments = self.comments.text;

[survey submit:^(NSError *error) {
if(error == nil) {
[self.navigationController popViewControllerAnimated:YES];
}
}];
[survey release];
}

- (void)viewDidUnload {
self.loadingView = nil;
self.view = nil;
self.tableView = nil;
self.speakerTabs = nil;
self.qualityTabs = nil;
self.comments = nil;
[super viewDidUnload];
}

- (void)dealloc {
self.loadingView = nil;
self.view = nil;
self.tableView = nil;
self.session = nil;
self.speakerTabs = nil;
self.qualityTabs = nil;
self.comments = nil;
[super dealloc];
}

@end
1 change: 1 addition & 0 deletions CoronaConnector/CCRequest.h
Expand Up @@ -11,6 +11,7 @@
@interface CCRequest : NSObject

- (NSData *)dictionaryToPOSTData:(NSDictionary *) parameters;
- (NSString *)encodeString:(NSString *)string;

@property (nonatomic, retain) NSURL *baseURL;
@property (nonatomic, retain) NSMutableDictionary *parameters;
Expand Down
10 changes: 7 additions & 3 deletions CoronaConnector/CCRequest.m
Expand Up @@ -25,16 +25,20 @@ - (id)init {
- (NSData *)dictionaryToPOSTData:(NSDictionary *) parameters {
NSMutableString *POSTParams = [[[NSMutableString alloc] init] autorelease];
for(NSString *key in parameters) {
NSString *encodedValue = ((NSString *) CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef) [parameters objectForKey:key], NULL, CFSTR("=/:"), kCFStringEncodingUTF8));
[POSTParams appendString: key];
[POSTParams appendString: @"="];
[POSTParams appendString: encodedValue];
[POSTParams appendString: [self encodeString:[parameters objectForKey:key]]];
[POSTParams appendString: @"&"];
[encodedValue release];
}
return [POSTParams dataUsingEncoding:NSUTF8StringEncoding];
}

- (NSString *)encodeString:(NSString *)string {
NSString *encodeString = ((NSString *) CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef) string, NULL, CFSTR("=/:"), kCFStringEncodingUTF8));
[encodeString autorelease];
return encodeString;
}

- (void)dealloc {
self.baseURL = nil;
self.parameters = nil;
Expand Down
12 changes: 12 additions & 0 deletions MarkLogic World.xcodeproj/project.pbxproj
Expand Up @@ -42,6 +42,8 @@
C213AC2F152CD04600DEFB90 /* Icon~ipad@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C213AC2E152CD04600DEFB90 /* Icon~ipad@2x.png */; };
C213AC32152E14DD00DEFB90 /* MLWSponsorDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C213AC31152E14DD00DEFB90 /* MLWSponsorDetailViewController.m */; };
C213AC34152E1DAA00DEFB90 /* tweets@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C213AC33152E1DAA00DEFB90 /* tweets@2x.png */; };
C213AC37152F4CAE00DEFB90 /* MLWSessionSurveyViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C213AC36152F4CAE00DEFB90 /* MLWSessionSurveyViewController.m */; };
C213AC3A152F585800DEFB90 /* MLWSessionSurvey.m in Sources */ = {isa = PBXBuildFile; fileRef = C213AC39152F585800DEFB90 /* MLWSessionSurvey.m */; };
C26D897A151B757A00934014 /* MLWFilterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C26D8979151B757A00934014 /* MLWFilterViewController.m */; };
C26D89C1151E3F5400934014 /* CCAndConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = C26D89AA151E3F5400934014 /* CCAndConstraint.m */; };
C26D89C2151E3F5400934014 /* CCBooleanConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = C26D89AC151E3F5400934014 /* CCBooleanConstraint.m */; };
Expand Down Expand Up @@ -132,6 +134,10 @@
C213AC30152E14DD00DEFB90 /* MLWSponsorDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MLWSponsorDetailViewController.h; path = Controllers/MLWSponsorDetailViewController.h; sourceTree = "<group>"; };
C213AC31152E14DD00DEFB90 /* MLWSponsorDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MLWSponsorDetailViewController.m; path = Controllers/MLWSponsorDetailViewController.m; sourceTree = "<group>"; };
C213AC33152E1DAA00DEFB90 /* tweets@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tweets@2x.png"; sourceTree = "<group>"; };
C213AC35152F4CAE00DEFB90 /* MLWSessionSurveyViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MLWSessionSurveyViewController.h; path = Controllers/MLWSessionSurveyViewController.h; sourceTree = "<group>"; };
C213AC36152F4CAE00DEFB90 /* MLWSessionSurveyViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MLWSessionSurveyViewController.m; path = Controllers/MLWSessionSurveyViewController.m; sourceTree = "<group>"; };
C213AC38152F585800DEFB90 /* MLWSessionSurvey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MLWSessionSurvey.h; path = Models/MLWSessionSurvey.h; sourceTree = "<group>"; };
C213AC39152F585800DEFB90 /* MLWSessionSurvey.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MLWSessionSurvey.m; path = Models/MLWSessionSurvey.m; sourceTree = "<group>"; };
C26D8978151B757A00934014 /* MLWFilterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MLWFilterViewController.h; path = Controllers/MLWFilterViewController.h; sourceTree = "<group>"; };
C26D8979151B757A00934014 /* MLWFilterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MLWFilterViewController.m; path = Controllers/MLWFilterViewController.m; sourceTree = "<group>"; };
C26D89A9151E3F5400934014 /* CCAndConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCAndConstraint.h; path = CoronaConnector/CCAndConstraint.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -381,6 +387,8 @@
C26D8979151B757A00934014 /* MLWFilterViewController.m */,
C213AC30152E14DD00DEFB90 /* MLWSponsorDetailViewController.h */,
C213AC31152E14DD00DEFB90 /* MLWSponsorDetailViewController.m */,
C213AC35152F4CAE00DEFB90 /* MLWSessionSurveyViewController.h */,
C213AC36152F4CAE00DEFB90 /* MLWSessionSurveyViewController.m */,
);
name = Controllers;
sourceTree = "<group>";
Expand All @@ -400,6 +408,8 @@
C20CEEB31517B5A9009AA0AD /* MLWTweet.m */,
C283A4CB1524F06F004BF170 /* MLWMySchedule.h */,
C283A4CC1524F06F004BF170 /* MLWMySchedule.m */,
C213AC38152F585800DEFB90 /* MLWSessionSurvey.h */,
C213AC39152F585800DEFB90 /* MLWSessionSurvey.m */,
);
name = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -523,6 +533,8 @@
C26D89CF151E447200934014 /* CCStringQueryConstraint.m in Sources */,
C283A4CD1524F06F004BF170 /* MLWMySchedule.m in Sources */,
C213AC32152E14DD00DEFB90 /* MLWSponsorDetailViewController.m in Sources */,
C213AC37152F4CAE00DEFB90 /* MLWSessionSurveyViewController.m in Sources */,
C213AC3A152F585800DEFB90 /* MLWSessionSurvey.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
22 changes: 22 additions & 0 deletions Models/MLWSessionSurvey.h
@@ -0,0 +1,22 @@
//
// MLWSessionSurvey.h
// MarkLogic World
//
// Created by Ryan Grimm on 4/6/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "CCRequest.h"
#import "MLWSession.h"

@interface MLWSessionSurvey : CCRequest

- (id)initWithSession:(MLWSession *)session;

@property NSInteger speakerRating;
@property NSInteger contentRating;
@property (nonatomic, retain) NSString *comments;

- (void)submit:(void (^)(NSError *)) callback;

@end

0 comments on commit aeb680a

Please sign in to comment.