sub overview { my $self = shift; return $self->authz->forbidden() unless $self->authz('privileges')->authorize(__PACKAGE__, $self->get_current_runmode()); my $schema = $self->schema(); my @topic_loop = (); my $trs = $schema->resultset('Topic')->search( undef, { order_by => 'me.position ASC', prefetch => [qw/boards/], } ); while( my $topic = $trs->next() ) { my @board_loop = (); my $board_rs = $topic->boards( undef, { '+select' => [{count => 'thread_id'}], '+as' => ['thread_count'],, join => [qw/threads/], group_by => [qw/board_id/], }, ); while( my $board = $board_rs->next() ) { # -- get the latest thread my ($lastthread) = $board->threads( undef, { order_by => 'date_of_creation DESC', } )->first(); my $lastpost = undef; if( defined $lastthread ) { ($lastpost) = $lastthread->posts( undef, { '+select' => [qw/user.username user.user_id/], '+as' => [qw/username user_id/], select => 'timestamp', order_by => 'timestamp DESC', join => [qw/user/], } )->first(); } my $reply_count = 0; if( defined $lastthread ) { # if there is a thread my $rs = $board->threads( undef, { '+select' => {count => 'posts.post_id'}, '+as' => 'reply_count', join => [qw/posts/], group_by => [qw/me.thread_id/], } ); foreach my $t ( $rs->all() ) { $reply_count += $t->get_column('reply_count') - 1; } } push @board_loop, { board_id => $board->board_id(), title => $board->title(), thread_count => $board->get_column('thread_count'), reply_count => $reply_count, last_post_username => (defined $lastpost ? $lastpost->get_column('username') : undef), last_post_timestamp => (defined $lastpost ? $lastpost->timestamp() : undef), last_post_user_id => (defined $lastpost ? $lastpost->get_column('user_id') : undef), last_thread_subject => (defined $lastthread ? $lastthread->subject() : undef), last_thread_id => (defined $lastthread ? $lastthread->thread_id() : undef), }; } push @topic_loop, { topic_id => $topic->topic_id(), topic => $topic->topic(), boards => \@board_loop, }; } $self->param(topics => \@topic_loop); my $t = $self->load_tmpl('_overview.tmpl', associate => $self); return $t->output(); } # /overview