Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display certificate not issuing message #620

Merged
merged 3 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Stepic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,7 @@
2CBCBD4920D1AAFC000B5732 /* AchievementsListTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AchievementsListTableViewCell.xib; sourceTree = "<group>"; };
2CBCD3A7213583EB005D10FF /* Model_CourseListRename_v25.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model_CourseListRename_v25.xcdatamodel; sourceTree = "<group>"; };
2CBD855B201799B700E14F83 /* AdaptiveRatingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveRatingsViewController.swift; sourceTree = "<group>"; };
2CBF593423C8A61D00C366A1 /* Model_is_certificate_issued.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model_is_certificate_issued.xcdatamodel; sourceTree = "<group>"; };
2CC0754620177A2E004A6005 /* AdaptiveStatsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveStatsViewController.swift; sourceTree = "<group>"; };
2CC16BA823875DE30000EF36 /* DiscussionsSkeletonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscussionsSkeletonView.swift; sourceTree = "<group>"; };
2CC2A78D235DE26700B2DC44 /* DiscussionsLoadMoreTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscussionsLoadMoreTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7631,6 +7632,7 @@
08D1EF6E1BB5618700BE84E6 /* Model.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
2CBF593423C8A61D00C366A1 /* Model_is_certificate_issued.xcdatamodel */,
2C8B6E0323A27D2D0078A4B3 /* Model_required_section.xcdatamodel */,
2C101009239E7A1E00440651 /* Model_discount_policy.xcdatamodel */,
2CEE97B0239123EA005503EF /* Model_step_passed_by_correct_ratio.xcdatamodel */,
Expand Down Expand Up @@ -7678,7 +7680,7 @@
0802AC531C7222B200C4F3E6 /* Model_v2.xcdatamodel */,
08D1EF6F1BB5618700BE84E6 /* Model.xcdatamodel */,
);
currentVersion = 2C8B6E0323A27D2D0078A4B3 /* Model_required_section.xcdatamodel */;
currentVersion = 2CBF593423C8A61D00C366A1 /* Model_is_certificate_issued.xcdatamodel */;
path = Model.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down
4 changes: 2 additions & 2 deletions Stepic/AnalyticsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ final class AnalyticsHelper {
static var sharedHelper = AnalyticsHelper()

func setupAnalytics() {
Fabric.with([Crashlytics.self])

FirebaseApp.configure()

Fabric.with([Crashlytics.self])

if let config = YMMYandexMetricaConfiguration(apiKey: Tokens.shared.appMetricaToken) {
YMMYandexMetrica.activate(with: config)
}
Expand Down
38 changes: 25 additions & 13 deletions Stepic/Course+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ extension Course {
@NSManaged var managedIntroURL: String?
@NSManaged var managedFormat: String?
@NSManaged var managedAudience: String?
@NSManaged var managedCertificate: String?
@NSManaged var managedCertificateRegularThreshold: NSNumber?
@NSManaged var managedCertificateDistinctionThreshold: NSNumber?
@NSManaged var managedRequirements: String?
@NSManaged var managedSlug: String?
@NSManaged var managedProgressId: String?
Expand All @@ -43,11 +40,16 @@ extension Course {
@NSManaged var managedLanguageCode: String?
@NSManaged var managedTotalUnits: NSNumber?

@NSManaged var managedCertificate: String?
@NSManaged var managedCertificateRegularThreshold: NSNumber?
@NSManaged var managedCertificateDistinctionThreshold: NSNumber?
@NSManaged var managedIsCertificateAutoIssued: NSNumber?
@NSManaged var managedIsCertificateIssued: NSNumber?

@NSManaged var managedSectionsArray: NSObject?
@NSManaged var managedInstructorsArray: NSObject?
@NSManaged var managedAuthorsArray: NSObject?

@NSManaged var managedIsCertificateAutoIssued: NSNumber?
@NSManaged var managedIsPaid: NSNumber?
@NSManaged var managedDisplayPrice: String?

Expand Down Expand Up @@ -88,6 +90,7 @@ extension Course {
}
}

@available(*, deprecated, message: "Use `lessons_count` instead. https://vyahhi.myjetbrains.com/youtrack/issue/EDY-9837#focus=streamItem-74-64368.0-0")
var totalUnits: Int {
get {
self.managedTotalUnits?.intValue ?? 0
Expand Down Expand Up @@ -214,15 +217,6 @@ extension Course {
}
}

var isCertificatesAutoIssued: Bool {
set {
self.managedIsCertificateAutoIssued = newValue as NSNumber?
}
get {
managedIsCertificateAutoIssued?.boolValue ?? false
}
}

var isPaid: Bool {
set {
self.managedIsPaid = newValue as NSNumber?
Expand Down Expand Up @@ -324,6 +318,24 @@ extension Course {
}
}

var isCertificatesAutoIssued: Bool {
set {
self.managedIsCertificateAutoIssued = newValue as NSNumber?
}
get {
self.managedIsCertificateAutoIssued?.boolValue ?? false
}
}

var isCertificateIssued: Bool {
get {
self.managedIsCertificateIssued?.boolValue ?? false
}
set {
self.managedIsCertificateIssued = newValue as NSNumber?
}
}

var requirements: String {
set(value) {
self.managedRequirements = value
Expand Down
166 changes: 113 additions & 53 deletions Stepic/Course.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,6 @@ import SwiftyJSON
final class Course: NSManagedObject, IDFetchable {
typealias IdType = Int

required convenience init(json: JSON) {
self.init()
initialize(json)
}

func initialize(_ json: JSON) {
id = json["id"].intValue
title = json["title"].stringValue
courseDescription = json["description"].stringValue
coverURLString = "\(StepicApplicationsInfo.stepicURL)" + json["cover"].stringValue

beginDate = Parser.shared.dateFromTimedateJSON(json["begin_date_source"])
endDate = Parser.shared.dateFromTimedateJSON(json["last_deadline"])

enrolled = json["enrollment"].int != nil
featured = json["is_featured"].boolValue
isPublic = json["is_public"].boolValue
readiness = json["readiness"].float

summary = json["summary"].stringValue
workload = json["workload"].stringValue
introURL = json["intro"].stringValue
format = json["course_format"].stringValue
audience = json["target_audience"].stringValue
certificate = json["certificate"].stringValue
certificateRegularThreshold = json["certificate_regular_threshold"].int
certificateDistinctionThreshold = json["certificate_distinction_threshold"].int
requirements = json["requirements"].stringValue
slug = json["slug"].string
progressId = json["progress"].string
lastStepId = json["last_step"].string
scheduleType = json["schedule_type"].string
learnersCount = json["learners_count"].int
totalUnits = json["total_units"].intValue
reviewSummaryId = json["review_summary"].int
sectionsArray = json["sections"].arrayObject as! [Int]
instructorsArray = json["instructors"].arrayObject as! [Int]
authorsArray = json["authors"].arrayObject as? [Int] ?? []
timeToComplete = json["time_to_complete"].int
languageCode = json["language"].stringValue
isCertificatesAutoIssued = json["is_certificate_auto_issued"].boolValue
isPaid = json["is_paid"].boolValue
displayPrice = json["display_price"].string

if let _ = json["intro_video"].null {
introVideo = nil
} else {
introVideo = Video(json: json["intro_video"])
}
}

var sectionDeadlines: [SectionDeadline]? {
(PersonalDeadlineLocalStorageManager().getRecord(for: self)?.data as? DeadlineStorageData)?.deadlines
}
Expand Down Expand Up @@ -120,10 +69,74 @@ final class Course: NSManagedObject, IDFetchable {
&& self.scheduleType != "upcoming"
}

var hasAnyCertificateTreshold: Bool {
(self.certificateRegularThreshold != nil) || (self.certificateDistinctionThreshold != nil)
}

var hasCertificate: Bool {
let hasText = !self.certificate.isEmpty
let isIssued = self.isCertificatesAutoIssued && self.isCertificateIssued
return self.hasAnyCertificateTreshold && (hasText || isIssued)
}

required convenience init(json: JSON) {
self.init()
self.initialize(json)
}

func initialize(_ json: JSON) {
self.id = json[JSONKey.id.rawValue].intValue
self.title = json[JSONKey.title.rawValue].stringValue
self.courseDescription = json[JSONKey.description.rawValue].stringValue
self.coverURLString = "\(StepicApplicationsInfo.stepicURL)" + json[JSONKey.cover.rawValue].stringValue

self.beginDate = Parser.shared.dateFromTimedateJSON(json[JSONKey.beginDateSource.rawValue])
self.endDate = Parser.shared.dateFromTimedateJSON(json[JSONKey.lastDeadline.rawValue])

self.enrolled = json[JSONKey.enrollment.rawValue].int != nil
self.featured = json[JSONKey.isFeatured.rawValue].boolValue
self.isPublic = json[JSONKey.isPublic.rawValue].boolValue
self.readiness = json[JSONKey.readiness.rawValue].float

self.summary = json[JSONKey.summary.rawValue].stringValue
self.workload = json[JSONKey.workload.rawValue].stringValue
self.introURL = json[JSONKey.intro.rawValue].stringValue
self.format = json[JSONKey.courseFormat.rawValue].stringValue
self.audience = json[JSONKey.targetAudience.rawValue].stringValue
self.requirements = json[JSONKey.requirements.rawValue].stringValue
self.slug = json[JSONKey.slug.rawValue].string
self.progressId = json[JSONKey.progress.rawValue].string
self.lastStepId = json[JSONKey.lastStep.rawValue].string
self.scheduleType = json[JSONKey.scheduleType.rawValue].string
self.learnersCount = json[JSONKey.learnersCount.rawValue].int
self.totalUnits = json[JSONKey.totalUnits.rawValue].intValue
self.reviewSummaryId = json[JSONKey.reviewSummary.rawValue].int
self.sectionsArray = json[JSONKey.sections.rawValue].arrayObject as! [Int]
self.instructorsArray = json[JSONKey.instructors.rawValue].arrayObject as! [Int]
self.authorsArray = json[JSONKey.authors.rawValue].arrayObject as? [Int] ?? []
self.timeToComplete = json[JSONKey.timeToComplete.rawValue].int
self.languageCode = json[JSONKey.language.rawValue].stringValue
self.isPaid = json[JSONKey.isPaid.rawValue].boolValue
self.displayPrice = json[JSONKey.displayPrice.rawValue].string

self.certificate = json[JSONKey.certificate.rawValue].stringValue
self.certificateRegularThreshold = json[JSONKey.certificateRegularThreshold.rawValue].int
self.certificateDistinctionThreshold = json[JSONKey.certificateDistinctionThreshold.rawValue].int
self.isCertificatesAutoIssued = json[JSONKey.isCertificateAutoIssued.rawValue].boolValue
self.isCertificateIssued = json[JSONKey.isCertificateIssued.rawValue].boolValue

if let _ = json[JSONKey.introVideo.rawValue].null {
self.introVideo = nil
} else {
self.introVideo = Video(json: json[JSONKey.introVideo.rawValue])
}
}

func update(json: JSON) {
initialize(json)
self.initialize(json)
}

@available(*, deprecated, message: "Legacy")
func loadAllInstructors(success: @escaping (() -> Void)) {
_ = ApiDataDownloader.users.retrieve(
ids: self.instructorsArray,
Expand All @@ -140,6 +153,7 @@ final class Course: NSManagedObject, IDFetchable {
)
}

@available(*, deprecated, message: "Legacy")
func loadAllSections(
success: @escaping (() -> Void),
error errorHandler : @escaping (() -> Void),
Expand Down Expand Up @@ -201,7 +215,12 @@ final class Course: NSManagedObject, IDFetchable {
}
}

func loadProgressesForSections(sections: [Section], success completion: @escaping (() -> Void), error errorHandler : @escaping (() -> Void)) {
@available(*, deprecated, message: "Legacy")
func loadProgressesForSections(
sections: [Section],
success completion: @escaping (() -> Void),
error errorHandler : @escaping (() -> Void)
) {
var progressIds: [String] = []
var progresses: [Progress] = []
for section in sections {
Expand Down Expand Up @@ -373,4 +392,45 @@ final class Course: NSManagedObject, IDFetchable {
return sections.filter({ $0.id == nextId }).first
}
}

// MARK: Inner Types

enum JSONKey: String {
case id
case title
case description
case cover
case beginDateSource = "begin_date_source"
case lastDeadline = "last_deadline"
case enrollment
case isFeatured = "is_featured"
case isPublic = "is_public"
case readiness
case summary
case workload
case intro
case courseFormat = "course_format"
case targetAudience = "target_audience"
case certificate
case certificateRegularThreshold = "certificate_regular_threshold"
case certificateDistinctionThreshold = "certificate_distinction_threshold"
case isCertificateAutoIssued = "is_certificate_auto_issued"
case isCertificateIssued = "is_certificate_issued"
case requirements
case slug
case progress
case lastStep = "last_step"
case scheduleType = "schedule_type"
case learnersCount = "learners_count"
case totalUnits = "total_units"
case reviewSummary = "review_summary"
case sections
case instructors
case authors
case timeToComplete = "time_to_complete"
case language
case isPaid = "is_paid"
case displayPrice = "display_price"
case introVideo = "intro_video"
}
}
2 changes: 1 addition & 1 deletion Stepic/Model.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Model_required_section.xcdatamodel</string>
<string>Model_is_certificate_issued.xcdatamodel</string>
</dict>
</plist>
Loading