From ab7b6222895b835b5fdbca160f7ca8038881ad07 Mon Sep 17 00:00:00 2001 From: Muhammad Umer Date: Fri, 29 Jan 2021 12:26:40 +0500 Subject: [PATCH] Suggested dates displaying in app to learners in instructor-paced courses - PLS (#1458) * added check for is_self_paced for PLS banner --- Source/CourseDatesViewController.swift | 23 ++++++++++++++++++++++- Source/CourseOutlineViewController.swift | 19 ++++++++++++++++++- Source/HTMLBlockViewController.swift | 4 +++- Source/OEXCourse.h | 3 +-- Source/OEXCourse.m | 2 ++ 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Source/CourseDatesViewController.swift b/Source/CourseDatesViewController.swift index ac6439280f..a35a23fa73 100644 --- a/Source/CourseDatesViewController.swift +++ b/Source/CourseDatesViewController.swift @@ -142,7 +142,7 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin courseBannerStream.listen(self) { [weak self] result in switch result { case .success(let courseBanner): - self?.loadCourseDateBannerView(bannerModel: courseBanner) + self?.handleDatesBanner(courseBanner: courseBanner) break case .failure(let error): @@ -152,6 +152,23 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin } } + private func handleDatesBanner(courseBanner: CourseDateBannerModel) { + guard let isSelfPaced = environment.dataManager.enrollmentManager.enrolledCourseWithID(courseID: courseID)?.course.isSelfPaced else { + updateDatesBannerVisibility(with: 0) + return + } + + if isSelfPaced { + loadCourseDateBannerView(bannerModel: courseBanner) + } else { + if let status = courseBanner.bannerInfo.status, status == .upgradeToCompleteGradedBanner { + loadCourseDateBannerView(bannerModel: courseBanner) + } else { + updateDatesBannerVisibility(with: 0) + } + } + } + private func loadCourseDateBannerView(bannerModel: CourseDateBannerModel) { let height: CGFloat if bannerModel.hasEnded { @@ -164,6 +181,10 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin height = courseDateBannerView.heightForView(width: tableView.frame.size.width) } + updateDatesBannerVisibility(with: height) + } + + private func updateDatesBannerVisibility(with height: CGFloat) { courseDateBannerView.snp.remakeConstraints { make in make.trailing.equalTo(tableView) make.leading.equalTo(tableView) diff --git a/Source/CourseOutlineViewController.swift b/Source/CourseOutlineViewController.swift index c430e44a47..de26b25012 100644 --- a/Source/CourseOutlineViewController.swift +++ b/Source/CourseOutlineViewController.swift @@ -190,7 +190,7 @@ public class CourseOutlineViewController : courseBannerStream.listen(self) { [weak self] result in switch result { case .success(let courseBanner): - self?.loadCourseDateBannerView(courseBanner: courseBanner) + self?.handleDatesBanner(courseBanner: courseBanner) break case .failure(let error): @@ -201,6 +201,23 @@ public class CourseOutlineViewController : } } + private func handleDatesBanner(courseBanner: CourseDateBannerModel) { + guard let isSelfPaced = environment.dataManager.enrollmentManager.enrolledCourseWithID(courseID: courseID)?.course.isSelfPaced else { + hideCourseBannerView() + return + } + + if isSelfPaced { + loadCourseDateBannerView(courseBanner: courseBanner) + } else { + if let status = courseBanner.bannerInfo.status, status == .upgradeToCompleteGradedBanner { + loadCourseDateBannerView(courseBanner: courseBanner) + } else { + hideCourseBannerView() + } + } + } + private func loadCourseStream() { loadController.state = .Initial loadCourseOutlineStream() diff --git a/Source/HTMLBlockViewController.swift b/Source/HTMLBlockViewController.swift index b118392658..bcf5b1b967 100644 --- a/Source/HTMLBlockViewController.swift +++ b/Source/HTMLBlockViewController.swift @@ -94,7 +94,9 @@ public class HTMLBlockViewController: UIViewController, CourseBlockViewControlle } private func loadBannerStream() { - guard subkind == .Problem else { return } + guard subkind == .Problem, + let isSelfPaced = environment.dataManager.enrollmentManager.enrolledCourseWithID(courseID: courseID)?.course.isSelfPaced, + isSelfPaced else { return } let courseBannerRequest = CourseDateBannerAPI.courseDateBannerRequest(courseID: courseID) let courseBannerStream = environment.networkManager.streamForRequest(courseBannerRequest) diff --git a/Source/OEXCourse.h b/Source/OEXCourse.h index 33c5572109..73416b56a7 100644 --- a/Source/OEXCourse.h +++ b/Source/OEXCourse.h @@ -69,8 +69,7 @@ OEXStartType OEXStartTypeForString(NSString* type); @property (readonly, nonatomic, assign) BOOL isStartDateOld; @property (readonly, nonatomic, assign) BOOL isEndDateOld; @property (readonly, nonatomic, assign) BOOL isAuditExpired; - - +@property (readonly, nonatomic) BOOL isSelfPaced; @end diff --git a/Source/OEXCourse.m b/Source/OEXCourse.m index 3800f5e117..5dded2b939 100644 --- a/Source/OEXCourse.m +++ b/Source/OEXCourse.m @@ -76,6 +76,7 @@ @interface OEXCourse () @property (nonatomic, copy) NSString* subscription_id; @property (nonatomic, copy) NSString* number; @property (nonatomic, copy) NSString* effort; +@property (nonatomic) BOOL isSelfPaced; @property (nonatomic, copy) NSString* short_description; @property (nonatomic, copy) NSString* overview_html; @property (nonatomic, copy) NSString* course_updates; // ANNOUNCEMENTS @@ -109,6 +110,7 @@ - (id)initWithDictionary:(NSDictionary *)info { self.root_block_usage_key = [info objectForKey:@"root_block_usage_key"]; self.number = [info objectForKey:@"number"]; self.effort = [info objectForKey:@"effort"]; + self.isSelfPaced = [[info objectForKey:@"is_self_paced"] boolValue]; self.short_description = [info objectForKey:@"short_description"]; self.overview_html = [info objectForKey:@"overview"]; self.course_updates = [info objectForKey:@"course_updates"];