mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use Slim\Views\Twig;
|
|
|
|
class SearchController extends Controller
|
|
{
|
|
private \PDO $pdo;
|
|
|
|
public function __construct(\PDO $pdo, Twig $view)
|
|
{
|
|
parent::__construct($view);
|
|
$this->pdo = $pdo;
|
|
}
|
|
|
|
public function index(Request $request, Response $response, $args)
|
|
{
|
|
$queryParams = $request->getQueryParams();
|
|
$search = trim($queryParams['q'] ?? '');
|
|
|
|
if (empty($search)) {
|
|
return $this->view->render($response, 'search/index.twig', [
|
|
'title' => 'Search',
|
|
'search' => $search,
|
|
'results' => []
|
|
]);
|
|
}
|
|
|
|
// Search across different media types
|
|
$results = [];
|
|
|
|
// Search movies (including adult videos)
|
|
$movieStmt = $this->pdo->prepare("
|
|
SELECT m.*, s.display_name as source_name, 'movie' as type
|
|
FROM movies m
|
|
JOIN sources s ON m.source_id = s.id
|
|
WHERE (m.title LIKE :search OR m.overview LIKE :search)
|
|
ORDER BY m.title
|
|
LIMIT 20
|
|
");
|
|
$searchParam = "%{$search}%";
|
|
$movieStmt->bindParam(':search', $searchParam, \PDO::PARAM_STR);
|
|
$movieStmt->execute();
|
|
$results['movies'] = $movieStmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
// Search games
|
|
$gameStmt = $this->pdo->prepare("
|
|
SELECT g.*, s.display_name as source_name, 'game' as type
|
|
FROM games g
|
|
JOIN sources s ON g.source_id = s.id
|
|
WHERE (g.name LIKE :search OR g.description LIKE :search)
|
|
ORDER BY g.name
|
|
LIMIT 20
|
|
");
|
|
$gameStmt->bindParam(':search', $searchParam, \PDO::PARAM_STR);
|
|
$gameStmt->execute();
|
|
$results['games'] = $gameStmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
return $this->view->render($response, 'search/index.twig', [
|
|
'title' => 'Search Results',
|
|
'search' => $search,
|
|
'results' => $results
|
|
]);
|
|
}
|
|
}
|