From f11e7602e3856eb8d758d92a5203836ce37c4e17 Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Tue, 29 Dec 2015 17:24:24 +0000 Subject: [PATCH] Handle terms with missing attendences correctly. --- Kinza/lib/Kinza/Reports.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Kinza/lib/Kinza/Reports.pm b/Kinza/lib/Kinza/Reports.pm index 61d48ab..e9ccd19 100644 --- a/Kinza/lib/Kinza/Reports.pm +++ b/Kinza/lib/Kinza/Reports.pm @@ -27,7 +27,7 @@ get '/form' => sub { header 'Content-Disposition' => 'attachment; filename="form.csv"'; my $csv; - my $terms = join ',', map { $_->name } $rs{Term}->all; + my $terms = join ',', map { $_->name } $rs{Term}->search({}, { order_by => 'seq' })->all; foreach my $y (schema->resultset('Year')->search({}, { order_by => 'id', @@ -40,9 +40,12 @@ get '/form' => sub { foreach my $s ($f->students->search({}, { order_by => 'name' })) { $csv .= $s->name; + my $term_seq = 1; foreach my $a ($s->sorted_attendances) { - for (1 .. $a->presentation->number_of_terms) { + if ($a->presentation->term->seq == $term_seq++) { $csv .= ',"' . $a->presentation->course->title . '"'; + } else { + $csv .= ','; } } $csv .= "\n";