Skip to content

Commit

Permalink
pdf sorted by ancode, examer and module
Browse files Browse the repository at this point in the history
  • Loading branch information
obcode committed Nov 11, 2023
1 parent 78c8ca8 commit c153951
Showing 1 changed file with 120 additions and 1 deletion.
121 changes: 120 additions & 1 deletion plexams/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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"}

Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c153951

Please sign in to comment.