|
10 | 10 | use Lio\Forum\ForumThreadUpdaterObserver;
|
11 | 11 | use Lio\Forum\ForumSectionCountManager;
|
12 | 12 |
|
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 |
14 | 19 | {
|
15 | 20 | protected $comments;
|
16 | 21 | protected $tags;
|
@@ -154,6 +159,54 @@ public function getSearch()
|
154 | 159 | $this->view('forum.search', compact('query', 'results'));
|
155 | 160 | }
|
156 | 161 |
|
| 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 | + |
157 | 210 | // ------------------------- //
|
158 | 211 | private function prepareViewData()
|
159 | 212 | {
|
|
0 commit comments