From fffbce22779b3f47ae7a9cfc06405cc26e5ca42f Mon Sep 17 00:00:00 2001 From: ScuffedNewt Date: Wed, 25 Sep 2024 21:21:32 +0100 Subject: [PATCH] feat(characters): dob / poucher code --- .../Admin/Characters/CharacterController.php | 4 +-- app/Http/Controllers/BrowseController.php | 3 ++ app/Models/Character/Character.php | 2 ++ app/Services/CharacterManager.php | 17 +++++++++-- ..._09_25_193855_add_fields_to_characters.php | 30 +++++++++++++++++++ .../browse/_masterlist_content.blade.php | 4 +++ .../views/character/_tab_stats.blade.php | 12 ++++++++ .../admin/_edit_stats_modal.blade.php | 12 ++++++-- resources/views/character/character.blade.php | 5 ++++ 9 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 database/migrations/2024_09_25_193855_add_fields_to_characters.php diff --git a/app/Http/Controllers/Admin/Characters/CharacterController.php b/app/Http/Controllers/Admin/Characters/CharacterController.php index 68e2cfc033..d24674e5a9 100644 --- a/app/Http/Controllers/Admin/Characters/CharacterController.php +++ b/app/Http/Controllers/Admin/Characters/CharacterController.php @@ -205,7 +205,7 @@ public function getEditMyoStats($id) { public function postEditCharacterStats(Request $request, CharacterManager $service, $slug) { $request->validate(Character::$updateRules); $data = $request->only([ - 'character_category_id', 'number', 'slug', + 'character_category_id', 'number', 'slug', 'poucher_code', 'is_giftable', 'is_tradeable', 'is_sellable', 'sale_value', 'transferrable_at', ]); @@ -364,7 +364,7 @@ public function postEditMyoDescription(Request $request, CharacterManager $servi */ public function postCharacterSettings(Request $request, CharacterManager $service, $slug) { $data = $request->only([ - 'is_visible', + 'is_visible', 'dob', ]); $this->character = Character::where('slug', $slug)->first(); if (!$this->character) { diff --git a/app/Http/Controllers/BrowseController.php b/app/Http/Controllers/BrowseController.php index 46bd765f46..0cb87048b5 100644 --- a/app/Http/Controllers/BrowseController.php +++ b/app/Http/Controllers/BrowseController.php @@ -283,6 +283,9 @@ private function handleMasterlistSearch(Request $request, $query, $imageQuery, $ $query->where('characters.name', 'LIKE', '%'.$request->get('name').'%')->orWhere('characters.slug', 'LIKE', '%'.$request->get('name').'%'); }); } + if ($request->get('poucher_code')) { + $query->where('characters.poucher_code', 'LIKE', '%'.$request->get('poucher_code').'%'); + } if ($request->get('rarity_id')) { $query->where('rarity_id', $request->get('rarity_id')); } diff --git a/app/Models/Character/Character.php b/app/Models/Character/Character.php index 756a059c3c..6f67790a12 100644 --- a/app/Models/Character/Character.php +++ b/app/Models/Character/Character.php @@ -33,6 +33,7 @@ class Character extends Model { 'sale_value', 'transferrable_at', 'is_visible', 'is_gift_art_allowed', 'is_gift_writing_allowed', 'is_trading', 'sort', 'is_myo_slot', 'name', 'trade_id', 'owner_url', + 'dob', 'poucher_code', ]; /** @@ -49,6 +50,7 @@ class Character extends Model { */ protected $casts = [ 'transferrable_at' => 'datetime', + 'dob' => 'datetime', ]; /** diff --git a/app/Services/CharacterManager.php b/app/Services/CharacterManager.php index 3431a6b1af..78b7e1d1cf 100644 --- a/app/Services/CharacterManager.php +++ b/app/Services/CharacterManager.php @@ -1142,6 +1142,7 @@ public function updateCharacterStats($data, $character, $user) { $characterData['is_giftable'] = isset($data['is_giftable']); $characterData['sale_value'] = $data['sale_value'] ?? 0; $characterData['transferrable_at'] = $data['transferrable_at'] ?? null; + $characterData['poucher_code'] = $data['poucher_code'] ?? null; if ($character->is_myo_slot) { $characterData['name'] = (isset($data['name']) && $data['name']) ? $data['name'] : null; } @@ -1198,6 +1199,11 @@ public function updateCharacterStats($data, $character, $user) { $old['transferrable_at'] = $character->transferrable_at; $new['transferrable_at'] = $characterData['transferrable_at']; } + if ($characterData['poucher_code'] != $character->poucher_code) { + $result[] = 'poucher code'; + $old['poucher_code'] = $character->poucher_code; + $new['poucher_code'] = $characterData['poucher_code']; + } if (count($result)) { $character->update($characterData); @@ -1268,14 +1274,21 @@ public function updateCharacterSettings($data, $character, $user) { throw new \Exception('Failed to log admin action.'); } - $old = ['is_visible' => $character->is_visible]; + $old = [ + 'dob' => $character->dob, + 'is_visible' => $character->is_visible, + ]; + $character->dob = $data['dob'] ?? null; $character->is_visible = isset($data['is_visible']); $character->save(); // Add a log for the character // This logs all the updates made to the character - $this->createLog($user->id, null, null, null, $character->id, 'Character Visibility Updated', '', 'character', true, $old, ['is_visible' => $character->is_visible]); + $this->createLog($user->id, null, null, null, $character->id, 'Character Settings Updated', '', 'character', true, $old, [ + 'dob' => $character->dob, + 'is_visible' => $character->is_visible, + ]); return $this->commitReturn(true); } catch (\Exception $e) { diff --git a/database/migrations/2024_09_25_193855_add_fields_to_characters.php b/database/migrations/2024_09_25_193855_add_fields_to_characters.php new file mode 100644 index 0000000000..15bafc996e --- /dev/null +++ b/database/migrations/2024_09_25_193855_add_fields_to_characters.php @@ -0,0 +1,30 @@ +text('poucher_code')->nullable()->default(null)->after('name'); + $table->timestamp('dob')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('characters', function (Blueprint $table) { + // + }); + } +}; diff --git a/resources/views/browse/_masterlist_content.blade.php b/resources/views/browse/_masterlist_content.blade.php index e4c5b9ea8f..20dccb1048 100644 --- a/resources/views/browse/_masterlist_content.blade.php +++ b/resources/views/browse/_masterlist_content.blade.php @@ -5,6 +5,10 @@ {!! Form::label('name', 'Character Name/Code: ', ['class' => 'mr-2']) !!} {!! Form::text('name', Request::get('name'), ['class' => 'form-control']) !!} +
+ {!! Form::label('poucher_code', 'Poucher Code: ', ['class' => 'mr-2']) !!} + {!! Form::text('poucher_code', Request::get('poucher_code'), ['class' => 'form-control']) !!} +
{!! Form::select('rarity_id', $rarities, Request::get('rarity_id'), ['class' => 'form-control mr-2']) !!}
diff --git a/resources/views/character/_tab_stats.blade.php b/resources/views/character/_tab_stats.blade.php index 686f3dfc4c..7633e20902 100644 --- a/resources/views/character/_tab_stats.blade.php +++ b/resources/views/character/_tab_stats.blade.php @@ -11,7 +11,19 @@
{!! $character->category->displayName !!}
+
+
+
Poucher Code
+
+
{!! $character->poucher_code ?? 'None' !!}
+
@endif +
+
+
DOB
+
+
{!! $character->dob->format('d M, Y') !!}
+
Created
diff --git a/resources/views/character/admin/_edit_stats_modal.blade.php b/resources/views/character/admin/_edit_stats_modal.blade.php index d71be2bd9f..3165ff993e 100644 --- a/resources/views/character/admin/_edit_stats_modal.blade.php +++ b/resources/views/character/admin/_edit_stats_modal.blade.php @@ -19,9 +19,15 @@
-
- {!! Form::label('Character Code') !!} {!! add_help('This code identifies the character itself. This must be unique among all characters (as it\'s used to generate the character\'s page URL).') !!} - {!! Form::text('slug', $character->slug, ['class' => 'form-control', 'id' => 'code']) !!} +
+
+ {!! Form::label('Character Code') !!} {!! add_help('This code identifies the character itself. This must be unique among all characters (as it\'s used to generate the character\'s page URL).') !!} + {!! Form::text('slug', $character->slug, ['class' => 'form-control', 'id' => 'code']) !!} +
+
+ {!! Form::label('poucher_code', 'Poucher Code') !!} + {!! Form::text('poucher_code', $character->poucher_code, ['class' => 'form-control']) !!} +
@endif diff --git a/resources/views/character/character.blade.php b/resources/views/character/character.blade.php index 6f1d795e24..f019da0810 100644 --- a/resources/views/character/character.blade.php +++ b/resources/views/character/character.blade.php @@ -68,6 +68,10 @@ class="image {{ $character->image->showContentWarnings(Auth::user() ?? null) ? ' {!! Form::checkbox('is_visible', 1, $character->is_visible, ['class' => 'form-check-input', 'data-toggle' => 'toggle']) !!} {!! Form::label('is_visible', 'Is Visible', ['class' => 'form-check-label ml-3']) !!} {!! add_help('Turn this off to hide the character. Only mods with the Manage Masterlist power (that\'s you!) can view it - the owner will also not be able to see the character\'s page.') !!}
+
+ {!! Form::label('Date of Birth (Optional)') !!} + {!! Form::text('dob', $character->dob, ['class' => 'form-control datepicker']) !!} +
{!! Form::submit('Edit', ['class' => 'btn btn-primary']) !!}
@@ -84,5 +88,6 @@ class="image {{ $character->image->showContentWarnings(Auth::user() ?? null) ? ' @section('scripts') @parent + @include('widgets._datetimepicker_js', ['dtvalue' => $character->transferrable_at]) @include('character._image_js', ['character' => $character]) @endsection