Skip to content

Commit

Permalink
add somes filters. solve #33
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienTant committed Feb 22, 2020
1 parent 5739ef2 commit ed2d9d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/app/Http/Controllers/TopicsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
use LaravelFrance\Http\Requests\SolveTopicRequest;
use LaravelFrance\Http\Requests\StoreTopicRequest;
use Redirect;
use function foo\func;


class TopicsController extends Controller
{
public function index($categorySlug = null)
public function index(Request $request, $categorySlug = null)
{
$chosenCategory = null;
if ($categorySlug) {
Expand All @@ -27,6 +28,22 @@ public function index($categorySlug = null)
if (!!$chosenCategory) {
$topicsQuery = $topicsQuery->whereForumsCategoryId($chosenCategory->id);
}

if ($request->get('author')) {
$topicsQuery = $topicsQuery->where('forums_topics.user_id', $request->get('author'));
}

if ($request->get('no-answers')) {
$topicsQuery = $topicsQuery->where('nb_messages', 1);
}

if ($from = $request->get('with-msg-from')) {
$topicsQuery = $topicsQuery->whereHas('forumsMessages', function ($q) use($from) {
$q->where('forums_messages.user_id', $from);
});
}


$topics = $topicsQuery->simplePaginate(Config::get('laravelfrance.forums.topics_per_page'));

return view('topics.index', compact('topics', 'chosenCategory'));
Expand Down
15 changes: 15 additions & 0 deletions src/resources/views/layouts/forums_sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@
<li><a href="{{ route('topics.by-category', ['slug' => $category->slug]) }}"><span class="category-color" style="background-color: {{$category->background_color}}"></span> {{ $category->name }}</a></li>
@endforeach
</ul>

@if(Auth::id())
<hr />
<ul>
<li>
<a href="/?author={{ Auth::id() }}">Mes sujets</a>
</li>
<li>
<a href="/?no-answers=1">Sujets sans réponse</a>
</li>
<li>
<a href="/?with-msg-from={{ Auth::id() }}">Sujets auxquels j'ai participé</a>
</li>
</ul>
@endif

0 comments on commit ed2d9d3

Please sign in to comment.