mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-03-31 17:15:38 +00:00
apply sensitive / locale filters for search results
This commit is contained in:
parent
d2cb66f51d
commit
3aa7e5ff3c
2 changed files with 62 additions and 1 deletions
|
|
@ -45,15 +45,38 @@ class SearchController extends AbstractController
|
||||||
case 'article':
|
case 'article':
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'torrent':
|
case 'torrent':
|
||||||
|
|
||||||
$torrents = [];
|
$torrents = [];
|
||||||
foreach ($torrentService->searchTorrents($request->query->get('query')) as $torrent)
|
foreach ($torrentService->searchTorrents($request->query->get('query')) as $torrent)
|
||||||
{
|
{
|
||||||
|
// Apply locales filter
|
||||||
|
if ($lastTorrentLocales = $torrentService->findLastTorrentLocalesByTorrentIdApproved($torrent->getId()))
|
||||||
|
{
|
||||||
|
if (!count(
|
||||||
|
array_intersect(
|
||||||
|
$lastTorrentLocales->getValue(),
|
||||||
|
$user->getLocales()
|
||||||
|
)
|
||||||
|
)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply sensitive filters
|
||||||
|
if ($lastTorrentSensitive = $torrentService->findLastTorrentSensitiveByTorrentIdApproved($torrent->getId()))
|
||||||
|
{
|
||||||
|
if ($user->isSensitive() && $lastTorrentSensitive->isValue())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Read file
|
// Read file
|
||||||
if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId()))
|
if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId()))
|
||||||
{
|
{
|
||||||
continue; // @TODO
|
continue; // @TODO exception
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate keywords
|
// Generate keywords
|
||||||
|
|
@ -134,7 +157,9 @@ class SearchController extends AbstractController
|
||||||
]);
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
throw $this->createNotFoundException();
|
throw $this->createNotFoundException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -355,6 +355,24 @@ class TorrentService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findLastTorrentLocalesByTorrentIdApproved(
|
||||||
|
int $torrentId,
|
||||||
|
bool $approved = true
|
||||||
|
): ?TorrentLocales
|
||||||
|
{
|
||||||
|
return $this->entityManagerInterface
|
||||||
|
->getRepository(TorrentLocales::class)
|
||||||
|
->findOneBy(
|
||||||
|
[
|
||||||
|
'torrentId' => $torrentId,
|
||||||
|
'approved' => $approved
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'DESC'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function findTorrentLocalesByTorrentId(int $torrentId): array
|
public function findTorrentLocalesByTorrentId(int $torrentId): array
|
||||||
{
|
{
|
||||||
return $this->entityManagerInterface
|
return $this->entityManagerInterface
|
||||||
|
|
@ -466,6 +484,24 @@ class TorrentService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findLastTorrentSensitiveByTorrentIdApproved(
|
||||||
|
int $torrentId,
|
||||||
|
bool $approved = true
|
||||||
|
): ?TorrentSensitive
|
||||||
|
{
|
||||||
|
return $this->entityManagerInterface
|
||||||
|
->getRepository(TorrentSensitive::class)
|
||||||
|
->findOneBy(
|
||||||
|
[
|
||||||
|
'torrentId' => $torrentId,
|
||||||
|
'approved' => $approved,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'DESC'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function findTorrentSensitiveByTorrentId(int $torrentId): array
|
public function findTorrentSensitiveByTorrentId(int $torrentId): array
|
||||||
{
|
{
|
||||||
return $this->entityManagerInterface
|
return $this->entityManagerInterface
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue