Skip to content

Commit

Permalink
课程包中的考试与考试中心的考试存放位置不同.
Browse files Browse the repository at this point in the history
  • Loading branch information
jay16 committed Aug 3, 2015
1 parent fc13357 commit f672454
Showing 11 changed files with 61 additions and 36 deletions.
1 change: 1 addition & 0 deletions iLearn/Source/Constants.h
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ extern NSString *const QuestionnaireFolder;
extern NSString *const ExamFolder;

extern NSString *const CommonFileName;
extern NSString *const CommonDBPath;

extern NSString *const QuestionnaireTitle;
extern NSString *const QuestionnaireDesc;
1 change: 1 addition & 0 deletions iLearn/Source/Constants.m
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
NSString *const ExamFolder = @"Exam";

NSString *const CommonFileName = @"filename";
NSString *const CommonDBPath = @"dbpath";

NSString *const QuestionnaireTitle = @"title";
NSString *const QuestionnaireDesc = @"desc";
4 changes: 2 additions & 2 deletions iLearn/Source/Exam/ExamTableViewController.m
Original file line number Diff line number Diff line change
@@ -470,11 +470,11 @@ - (void)enterExamPageForContent:(NSDictionary*)content
hud.labelText = NSLocalizedString(@"LIST_LOADING", nil);

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[ExamUtil parseContentIntoDB:content];

NSString *dbPath = [ExamUtil examDBPath:content[CommonFileName]];
[ExamUtil parseContentIntoDB:content Path:dbPath];

NSDictionary *dbContent = [ExamUtil examContentFromDBFile:dbPath];
[dbContent setValue:dbPath forKey:CommonDBPath];
//NSLog(@"dbContent: %@", [ExamUtil jsonStringOfContent:dbContent]);

dispatch_async(dispatch_get_main_queue(), ^{
36 changes: 20 additions & 16 deletions iLearn/Source/Exam/ExamViewController.m
Original file line number Diff line number Diff line change
@@ -490,14 +490,14 @@ - (void)saveSelections

NSMutableDictionary *subject = _examContent[ExamQuestions][_selectedCellIndex];
NSString *subjectId = subject[ExamQuestionId];
NSString *fileName = _examContent[CommonFileName];
//NSString *fileName = _examContent[CommonFileName];

for (int i = 0; i<[subject[ExamQuestionOptions] count]; i++) {

NSMutableDictionary *option = subject[ExamQuestionOptions][i];
NSString *optionId = option[ExamQuestionOptionId];

NSString *dbPath = [ExamUtil examDBPath:fileName];
NSString *dbPath = _examContent[CommonDBPath];

BOOL selected = [_selectedRowsOfSubject containsObject:@(i)];

@@ -667,8 +667,8 @@ - (void)submit

[self saveSelections];

NSString *fileName = _examContent[CommonFileName];
NSString *dbPath = [ExamUtil examDBPath:fileName];
//NSString *fileName = _examContent[CommonFileName];
NSString *dbPath = _examContent[CommonDBPath];

NSInteger score = [ExamUtil examScoreOfDBPath:dbPath];

@@ -681,24 +681,28 @@ - (void)submit

ExamTypes examType = [_examContent[ExamType] integerValue];
BOOL isUploadExamResult = YES;
scoreString = [NSString stringWithFormat:NSLocalizedString(@"EXAM_SCORE_TEMPLATE", nil), score];

if (examType == ExamTypesFormal &&
score < qualityLine &&
newSubmitTimes < allowTimes) { // Should test again
if (examType == ExamTypesFormal) {
if(score < qualityLine && newSubmitTimes < allowTimes) { // Should test again

[ExamUtil resetExamStatusOfDBPath:dbPath];
scoreString = [NSString stringWithFormat:NSLocalizedString(@"EXAM_UNDER_QUALIFY_TEMPLATE", nil), [NSNumber numberWithInteger:qualityLine],[NSNumber numberWithInteger:score], [NSNumber numberWithInteger:(allowTimes - newSubmitTimes)]];
isUploadExamResult = NO;
}
else {
if (newSubmitTimes > 1 && score > qualityLine) { // Qualitied and has submitted, the score should be just qualified
score = qualityLine;
[ExamUtil updateExamScore:score ofDBPath:dbPath];

}

[ExamUtil generateExamUploadJsonOfDBPath:dbPath];
scoreString = [NSString stringWithFormat:NSLocalizedString(@"EXAM_SCORE_TEMPLATE", nil), score];
isUploadExamResult = YES;
else {
if (newSubmitTimes > 1 && score > qualityLine) { // Qualitied and has submitted, the score should be just qualified
score = qualityLine;
[ExamUtil updateExamScore:score ofDBPath:dbPath];
}

[ExamUtil generateExamUploadJsonOfDBPath:dbPath];
isUploadExamResult = YES;
}
}
else if(examType == ExamTypesPractice) {
isUploadExamResult = NO;
}
//UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"EXAM_SCORE_TITLE", nil) message:scoreString delegate:weakSelf cancelButtonTitle:NSLocalizedString(@"COMMON_OK", nil) otherButtonTitles:nil];

22 changes: 12 additions & 10 deletions iLearn/Source/Lecture/LectureTableViewController.m
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
#import "ExamViewController.h"
#import "LicenseUtil.h"
#import "ExamUtil.h"
#import "FileUtils.h"
#import <MBProgressHUD.h>
#import "ListViewController.h"
#import "DataHelper.h"
@@ -23,9 +24,8 @@
#import "LectureTableViewCell.h"

static NSString *const kExamVCStoryBoardID = @"ExamViewController";
static NSString *const kShowDetailSegue = @"showDetailPage";
static NSString *const kShowPasswordSegue = @"showPasswordPage";
static NSString *const kShowSettingsSegue = @"showSettingsPage";
static NSString *const kShowDetailSegue = @"showDetailPage";
static NSString *const kShowSettingsSegue = @"showSettingsPage";

static NSString *const kTableViewCellIdentifier = @"LectureTableViewCell";

@@ -84,11 +84,8 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
detailVC.descString = [sender desc];
if (self.showBeginTestInfo) {
detailVC.delegate = self;
detailVC.shownFromBeginTest = self.showBeginTestInfo;
}
else {
detailVC.shownFromBeginTest = self.showBeginTestInfo;
}
detailVC.shownFromBeginTest = self.showBeginTestInfo;
}
}

@@ -271,11 +268,12 @@ - (void)enterExamPageForContent:(NSDictionary*)content {
hud.labelText = NSLocalizedString(@"LIST_LOADING", nil);

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[ExamUtil parseContentIntoDB:content];
NSString *examDBPath = [FileUtils coursePath:content[CommonFileName] Ext:@"db"];
[ExamUtil parseContentIntoDB:content Path:examDBPath];

NSString *dbPath = [ExamUtil examDBPath:content[CommonFileName]];

NSDictionary *dbContent = [ExamUtil examContentFromDBFile:dbPath];
NSDictionary *dbContent = [ExamUtil examContentFromDBFile:examDBPath];
[dbContent setValue:examDBPath forKey:CommonDBPath];
[dbContent setValue:[NSNumber numberWithInt:ExamTypesPractice] forKey:ExamType];

dispatch_async(dispatch_get_main_queue(), ^{
@@ -312,6 +310,10 @@ - (void)connectionManagerDidDownloadExam:(NSString *)examId withError:(NSError *
[_progressHUD hide:YES];

if(!error) {
NSString *examPath = [ExamUtil examPath:examId];
NSString *coursePath = [FileUtils coursePath:examId Ext:[examPath pathExtension]];
[FileUtils move:examPath to:coursePath];

[self.tableView reloadData];
}
}
2 changes: 2 additions & 0 deletions iLearn/Source/SubjectView/UploadExamViewController.m
Original file line number Diff line number Diff line change
@@ -72,6 +72,8 @@ - (void)connectionManagerDidDownloadExamsForUser:(NSString *)userId withError:(N

- (void)connectionManagerDidDownloadExam:(NSString *)examId withError:(NSError *)error {}

- (void)connectionManagerDidDownloadCourse:(NSString *)courseID Ext:(NSString *)extName withError:(NSError *)error {};

- (void)connectionManagerDidUploadExamResult:(NSString *)examId withError:(NSError *)error
{
if (!error) {
1 change: 1 addition & 0 deletions iLearn/Source/Utilities/ExamUtil.h
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
+ (void)cleanExamFolder;

+ (void)parseContentIntoDB:(NSDictionary*)content;
+ (void)parseContentIntoDB:(NSDictionary*)content Path:(NSString *)dbPath;
+ (NSDictionary*)examContentFromDBFile:(NSString*)dbPath;
+ (void)setOptionSelected:(BOOL)selected withSubjectId:(NSString*)subjectId optionId:(NSString*)optionId andDBPath:(NSString*)dbPath;

8 changes: 5 additions & 3 deletions iLearn/Source/Utilities/ExamUtil.m
Original file line number Diff line number Diff line change
@@ -264,10 +264,12 @@ + (NSString*)examSourceFolderPath
}
}


+ (void)parseContentIntoDB:(NSDictionary*)content
{
+ (void)parseContentIntoDB:(NSDictionary*)content {
NSString *dbPath = [self examDBPath:content[CommonFileName]];
[self parseContentIntoDB:content Path:dbPath];
}

+ (void)parseContentIntoDB:(NSDictionary*)content Path:(NSString *)dbPath {

NSFileManager *fileMgr = [NSFileManager defaultManager];
BOOL isFolder;
Original file line number Diff line number Diff line change
@@ -205,18 +205,20 @@ - (void)recordProgress:(NSDictionary *)dict {

#pragma mark - Around Exam
- (BOOL)isExamDownload {
return [ExamUtil isExamDownloaded:self.examId];
NSString *examPath = [FileUtils coursePath:self.examId Ext:@"json"];
return [FileUtils checkFileExist:examPath isDir:NO];
}

- (NSDictionary *)examDictContent {
if(!_examDictContent) {
NSString *examDBPath = [ExamUtil examDBPath:self.examId];
NSString *examDBPath = [FileUtils coursePath:self.examId Ext:@"db"];
NSDictionary *dict;
if([FileUtils checkFileExist:examDBPath isDir:NO]) {
dict = [ExamUtil examContentFromDBFile:examDBPath];
}
else {
dict = [FileUtils readConfigFile:[ExamUtil examPath:self.examId]];
NSString *examPath = [FileUtils coursePath:self.examId Ext:@"json"];
dict = [FileUtils readConfigFile:examPath];
}
_examDictContent = dict;
}
3 changes: 2 additions & 1 deletion iLearn/Source/iSearchShared/Utils/FileUtils/FileUtils.h
Original file line number Diff line number Diff line change
@@ -71,7 +71,8 @@
*
* @return 是否删除成功的布尔值
*/
+ (BOOL) removeFile:(NSString *)filePath;
+ (BOOL)removeFile:(NSString *)filePath;
+ (BOOL)move:(NSString *)source to:(NSString *)target;

/**
* 文件体积大小转化为可读文字;
11 changes: 10 additions & 1 deletion iLearn/Source/iSearchShared/Utils/FileUtils/FileUtils.m
Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ + (void) printDir: (NSString *)dirName {
*
* @return 是否删除成功的布尔值
*/
+ (BOOL) removeFile:(NSString *)filePath {
+ (BOOL)removeFile:(NSString *)filePath {
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL removed = [fileManager removeItemAtPath: filePath error: &error];
@@ -201,6 +201,15 @@ + (BOOL) removeFile:(NSString *)filePath {
}


+ (BOOL)move:(NSString *)source to:(NSString *)target {
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL moved = [fileManager moveItemAtPath:source toPath:target error:&error];
if(error)
NSLog(@"<# move %@ => %@ failed for %@", source, target, [error localizedDescription]);

return moved;
}

/**
* 文件体积大小转化为可读文字;

0 comments on commit f672454

Please sign in to comment.