From c672a9e8ce6384f9ab4c56b18972737e8b275573 Mon Sep 17 00:00:00 2001 From: ScuffedNewt Date: Sun, 12 Jan 2025 15:04:44 +0000 Subject: [PATCH 1/3] fix: criteria loot --- .../Commands/FixEqualsCriteriaLoots.php | 47 +++++++++++++++++++ app/Models/Invitation.php | 1 + app/Models/Loot/Loot.php | 29 ++++-------- .../create_edit_loot_table.blade.php | 8 ++-- 4 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 app/Console/Commands/FixEqualsCriteriaLoots.php diff --git a/app/Console/Commands/FixEqualsCriteriaLoots.php b/app/Console/Commands/FixEqualsCriteriaLoots.php new file mode 100644 index 0000000000..b551d734a4 --- /dev/null +++ b/app/Console/Commands/FixEqualsCriteriaLoots.php @@ -0,0 +1,47 @@ +get(); + + foreach ($loots as $loot) { + $data = $loot->data; + + if (isset($data['criteria']) && $data['criteria'] == '=') { + $data['criteria'] = '=='; + + Loot::where([ + ['loot_table_id', '=', $loot->loot_table_id], + ['rewardable_type', '=', $loot->rewardable_type], + ['rewardable_id', '=', $loot->rewardable_id], + ])->update(['data' => $data]); + } + } + + } +} diff --git a/app/Models/Invitation.php b/app/Models/Invitation.php index f124fdd051..844b335715 100644 --- a/app/Models/Invitation.php +++ b/app/Models/Invitation.php @@ -20,6 +20,7 @@ class Invitation extends Model { * @var string */ protected $table = 'invitations'; + /** * Whether the model contains timestamps to be saved and updated. * diff --git a/app/Models/Loot/Loot.php b/app/Models/Loot/Loot.php index d69bae2243..673f8c2d12 100644 --- a/app/Models/Loot/Loot.php +++ b/app/Models/Loot/Loot.php @@ -24,6 +24,16 @@ class Loot extends Model { * @var string */ protected $table = 'loots'; + + /** + * The attributes that should be cast to native types. + * + * @var array + */ + protected $casts = [ + 'data' => 'array', + ]; + /** * Validation rules for creation. * @@ -78,23 +88,4 @@ public function reward() { return null; } - - /********************************************************************************************** - - ACCESSORS - - **********************************************************************************************/ - - /** - * Get the data attribute as an associative array. - * - * @return array - */ - public function getDataAttribute() { - if (!$this->attributes['data']) { - return null; - } - - return json_decode($this->attributes['data'], true); - } } diff --git a/resources/views/admin/loot_tables/create_edit_loot_table.blade.php b/resources/views/admin/loot_tables/create_edit_loot_table.blade.php index 02f1e18b50..dea2023678 100644 --- a/resources/views/admin/loot_tables/create_edit_loot_table.blade.php +++ b/resources/views/admin/loot_tables/create_edit_loot_table.blade.php @@ -67,7 +67,7 @@ {!! Form::select('rewardable_id[]', $items, $loot->rewardable_id, ['class' => 'form-control item-select selectize', 'placeholder' => 'Select Item']) !!} @elseif($loot->rewardable_type == 'ItemRarity')
- {!! Form::select('criteria[]', ['=' => '=', '<' => '<', '>' => '>', '<=' => '<=', '>=' => '>='], isset($loot->data['criteria']) ? $loot->data['criteria'] : null, ['class' => 'form-control', 'placeholder' => 'Criteria']) !!} + {!! Form::select('criteria[]', ['==' => '=', '<' => '<', '>' => '>', '<=' => '<=', '>=' => '>='], isset($loot->data['criteria']) ? $loot->data['criteria'] : null, ['class' => 'form-control', 'placeholder' => 'Criteria']) !!} {!! Form::select('rarity[]', $rarities, isset($loot->data['rarity']) ? $loot->data['rarity'] : null, ['class' => 'form-control', 'placeholder' => 'Rarity']) !!}
@elseif($loot->rewardable_type == 'Currency') @@ -77,7 +77,7 @@ @elseif($loot->rewardable_type == 'ItemCategoryRarity')
{!! Form::select('rewardable_id[]', $categories, $loot->rewardable_id, ['class' => 'form-control selectize', 'placeholder' => 'Category']) !!} - {!! Form::select('criteria[' . $loop->index . ']', ['=' => '=', '<' => '<', '>' => '>', '<=' => '<=', '>=' => '>='], isset($loot->data['criteria']) ? $loot->data['criteria'] : null, ['class' => 'form-control', 'placeholder' => 'Criteria']) !!} + {!! Form::select('criteria[' . $loop->index . ']', ['==' => '=', '<' => '<', '>' => '>', '<=' => '<=', '>=' => '>='], isset($loot->data['criteria']) ? $loot->data['criteria'] : null, ['class' => 'form-control', 'placeholder' => 'Criteria']) !!} {!! Form::select('rarity[' . $loop->index . ']', $rarities, isset($loot->data['rarity']) ? $loot->data['rarity'] : null, ['class' => 'form-control', 'placeholder' => 'Rarity']) !!}
@elseif($loot->rewardable_type == 'ItemCategory') @@ -124,7 +124,7 @@ {!! Form::select('rewardable_id[]', $items, null, ['class' => 'form-control item-select', 'placeholder' => 'Select Item']) !!}
- {!! Form::select('criteria[]', ['=' => '=', '<' => '<', '>' => '>', '<=' => '<=', '>=' => '>='], null, ['class' => 'form-control criteria-select', 'placeholder' => 'Criteria']) !!} + {!! Form::select('criteria[]', ['==' => '=', '<' => '<', '>' => '>', '<=' => '<=', '>=' => '>='], null, ['class' => 'form-control criteria-select', 'placeholder' => 'Criteria']) !!} {!! Form::select('rarity[]', $rarities, null, ['class' => 'form-control criteria-select', 'placeholder' => 'Rarity']) !!}
{!! Form::select('rewardable_id[]', $currencies, null, ['class' => 'form-control currency-select', 'placeholder' => 'Select Currency']) !!} @@ -132,7 +132,7 @@ {!! Form::select('rewardable_id[]', $categories, null, ['class' => 'form-control category-select', 'placeholder' => 'Select Item Category']) !!}
{!! Form::select('rewardable_id[]', $categories, null, ['class' => 'form-control', 'placeholder' => 'Category']) !!} - {!! Form::select('criteria[]', ['=' => '=', '<' => '<', '>' => '>', '<=' => '<=', '>=' => '>='], null, ['class' => 'form-control criteria-select', 'placeholder' => 'Criteria']) !!} + {!! Form::select('criteria[]', ['==' => '=', '<' => '<', '>' => '>', '<=' => '<=', '>=' => '>='], null, ['class' => 'form-control criteria-select', 'placeholder' => 'Criteria']) !!} {!! Form::select('rarity[]', $rarities, null, ['class' => 'form-control criteria-select', 'placeholder' => 'Rarity']) !!}
{!! Form::select('rewardable_id[]', [1 => 'No reward given.'], null, ['class' => 'form-control none-select']) !!} From 10f6f9815baf3dfe498d2b02d6dd09d63b984d98 Mon Sep 17 00:00:00 2001 From: ScuffedNewt Date: Sun, 12 Jan 2025 15:07:21 +0000 Subject: [PATCH 2/3] refactor: fix PHP styling --- app/Console/Commands/FixEqualsCriteriaLoots.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/Console/Commands/FixEqualsCriteriaLoots.php b/app/Console/Commands/FixEqualsCriteriaLoots.php index b551d734a4..94a629aaef 100644 --- a/app/Console/Commands/FixEqualsCriteriaLoots.php +++ b/app/Console/Commands/FixEqualsCriteriaLoots.php @@ -2,11 +2,10 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; use App\Models\Loot\Loot; +use Illuminate\Console\Command; -class FixEqualsCriteriaLoots extends Command -{ +class FixEqualsCriteriaLoots extends Command { /** * The name and signature of the console command. * @@ -24,17 +23,16 @@ class FixEqualsCriteriaLoots extends Command /** * Execute the console command. */ - public function handle() - { + public function handle() { // $loots = Loot::whereNotNull('data')->get(); foreach ($loots as $loot) { $data = $loot->data; - + if (isset($data['criteria']) && $data['criteria'] == '=') { $data['criteria'] = '=='; - + Loot::where([ ['loot_table_id', '=', $loot->loot_table_id], ['rewardable_type', '=', $loot->rewardable_type], @@ -42,6 +40,5 @@ public function handle() ])->update(['data' => $data]); } } - } } From 772b3e8212445dad17561270ca1558e9316d7054 Mon Sep 17 00:00:00 2001 From: ScuffedNewt Date: Sun, 12 Jan 2025 15:44:13 +0000 Subject: [PATCH 3/3] feat: command descriptions --- app/Console/Commands/FixEqualsCriteriaLoots.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/FixEqualsCriteriaLoots.php b/app/Console/Commands/FixEqualsCriteriaLoots.php index 94a629aaef..70ecb67288 100644 --- a/app/Console/Commands/FixEqualsCriteriaLoots.php +++ b/app/Console/Commands/FixEqualsCriteriaLoots.php @@ -18,7 +18,7 @@ class FixEqualsCriteriaLoots extends Command { * * @var string */ - protected $description = 'Command description'; + protected $description = 'Fix equals criteria loots to double equals for use in where clause'; /** * Execute the console command.