Change setting table ID to string, handle the converison of . to _

This commit is contained in:
Nabeel Shahzad 2017-12-31 11:09:56 -06:00
parent 528a7c7440
commit 948338d2b6
5 changed files with 53 additions and 30 deletions

View File

@ -2,4 +2,4 @@ dnsmasq: /usr/local/sbin/dnsmasq --keep-in-foreground
php-fpm: /usr/local/sbin/php-fpm --nodaemonize
nginx: /usr/local/bin/nginx
#mysql: /usr/local/bin/mysqld
#mailhog: /usr/local/bin/mailhog
mailhog: /usr/local/bin/mailhog

View File

@ -13,19 +13,17 @@ class CreateSettingsTable extends Migration
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->increments('id');
$table->string('id');
$table->unsignedInteger('order')->default(99);
$table->string('name');
$table->string('key');
$table->string('value');
$table->string('group')->nullable();
$table->string('type')->nullable();
$table->string('options')->nullable();
$table->string('description')->nullable();
$table->primary('id');
$table->timestamps();
$table->unique('key');
$table->index('key');
});
/**
@ -33,86 +31,95 @@ class CreateSettingsTable extends Migration
*/
$settings = [
[
'id' => 'general_start_date',
'order' => 1,
'name' => 'Start Date',
'group' => 'general',
'key' => 'general.start_date',
'value' => '',
'type' => 'date',
'description' => 'The date your VA started',
],
[
'id' => 'general_admin_email',
'order' => 2,
'name' => 'Admin Email',
'group' => 'general',
'key' => 'general.admin_email',
'value' => '',
'type' => 'text',
'description' => 'Email where notices, etc are sent',
],
[
'id' => 'general_currency',
'order' => 3,
'name' => 'Currency to Use',
'group' => 'general',
'key' => 'general.currency',
'value' => 'dollar',
'type' => 'select',
'options' => 'dollar,euro,gbp,yen,jpy,rupee,ruble',
'description' => 'Currency to show in the interface',
],
[
'id' => 'flight_only_flights_from_current',
'order' => 10,
'name' => 'Flights from Current',
'group' => 'flights',
'key' => 'flights.only_flights_from_current',
'value' => true,
'type' => 'boolean',
'description' => 'Only allow flights from current location',
],
[
'id' => 'bids_disable_flight_on_bid',
'order' => 20,
'name' => 'Disable flight on bid',
'group' => 'bids',
'key' => 'bids.disable_flight_on_bid',
'value' => true,
'type' => 'boolean',
'description' => 'When a flight is bid on, no one else can bid on it',
],
[
'id' => 'bids_allow_multiple_bids',
'order' => 21,
'name' => 'Allow multiple bids',
'group' => 'bids',
'key' => 'bids.allow_multiple_bids',
'value' => true,
'type' => 'boolean',
'description' => 'Whether or not someone can bid on multiple flights',
],
[
'id' => 'pilots_id_length',
'order' => 30,
'name' => 'Hide Inactive Pilots',
'name' => 'Pilot ID Length',
'group' => 'pilots',
'key' => 'pilots.hide_inactive',
'value' => true,
'type' => 'boolean',
'description' => 'Don\'t show inactive pilots in the public view',
'value' => 4,
'type' => 'int',
'description' => 'The length of a pilot\'s ID',
],
[
'id' => 'pilot_auto_accept',
'order' => 31,
'name' => 'Auto Accept New Pilot',
'group' => 'pilots',
'key' => 'pilot.auto_accept',
'value' => true,
'type' => 'boolean',
'description' => 'Automatically accept a pilot when they register',
],
[
'order' => 32,
'name' => 'Pilot ID Length',
'id' => 'pilot_auto_leave_days',
'order' => 31,
'name' => 'Pilot to ON LEAVE days',
'group' => 'pilots',
'key' => 'pilots.id_length',
'value' => 4,
'value' => 30,
'type' => 'int',
'description' => 'The length of a pilot\'s ID',
'description' => 'Automatically set a pilot to ON LEAVE status after N days of no activity',
],
[
'id' => 'pilots_hide_inactive',
'order' => 32,
'name' => 'Hide Inactive Pilots',
'group' => 'pilots',
'value' => true,
'type' => 'boolean',
'description' => 'Don\'t show inactive pilots in the public view',
],
];

View File

@ -5,6 +5,7 @@ namespace App\Listeners;
use Log;
use Illuminate\Support\Facades\Mail;
use App\Events\UserRegistered;
use App\Models\Enums\UserState;
/**
@ -39,6 +40,8 @@ class NotificationEventListener
# First send the admin a notification
$admin_email = setting('general.admin_email');
Log::info('Sending admin notification email to "'.$admin_email.'"');
if (!empty($admin_email)) {
$email = new \App\Mail\Admin\UserRegistered($event->user);
Mail::to($admin_email)->send($email);

View File

@ -1,16 +1,11 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: nshahzad
* Date: 12/9/17
* Time: 6:24 PM
*/
namespace App\Models;
class Setting extends BaseModel
{
public $table = 'settings';
public $incrementing = false;
public $fillable = [
'name',
@ -22,4 +17,18 @@ class Setting extends BaseModel
'description',
];
protected static function boot()
{
parent::boot();
/**
* Make sure any dots are replaced with underscores
*/
static::creating(function (Setting $model) {
if (!empty($model->id)) {
$model->id = str_replace('.', '_', strtolower($model->id));
}
});
}
}

View File

@ -28,8 +28,8 @@ class SettingRepository extends BaseRepository implements CacheableInterface
*/
public function retrieve($key)
{
$key = strtolower($key);
$setting = $this->findWhere(['key' => $key], ['type', 'value'])->first();
$key = str_replace('.', '_', strtolower($key));
$setting = $this->findWhere(['id' => $key], ['type', 'value'])->first();
if(!$setting) {
return null;
@ -46,8 +46,12 @@ class SettingRepository extends BaseRepository implements CacheableInterface
break;
case 'int':
case 'integer':
case 'number':
return (int) $setting->value;
break;
case 'float':
return (float) $setting->value;
break;
default:
return $setting->value;
}