Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: criteria loot #1191

Merged
merged 3 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app/Console/Commands/FixEqualsCriteriaLoots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Console\Commands;

use App\Models\Loot\Loot;
use Illuminate\Console\Command;

class FixEqualsCriteriaLoots extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fix-equals-criteria-loots';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Fix equals criteria loots to double equals for use in where clause';

/**
* Execute the console command.
*/
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],
['rewardable_id', '=', $loot->rewardable_id],
])->update(['data' => $data]);
}
}
}
}
1 change: 1 addition & 0 deletions app/Models/Invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Invitation extends Model {
* @var string
*/
protected $table = 'invitations';

/**
* Whether the model contains timestamps to be saved and updated.
*
Expand Down
29 changes: 10 additions & 19 deletions app/Models/Loot/Loot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')
<div class="item-rarity-select d-flex">
{!! 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']) !!}
</div>
@elseif($loot->rewardable_type == 'Currency')
Expand All @@ -77,7 +77,7 @@
@elseif($loot->rewardable_type == 'ItemCategoryRarity')
<div class="category-rarity-select d-flex">
{!! 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']) !!}
</div>
@elseif($loot->rewardable_type == 'ItemCategory')
Expand Down Expand Up @@ -124,15 +124,15 @@
</table>
{!! Form::select('rewardable_id[]', $items, null, ['class' => 'form-control item-select', 'placeholder' => 'Select Item']) !!}
<div class="item-rarity-select d-flex">
{!! 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']) !!}
</div>
{!! Form::select('rewardable_id[]', $currencies, null, ['class' => 'form-control currency-select', 'placeholder' => 'Select Currency']) !!}
{!! Form::select('rewardable_id[]', $tables, null, ['class' => 'form-control table-select', 'placeholder' => 'Select Loot Table']) !!}
{!! Form::select('rewardable_id[]', $categories, null, ['class' => 'form-control category-select', 'placeholder' => 'Select Item Category']) !!}
<div class="category-rarity-select d-flex">
{!! 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']) !!}
</div>
{!! Form::select('rewardable_id[]', [1 => 'No reward given.'], null, ['class' => 'form-control none-select']) !!}
Expand Down
Loading