Skip to content

Commit 7ef2a93

Browse files
author
Shawn McCool
committed
more forum cleanup
1 parent ed39cf0 commit 7ef2a93

File tree

5 files changed

+58
-116
lines changed

5 files changed

+58
-116
lines changed

app/controllers/Forum/ForumReplyController.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

app/controllers/Forum/ForumThreadController.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/controllers/ForumController.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
use Lio\Forum\ForumThreadUpdaterObserver;
1111
use Lio\Forum\ForumSectionCountManager;
1212

13-
class ForumController extends BaseController implements ForumThreadCreatorObserver, ForumThreadUpdaterObserver
13+
use Lio\Forum\ForumReplyForm;
14+
use Lio\Forum\ForumReplyCreatorObserver;
15+
use Lio\Forum\ForumReplyUpdaterObserver;
16+
use Lio\Forum\ForumSectionCountManager;
17+
18+
class ForumController extends BaseController implements ForumThreadCreatorObserver, ForumThreadUpdaterObserver, ForumReplyCreatorObserver, ForumReplyUpdaterObserver
1419
{
1520
protected $comments;
1621
protected $tags;
@@ -154,6 +159,54 @@ public function getSearch()
154159
$this->view('forum.search', compact('query', 'results'));
155160
}
156161

162+
// reply to a thread
163+
public function postCreateReply()
164+
{
165+
return App::make('Lio\Forum\ForumReplyCreator')->create($this, [
166+
'body' => Input::get('body'),
167+
'author_id' => Auth::user()->id,
168+
'type' => Comment::TYPE_FORUM,
169+
'thread' => App::make('slugModel'),
170+
], new ForumReplyForm);
171+
}
172+
173+
// edit a reply
174+
public function getEditReply($replyId)
175+
{
176+
$reply = $this->comments->requireForumThreadById($replyId);
177+
if (Auth::user()->id != $reply->author_id) return Redirect::to('/');
178+
$this->view('forum.editcomment', compact('reply'));
179+
}
180+
181+
public function postEditReply($replyId)
182+
{
183+
$reply = $this->comments->requireForumThreadById($replyId);
184+
if (Auth::user()->id != $reply->author_id) return Redirect::to('/');
185+
186+
return App::make('Lio\Forum\ForumReplyUpdater')->update($reply, $this, [
187+
'body' => Input::get('body'),
188+
], new ForumReplyForm);
189+
}
190+
191+
// observer methods
192+
public function forumReplyValidationError($errors)
193+
{
194+
return $this->redirectBack(['errors' => $errors]);
195+
}
196+
197+
public function forumReplyCreated($reply)
198+
{
199+
// update cache for sidebar counts
200+
$this->sections->cacheSections(Config::get('forum.sections'));
201+
// awful demeter chain - clean up
202+
return $this->redirectAction('ForumController@getShowThread', [$reply->parent()->first()->slug->slug]);
203+
}
204+
205+
public function forumReplyUpdated($reply)
206+
{
207+
return $this->redirectAction('ForumController@getShowThread', [$reply->parent->slug->slug]);
208+
}
209+
157210
// ------------------------- //
158211
private function prepareViewData()
159212
{

app/routes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
Route::post('forum/create-thread', 'ForumController@postCreateThread');
5353
Route::get('forum/edit-thread/{threadId}', 'ForumController@getEditThread');
5454
Route::post('forum/edit-thread/{threadId}', 'ForumController@postEditThread');
55-
Route::get('forum/edit-reply/{commentId}', 'ForumReplyController@edit');
56-
Route::post('forum/edit-reply/{commentId}', 'ForumReplyController@update');
55+
Route::get('forum/edit-reply/{commentId}', 'ForumController@getEditReply');
56+
Route::post('forum/edit-reply/{commentId}', 'ForumController@postEditReply');
5757

5858
// move to new controller
5959
Route::get('forum/delete/{commentId}', 'ForumController@getDeleteThread');
6060
Route::post('forum/delete/{commentId}', 'ForumController@postDeleteThread');
6161

62-
Route::post('forum/{slug}', ['before' => 'handle_slug', 'uses' => 'ForumReplyController@store']);
62+
Route::post('forum/{slug}', ['before' => 'handle_slug', 'uses' => 'ForumController@postCreateReply']);
6363
});
6464

6565
Route::get('forum/{slug}', ['before' => 'handle_slug', 'uses' => 'ForumController@getShowThread']);

app/views/forum/_comment.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</div>
1313
@if(Auth::user() && $comment->author_id == Auth::user()->id)
1414
<div class="admin-bar">
15-
<li><a class="button" href="{{ action('ForumReplyController@edit', [$comment->id]) }}">Edit</a></li>
15+
<li><a class="button" href="{{ action('ForumController@getEditReply', [$comment->id]) }}">Edit</a></li>
1616
<li><a class="button" href="{{ action('ForumController@getDeleteThread', [$comment->id]) }}">Delete</a></li>
1717
</div>
1818
@endif

0 commit comments

Comments
 (0)