This repository was archived by the owner on Jun 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddClassViewController.m
More file actions
186 lines (161 loc) · 6.56 KB
/
AddClassViewController.m
File metadata and controls
186 lines (161 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// AddClassViewController.m
// TeachNotes With Parse
//
// Created by Davis Carlson on 2014-06-06.
// Copyright (c) 2014 Davis Carlson. All rights reserved.
//
#import "AddClassViewController.h"
@interface AddClassViewController () {
ZBarReaderViewController *readerqr;
}
@end
@implementation AddClassViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
readerqr = [ZBarReaderViewController new];
readerqr.readerDelegate = self;
readerqr.showsHelpOnFail = NO;
UIView * infoButton = [[[[[readerqr.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:3];
[infoButton setHidden:YES];
ZBarImageScanner *scanner = readerqr.scanner;
[scanner setSymbology: 0
config: ZBAR_CFG_ENABLE
to: 0];
[scanner setSymbology: ZBAR_QRCODE
config: ZBAR_CFG_ENABLE
to: 1];
// you can use this to support the simulator
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
ClassListViewController *classList = [[ClassListViewController alloc] init];
[classList reloadTheTable];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
-(IBAction)timePickerEnd:(id)sender {
NSDate *time = timePickerEnd.date;
NSDateFormatter *timeDF = [[NSDateFormatter alloc] init];
[timeDF setDateFormat:@"hh:mm a"];
NSString *endTime = [NSString stringWithFormat:@"%@", [timeDF stringFromDate:time]];
endTimePickerString = [NSString stringWithString:endTime];
}
-(IBAction)timePickerStart:(id)sender {
NSDate *time = timePickerStart.date;
NSDateFormatter *timeDF = [[NSDateFormatter alloc] init];
[timeDF setDateFormat:@"hh:mm a"];
NSString *startTime = [NSString stringWithFormat:@"%@", [timeDF stringFromDate:time]];
startTimePickerString = [NSString stringWithString:startTime];
}
-(void)imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
//1
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
//2
ZBarSymbol *symbol = nil;
for (symbol in results) break;
//3
barcode = symbol.data;
classCode.text = barcode;
[reader dismissViewControllerAnimated:YES completion:nil];
[self performSelector:@selector(addClassFromCode:) withObject:self afterDelay:0.5];
}
-(IBAction)scan {
// present and release the controller
[self presentViewController:readerqr
animated:YES completion:nil];
}
//---------------------------------------------------------------------------------------
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
-(IBAction)save:(id)sender {
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.transform = CGAffineTransformMakeScale(1.5, 1.5);
activityIndicator.frame = CGRectMake(0.0, 0.0, 150.0, 100.0);
activityIndicator.center = self.view.center;
[activityIndicator.layer setCornerRadius:8];
activityIndicator.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8f];
[self.view addSubview:activityIndicator];
[activityIndicator startAnimating];
NSString *name = teacherName.text;
NSString *email = teacherEmail.text;
NSString *className = teacherClassName.text;
NSString *userID = [[PFUser currentUser] objectId];
PFObject *newClass = [PFObject objectWithClassName:@"Classes"];
newClass[@"teacherName"] = name;
newClass[@"teacherEmail"] = email;
newClass[@"classname_number"] = className;
newClass[@"UserID"] = userID;
newClass[@"primaryTeacher"] = userID;
[newClass saveInBackground];
ClassListViewController *ClassListViewObj = [[ClassListViewController alloc] init];
[ClassListViewObj getAllClasses];
[self performSelector:@selector(dismissActivity) withObject:self afterDelay:3.0];
}
-(void)dismissActivity {
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(IBAction)cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
-(IBAction)addClassFromCode:(id)sender {
NSString *classCodeString = [NSString stringWithFormat:@"%@",classCode.text];
PFQuery *query = [PFQuery queryWithClassName:@"Classes"];
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.transform = CGAffineTransformMakeScale(1.5, 1.5);
activityIndicator.frame = CGRectMake(0.0, 0.0, 150.0, 100.0);
activityIndicator.center = self.view.center;
[activityIndicator.layer setCornerRadius:8];
activityIndicator.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8f];
[self.view addSubview:activityIndicator];
[activityIndicator startAnimating];
[query getObjectInBackgroundWithId:classCodeString block:^(PFObject *object, NSError *error) {
if (!object) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"That is not a Valid Class Code. Please Try Again" delegate:self cancelButtonTitle:@"Try Again" otherButtonTitles:nil];
// optional - add more buttons:
[alert show];
} else {
[object addObject:[[PFUser currentUser] objectId] forKey:@"addedTeachers"];
[object saveInBackground];
[self performSelector:@selector(dismissViewAddClass) withObject:self afterDelay:0.1];
}
}];
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[self dismissViewAddClass];
}
}
-(void)dismissViewAddClass {
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
[self dismissViewControllerAnimated:YES completion:nil];
}
@end