Skip to content

Commit

Permalink
feat(characters): dob / poucher code
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Sep 25, 2024
1 parent 15d3ec7 commit fffbce2
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/Characters/CharacterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/BrowseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Character/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

/**
Expand All @@ -49,6 +50,7 @@ class Character extends Model {
*/
protected $casts = [
'transferrable_at' => 'datetime',
'dob' => 'datetime',
];

/**
Expand Down
17 changes: 15 additions & 2 deletions app/Services/CharacterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions database/migrations/2024_09_25_193855_add_fields_to_characters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('characters', function (Blueprint $table) {
//
$table->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) {
//
});
}
};
4 changes: 4 additions & 0 deletions resources/views/browse/_masterlist_content.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
{!! Form::label('name', 'Character Name/Code: ', ['class' => 'mr-2']) !!}
{!! Form::text('name', Request::get('name'), ['class' => 'form-control']) !!}
</div>
<div class="form-group mr-3 mb-3">
{!! Form::label('poucher_code', 'Poucher Code: ', ['class' => 'mr-2']) !!}
{!! Form::text('poucher_code', Request::get('poucher_code'), ['class' => 'form-control']) !!}
</div>
<div class="form-group mb-3 mr-1">
{!! Form::select('rarity_id', $rarities, Request::get('rarity_id'), ['class' => 'form-control mr-2']) !!}
</div>
Expand Down
12 changes: 12 additions & 0 deletions resources/views/character/_tab_stats.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@
</div>
<div class="col-lg-9 col-8">{!! $character->category->displayName !!}</div>
</div>
<div class="row">
<div class="col-lg-3 col-4">
<h5>Poucher Code</h5>
</div>
<div class="col-lg-9 col-8">{!! $character->poucher_code ?? 'None' !!}</div>
</div>
@endif
<div class="row">
<div class="col-lg-3 col-4">
<h5>DOB</h5>
</div>
<div class="col-lg-9 col-8">{!! $character->dob->format('d M, Y') !!}</div>
</div>
<div class="row">
<div class="col-lg-3 col-4">
<h5 class="mb-0">Created</h5>
Expand Down
12 changes: 9 additions & 3 deletions resources/views/character/admin/_edit_stats_modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
</div>
</div>
</div>
<div class="form-group">
{!! 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']) !!}
<div class="row">
<div class="col-md-6 form-group">
{!! 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']) !!}
</div>
<div class="col-md-6 form-group">
{!! Form::label('poucher_code', 'Poucher Code') !!}
{!! Form::text('poucher_code', $character->poucher_code, ['class' => 'form-control']) !!}
</div>
</div>
@endif

Expand Down
5 changes: 5 additions & 0 deletions resources/views/character/character.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.') !!}
</div>
<div class="form-group">
{!! Form::label('Date of Birth (Optional)') !!}
{!! Form::text('dob', $character->dob, ['class' => 'form-control datepicker']) !!}
</div>
<div class="text-right">
{!! Form::submit('Edit', ['class' => 'btn btn-primary']) !!}
</div>
Expand All @@ -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

0 comments on commit fffbce2

Please sign in to comment.