mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
first commit
This commit is contained in:
99
app/Controllers/AdultController.php
Normal file
99
app/Controllers/AdultController.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?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);
|
||||
|
||||
// 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);
|
||||
|
||||
return $this->view->render($response, 'adult/show.twig', [
|
||||
'title' => $adultVideo['title'],
|
||||
'movie' => $adultVideo, // Keep same variable name for template compatibility
|
||||
'metadata' => $metadata
|
||||
]);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user