Added User Settings
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
<?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 After Login',
|
||||
'category' => 'FlightsGoneBy Settings',
|
||||
'default' => 'feed_first',
|
||||
'options' => [
|
||||
['value' => 'feed_first', 'label' => 'Feed if Following People, Profile if Not'],
|
||||
['value' => 'profile', 'label' => 'Your Profile'],
|
||||
['value' => 'feed', 'label' => 'Your Feed'],
|
||||
['value' => 'dashboard', 'label' => 'Your 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'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user