diff --git a/src/Utils/Schedule.hs b/src/Utils/Schedule.hs index 372fba5ca..ebcf4dd4f 100644 --- a/src/Utils/Schedule.hs +++ b/src/Utils/Schedule.hs @@ -52,11 +52,16 @@ fetchExamOccurrences muid ata now = E.select $ E.from $ \(course `E.InnerJoin` e E.&&. (E.exists $ E.from $ \examRegistration -> E.where_ $ examRegistration E.^. ExamRegistrationExam E.==. exam E.^. ExamId E.&&. E.just (examRegistration E.^. ExamRegistrationUser) E.==. E.val muid - E.&&. E.maybe E.true (\registrationOccurrence -> registrationOccurrence E.==. examOccurrence E.^. ExamOccurrenceId) (examRegistration E.^. ExamRegistrationOccurrence) -- if registered for a specific occurrence, get only this one, otherwise get every occurrence available + E.&&. E.maybe E.true (\registrationOccurrence -> hasExamOccurrenceDisplayOptIn examOccurrence E.||. registrationOccurrence E.==. examOccurrence E.^. ExamOccurrenceId) (examRegistration E.^. ExamRegistrationOccurrence) -- if registered for a specific occurrence, get only this one and occurrences with an opt-in, otherwise get every occurrence available ) ) ) return (course, exam, examOccurrence) + where + hasExamOccurrenceDisplayOptIn examOccurrence = E.exists . E.from $ \examOccurrenceScheduleOpt -> E.where_ $ + examOccurrenceScheduleOpt E.^. ExamOccurrenceScheduleOptExamOccurrence E.==. examOccurrence E.^. ExamOccurrenceId + E.&&. E.just (examOccurrenceScheduleOpt E.^. ExamOccurrenceScheduleOptUser) E.==. E.val muid + E.&&. examOccurrenceScheduleOpt E.^. ExamOccurrenceScheduleOptOpt courseEventShouldBeDisplayed :: Maybe UserId -> E.SqlExpr (Entity Course) -> E.SqlExpr (Entity CourseEvent) -> E.SqlExpr (E.Value Bool)