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.
83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/BaseModel.php';
|
|
|
|
class Settings extends BaseModel {
|
|
protected $table = 'settings';
|
|
|
|
public function __construct($pdo) {
|
|
parent::__construct($pdo);
|
|
}
|
|
|
|
public function getSettings() {
|
|
$stmt = $this->pdo->prepare("SELECT * FROM {$this->table} WHERE id = 1");
|
|
$stmt->execute();
|
|
$settings = $stmt->fetch();
|
|
|
|
if ($settings) {
|
|
// Decode enabled_categories from JSON
|
|
$settings['enabled_categories'] = $settings['enabled_categories'] ? json_decode($settings['enabled_categories'], true) : [];
|
|
// Convert boolean fields from tinyint to boolean
|
|
$settings['show_adult_content'] = (bool)$settings['show_adult_content'];
|
|
$settings['auto_play_trailers'] = (bool)$settings['auto_play_trailers'];
|
|
}
|
|
|
|
return $settings;
|
|
}
|
|
|
|
public function updateSettings($data) {
|
|
$updateData = [];
|
|
|
|
if (isset($data['enabled_categories']) && is_array($data['enabled_categories'])) {
|
|
$updateData['enabled_categories'] = json_encode($data['enabled_categories']);
|
|
}
|
|
|
|
if (isset($data['items_per_page'])) {
|
|
$updateData['items_per_page'] = (int)$data['items_per_page'];
|
|
}
|
|
|
|
if (isset($data['default_view'])) {
|
|
$updateData['default_view'] = $data['default_view'];
|
|
}
|
|
|
|
if (isset($data['show_adult_content'])) {
|
|
$updateData['show_adult_content'] = $data['show_adult_content'] ? 1 : 0;
|
|
}
|
|
|
|
if (isset($data['auto_play_trailers'])) {
|
|
$updateData['auto_play_trailers'] = $data['auto_play_trailers'] ? 1 : 0;
|
|
}
|
|
|
|
if (isset($data['language'])) {
|
|
$updateData['language'] = $data['language'];
|
|
}
|
|
|
|
if (isset($data['theme'])) {
|
|
$updateData['theme'] = $data['theme'];
|
|
}
|
|
|
|
// Check if settings row exists
|
|
$existing = $this->findById(1);
|
|
|
|
if ($existing) {
|
|
$this->update(1, $updateData);
|
|
return $this->getSettings();
|
|
} else {
|
|
// Create default settings if not exists
|
|
$defaultData = [
|
|
'enabled_categories' => json_encode(['Anime', 'Movies', 'TV Series', 'Music', 'Books', 'Consoles', 'Games', 'Adult']),
|
|
'items_per_page' => 20,
|
|
'default_view' => 'grid',
|
|
'show_adult_content' => 0,
|
|
'auto_play_trailers' => 0,
|
|
'language' => 'en',
|
|
'theme' => 'system',
|
|
'theme' => 'system'
|
|
];
|
|
$mergedData = array_merge($defaultData, $updateData);
|
|
$this->create($mergedData);
|
|
return $this->getSettings();
|
|
}
|
|
}
|
|
}
|