Files
mystuff_backend/api/models/Adult.php
Lars Behrends 66f69bc90d Add PHP Media API scaffold and Docker configs
Initial project scaffold for a PHP Media API including routing, controllers, models and services under api/ (Router, Media/Cast/Image/Settings controllers, models, database/bootstrap files and automatic docs service). Adds Docker support (Dockerfile, docker-compose.yml, DOCKER_README.md, php-custom.ini), .htaccess for pretty URLs, API documentation and example payloads (API_EXAMPLES.md, api/README.md, api_examples/*.json), image handling service and logging, plus a comprehensive .gitignore. This commit provides a runnable development environment and example requests to get the API up and tested quickly.
2026-04-12 00:46:30 +02:00

86 lines
3.2 KiB
PHP

<?php
require_once __DIR__ . '/MediaType.php';
require_once __DIR__ . '/../services/ImageHandler.php';
class Adult extends MediaType {
private $imageHandler;
private $isUpdate = false;
private $mediaId = null;
public function __construct($pdo) {
parent::__construct($pdo);
$this->imageHandler = new ImageHandler();
}
protected function getType() {
return 'Adult';
}
protected function getTypeSpecificFields() {
return [];
}
protected function validateTypeSpecificFields($data) {
// Adult spezifische Validierung
// Eventuell Altersverifikation etc.
}
protected function processPosterField($data) {
error_log("Adult::processPosterField - Checking for poster field, isUpdate: " . ($this->isUpdate ? 'yes' : 'no'));
if ($this->isUpdate && $this->mediaId && isset($data['poster']) && !empty($data['poster'])) {
$currentMedia = $this->findById($this->mediaId);
if ($currentMedia && !empty($currentMedia['poster'])) {
$oldPoster = $currentMedia['poster'];
if (strpos($oldPoster, '/images/') === 0) {
error_log("Adult::processPosterField - Deleting old poster: " . $oldPoster);
$this->imageHandler->deleteImage($oldPoster);
}
}
}
if (isset($data['poster']) && !empty($data['poster'])) {
error_log("Adult::processPosterField - Poster found, length: " . strlen($data['poster']));
if (strpos($data['poster'], '/images/') === 0 || filter_var($data['poster'], FILTER_VALIDATE_URL)) {
error_log("Adult::processPosterField - Poster is already a path or URL, skipping processing");
return $data;
}
$posterPath = $this->imageHandler->saveBase64Image($data['poster'], 'adult/poster');
error_log("Adult::processPosterField - ImageHandler returned: " . ($posterPath ?: 'null'));
if ($posterPath) {
$data['poster'] = $posterPath;
error_log("Adult::processPosterField - Poster path set to: " . $posterPath);
} else {
error_log("Adult::processPosterField - Failed to process poster, keeping original data");
}
} else {
error_log("Adult::processPosterField - No poster field found or empty");
}
return $data;
}
public function createWithRelations($data) {
$data['type'] = 'Adult';
$this->validateTypeSpecificFields($data);
$data = $this->processPosterField($data);
return parent::createWithRelations($data);
}
public function updateWithRelations($id, $data) {
$this->isUpdate = true;
$this->mediaId = $id;
$this->validateTypeSpecificFields($data);
$data = $this->processPosterField($data);
parent::updateWithRelations($id, $data);
}
public function search($filters = [], $page = 1, $limit = 20) {
// Nur Adult Content suchen
$filters['type'] = 'Adult';
return parent::search($filters, $page, $limit);
}
}