Archived
Added teacher column to substitutions
This commit is contained in:
+16
-12
@@ -30,6 +30,7 @@ class DataFetcher {
|
||||
let date = Expression<String>("date")
|
||||
let time = Expression<String>("time")
|
||||
let room = Expression<String>("room")
|
||||
let teacher = Expression<String>("teacher")
|
||||
let text = Expression<String>("text")
|
||||
|
||||
func doAsync(do task: String, completionHandler: @escaping (_ substitutions: [Any]) -> ()) {
|
||||
@@ -74,6 +75,7 @@ class DataFetcher {
|
||||
t.column(date)
|
||||
t.column(time)
|
||||
t.column(room)
|
||||
t.column(teacher)
|
||||
})
|
||||
|
||||
try db.run(personal.create(ifNotExists: true) { t in
|
||||
@@ -84,6 +86,7 @@ class DataFetcher {
|
||||
t.column(date)
|
||||
t.column(time)
|
||||
t.column(room)
|
||||
t.column(teacher)
|
||||
})
|
||||
|
||||
try db.run(substitutions.delete())
|
||||
@@ -99,25 +102,26 @@ class DataFetcher {
|
||||
let mDate = try cols.get(1).text()
|
||||
let mTime = try cols.get(2).text()
|
||||
let mRoom = try cols.get(4).text()
|
||||
let mTeacher = try cols.get(6).text()
|
||||
|
||||
subst.append(SubstModel(group: mGroup, course: mCourse, additional: mAdditional,
|
||||
date: mDate, time: mTime, room: mRoom))
|
||||
date: mDate, time: mTime, room: mRoom, teacher: mTeacher))
|
||||
let insert = substitutions.insert(group <- mGroup, course <- mCourse, additional <- mAdditional,
|
||||
date <- mDate, time <- mTime, room <- mRoom)
|
||||
date <- mDate, time <- mTime, room <- mRoom, teacher <- mTeacher)
|
||||
_ = try db.run(insert)
|
||||
if mDate.count > 2 && mDate[...mDate.index(mDate.startIndex, offsetBy: 2)] == "psa" {
|
||||
personalSubst.append(SubstModel(group: mGroup, course: mCourse, additional: mAdditional,
|
||||
date: mDate, time: mTime, room: mRoom))
|
||||
date: mDate, time: mTime, room: mRoom, teacher: mTeacher))
|
||||
let insertPersonal = personal.insert(group <- mGroup, course <- mCourse, additional <- mAdditional,
|
||||
date <- mDate, time <- mTime, room <- mRoom)
|
||||
date <- mDate, time <- mTime, room <- mRoom, teacher <- mTeacher)
|
||||
_ = try db.run(insertPersonal)
|
||||
} else if courses == nil || courses == "", classes != nil && classes != "" {
|
||||
if !mGroup.isEmpty && mGroup != "" {
|
||||
if classes!.contains(mGroup) || mGroup.contains(classes!) {
|
||||
personalSubst.append(SubstModel(group: mGroup, course: mCourse, additional: mAdditional,
|
||||
date: mDate, time: mTime, room: mRoom))
|
||||
date: mDate, time: mTime, room: mRoom, teacher: mTeacher))
|
||||
let insertPersonal = personal.insert(group <- mGroup, course <- mCourse, additional <- mAdditional,
|
||||
date <- mDate, time <- mTime, room <- mRoom)
|
||||
date <- mDate, time <- mTime, room <- mRoom, teacher <- mTeacher)
|
||||
_ = try db.run(insertPersonal)
|
||||
isPersonalEmpty = false
|
||||
personalPlanCount += 1
|
||||
@@ -128,9 +132,9 @@ class DataFetcher {
|
||||
if courses!.contains(mCourse) {
|
||||
if classes!.contains(mGroup) || mGroup.contains(classes!) {
|
||||
personalSubst.append(SubstModel(group: mGroup, course: mCourse, additional: mAdditional,
|
||||
date: mDate, time: mTime, room: mRoom))
|
||||
date: mDate, time: mTime, room: mRoom, teacher: mTeacher))
|
||||
let insertPersonal = personal.insert(group <- mGroup, course <- mCourse, additional <- mAdditional,
|
||||
date <- mDate, time <- mTime, room <- mRoom)
|
||||
date <- mDate, time <- mTime, room <- mRoom, teacher <- mTeacher)
|
||||
_ = try db.run(insertPersonal)
|
||||
isPersonalEmpty = false
|
||||
personalPlanCount += 1
|
||||
@@ -143,8 +147,8 @@ class DataFetcher {
|
||||
|
||||
prefs.set(personalPlanCount, forKey: "personalPlanCount")
|
||||
if isPersonalEmpty {
|
||||
personalSubst.append(SubstModel(group: NSLocalizedString("personal_plan_empty", comment: ""), course: "", additional: "", date: "", time: "", room: ""))
|
||||
let insertPersonal = personal.insert(group <- NSLocalizedString("personal_plan_empty", comment: ""), course <- "", additional <- "", date <- "", time <- "", room <- "")
|
||||
personalSubst.append(SubstModel(group: NSLocalizedString("personal_plan_empty", comment: ""), course: "", additional: "", date: "", time: "", room: "", teacher: ""))
|
||||
let insertPersonal = personal.insert(group <- NSLocalizedString("personal_plan_empty", comment: ""), course <- "", additional <- "", date <- "", time <- "", room <- "", teacher <- "")
|
||||
_ = try db.run(insertPersonal)
|
||||
}
|
||||
|
||||
@@ -225,7 +229,7 @@ class DataFetcher {
|
||||
do {
|
||||
let db = try Connection("\(path)/db.sqlite3")
|
||||
for subst in try db.prepare(substitutions) {
|
||||
substs.append(SubstModel(group: subst[group], course: subst[course], additional: subst[additional], date: subst[date], time: subst[time], room: subst[room]))
|
||||
substs.append(SubstModel(group: subst[group], course: subst[course], additional: subst[additional], date: subst[date], time: subst[time], room: subst[room], teacher: subst[teacher]))
|
||||
}
|
||||
} catch {}
|
||||
return substs
|
||||
@@ -236,7 +240,7 @@ class DataFetcher {
|
||||
do {
|
||||
let db = try Connection("\(path)/db.sqlite3")
|
||||
for subst in try db.prepare(personal) {
|
||||
substs.append(SubstModel(group: subst[group], course: subst[course], additional: subst[additional], date: subst[date], time: subst[time], room: subst[room]))
|
||||
substs.append(SubstModel(group: subst[group], course: subst[course], additional: subst[additional], date: subst[date], time: subst[time], room: subst[room], teacher: subst[teacher]))
|
||||
}
|
||||
} catch {}
|
||||
return substs
|
||||
|
||||
@@ -17,4 +17,5 @@ class PlanViewCell: GenericViewCell {
|
||||
@IBOutlet weak var additional: UILabel!
|
||||
@IBOutlet weak var room: UILabel!
|
||||
@IBOutlet weak var tintView: UIView!
|
||||
@IBOutlet weak var teacher: UILabel!
|
||||
}
|
||||
|
||||
@@ -133,10 +133,10 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
cell.additional.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
|
||||
}
|
||||
|
||||
let mutableStrings = [NSMutableAttributedString(string: self.substs[indexPath.item].group), NSMutableAttributedString(string: self.substs[indexPath.item].time), NSMutableAttributedString(string: self.substs[indexPath.item].course), NSMutableAttributedString(string: self.substs[indexPath.item].room)]
|
||||
let strings = [self.substs[indexPath.item].group, self.substs[indexPath.item].time, self.substs[indexPath.item].course, self.substs[indexPath.item].room]
|
||||
let mutableStrings = [NSMutableAttributedString(string: self.substs[indexPath.item].group), NSMutableAttributedString(string: self.substs[indexPath.item].time), NSMutableAttributedString(string: self.substs[indexPath.item].course), NSMutableAttributedString(string: self.substs[indexPath.item].room), NSMutableAttributedString(string: self.substs[indexPath.item].teacher)]
|
||||
let strings = [self.substs[indexPath.item].group, self.substs[indexPath.item].time, self.substs[indexPath.item].course, self.substs[indexPath.item].room, self.substs[indexPath.item].teacher]
|
||||
|
||||
for i in 0..<4 {
|
||||
for i in 0...4 {
|
||||
if let qmark = strings[i].firstIndex(of: "?") {
|
||||
let distance = strings[i].distance(from: strings[i].startIndex, to: qmark)
|
||||
mutableStrings[i].addAttribute(NSAttributedString.Key.strikethroughStyle, value: 2, range: NSMakeRange(0, distance))
|
||||
@@ -145,8 +145,9 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
|
||||
let add = self.substs[indexPath.item].additional.lowercased()
|
||||
if add.contains("eigenverantwortliches arbeiten") || add.contains("entfall") || add.contains("fällt aus"){
|
||||
mutableStrings[2].addAttribute(NSAttributedString.Key.strikethroughStyle, value: 2, range: NSMakeRange(0, mutableStrings[2].length))
|
||||
mutableStrings[3].addAttribute(NSAttributedString.Key.strikethroughStyle, value: 2, range: NSMakeRange(0, mutableStrings[3].length))
|
||||
for i in 2...4 {
|
||||
mutableStrings[i].addAttribute(NSAttributedString.Key.strikethroughStyle, value: 2, range: NSMakeRange(0, mutableStrings[i].length))
|
||||
}
|
||||
}
|
||||
|
||||
cell.group.attributedText = mutableStrings[0]
|
||||
@@ -154,6 +155,7 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
cell.time.attributedText = mutableStrings[1]
|
||||
cell.room.attributedText = mutableStrings[3]
|
||||
|
||||
var courseText = NSMutableAttributedString(string: "")
|
||||
if image != nil {
|
||||
let attachment: NSTextAttachment = NSTextAttachment()
|
||||
if indexOfPSA == indexPath.item {
|
||||
@@ -172,10 +174,17 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
courseImage.addAttribute(NSAttributedString.Key.foregroundColor, value: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), range: NSMakeRange(0, 3))
|
||||
}
|
||||
|
||||
cell.course.attributedText = courseImage
|
||||
courseText = courseImage
|
||||
} else {
|
||||
cell.course.attributedText = mutableStrings[2]
|
||||
courseText = mutableStrings[2]
|
||||
}
|
||||
if !courseText.isEqual(to: NSAttributedString(string: "")) && !substs[indexPath.item].teacher.isEmpty {
|
||||
courseText.append(NSAttributedString(string: " • "))
|
||||
courseText.append(mutableStrings[4])
|
||||
} else if courseText.isEqual(to: NSAttributedString(string: "")) && !substs[indexPath.item].teacher.isEmpty {
|
||||
courseText.append(mutableStrings[4])
|
||||
}
|
||||
cell.course.attributedText = courseText
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
@@ -15,13 +15,15 @@ class SubstModel {
|
||||
var date: String
|
||||
var time: String
|
||||
var room: String
|
||||
var teacher: String
|
||||
|
||||
init(group: String, course: String, additional: String, date: String, time: String, room: String) {
|
||||
init(group: String, course: String, additional: String, date: String, time: String, room: String, teacher: String) {
|
||||
self.group = group
|
||||
self.course = course
|
||||
self.additional = additional
|
||||
self.date = date
|
||||
self.time = time
|
||||
self.room = room
|
||||
self.teacher = teacher
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user