]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Generic.pm
Fix standings and contest logs
[gruntmaster-page.git] / lib / Gruntmaster / Page / Generic.pm
index 9c5687b2b705ab77622da9217b453e9df41f1e05..efb2721848ed879b404a84b2f3380888bba38a30 100644 (file)
@@ -38,11 +38,15 @@ sub list {
        $rs = $rs->search(undef, {order_by => 'me.id'}) unless $rs->is_ordered;
        if (my $page = $env->{'gruntmaster.page'}) {
                my $pages = int ($rs->count / PAGE_SIZE);
+               $pages = 1 if $pages < 1;
                $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};
+       $rs = $rs->search(undef, {
+               exists $thing{prefetch} ? (prefetch => $thing{prefetch}) : (),
+               exists $thing{columns} ? (columns => $thing{columns}) : (),
+       });
        my @thing = map +{rs => $_, $_->get_columns}, $rs->all;
        @thing = map  { $thing{mangle}->(); $_ } @thing if exists $thing{mangle};
        @thing = grep { $thing{choose}->() } @thing if exists $thing{choose};
@@ -60,8 +64,7 @@ sub entry {
        my ($thing, $lang, $env, $id) = @_;
        my %thing = %$thing;
        debug $env => "Rsname is $thing{rsname} and id is $id";
-       $thing{makers} //= sub { db(shift)->resultset($thing{rsname}) };
-       my %params = map {+ rs => $_, $_->get_columns } $thing{makers}->($env)->find($id);
+       my %params = map {+ rs => $_, $_->get_columns } db($env)->resultset($thing{rsname})->find($id);
        $thing{mangle}->(local $_ = \%params) if exists $thing{mangle};
        wantarray ? %params : \%params
 }
@@ -86,6 +89,7 @@ sub sortby (&);
 sub group  (&);
 sub mangle (&);
 sub prefetch;
+sub columns;
 
 sub thing (&){
        my %thing;
@@ -97,6 +101,7 @@ sub thing (&){
        local *{"group"} = sub { $thing{group} = shift };
        local *{"makers"} = sub { $thing{makers} = shift };
        local *{"prefetch"} = sub { $thing{prefetch} = \@_ };
+       local *{"columns"} = sub { $thing{columns} = \@_ };
        use strict 'refs';
 
        shift->();
@@ -119,7 +124,7 @@ thing {
                my $db = db $env;
                return $db->problems->search({owner => $env->{'gruntmaster.user'}}) if exists $env->{'gruntmaster.user'};
                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'}});
+               $db->problems->search({-or => ['contest_problems.contest' => undef, 'contest.stop' => {'<=', time}], 'me.private' => 0}, {join => {'contest_problems' => 'contest'}, distinct => 1});
        };
        sortby { $a->{name} cmp $b->{name}};
        group { $_->{level} };
This page took 0.024954 seconds and 4 git commands to generate.