From c15395122b534fc58fcf21a6fa1d3e43698aa293 Mon Sep 17 00:00:00 2001 From: Oliver Braun Date: Sat, 11 Nov 2023 20:45:11 +0100 Subject: [PATCH] pdf sorted by ancode, examer and module --- plexams/pdf.go | 121 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/plexams/pdf.go b/plexams/pdf.go index c1d5237..0ae6116 100644 --- a/plexams/pdf.go +++ b/plexams/pdf.go @@ -60,7 +60,7 @@ func (p *Plexams) GenerateExamsToPlanPDF(ctx context.Context, outfile string) er }) }) }) - m.Row(20, func() { + m.Row(10, func() { m.Col(12, func() { m.Text( fmt.Sprintf("Melden Sie sich bitte umgehend per E-Mail (%s) bei mir (%s), wenn Ihre Prüfung hier fehlt oder hier nicht stehen sollte.", @@ -71,6 +71,16 @@ func (p *Plexams) GenerateExamsToPlanPDF(ctx context.Context, outfile string) er }) }) }) + m.Row(10, func() { + m.Col(12, func() { + m.Text( + "Dieses Dokument enthält alle Prüfungen in 3 Sortierungen.", props.Text{ + Top: 3, + Style: consts.Normal, + Align: consts.Center, + }) + }) + }) header := []string{"AnCode", "Modul", "Prüfer:in", "Gruppe(n)", "Form"} @@ -79,6 +89,17 @@ func (p *Plexams) GenerateExamsToPlanPDF(ctx context.Context, outfile string) er log.Error().Err(err).Msg("error while getting exams") } + m.Row(20, func() { + m.Col(12, func() { + m.Text( + "Sortiert nach AnCode (= der Code im ZPA)", props.Text{ + Top: 5, + Style: consts.Bold, + Align: consts.Center, + }) + }) + }) + contents := make([][]string, 0, len(exams)) for _, exam := range exams { @@ -106,6 +127,104 @@ func (p *Plexams) GenerateExamsToPlanPDF(ctx context.Context, outfile string) er Line: false, }) + m.Row(20, func() { + m.Col(12, func() { + m.Text( + "Sortiert nach dem Namen der Prüfer:in", props.Text{ + Top: 5, + Style: consts.Bold, + Align: consts.Center, + }) + }) + }) + + examsByExamers := make(map[string][]*model.ZPAExam) + for _, exam := range exams { + examsByExamer, ok := examsByExamers[exam.MainExamer] + if !ok { + examsByExamer = make([]*model.ZPAExam, 0, 1) + } + examsByExamers[exam.MainExamer] = append(examsByExamer, exam) + } + + keys := make([]string, 0, len(examsByExamers)) + for k := range examsByExamers { + keys = append(keys, k) + } + sort.Strings(keys) + + contents = make([][]string, 0, len(exams)) + + for _, key := range keys { + for _, exam := range examsByExamers[key] { + contents = append(contents, []string{strconv.Itoa(exam.AnCode), exam.Module, exam.MainExamer, fmt.Sprintf("%v", exam.Groups), exam.ExamTypeFull}) + } + } + + m.TableList(header, contents, props.TableList{ + HeaderProp: props.TableListContent{ + Size: 9, + GridSizes: []uint{1, 4, 2, 2, 3}, + }, + ContentProp: props.TableListContent{ + Size: 8, + GridSizes: []uint{1, 4, 2, 2, 3}, + }, + Align: consts.Left, + AlternatedBackground: &grayColor, + HeaderContentSpace: 1, + Line: false, + }) + + m.Row(20, func() { + m.Col(12, func() { + m.Text( + "Sortiert nach dem Prüfungsnamen", props.Text{ + Top: 5, + Style: consts.Bold, + Align: consts.Center, + }) + }) + }) + + examsByModules := make(map[string][]*model.ZPAExam) + for _, exam := range exams { + examsByModule, ok := examsByModules[exam.Module] + if !ok { + examsByModule = make([]*model.ZPAExam, 0, 1) + } + examsByModules[exam.Module] = append(examsByModule, exam) + } + + keys = make([]string, 0, len(examsByModules)) + for k := range examsByModules { + keys = append(keys, k) + } + sort.Strings(keys) + + contents = make([][]string, 0, len(exams)) + + for _, key := range keys { + for _, exam := range examsByModules[key] { + contents = append(contents, []string{strconv.Itoa(exam.AnCode), exam.Module, exam.MainExamer, fmt.Sprintf("%v", exam.Groups), exam.ExamTypeFull}) + } + } + + m.TableList(header, contents, props.TableList{ + HeaderProp: props.TableListContent{ + Size: 9, + GridSizes: []uint{1, 4, 2, 2, 3}, + }, + ContentProp: props.TableListContent{ + Size: 8, + GridSizes: []uint{1, 4, 2, 2, 3}, + }, + Align: consts.Left, + AlternatedBackground: &grayColor, + HeaderContentSpace: 1, + Line: false, + }) + err = m.OutputFileAndClose(outfile) if err != nil { log.Error().Err(err).Msg("Could not save PDF")