my $dbh = $c->model;
$c->forward('findThread');
- $thread = $c->stash->{thread};
+ $c->forward('findPosts') if $c->stash->{thread};
+ $c->forward('markThreadAsRead') if $c->user_exists;
+}
+
+sub findPosts :Private {
+ my ( $self, $c, $thread ) = @_;
+ my $dbh = $c->model;
my $posts = $dbh->prepare(q{
SELECT u.username,date_trunc('seconds',fp.time::timestamp) AS time
WHERE ft.ftid = $1
ORDER BY fp.time ASC
});
- $posts->execute($c->stash->{thread}->{ftid},$c->stash->{UID});
+ $posts->execute($thread,$c->stash->{UID});
my @posts;
while (my $post = $posts->fetchrow_hashref){
}
$c->stash(posts => \@posts);
- $c->forward('markThreadAsRead') if $c->user_exists;
}
sub newThread : Local {
my ( $self, $c, $board ) = @_;
- my $dbh = $c->model;
$c->forward('findBoard');
$board = $c->stash->{board};
unless ($c->stash->{board}->{post}){
$c->acl_access_denied('test',$c->action,'No post access to board.')
}
-
+
+ $c->forward('insertThread');
+ $c->forward('addPost',[$c->stash->{thread}]);
+}
+
+sub insertThread : Private {
+ my ( $self, $c, $board ) = @_;
+ my $dbh = $c->model;
+
my $insert = $dbh->prepare(q{INSERT INTO forum_threads (ftid,fbid,subject,uid)
VALUES(DEFAULT,$1,$2,$3) RETURNING (ftid);
});
-
- $insert->execute($board->{fbid},html_escape($c->req->param('subject')),$c->stash->{UID});
- my $thread = $insert->fetchrow;
+ $insert->execute($board,html_escape($c->req->param('subject')),$c->stash->{UID});
+ $c->stash(thread => $insert->fetchrow);
$insert->finish;
- $c->forward('addPost',[$thread]);
-
}
sub addPost : Local {