diff --git a/Kinza/lib/Kinza.pm b/Kinza/lib/Kinza.pm index e0fa1f8..d79b720 100644 --- a/Kinza/lib/Kinza.pm +++ b/Kinza/lib/Kinza.pm @@ -1,4 +1,5 @@ package Kinza; +use 5.010; use Dancer ':syntax'; use Dancer::Plugin::DBIC; use Dancer::Plugin::Email; @@ -155,6 +156,36 @@ get '/dummies' => sub { template 'dummies', { students => \@students }; }; +get '/reports' => sub { + template 'reports'; +}; + +get '/reports/form' => sub { + content_type 'text/csv'; + + my $csv; + + foreach my $y (schema->resultset('Year')->search({}, { + order_by => 'id', + })) { + $csv .= $y->name . "\n"; + + foreach my $f ($y->forms->search({}, { order_by => 'id' })) { + $csv .= $f->name . "\n"; + + foreach my $s ($f->students->search({}, { order_by => 'name' })) { + $csv .= $s->name; + foreach my $a ($s->sorted_attendances) { + $csv .= ',' . $a->presentation->course->title . + ' / ' . $a->presentation->term->name; + } + } + } + } + + return $csv; +}; + get '/register' => sub { if ($now le $live) { return template 'comingsoon'; diff --git a/Kinza/lib/Kinza/Schema/Result/Form.pm b/Kinza/lib/Kinza/Schema/Result/Form.pm index 74b055f..2906eda 100644 --- a/Kinza/lib/Kinza/Schema/Result/Form.pm +++ b/Kinza/lib/Kinza/Schema/Result/Form.pm @@ -83,6 +83,21 @@ __PACKAGE__->set_primary_key("id"); =head1 RELATIONS +=head2 students + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "students", + "Kinza::Schema::Result::Student", + { "foreign.form_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 year Type: belongs_to @@ -99,8 +114,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-09-07 16:18:05 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EMHLaKP8SKqzMLixsT0NGg +# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-09-08 21:57:00 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tSCNpYA3zowtPu7cUYitNQ # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/Kinza/lib/Kinza/Schema/Result/Student.pm b/Kinza/lib/Kinza/Schema/Result/Student.pm index 062c37d..0a87019 100644 --- a/Kinza/lib/Kinza/Schema/Result/Student.pm +++ b/Kinza/lib/Kinza/Schema/Result/Student.pm @@ -67,6 +67,7 @@ __PACKAGE__->table("student"); =head2 form_id data_type: 'integer' + is_foreign_key: 1 is_nullable: 1 =head2 verify @@ -87,7 +88,7 @@ __PACKAGE__->add_columns( "password", { data_type => "varchar", is_nullable => 0, size => 255 }, "form_id", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "verify", { data_type => "varchar", is_nullable => 1, size => 255 }, ); @@ -121,6 +122,26 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 form + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "form", + "Kinza::Schema::Result::Form", + { id => "form_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "RESTRICT", + on_update => "RESTRICT", + }, +); + =head2 password_resets Type: has_many @@ -137,8 +158,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-09-07 16:26:50 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fWMkkeXm2GOsOwXsmSBr9g +# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-09-08 21:57:00 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:WItYpQSEGRBD4mS7LjkZWQ sub sorted_attendances { my $self = shift; diff --git a/Kinza/views/reports.tt b/Kinza/views/reports.tt new file mode 100644 index 0000000..a20b1b2 --- /dev/null +++ b/Kinza/views/reports.tt @@ -0,0 +1,5 @@ +

Reports

+

Select a report:

+