Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func retrieveSelfServiceData (completion: @escaping (Bool) -> ()) {
- database.collection(SelfServiceKeys.collectionKey).getDocuments { (querySnapshot, error) in
- if let error = error {
- print("Error getting documents: \(error)")
- completion(false)
- } else {
- self.courses.removeAll()
- for document in querySnapshot!.documents {
- if let documentData = document.data() as? [String : Any] {
- let newAdmins = documentData[SelfServiceKeys.adminsKey] as? [String]
- let newCourses = documentData[SelfServiceKeys.coursesKey] as? [Any]
- for course in newCourses! {
- let dictCourse = course as! [String: Any]
- let newCicles = dictCourse[SelfServiceKeys.CoursesKeys.cicles] as? Int
- let newDescription = dictCourse[SelfServiceKeys.CoursesKeys.description] as? String
- let newEmphasis = dictCourse[SelfServiceKeys.CoursesKeys.emphasis] as? [String]
- let newImage = dictCourse[SelfServiceKeys.CoursesKeys.image] as? String
- let newMissions = dictCourse[SelfServiceKeys.CoursesKeys.missions] as? Int
- let newSeasons = dictCourse[SelfServiceKeys.CoursesKeys.seasons] as? Int
- self.courses.append(Course(cicles: newCicles, description: newDescription, emphasis: newEmphasis, image: newImage, missions: newMissions, seasons: newSeasons))
- }
- }
- }
- completion(true)
- }
- }
- }
- func retrieveSubjectsByCourseCicleEmphasis (completion: @escaping (Bool) -> ()) {
- let cicleFirestoreString = String(format: "Ciclo %d", (self.selectedCicle! + 1))
- print(cicleFirestoreString)
- database.collection(SubjectsKeys.collectionKey).whereField(SubjectsKeys.formation, isEqualTo: self.selectedCourse!).whereField(SubjectsKeys.cicleKey, isEqualTo: cicleFirestoreString).whereField(SubjectsKeys.emphasis, isEqualTo: self.selectedEmphasis!).getDocuments { (querySnapshot, error) in
- if let error = error {
- print("Error getting documents: \(error)")
- completion(false)
- } else {
- self.subjects.removeAll()
- for document in querySnapshot!.documents {
- let newArrayLearningObject = document[SubjectsKeys.learningObjectKey] as? [Any]
- let newImage = document[SubjectsKeys.image] as? String
- let newName = document[SubjectsKeys.name] as? String
- let newSubject = Subject.init(arrayLearningObject: newArrayLearningObject!, image: newImage!, name: newName!)
- self.subjects.append(newSubject)
- }
- completion(true)
- }
- }
- }
- func retrieveTeamMembers (completion: @escaping (Bool) -> ()) {
- database.collection(TeamMemberKeys.collectionKey).whereField(TeamMemberKeys.teamIDKey, isEqualTo: team!.reference!).getDocuments() { (querySnapshot, error) in
- if let error = error {
- print("Error getting documents: \(error)")
- completion(false)
- } else {
- self.members.removeAll()
- for document in querySnapshot!.documents {
- if let documentData = document.data() as? [String : Any] {
- let newCourse = documentData[TeamMemberKeys.courseKey] as? String
- let newEmail = documentData[TeamMemberKeys.emailKey] as? String
- let newTeamID = documentData[TeamMemberKeys.teamIDKey] as? DocumentReference
- let newName = documentData[TeamMemberKeys.nameKey] as? String
- let ID = document.documentID
- let newTeamMember = TeamMember.init(course: newCourse, email: newEmail, teamID: newTeamID, name: newName, ID: ID)
- self.members.append(newTeamMember)
- }
- }
- completion(true)
- }
- }
- }
- struct SelfServiceKeys {
- static let collectionKey = "meta-info"
- static let adminsKey = "admins"
- static let coursesKey = "cursos"
- struct CoursesKeys {
- static let cicles = "ciclos"
- static let description = "desc"
- static let emphasis = "enfases"
- static let image = "img"
- static let missions = "missoes"
- static let seasons = "temporadas"
- }
- }
- struct SubjectsKeys {
- static let collectionKey = "self"
- static let learningObjectKey = "arrayObjAprendizagem"
- static let cicleKey = "ciclo"
- static let emphasis = "enfase"
- static let formation = "formacao"
- static let image = "img"
- static let name = "nome"
- struct LearningObjectKeys {
- static let format = "formato"
- static let link = "link"
- static let name = "nome"
- static let type = "tipo"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement