Skip to content

Commit

Permalink
Added first report.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Sep 8, 2014
1 parent 37a3299 commit 5662c59
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
31 changes: 31 additions & 0 deletions Kinza/lib/Kinza.pm
@@ -1,4 +1,5 @@
package Kinza;
use 5.010;
use Dancer ':syntax';
use Dancer::Plugin::DBIC;
use Dancer::Plugin::Email;
Expand Down Expand Up @@ -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';
Expand Down
19 changes: 17 additions & 2 deletions Kinza/lib/Kinza/Schema/Result/Form.pm
Expand Up @@ -83,6 +83,21 @@ __PACKAGE__->set_primary_key("id");

=head1 RELATIONS
=head2 students
Type: has_many
Related object: L<Kinza::Schema::Result::Student>
=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
Expand All @@ -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
Expand Down
27 changes: 24 additions & 3 deletions Kinza/lib/Kinza/Schema/Result/Student.pm
Expand Up @@ -67,6 +67,7 @@ __PACKAGE__->table("student");
=head2 form_id
data_type: 'integer'
is_foreign_key: 1
is_nullable: 1
=head2 verify
Expand All @@ -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 },
);
Expand Down Expand Up @@ -121,6 +122,26 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 form
Type: belongs_to
Related object: L<Kinza::Schema::Result::Form>
=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
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Kinza/views/reports.tt
@@ -0,0 +1,5 @@
<h1>Reports</h1>
<p>Select a report:</p>
<ul>
<li><a href="/reports/form">Student choices by form</a></li>
</ul>

0 comments on commit 5662c59

Please sign in to comment.