|
|
|
@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\Response;
@@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
|
|
|
|
|
use App\Service\UserService; |
|
|
|
|
use App\Service\TorrentService; |
|
|
|
|
use App\Service\ActivityService; |
|
|
|
|
|
|
|
|
|
class SearchController extends AbstractController |
|
|
|
@ -16,6 +17,7 @@ class SearchController extends AbstractController
@@ -16,6 +17,7 @@ class SearchController extends AbstractController
|
|
|
|
|
public function module( |
|
|
|
|
Request $request, |
|
|
|
|
UserService $userService, |
|
|
|
|
TorrentService $torrentService, |
|
|
|
|
ActivityService $activityService |
|
|
|
|
): Response |
|
|
|
|
{ |
|
|
|
@ -23,8 +25,12 @@ class SearchController extends AbstractController
@@ -23,8 +25,12 @@ class SearchController extends AbstractController
|
|
|
|
|
$locales = []; |
|
|
|
|
$categories = []; |
|
|
|
|
|
|
|
|
|
// Request |
|
|
|
|
$query = $request->get('query') ? urldecode($request->get('query')) : ''; |
|
|
|
|
$filter = $request->get('filter') ? true : false; |
|
|
|
|
|
|
|
|
|
// Extended search |
|
|
|
|
if ($request->get('filter')) |
|
|
|
|
if ($filter) |
|
|
|
|
{ |
|
|
|
|
// Init user |
|
|
|
|
$user = $this->initUser( |
|
|
|
@ -33,26 +39,37 @@ class SearchController extends AbstractController
@@ -33,26 +39,37 @@ class SearchController extends AbstractController
|
|
|
|
|
$activityService |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Keywords |
|
|
|
|
$keywords = explode(' ', $query); |
|
|
|
|
|
|
|
|
|
// Locales |
|
|
|
|
foreach (explode('|', $this->getParameter('app.locales')) as $locale) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
if ($request->get('locales')) |
|
|
|
|
{ |
|
|
|
|
$locales[] = |
|
|
|
|
[ |
|
|
|
|
'value' => $locale, |
|
|
|
|
'checked' => in_array($locale, (array) $request->get('locales')) ? true : false, |
|
|
|
|
]; |
|
|
|
|
$checked = in_array($locale, (array) $request->get('locales')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$locales[] = |
|
|
|
|
[ |
|
|
|
|
'value' => $locale, |
|
|
|
|
'checked' => in_array($locale, $user->getLocales()) ? true : false, |
|
|
|
|
]; |
|
|
|
|
$checked = in_array($locale, $user->getLocales()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$locales[] = |
|
|
|
|
[ |
|
|
|
|
'value' => $locale, |
|
|
|
|
'checked' => $checked, |
|
|
|
|
'total' => $torrentService->findTorrentsTotal( |
|
|
|
|
0, |
|
|
|
|
$keywords, |
|
|
|
|
[$locale], |
|
|
|
|
$request->get('categories') ? $request->get('categories') : $user->getCategories(), |
|
|
|
|
$sensitive, |
|
|
|
|
!$user->isModerator() ? true : null, |
|
|
|
|
!$user->isModerator() ? true : null, |
|
|
|
|
) |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Categories |
|
|
|
@ -60,30 +77,52 @@ class SearchController extends AbstractController
@@ -60,30 +77,52 @@ class SearchController extends AbstractController
|
|
|
|
|
{ |
|
|
|
|
if ($request->get('categories')) |
|
|
|
|
{ |
|
|
|
|
$categories[] = |
|
|
|
|
[ |
|
|
|
|
'value' => $category, |
|
|
|
|
'checked' => in_array($category, (array) $request->get('categories')) ? true : false, |
|
|
|
|
]; |
|
|
|
|
$checked = in_array($category, (array) $request->get('categories')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$categories[] = |
|
|
|
|
[ |
|
|
|
|
'value' => $category, |
|
|
|
|
'checked' => in_array($category, $user->getCategories()) ? true : false, |
|
|
|
|
]; |
|
|
|
|
$checked = in_array($category, $user->getCategories()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$categories[] = |
|
|
|
|
[ |
|
|
|
|
'value' => $category, |
|
|
|
|
'checked' => $checked, |
|
|
|
|
'total' => $torrentService->findTorrentsTotal( |
|
|
|
|
0, |
|
|
|
|
$keywords, |
|
|
|
|
$request->get('locales') ? $request->get('locales') : $user->getLocales(), |
|
|
|
|
[$category], |
|
|
|
|
$sensitive, |
|
|
|
|
!$user->isModerator() ? true : null, |
|
|
|
|
!$user->isModerator() ? true : null, |
|
|
|
|
) |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sensitive |
|
|
|
|
$sensitive = |
|
|
|
|
[ |
|
|
|
|
'checked' => $request->get('sensitive'), |
|
|
|
|
'total' => $torrentService->findTorrentsTotal( |
|
|
|
|
0, |
|
|
|
|
$keywords, |
|
|
|
|
$request->get('locales') ? $request->get('locales') : $user->getLocales(), |
|
|
|
|
$request->get('categories') ? $request->get('categories') : $user->getCategories(), |
|
|
|
|
true, |
|
|
|
|
!$user->isModerator() ? true : null, |
|
|
|
|
!$user->isModerator() ? true : null, |
|
|
|
|
) |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $this->render( |
|
|
|
|
'default/search/module.html.twig', |
|
|
|
|
[ |
|
|
|
|
'query' => $request->get('query') ? urldecode($request->get('query')) : '', |
|
|
|
|
'filter' => $request->get('filter'), |
|
|
|
|
'sensitive' => $request->get('sensitive'), |
|
|
|
|
'query' => $query, |
|
|
|
|
'filter' => $filter, |
|
|
|
|
'sensitive' => $sensitive, |
|
|
|
|
'locales' => $locales, |
|
|
|
|
'categories' => $categories, |
|
|
|
|
] |
|
|
|
|