]> iEval git - gruntmaster-data.git/blobdiff - lib/Gruntmaster/Data/Result/Contest.pm
Add problem_status, contest_status and a method that updates them
[gruntmaster-data.git] / lib / Gruntmaster / Data / Result / Contest.pm
index 829cde652d0900345c88dc0519f4da96bc68e7dd..59334433c08e839b4c4aa5c3306b1cfc28d7abf5 100644 (file)
@@ -93,6 +93,21 @@ __PACKAGE__->has_many(
   { cascade_copy => 0, cascade_delete => 0 },
 );
 
+=head2 contest_statuses
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::ContestStatus>
+
+=cut
+
+__PACKAGE__->has_many(
+  "contest_statuses",
+  "Gruntmaster::Data::Result::ContestStatus",
+  { "foreign.contest" => "self.id" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
 =head2 jobs
 
 Type: has_many
@@ -135,7 +150,7 @@ __PACKAGE__->belongs_to(
   "owner",
   "Gruntmaster::Data::Result::User",
   { id => "owner" },
-  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+  { is_deferrable => 0, on_delete => "CASCADE", on_update => "NO ACTION" },
 );
 
 =head2 problems
@@ -149,9 +164,53 @@ Composing rels: L</contest_problems> -> problem
 __PACKAGE__->many_to_many("problems", "contest_problems", "problem");
 
 
-# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-06 12:41:16
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:T5tUpU1TOahLKzx9iVie3A
+# Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-11 23:51:27
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nu+Io9AhYkzYCky5UpCaKQ
+
+sub is_pending {
+       my ($self, $time) = @_;
+       $self->start > ($time // time)
+}
 
+sub is_finished {
+       my ($self, $time) = @_;
+       $self->stop <= ($time // time)
+}
+
+sub is_running {
+       my ($self, $time) = @_;
+       !$self->is_pending($time) && !$self->is_finished($time)
+}
 
-# You can replace this text with custom code or comments, and it will be preserved on regeneration
 1;
+
+__END__
+
+=head1 METHODS
+
+=head2 is_pending(I<[$time]>)
+
+Returns true if the contest is pending at time I<$time> (which defaults to C<time>).
+
+=head2 is_finished(I<[$time]>)
+
+Returns true if the contest is finished at time I<$time> (which defaults to C<time>).
+
+=head2 is_running(I<[$time]>)
+
+Returns true if the contest is running at time I<$time> (which defaults to C<time>).
+
+=head1 AUTHOR
+
+Marius Gavrilescu E<lt>marius@ieval.roE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2014 by Marius Gavrilescu
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.18.1 or,
+at your option, any later version of Perl 5 you may have available.
+
+
+=cut
This page took 0.023633 seconds and 4 git commands to generate.