Skip to content

Commit 2ce658a

Browse files
author
Shawn McCool
committed
more refactoring of the forum system
1 parent e5f583a commit 2ce658a

File tree

9 files changed

+23
-45
lines changed

9 files changed

+23
-45
lines changed

app/Controllers/ForumController.php

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,28 @@ public function getIndex()
2222
$this->view('forum.index', compact('threads'));
2323
}
2424

25-
public function getCategory($categorySlug)
25+
public function getThread()
2626
{
27-
$category = $this->categories->requireCategoryBySlug($categorySlug);
28-
$threads = $this->comments->getForumThreadsByCategoryPaginated($category);
29-
30-
$this->view('forum.category', compact('category', 'threads'));
31-
}
32-
33-
public function getThread($categorySlug)
34-
{
35-
$thread = App::make('slugModel');
36-
$category = $thread->owner;
27+
$thread = App::make('slugModel');
3728
$comments = $this->comments->getThreadCommentsPaginated($thread);
3829

39-
$this->view('forum.thread', compact('thread', 'category', 'comments'));
30+
$this->view('forum.thread', compact('thread', 'comments'));
4031
}
4132

42-
public function postThread($categorySlug)
33+
public function postThread()
4334
{
4435
$thread = App::make('slugModel');
4536

46-
$category = $this->categories->requireCategoryBySlug($categorySlug);
47-
4837
$form = $this->categories->getReplyForm();
4938

5039
if ( ! $form->isValid()) {
5140
return $this->redirectBack(['errors' => $form->getErrors()]);
5241
}
5342

5443
$comment = $this->comments->getNew([
55-
'body' => Input::get('body'),
56-
'author_id' => Auth::user()->id,
57-
'parent_id' => $thread->id,
58-
'type' => Comment::TYPE_FORUM,
44+
'body' => Input::get('body'),
45+
'author_id' => Auth::user()->id,
46+
'type' => Comment::TYPE_FORUM,
5947
]);
6048

6149
if ( ! $comment->isValid()) {
@@ -64,18 +52,16 @@ public function postThread($categorySlug)
6452

6553
$thread->children()->save($comment);
6654

67-
return $this->redirectAction('Controllers\ForumController@getThread', [$categorySlug, $thread->slug->slug]);
55+
return $this->redirectAction('Controllers\ForumController@getThread', [$thread->slug->slug]);
6856
}
6957

7058
public function getCreateThread()
7159
{
7260
$this->view('forum.createthread');
7361
}
7462

75-
public function postCreateThread($categorySlug)
63+
public function postCreateThread()
7664
{
77-
$category = $this->categories->requireCategoryBySlug($categorySlug);
78-
7965
$form = $this->categories->getThreadForm();
8066

8167
if ( ! $form->isValid()) {
@@ -86,18 +72,17 @@ public function postCreateThread($categorySlug)
8672
'title' => Input::get('title'),
8773
'body' => Input::get('body'),
8874
'author_id' => Auth::user()->id,
89-
'category_slug' => $category->slug,
9075
'type' => Comment::TYPE_FORUM,
9176
]);
9277

9378
if ( ! $comment->isValid()) {
9479
return $this->redirectBack(['errors' => $comment->getErrors()]);
9580
}
9681

97-
$category->rootThreads()->save($comment);
82+
$this->comments->save($comment);
9883

9984
$commentSlug = $comment->slug()->first()->slug;
10085

101-
return $this->redirectAction('Controllers\ForumController@getThread', [$categorySlug, $commentSlug]);
86+
return $this->redirectAction('Controllers\ForumController@getThread', [$commentSlug]);
10287
}
10388
}

app/domain/Lio/Comments/Comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function slug()
6969

7070
public function getSlugString()
7171
{
72-
if ($this->owner_type == 'Lio\Forum\ForumCategory') {
72+
if ($this->type == static::TYPE_FORUM && is_null($this->parent_id)) {
7373
return $this->getForumPostSlugString();
7474
}
7575
}

app/domain/Lio/Comments/CommentPresenter.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ class CommentPresenter extends BasePresenter
66
{
77
public function forumThreadUrl()
88
{
9-
$comment = $this->resource;
9+
$slug = $this->resource->slug;
1010

11-
$commentSlug = $comment->slug->slug;
12-
$forumSlug = $comment->category_slug;
11+
if ( ! $slug) return '';
1312

14-
return action('Controllers\ForumController@getThread', [$forumSlug, $commentSlug]);
13+
return action('Controllers\ForumController@getThread', [$slug->slug]);
1514
}
1615

1716
public function child_count_label()

app/routes.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@
3636

3737
// forum
3838
Route::get('forum', 'Controllers\ForumController@getIndex');
39-
Route::get('forum/{forumCategory}', 'Controllers\ForumController@getCategory');
4039
Route::get('forum/create-thread', ['before' => 'auth', 'uses' => 'Controllers\ForumController@getCreateThread']);
4140
Route::post('forum/create-thread', ['before' => 'auth', 'uses' => 'Controllers\ForumController@postCreateThread']);
42-
Route::get('forum/{forumCategory}/{slug}', ['before' => 'handle_slug', 'uses' => 'Controllers\ForumController@getThread']);
43-
Route::post('forum/{forumCategory}/{slug}', ['before' => 'auth|handle_slug', 'uses' => 'Controllers\ForumController@postThread']);
41+
Route::get('forum/{slug}', ['before' => 'handle_slug', 'uses' => 'Controllers\ForumController@getThread']);
42+
Route::post('forum/{slug}', ['before' => 'auth|handle_slug', 'uses' => 'Controllers\ForumController@postThread']);
4443

4544
// admin
4645
Route::group(['before' => 'auth', 'prefix' => 'admin'], function() {
File renamed without changes.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
_thread_summary.blade.php
1+
<div>
2+
<a href="{{ $thread->forumThreadUrl }}">{{ $thread->title }}</a>
3+
<a href="{{ $thread->author->profileUrl }}">{{ $thread->author->name }}</a>
4+
</div>

app/views/forum/createthread.blade.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
<div class="row">
33
<div class="small-12 columns">
4-
<h2>Category {{ $category->title }}</h2>
5-
64
{{ Form::open() }}
75

86
<fieldset>

app/views/forum/thread.blade.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
<h1><a href="{{ $category->categoryIndexUrl }}">Forum Category {{ $category->title }}</a></h1>
2-
3-
<p>{{ $category->description }}</p>
4-
5-
<hr/>
6-
71
<ul>
82
@foreach($comments as $comment)
93
<li>

app/views/home/index.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
<secion class="hero-section dark">
1919
<div class="description">
20-
<h1>Forum Posts</h1>
20+
<h1>Forum Threads</h1>
2121
<p class="lead">
2222
Discuss development related topics, ask for, and provide help.
2323
</p>
2424
</div>
2525
<div class="posts">
2626
@foreach($threads as $thread)
27-
@include('forum._small_summary')
27+
@include('forum._home_summary')
2828
@endforeach
2929
</div>
3030
</section>

0 commit comments

Comments
 (0)