sub index : Private { my ( $self, $c ) = @_; my @threads; ## set up the query to get all threads that aren't children my $rs = $c->model('OnTheBeachDB::Messages')->search ( { parent_id => '0' }, { order_by => 'created DESC'} ); ## loop through the parent threads, ## count the number of children, ## and push a reference to %thread_info into @threads while ( my $thread = $rs->next ) { my %thread_info; $thread_info{'name'} = $thread->name; $thread_info{'created'} = $thread->created; $thread_info{'title'} = $thread->title; $thread_info{'message_id'} = $thread->message_id; $thread_info{'message'} = $thread->message; $thread_info{'comment_count'} = OnTheBeachDB::Messages->number_of_children( $c, $thread->message_id ); push (@threads, \%thread_info) } $c->log->debug($c->model("OnTheBeachDB::Forums")->find(1)->posts_rs->next->title); $c->stash->{page} = $c->model('OnTheBeachDB::Page')->find({ name => "forum_main" }); $c->stash->{threads} = \@threads; } sub create : Local { my ( $self, $c ) = @_; } sub do_create : Local { my ( $self, $c ) = @_; ## for validation #unless ( $c->form->has_error ) { OnTheBeachDB::Messages->create( $c, $c->req->param('name'), $c->req->param('title'), $c->req->param('comments'), 0, # since it's a new thread ); #} else { # $c->detach('create'); #} } sub reply : Local { my ( $self, $c, $replyid ) = @_; my $thread = $c->model('OnTheBeachDB::Messages')->find($replyid); $c->stash->{thread} = $thread; } sub do_reply : Local { my ( $self, $c ) = @_; ## form validation ## change to ::Controller::FormBuilder #unless ( $c->form->has_error ) { OnTheBeachDB::Messages->create( $c, $c->req->param('name'), $c->req->param('title'), $c->req->param('comments'), $c->req->param('parent_id'), # since it's a new thread ); #} else { # $c->detach('create'); #} $c->stash->{template } = 'forum/do_create.tt2'; } sub view : Local { my ( $self, $c, $id ) = @_; my $thread = OnTheBeachDB::Messages->get_thread_messages($c, $id, 'replies'); $c->stash->{threads} = $thread; }