mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
Add search functionality for adult content in MediaController
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -149,6 +149,3 @@ composer.lock
|
|||||||
/public/public/images/backdrops
|
/public/public/images/backdrops
|
||||||
/public/public/images/posters
|
/public/public/images/posters
|
||||||
/storage/images
|
/storage/images
|
||||||
|
|
||||||
|
|
||||||
/frontend/
|
|
||||||
@@ -426,6 +426,14 @@ class MediaController extends ApiController
|
|||||||
$results['actors'] = $this->searchActors($query, $pagination);
|
$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);
|
return $this->success($response, $results);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->error($response, 'Search failed: ' . $e->getMessage(), 500);
|
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
|
// List all movies with pagination
|
||||||
public function listMovies(Request $request, Response $response): Response
|
public function listMovies(Request $request, Response $response): Response
|
||||||
{
|
{
|
||||||
@@ -785,6 +832,16 @@ class MediaController extends ApiController
|
|||||||
$pagination['offset']
|
$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);
|
$total = $this->adultModel->count($filters);
|
||||||
|
|
||||||
// Get available filter options
|
// Get available filter options
|
||||||
|
|||||||
Reference in New Issue
Block a user