Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 5.14 KB | None | 0 0
  1. func retrieveSelfServiceData (completion: @escaping (Bool) -> ()) {
  2.         database.collection(SelfServiceKeys.collectionKey).getDocuments { (querySnapshot, error) in
  3.             if let error = error {
  4.                 print("Error getting documents: \(error)")
  5.                 completion(false)
  6.             } else {
  7.                 self.courses.removeAll()
  8.                 for document in querySnapshot!.documents {
  9.                     if let documentData = document.data() as? [String : Any] {
  10.                         let newAdmins = documentData[SelfServiceKeys.adminsKey] as? [String]
  11.                         let newCourses = documentData[SelfServiceKeys.coursesKey] as? [Any]
  12.                         for course in newCourses! {
  13.                             let dictCourse = course as! [String: Any]
  14.                             let newCicles = dictCourse[SelfServiceKeys.CoursesKeys.cicles] as? Int
  15.                             let newDescription = dictCourse[SelfServiceKeys.CoursesKeys.description] as? String
  16.                             let newEmphasis = dictCourse[SelfServiceKeys.CoursesKeys.emphasis] as? [String]
  17.                             let newImage = dictCourse[SelfServiceKeys.CoursesKeys.image] as? String
  18.                             let newMissions = dictCourse[SelfServiceKeys.CoursesKeys.missions] as? Int
  19.                             let newSeasons = dictCourse[SelfServiceKeys.CoursesKeys.seasons] as? Int
  20.                             self.courses.append(Course(cicles: newCicles, description: newDescription, emphasis: newEmphasis, image: newImage, missions: newMissions, seasons: newSeasons))
  21.                         }
  22.                     }
  23.                 }
  24.                 completion(true)
  25.             }
  26.         }
  27.     }
  28.  
  29. func retrieveSubjectsByCourseCicleEmphasis (completion: @escaping (Bool) -> ()) {
  30.         let cicleFirestoreString = String(format: "Ciclo %d", (self.selectedCicle! + 1))
  31.         print(cicleFirestoreString)
  32.         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
  33.             if let error = error {
  34.                 print("Error getting documents: \(error)")
  35.                 completion(false)
  36.             } else {
  37.                 self.subjects.removeAll()
  38.                 for document in querySnapshot!.documents {
  39.                     let newArrayLearningObject = document[SubjectsKeys.learningObjectKey] as? [Any]
  40.                     let newImage = document[SubjectsKeys.image] as? String
  41.                     let newName = document[SubjectsKeys.name] as? String
  42.                     let newSubject = Subject.init(arrayLearningObject: newArrayLearningObject!, image: newImage!, name: newName!)
  43.                     self.subjects.append(newSubject)
  44.                 }
  45.                 completion(true)
  46.             }
  47.         }
  48.     }
  49.  
  50. func retrieveTeamMembers (completion: @escaping (Bool) -> ()) {
  51.         database.collection(TeamMemberKeys.collectionKey).whereField(TeamMemberKeys.teamIDKey, isEqualTo: team!.reference!).getDocuments() { (querySnapshot, error) in
  52.             if let error = error {
  53.                 print("Error getting documents: \(error)")
  54.                 completion(false)
  55.             } else {
  56.                 self.members.removeAll()
  57.                 for document in querySnapshot!.documents {
  58.                     if let documentData = document.data() as? [String : Any] {
  59.                         let newCourse = documentData[TeamMemberKeys.courseKey] as? String
  60.                         let newEmail = documentData[TeamMemberKeys.emailKey] as? String
  61.                         let newTeamID = documentData[TeamMemberKeys.teamIDKey] as? DocumentReference
  62.                         let newName = documentData[TeamMemberKeys.nameKey] as? String
  63.                         let ID = document.documentID
  64.                         let newTeamMember = TeamMember.init(course: newCourse, email: newEmail, teamID: newTeamID, name: newName, ID: ID)
  65.                         self.members.append(newTeamMember)
  66.                     }
  67.                 }
  68.                 completion(true)
  69.             }
  70.         }
  71.     }
  72.  
  73. struct SelfServiceKeys {
  74.     static let collectionKey = "meta-info"
  75.     static let adminsKey = "admins"
  76.     static let coursesKey = "cursos"
  77.     struct CoursesKeys {
  78.         static let cicles = "ciclos"
  79.         static let description = "desc"
  80.         static let emphasis = "enfases"
  81.         static let image = "img"
  82.         static let missions = "missoes"
  83.         static let seasons = "temporadas"
  84.     }
  85. }
  86.  
  87. struct SubjectsKeys {
  88.     static let collectionKey = "self"
  89.     static let learningObjectKey = "arrayObjAprendizagem"
  90.     static let cicleKey = "ciclo"
  91.     static let emphasis = "enfase"
  92.     static let formation = "formacao"
  93.     static let image = "img"
  94.     static let name = "nome"
  95.     struct LearningObjectKeys {
  96.         static let format = "formato"
  97.         static let link = "link"
  98.         static let name = "nome"
  99.         static let type = "tipo"
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement