From b69d35c7febcbfd735c68185d960cfd641239129 Mon Sep 17 00:00:00 2001 From: Lars Behrends Date: Wed, 21 Jan 2026 22:12:55 +0100 Subject: [PATCH] Add search functionality for adult content in MediaController --- .gitignore | 5 +-- app/Controllers/Api/MediaController.php | 59 ++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 5e3417e..850aacd 100644 --- a/.gitignore +++ b/.gitignore @@ -148,7 +148,4 @@ composer.lock /public/public/images/adult_videos /public/public/images/backdrops /public/public/images/posters -/storage/images - - -/frontend/ \ No newline at end of file +/storage/images \ No newline at end of file diff --git a/app/Controllers/Api/MediaController.php b/app/Controllers/Api/MediaController.php index 6d429d8..5f20461 100644 --- a/app/Controllers/Api/MediaController.php +++ b/app/Controllers/Api/MediaController.php @@ -425,7 +425,15 @@ class MediaController extends ApiController if ($type === 'all' || $type === 'actors') { $results['actors'] = $this->searchActors($query, $pagination); } - + + if ($type === 'all' || $type === 'adult') { + $results['adult'] = $this->searchAdult($query, $pagination); + } +/* + print_r($results); + print_r($query); + die("results"); +*/ return $this->success($response, $results); } catch (\Exception $e) { return $this->error($response, 'Search failed: ' . $e->getMessage(), 500); @@ -628,6 +636,45 @@ class MediaController extends ApiController } } + private function searchAdult(string $query, array $pagination): array + { + try { + // Use the actor model's search method if available + if (method_exists($this->actorModel, 'search')) { + $actors = $this->adultModel->search($query, $pagination['per_page'], $pagination['offset']); + $total = method_exists($this->actorModel, 'countSearchResults') + ? $this->adultModel->countSearchResults($query) + : count($actors); + } + // Fallback to basic filtering + else { + $allActors = $this->adultModel->findAll(); + $filtered = array_filter($allActors, function($actor) use ($query) { + return stripos($actor['title'] ?? '', $query) !== false; + }); + + // Apply pagination + $actors = array_slice($filtered, $pagination['offset'], $pagination['per_page']); + $total = count($filtered); + } + + return [ + 'items' => $actors, + 'total' => $total, + 'page' => $pagination['page'], + 'per_page' => $pagination['per_page'] + ]; + } catch (\Exception $e) { + return [ + 'items' => [], + 'total' => 0, + 'page' => $pagination['page'], + 'per_page' => $pagination['per_page'], + 'error' => $e->getMessage() + ]; + } + } + // List all movies with pagination public function listMovies(Request $request, Response $response): Response { @@ -785,6 +832,16 @@ class MediaController extends ApiController $pagination['offset'] ); + // Add actors to each adult video + foreach ($adultContent as &$video) { + try { + $adultVideoModel = new \App\Models\AdultVideo($this->pdo); + $video['actors'] = $adultVideoModel->actors($video['id']); + } catch (\Exception $e) { + $video['actors'] = []; + } + } + $total = $this->adultModel->count($filters); // Get available filter options