diff --git a/app/Filament/Resources/System/MedalResource.php b/app/Filament/Resources/System/MedalResource.php index 17737f34..92fdf0aa 100644 --- a/app/Filament/Resources/System/MedalResource.php +++ b/app/Filament/Resources/System/MedalResource.php @@ -34,6 +34,7 @@ class MedalResource extends Resource return self::getNavigationLabel(); } + public static function form(Form $form): Form { return $form @@ -82,6 +83,12 @@ class MedalResource extends Resource ->numeric() ->default(0) , + Forms\Components\TextInput::make('priority') + ->label(__('label.priority')) + ->helperText(__('label.priority_help')) + ->numeric() + ->default(0) + , Forms\Components\Textarea::make('description') ->label(__('label.description')) , @@ -107,13 +114,12 @@ class MedalResource extends Resource Tables\Columns\TextColumn::make('duration')->label(__('label.medal.duration')), - Tables\Columns\TextColumn::make('inventory') + Tables\Columns\TextColumn::make('inventoryText') ->label(__('medal.fields.inventory')) - ->formatStateUsing(fn ($record) => $record->inventory ?? nexus_trans('label.infinite')) , Tables\Columns\TextColumn::make('users_count')->label(__('medal.fields.users_count')), + Tables\Columns\TextColumn::make('priority')->label(__('label.priority')), ]) - ->defaultSort('id', 'desc') ->filters([ // ]) @@ -122,7 +128,9 @@ class MedalResource extends Resource ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make(), - ]); + ]) + ->modifyQueryUsing(fn (Builder $query) => $query->orderBy("priority", 'desc')->orderBy('id', 'desc')) + ; } public static function getRelations(): array diff --git a/app/Models/Medal.php b/app/Models/Medal.php index c72faa33..d41078f0 100644 --- a/app/Models/Medal.php +++ b/app/Models/Medal.php @@ -18,7 +18,7 @@ class Medal extends NexusModel protected $fillable = [ 'name', 'description', 'image_large', 'image_small', 'price', 'duration', 'get_type', 'display_on_medal_page', 'sale_begin_time', 'sale_end_time', 'inventory', 'bonus_addition_factor', - 'gift_fee_factor', + 'gift_fee_factor', 'priority' ]; public $timestamps = true; @@ -48,6 +48,11 @@ class Medal extends NexusModel return nexus_trans("medal.get_types." . $this->get_type); } + public function getInventoryTextAttribute(): string + { + return $this->inventory ?? nexus_trans("label.infinite"); + } + public function getDurationTextAttribute($value): string { if ($this->duration > 0) { diff --git a/database/migrations/2025_04_21_113522_add_priority_field_to_medals_table.php b/database/migrations/2025_04_21_113522_add_priority_field_to_medals_table.php new file mode 100644 index 00000000..0a7abcf3 --- /dev/null +++ b/database/migrations/2025_04_21_113522_add_priority_field_to_medals_table.php @@ -0,0 +1,28 @@ +integer("priority")->default(0); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('medals', function (Blueprint $table) { + $table->dropColumn("priority"); + }); + } +}; diff --git a/public/medal.php b/public/medal.php index e8a7c426..aed18267 100644 --- a/public/medal.php +++ b/public/medal.php @@ -2,7 +2,8 @@ require "../include/bittorrent.php"; dbconn(); loggedinorreturn(); -$query = \App\Models\Medal::query()->where('display_on_medal_page', 1); +$query = \App\Models\Medal::query()->where('display_on_medal_page', 1) + ->orderBy('priority', 'desc')->orderBy("id", 'desc'); $q = htmlspecialchars($_REQUEST['q'] ?? ''); if (!empty($q)) { $query->where('username', 'name', "%{$q}%");