mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-01-22 04:34:17 +00:00
init extended search feature #35
This commit is contained in:
parent
7a1fa12271
commit
5a0342a998
@ -14,15 +14,111 @@ use App\Service\ActivityService;
|
||||
class SearchController extends AbstractController
|
||||
{
|
||||
public function module(
|
||||
?string $query,
|
||||
?string $type
|
||||
Request $request,
|
||||
UserService $userService,
|
||||
ActivityService $activityService
|
||||
): Response
|
||||
{
|
||||
// Defaults
|
||||
$locales = [];
|
||||
$categories = [];
|
||||
|
||||
// Extended search
|
||||
if ($request->get('filter'))
|
||||
{
|
||||
// Init user
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
// 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,
|
||||
];
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$locales[] =
|
||||
[
|
||||
'value' => $locale,
|
||||
'checked' => in_array($locale, $user->getLocales()) ? true : false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Categories
|
||||
foreach (explode('|', $this->getParameter('app.categories')) as $category)
|
||||
{
|
||||
if ($request->get('categories'))
|
||||
{
|
||||
$categories[] =
|
||||
[
|
||||
'value' => $category,
|
||||
'checked' => in_array($category, (array) $request->get('categories')) ? true : false,
|
||||
];
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$categories[] =
|
||||
[
|
||||
'value' => $category,
|
||||
'checked' => in_array($category, $user->getCategories()) ? true : false,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'default/search/module.html.twig',
|
||||
[
|
||||
'query' => $query ? urldecode($query) : '',
|
||||
'query' => $request->get('query') ? urldecode($request->get('query')) : '',
|
||||
'filter' => $request->get('filter'),
|
||||
'sensitive' => $request->get('sensitive'),
|
||||
'locales' => $locales,
|
||||
'categories' => $categories,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function initUser(
|
||||
Request $request,
|
||||
UserService $userService,
|
||||
ActivityService $activityService
|
||||
): ?\App\Entity\User
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$activityService->getEventCodes(),
|
||||
$this->getParameter('app.theme'),
|
||||
$this->getParameter('app.sensitive'),
|
||||
$this->getParameter('app.yggdrasil'),
|
||||
$this->getParameter('app.posters'),
|
||||
$this->getParameter('app.approved')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
@ -265,22 +265,22 @@ class TorrentController extends AbstractController
|
||||
|
||||
// Get total torrents
|
||||
$total = $torrentService->findTorrentsTotal(
|
||||
$user->getId(),
|
||||
$request->get('filter') ? 0 : $user->getId(),
|
||||
$query,
|
||||
$user->getLocales(),
|
||||
$user->getCategories(),
|
||||
$user->isSensitive() ? false : null,
|
||||
$request->get('filter') ? (array) $request->get('locales') : $user->getLocales(),
|
||||
$request->get('filter') ? (array) $request->get('categories') : $user->getCategories(),
|
||||
$request->get('filter') ? ($request->get('sensitive') ? null : false) : ($user->isSensitive() ? false : null),
|
||||
!$user->isModerator() ? true : null,
|
||||
!$user->isModerator() ? true : null,
|
||||
);
|
||||
|
||||
$torrents = [];
|
||||
foreach ($torrentService->findTorrents(
|
||||
$user->getId(),
|
||||
$request->get('filter') ? 0 : $user->getId(),
|
||||
$query,
|
||||
$user->getLocales(),
|
||||
$user->getCategories(),
|
||||
$user->isSensitive() ? false : null,
|
||||
$request->get('filter') ? (array) $request->get('locales') : $user->getLocales(),
|
||||
$request->get('filter') ? (array) $request->get('categories') : $user->getCategories(),
|
||||
$request->get('filter') ? ($request->get('sensitive') ? null : false) : ($user->isSensitive() ? false : null),
|
||||
!$user->isModerator() ? true : null,
|
||||
!$user->isModerator() ? true : null,
|
||||
$this->getParameter('app.pagination'),
|
||||
|
@ -26,8 +26,7 @@
|
||||
{{ render(controller(
|
||||
'App\\Controller\\SearchController::module',
|
||||
{
|
||||
query : app.request.get('query'),
|
||||
type : app.request.get('type')
|
||||
request: app.request
|
||||
}
|
||||
)) }}
|
||||
{% endblock %}
|
||||
|
@ -1,4 +1,62 @@
|
||||
<form class="margin-t-16-px" name="search" method="get" action="{{ path('torrent_search') }}">
|
||||
<input class="min-width-200-px" type="text" name="query" value="{{ query }}" placeholder="{{ 'Keyword, file, hash...' | trans }}" />
|
||||
<input {% if query %}class="button-green"{% endif %} type="submit" value="{{ 'Search' | trans }}" />
|
||||
{% if filter %}
|
||||
<input type="hidden" name="filter" value="true" />
|
||||
<div class="text-left">
|
||||
<div class="margin-t-16-px margin-b-4-px text-right">
|
||||
<h2 class="margin-x-4-px">
|
||||
{{ 'Locales' | trans }}
|
||||
</h2>
|
||||
</div>
|
||||
<div class="padding-t-16-px padding-b-8-px padding-x-24-px border-top-default">
|
||||
{% for locale in locales | sort %}
|
||||
<div class="margin-t-4-px margin-b-8-px margin-r-8-px display-inline-block min-width-120-px">
|
||||
{% if locale.checked %}
|
||||
<input name="locales[]" id="{{ locale.value }}" type="checkbox" value="{{ locale.value }}" checked="checked" />
|
||||
{% else %}
|
||||
<input name="locales[]" id="{{ locale.value }}" type="checkbox" value="{{ locale.value }}" />
|
||||
{% endif %}
|
||||
<label class="margin-x-4-px" for="{{ locale.value }}">
|
||||
{{ locale.value | locale_name(locale.value) | u.title }}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="margin-b-4-px text-right">
|
||||
<h2 class="margin-x-4-px">
|
||||
{{ 'Categories' | trans }}
|
||||
</h2>
|
||||
</div>
|
||||
<div class="padding-t-16-px padding-b-8-px padding-x-24-px border-top-default">
|
||||
{% for category in categories | sort %}
|
||||
<div class="margin-t-4-px margin-b-8-px margin-r-8-px display-inline-block min-width-120-px">
|
||||
{% if category.checked %}
|
||||
<input name="categories[]" id="{{ category.value }}" type="checkbox" value="{{ category.value }}" checked="checked" />
|
||||
{% else %}
|
||||
<input name="categories[]" id="{{ category.value }}" type="checkbox" value="{{ category.value }}" />
|
||||
{% endif %}
|
||||
<label class="margin-x-4-px" for="{{ category.value }}">
|
||||
{{ category.value | trans_category | u.title }}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="margin-b-4-px text-right">
|
||||
<h2 class="margin-x-4-px">
|
||||
{{ 'other' | trans | u.title }}
|
||||
</h2>
|
||||
</div>
|
||||
<div class="padding-t-16-px padding-b-8-px padding-x-24-px border-top-default">
|
||||
{% if sensitive %}
|
||||
<input name="sensitive" id="sensitive" type="checkbox" value="true" checked="checked" />
|
||||
{% else %}
|
||||
<input name="sensitive" id="sensitive" type="checkbox" value="true" />
|
||||
{% endif %}
|
||||
<label class="margin-x-4-px" for="sensitive">
|
||||
{{ 'Sensitive' | trans }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
Loading…
x
Reference in New Issue
Block a user