sub list {
my ($thing, $lang, $env) = @_;
my %thing = %$thing;
+ my %params;
#debug $env => "Contest is $ct";
$thing{makers} //= sub { db(shift)->resultset($thing{rsname}) };
my $rs = $thing{makers}->($env);
$rs = $rs->search(undef, {order_by => 'me.id'}) unless $rs->is_ordered;
if (my $page = $env->{'gruntmaster.page'}) {
- my $pages = $rs->count / PAGE_SIZE;
+ my $pages = int ($rs->count / PAGE_SIZE);
$page = $pages if $page == -1;
+ @params{'page', 'pages'} = ($page, $pages);
$rs = $rs->search(undef, {offset => ($page - 1) * PAGE_SIZE, ($page == $pages ? () : (rows => PAGE_SIZE))});
}
$rs = $rs->search(undef, {prefetch => $thing{prefetch}}) if exists $thing{prefetch};
@thing = map { $thing{mangle}->(); $_ } @thing if exists $thing{mangle};
@thing = grep { $thing{choose}->() } @thing if exists $thing{choose};
@thing = sort { $thing{sortby}->() } @thing if exists $thing{sortby};
- my %params;
$thing{group} //= sub { $thing{id} };
for (@thing) {
my $group = $thing{group}->();
makers {
my $env = $_[0];
my $db = db $env;
- return $db->contest($env->{'gruntmaster.contest'})->problems->search(undef, {order_by => 'problem.id'}) if exists $env->{'gruntmaster.contest'};
return $db->problems->search({owner => $env->{'gruntmaster.user'}}) if exists $env->{'gruntmaster.user'};
- $db->problems->search({private => 0});
+ return $db->problems->search({'contest_problems.contest' => $env->{'gruntmaster.contest'}}, {join => 'contest_problems'}) if exists $env->{'gruntmaster.contest'};
+ $db->problems->search({-or => ['contest_problems.contest' => undef, 'contest.stop' => {'<=', time}], 'me.private' => 0}, {join => {'contest_problems' => 'contest'}});
};
sortby { $a->{name} cmp $b->{name}};
group { $_->{level} };
mangle {
my $env = shift;
$_->{owner_name} = $_->{rs}->owner->name;
- $_->{cansubmit} = $_->{contest} ? time < $_->{rs}->contest->stop : 1;
+ $_->{cansubmit} = $env->{'gruntmaster.contest'} ? time < db($env)->contest($env->{'gruntmaster.contest'})->stop : 1;
eval {
db($env)->open->create({
- contest => $_->{contest},
+ contest => $env->{'gruntmaster.contest'},
problem => $_->{id},
owner => $env->{REMOTE_USER},
})
- } if $_->{contest} && time >= $_->{rs}->contest->start;
+ } if $env->{'gruntmaster.contest'} && time >= db($env)->contest($env->{'gruntmaster.contest'})->start;
};
};
<table border class="table table-bordered table-striped table-fixed">
<thead><tr><th>Name<th>Author<th>Owner
<tbody>
-<tmpl_loop beginner><tr><td><a href="/pb/<tmpl_var id>"><tmpl_var name></a><td><tmpl_var author><td><a href="/us/<tmpl_var owner>"><tmpl_if owner_name><tmpl_var owner_name><tmpl_else><tmpl_var owner></tmpl_if></a>
+<tmpl_loop beginner><tr><td><a href="<tmpl_var id>"><tmpl_var name></a><td><tmpl_var author><td><a href="/us/<tmpl_var owner>"><tmpl_if owner_name><tmpl_var owner_name><tmpl_else><tmpl_var owner></tmpl_if></a>
</tmpl_loop>
</table>
</tmpl_if>
<table border class="table table-bordered table-striped table-fixed">
<thead><tr><th>Name<th>Author<th>Owner
<tbody>
-<tmpl_loop easy><tr><td><a href="/pb/<tmpl_var id>"><tmpl_var name></a><td><tmpl_var author><td><a href="/us/<tmpl_var owner>"><tmpl_if owner_name><tmpl_var owner_name><tmpl_else><tmpl_var owner></tmpl_if></a>
+<tmpl_loop easy><tr><td><a href="<tmpl_var id>"><tmpl_var name></a><td><tmpl_var author><td><a href="/us/<tmpl_var owner>"><tmpl_if owner_name><tmpl_var owner_name><tmpl_else><tmpl_var owner></tmpl_if></a>
</tmpl_loop>
</table>
</tmpl_if>
<table border class="table table-bordered table-striped table-fixed">
<thead><tr><th>Name<th>Author<th>Owner
<tbody>
-<tmpl_loop medium><tr><td><a href="/pb/<tmpl_var id>"><tmpl_var name></a><td><tmpl_var author><td><a href="/us/<tmpl_var owner>"><tmpl_if owner_name><tmpl_var owner_name><tmpl_else><tmpl_var owner></tmpl_if></a>
+<tmpl_loop medium><tr><td><a href="<tmpl_var id>"><tmpl_var name></a><td><tmpl_var author><td><a href="/us/<tmpl_var owner>"><tmpl_if owner_name><tmpl_var owner_name><tmpl_else><tmpl_var owner></tmpl_if></a>
</tmpl_loop>
</table>
</tmpl_if>
<table border class="table table-bordered table-striped table-fixed">
<thead><tr><th>Name<th>Author<th>Owner
<tbody>
-<tmpl_loop hard><tr><td><a href="/pb/<tmpl_var id>"><tmpl_var name></a><td><tmpl_var author><td><a href="/us/<tmpl_var owner>"><tmpl_if owner_name><tmpl_var owner_name><tmpl_else><tmpl_var owner></tmpl_if></a>
+<tmpl_loop hard><tr><td><a href="<tmpl_var id>"><tmpl_var name></a><td><tmpl_var author><td><a href="/us/<tmpl_var owner>"><tmpl_if owner_name><tmpl_var owner_name><tmpl_else><tmpl_var owner></tmpl_if></a>
</tmpl_loop>
</table>
</tmpl_if>