Files
FlightsAPI/app/Settings/SettingsRegistry.php
2026-06-20 22:21:17 +10:00

146 lines
6.1 KiB
PHP

<?php
namespace App\Settings;
class SettingsRegistry
{
public static function categories(): array
{
return [
'Units of Measurement' => 'Select either metric or incorrect units.',
'FlightsGoneBy Settings' => 'Settings for Site Behaviour',
'AI Generated Content' => 'Airline tail logos and liveries are AI generated with human cleanup. If you would rather not see any AI, then our blank aircraft templates are human created.',
'Account & Privacy' => 'Everything to do with your account.',
];
}
public static function schema(): array
{
return [
[
'key' => 'distance_unit',
'type' => 'select',
'label' => 'Distance Units',
'category' => 'Units of Measurement',
'default' => 'km',
'options' => [
['value' => 'km', 'label' => 'Kilometres (km)'],
['value' => 'mi', 'label' => 'Miles (mi)'],
['value' => 'nm', 'label' => 'Nautical miles (nm)'],
],
],
[
'category' => 'Account & Privacy',
'key' => 'private_profile',
'type' => 'select',
'label' => 'Account Privacy',
'default' => 'public',
'options' => [
['value' => 'public', 'label' => 'Public Profile Viewable By Everyone'],
['value' => 'private', 'label' => 'Private Profile Viewable Only By You and Your Approved Followers'],
]
],
[
'key' => 'default_login_page',
'type' => 'select',
'label' => 'Default Page',
'category' => 'FlightsGoneBy Settings',
'default' => 'feed_first',
'options' => [
['value' => 'feed_first', 'label' => 'My Feed if Following People, My Profile if Not'],
['value' => 'profile', 'label' => 'My Profile'],
['value' => 'feed', 'label' => 'My Feed'],
['value' => 'dashboard', 'label' => 'My Dashboard'],
],
],
[
'key' => 'default_profile_view',
'type' => 'select',
'label' => 'Default View When Loading a Profile',
'category' => 'FlightsGoneBy Settings',
'default' => 'departure-board',
'options' => [
['value' => 'departure-board', 'label' => 'Departure Board'],
['value' => 'map', 'label' => 'Map'],
['value' => 'boarding-passes', 'label' => 'Boarding Passes'],
['value' => 'achievements', 'label' => 'Achievements'],
],
],
[
'key' => 'show_map_legend',
'type' => 'checkbox',
'label' => 'Expand Map Legend By Default',
'category' => 'FlightsGoneBy Settings',
'default' => true,
],
[
'key' => 'hide_impossible_achievements',
'type' => 'checkbox',
'label' => 'Hide Impossible Achievements By Default',
'category' => 'FlightsGoneBy Settings',
'default' => true,
],
[
'category' => 'AI Generated Content',
'key' => 'ai_liveries',
'type' => 'checkbox',
'label' => 'Show AI Generated Livery Images',
'default' => true,
],
[
'category' => 'AI Generated Content',
'key' => 'ai_tail_logos',
'type' => 'checkbox',
'label' => 'Show AI Generated Tail Logos',
'default' => true,
],
[
'key' => 'departure_board_columns',
'category' => 'FlightsGoneBy Settings',
'type' => 'multiselect',
'label' => 'Which columns to show on the Departure Board',
'default' => ['airline', 'flight_number', 'from', 'to', 'departure_date', 'departure_time', 'arrival_time', 'duration', 'distance', 'aircraft', 'registration', 'class_seat_combined'],
'options' => [
['value' => 'airline', 'label' => 'Airline'],
['value' => 'flight_number', 'label' => 'Flight Number'],
['value' => 'from', 'label' => 'From'],
['value' => 'to', 'label' => 'To'],
['value' => 'departure_date', 'label' => 'Departure Date'],
['value' => 'departure_time', 'label' => 'Departure Time'],
['value' => 'arrival_time', 'label' => 'Arrival Time'],
['value' => 'duration', 'label' => 'Duration'],
['value' => 'distance', 'label' => 'Distance'],
['value' => 'aircraft', 'label' => 'Aircraft'],
['value' => 'registration', 'label' => 'Aircraft Registration'],
['value' => 'class_seat_combined', 'label' => 'Class/Seat Type/Seat Number Combined'],
],
],
];
}
public static function defaults(): array
{
return collect(static::schema())
->pluck('default', 'key')
->toArray();
}
public static function validationRules(): array
{
$rules = [];
foreach (static::schema() as $field) {
$key = "settings.{$field['key']}";
$rules[$key] = match ($field['type']) {
'select' => ['required', 'string', 'in:' . implode(',', array_column($field['options'], 'value'))],
'checkbox' => ['boolean'],
'text' => ['nullable', 'string', 'max:255'],
'multiselect' => ['nullable', 'array'],
"settings.{$field['key']}.*" => ['string'],
default => ['nullable'],
};
}
return $rules;
}
}