diff --git a/Kinza/lib/Kinza.pm b/Kinza/lib/Kinza.pm index 5000c14..d3c1d85 100644 --- a/Kinza/lib/Kinza.pm +++ b/Kinza/lib/Kinza.pm @@ -61,11 +61,15 @@ hook before_template => sub { $params->{domain} = $ENV{KZ_DOMAIN}; $params->{reg_live} = $reg_live; $params->{sel_live} = $sel_live; - if (session('email')) { + if (session('email') and ! $params->{student}) { $params->{student} = $rs{Student}->find({ email => session('email') + }, { + prefetch => { form => 'year' }, }); - } else { + } + + if (!session('email')) { delete $params->{student}; } }; @@ -88,6 +92,8 @@ get '/' => sub { if (session('email')) { $student = $rs{Student}->find({ email => session('email'), + }, { + prefetch => [{ attendances => 'presentation' }, { form => 'year' } ], }); } @@ -96,7 +102,7 @@ get '/' => sub { } my @terms = $rs{Term}->search({}, { - prefetch => { presentations => 'attendances' }, + prefetch => { presentations => ['course', 'attendances'] }, order_by => 'seq', })->all; @@ -111,7 +117,6 @@ get '/' => sub { error => $error, choices => $choices, student => $student, - courses => [ $rs{Course}->all ], terms => \@terms, term_course => \%term_course, }; @@ -128,8 +133,14 @@ post '/save' => sub { my $terms = 0; my %courses; my @unavailable; - foreach (keys %params) { - my $pres = $rs{Presentation}->find({ id => $params{$_} }); + + my @pres = $rs{Presentation}->search({ + 'me.id' => [ values %params], + }, { + prefetch => [ 'course', 'term', 'attendances' ], + }); + + foreach my $pres (@pres) { $terms += $pres->number_of_terms; $courses{$pres->course->id} = 1; push @unavailable, $pres->course->title . ' (' . $pres->term->name . ')' diff --git a/Kinza/lib/Kinza/Schema/Result/Student.pm b/Kinza/lib/Kinza/Schema/Result/Student.pm index 42293ca..e779a22 100644 --- a/Kinza/lib/Kinza/Schema/Result/Student.pm +++ b/Kinza/lib/Kinza/Schema/Result/Student.pm @@ -171,7 +171,7 @@ sub sorted_attendances { my $self = shift; return $self->attendances->search({}, { - join => { presentation => 'term' }, + prefetch => { presentation => ['term', 'course'] }, order_by => 'term.seq', }); } diff --git a/Kinza/views/index.tt b/Kinza/views/index.tt index e17ca5d..950c795 100644 --- a/Kinza/views/index.tt +++ b/Kinza/views/index.tt @@ -42,7 +42,7 @@ IF ! skip_terms; THEN; SET p = term_course.${t.id}.${c.id}; IF p; THEN -%] - 1; THEN %] colspan=[% p.number_of_terms; END %] title="[% t.name %]"> + 1; THEN %] colspan=[% p.number_of_terms; END %] title="[% t.name %]"> [% SET skip_terms = p.number_of_terms - 1; ELSE -%]