mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
147 lines
5.1 KiB
PHP
147 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use App\Models\AdultVideo;
|
|
use Slim\Views\Twig;
|
|
|
|
class AdultController 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();
|
|
|
|
// Get pagination parameters
|
|
$page = max(1, (int)($queryParams['page'] ?? 1));
|
|
$perPage = max(12, min(100, (int)($queryParams['per_page'] ?? 24)));
|
|
|
|
// Get search parameters
|
|
$search = trim($queryParams['search'] ?? '');
|
|
|
|
// Get view mode
|
|
$viewMode = $queryParams['view'] ?? 'grid'; // grid, list, covers
|
|
|
|
// Get adult videos with pagination and search
|
|
$adultVideos = AdultVideo::getAllWithPagination($this->pdo, $page, $perPage, $search);
|
|
|
|
// Process metadata to extract local image paths for template compatibility
|
|
foreach ($adultVideos as &$video) {
|
|
if (!empty($video['metadata'])) {
|
|
$metadata = json_decode($video['metadata'], true);
|
|
|
|
// Use local cover path if available, otherwise fall back to original URL
|
|
if (!empty($metadata['local_cover_path'])) {
|
|
$video['poster_url'] = '/public/images/'.$metadata['local_cover_path'];
|
|
} elseif (!empty($metadata['cover_url'])) {
|
|
$video['poster_url'] = $metadata['cover_url'];
|
|
}
|
|
|
|
// Add actors data if available
|
|
if (!empty($metadata['actors'])) {
|
|
$video['actors'] = $metadata['actors'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Get total count for pagination
|
|
$totalCount = AdultVideo::getTotalCount($this->pdo, $search);
|
|
|
|
// Calculate pagination info
|
|
$totalPages = ceil($totalCount / $perPage);
|
|
$hasNextPage = $page < $totalPages;
|
|
$hasPrevPage = $page > 1;
|
|
|
|
return $this->view->render($response, 'adult/index.twig', [
|
|
'title' => 'Adult Videos',
|
|
'movies' => $adultVideos, // Keep same variable name for template compatibility
|
|
'pagination' => [
|
|
'current_page' => $page,
|
|
'per_page' => $perPage,
|
|
'total_pages' => $totalPages,
|
|
'total_items' => $totalCount,
|
|
'has_next' => $hasNextPage,
|
|
'has_prev' => $hasPrevPage,
|
|
'next_page' => $page + 1,
|
|
'prev_page' => $page - 1
|
|
],
|
|
'search' => $search,
|
|
'view_mode' => $viewMode,
|
|
'view_modes' => ['grid', 'list', 'covers']
|
|
]);
|
|
}
|
|
|
|
public function show(Request $request, Response $response, $args)
|
|
{
|
|
$adultVideoId = (int) $args['id'];
|
|
|
|
// Get adult video details
|
|
$stmt = $this->pdo->prepare("
|
|
SELECT av.*, s.display_name as source_name
|
|
FROM adult_videos av
|
|
JOIN sources s ON av.source_id = s.id
|
|
WHERE av.id = :id
|
|
");
|
|
$stmt->execute(['id' => $adultVideoId]);
|
|
$adultVideo = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
|
|
if (!$adultVideo) {
|
|
return $response->withStatus(404);
|
|
}
|
|
|
|
// Decode metadata for display
|
|
$metadata = json_decode($adultVideo['metadata'], true);
|
|
|
|
// Add local image paths and other metadata to the video data for template compatibility
|
|
if (!empty($metadata['local_cover_path'])) {
|
|
$adultVideo['poster_url'] = '/public/images/'.$metadata['local_cover_path'];
|
|
} elseif (!empty($metadata['cover_url'])) {
|
|
$adultVideo['poster_url'] = $metadata['cover_url'];
|
|
}
|
|
|
|
if (!empty($metadata['local_screenshot_path'])) {
|
|
$adultVideo['screenshot_url'] = '/public/images/'.$metadata['local_screenshot_path'];
|
|
}
|
|
|
|
// Add actors data if available
|
|
if (!empty($metadata['actors'])) {
|
|
$adultVideo['actors'] = $metadata['actors'];
|
|
}
|
|
|
|
// Get actors for this adult video from the pivot table
|
|
$stmt = $this->pdo->prepare("
|
|
SELECT a.*
|
|
FROM actors a
|
|
JOIN actor_adult_video aav ON a.id = aav.actor_id
|
|
WHERE aav.adult_video_id = :adult_video_id
|
|
ORDER BY a.name ASC
|
|
");
|
|
$stmt->execute(['adult_video_id' => $adultVideoId]);
|
|
$actors = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
return $this->view->render($response, 'adult/show.twig', [
|
|
'title' => $adultVideo['title'],
|
|
'movie' => $adultVideo, // Keep same variable name for template compatibility
|
|
'metadata' => $metadata,
|
|
'actors' => $actors
|
|
]);
|
|
}
|
|
|
|
private function getAdultSourceId(): ?int
|
|
{
|
|
$stmt = $this->pdo->prepare("SELECT id FROM sources WHERE name = 'adult' LIMIT 1");
|
|
$stmt->execute();
|
|
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
return $result ? (int) $result['id'] : null;
|
|
}
|
|
}
|