X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FGeneric.pm;h=efb2721848ed879b404a84b2f3380888bba38a30;hb=d4306a0b61dd5737b1d68b36ca86b337febc48a7;hp=36ca445a98c00c26ee4cae0b3b5190936d56d75d;hpb=a46fb222e6ce50102b7c61a95af435afc74f5e33;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Generic.pm b/lib/Gruntmaster/Page/Generic.pm index 36ca445..efb2721 100644 --- a/lib/Gruntmaster/Page/Generic.pm +++ b/lib/Gruntmaster/Page/Generic.pm @@ -38,6 +38,7 @@ 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))}); @@ -63,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 } @@ -124,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} };