]>
Commit | Line | Data |
---|---|---|
4ed3f8e7 MG |
1 | use utf8; |
2 | package Gruntmaster::Data::Result::Contest; | |
3 | ||
4 | # Created by DBIx::Class::Schema::Loader | |
5 | # DO NOT MODIFY THE FIRST PART OF THIS FILE | |
6 | ||
7 | =head1 NAME | |
8 | ||
9 | Gruntmaster::Data::Result::Contest | |
10 | ||
11 | =cut | |
12 | ||
13 | use strict; | |
14 | use warnings; | |
15 | ||
16 | use base 'DBIx::Class::Core'; | |
17 | ||
18 | =head1 TABLE: C<contests> | |
19 | ||
20 | =cut | |
21 | ||
22 | __PACKAGE__->table("contests"); | |
23 | ||
24 | =head1 ACCESSORS | |
25 | ||
26 | =head2 id | |
27 | ||
28 | data_type: 'text' | |
29 | is_nullable: 0 | |
30 | ||
31 | =head2 name | |
32 | ||
33 | data_type: 'text' | |
34 | is_nullable: 0 | |
35 | ||
36 | =head2 start | |
37 | ||
38 | data_type: 'integer' | |
39 | is_nullable: 0 | |
40 | ||
41 | =head2 stop | |
42 | ||
43 | data_type: 'integer' | |
44 | is_nullable: 0 | |
45 | ||
46 | =head2 owner | |
47 | ||
48 | data_type: 'text' | |
49 | is_foreign_key: 1 | |
50 | is_nullable: 0 | |
51 | ||
52 | =cut | |
53 | ||
54 | __PACKAGE__->add_columns( | |
55 | "id", | |
56 | { data_type => "text", is_nullable => 0 }, | |
57 | "name", | |
58 | { data_type => "text", is_nullable => 0 }, | |
59 | "start", | |
60 | { data_type => "integer", is_nullable => 0 }, | |
61 | "stop", | |
62 | { data_type => "integer", is_nullable => 0 }, | |
63 | "owner", | |
64 | { data_type => "text", is_foreign_key => 1, is_nullable => 0 }, | |
65 | ); | |
66 | ||
67 | =head1 PRIMARY KEY | |
68 | ||
69 | =over 4 | |
70 | ||
71 | =item * L</id> | |
72 | ||
73 | =back | |
74 | ||
75 | =cut | |
76 | ||
77 | __PACKAGE__->set_primary_key("id"); | |
78 | ||
79 | =head1 RELATIONS | |
80 | ||
81 | =head2 contest_problems | |
82 | ||
83 | Type: has_many | |
84 | ||
85 | Related object: L<Gruntmaster::Data::Result::ContestProblem> | |
86 | ||
87 | =cut | |
88 | ||
89 | __PACKAGE__->has_many( | |
90 | "contest_problems", | |
91 | "Gruntmaster::Data::Result::ContestProblem", | |
92 | { "foreign.contest" => "self.id" }, | |
93 | { cascade_copy => 0, cascade_delete => 0 }, | |
94 | ); | |
95 | ||
96 | =head2 jobs | |
97 | ||
98 | Type: has_many | |
99 | ||
100 | Related object: L<Gruntmaster::Data::Result::Job> | |
101 | ||
102 | =cut | |
103 | ||
104 | __PACKAGE__->has_many( | |
105 | "jobs", | |
106 | "Gruntmaster::Data::Result::Job", | |
107 | { "foreign.contest" => "self.id" }, | |
108 | { cascade_copy => 0, cascade_delete => 0 }, | |
109 | ); | |
110 | ||
111 | =head2 opens | |
112 | ||
113 | Type: has_many | |
114 | ||
115 | Related object: L<Gruntmaster::Data::Result::Open> | |
116 | ||
117 | =cut | |
118 | ||
119 | __PACKAGE__->has_many( | |
120 | "opens", | |
121 | "Gruntmaster::Data::Result::Open", | |
122 | { "foreign.contest" => "self.id" }, | |
123 | { cascade_copy => 0, cascade_delete => 0 }, | |
124 | ); | |
125 | ||
126 | =head2 owner | |
127 | ||
128 | Type: belongs_to | |
129 | ||
130 | Related object: L<Gruntmaster::Data::Result::User> | |
131 | ||
132 | =cut | |
133 | ||
134 | __PACKAGE__->belongs_to( | |
135 | "owner", | |
136 | "Gruntmaster::Data::Result::User", | |
137 | { id => "owner" }, | |
9bb39921 | 138 | { is_deferrable => 0, on_delete => "CASCADE", on_update => "NO ACTION" }, |
4ed3f8e7 MG |
139 | ); |
140 | ||
141 | =head2 problems | |
142 | ||
143 | Type: many_to_many | |
144 | ||
145 | Composing rels: L</contest_problems> -> problem | |
146 | ||
147 | =cut | |
148 | ||
149 | __PACKAGE__->many_to_many("problems", "contest_problems", "problem"); | |
150 | ||
151 | ||
9bb39921 MG |
152 | # Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-05-16 15:03:32 |
153 | # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:8PPzBpDmSTq4ukKuxIlLlQ | |
4ed3f8e7 | 154 | |
4a8747ef MG |
155 | sub is_pending { |
156 | my ($self, $time) = @_; | |
157 | $self->start > ($time // time) | |
158 | } | |
159 | ||
160 | sub is_finished { | |
161 | my ($self, $time) = @_; | |
162 | $self->stop <= ($time // time) | |
163 | } | |
164 | ||
165 | sub is_running { | |
166 | my ($self, $time) = @_; | |
167 | !$self->is_pending($time) && !$self->is_finished($time) | |
168 | } | |
4ed3f8e7 | 169 | |
4ed3f8e7 | 170 | 1; |
4a8747ef MG |
171 | |
172 | __END__ | |
173 | ||
174 | =head1 METHODS | |
175 | ||
176 | =head2 is_pending(I<[$time]>) | |
177 | ||
178 | Returns true if the contest is pending at time I<$time> (which defaults to C<time>). | |
179 | ||
180 | =head2 is_finished(I<[$time]>) | |
181 | ||
182 | Returns true if the contest is finished at time I<$time> (which defaults to C<time>). | |
183 | ||
184 | =head2 is_running(I<[$time]>) | |
185 | ||
186 | Returns true if the contest is running at time I<$time> (which defaults to C<time>). | |
187 | ||
188 | =head1 AUTHOR | |
189 | ||
190 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
191 | ||
192 | =head1 COPYRIGHT AND LICENSE | |
193 | ||
194 | Copyright (C) 2014 by Marius Gavrilescu | |
195 | ||
196 | This library is free software; you can redistribute it and/or modify | |
197 | it under the same terms as Perl itself, either Perl version 5.18.1 or, | |
198 | at your option, any later version of Perl 5 you may have available. | |
199 | ||
200 | ||
201 | =cut |