Merge remote-tracking branch 'origin/main' into fix-achievement-category-ordering
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\IgnoredMissingLivery;
|
||||
use App\Models\User;
|
||||
use App\Models\UserFlight;
|
||||
use App\Services\AdminService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Inertia\Inertia;
|
||||
@@ -66,4 +67,17 @@ class AdminController extends Controller
|
||||
return back();
|
||||
}
|
||||
|
||||
public function ignoreMissingAirline(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'flight_id' => ['required', 'integer', 'exists:user_flights,id'],
|
||||
]);
|
||||
|
||||
$flight = UserFlight::findOrFail($validated['flight_id']);
|
||||
|
||||
$flight->ignoreMissingAirline()->firstOrCreate([]);
|
||||
|
||||
return response()->json(['status' => 'ok']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -245,15 +245,19 @@ class FlightController extends Controller
|
||||
$newFlight = auth()->user()->flights()->create($this->flightPayload($validated));
|
||||
|
||||
UserAction::create([
|
||||
'user_id' => $newFlight->user_id,
|
||||
'type' => $newFlight->departure_date->isFuture() ? 'flight_booked' : 'flight_logged',
|
||||
'data' => [
|
||||
'user_id' => $newFlight->user_id,
|
||||
'type' => $newFlight->departure_date->isFuture() ? 'flight_booked' : 'flight_logged',
|
||||
'data' => [
|
||||
'flight' => $newFlight->snapshot($newFlight->id),
|
||||
],
|
||||
]);
|
||||
|
||||
if ($request->boolean('add_more')) {
|
||||
return redirect()->route('flights.add')
|
||||
->with('success', 'Flight saved. Add another below.');
|
||||
}
|
||||
|
||||
return redirect()->route('profile.departure-board', [Auth::user()->name, $newFlight->id]);
|
||||
return redirect()->route('profile.flight', [Auth::user()->name, $newFlight->id]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
@@ -271,6 +272,16 @@ class UserFlight extends Model
|
||||
}
|
||||
|
||||
|
||||
public function ignoreMissingAirline(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserFlightIgnoreMissingAirline::class);
|
||||
}
|
||||
|
||||
public function isIgnoringMissingAirline(): bool
|
||||
{
|
||||
return $this->ignoreMissingAirline()->exists();
|
||||
}
|
||||
|
||||
public function aircraft(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Aircraft::class);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserFlightIgnoreMissingAirline extends Model
|
||||
{
|
||||
protected $table = 'user_flights_ignore_missing_airlines';
|
||||
|
||||
protected $fillable = [
|
||||
'user_flight_id',
|
||||
];
|
||||
|
||||
public function userFlight(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserFlight::class);
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,8 @@ class AchievementService
|
||||
->where('achievement_id', $achievement->id)
|
||||
->first();
|
||||
|
||||
$alreadyUnlocked = $existing !== null;
|
||||
$alreadyUnlocked = $existing !== null
|
||||
&& (! $achievement->progressive || $existing->progress >= $achievement->threshold);
|
||||
|
||||
UserAchievement::updateOrCreate(
|
||||
['user_id' => $user->id, 'achievement_id' => $achievement->id],
|
||||
|
||||
@@ -51,26 +51,28 @@ class AdminService
|
||||
{
|
||||
$flights = UserFlight::whereNotNull('flight_number')
|
||||
->whereNull('airline_id')
|
||||
->with('user:id,name') // adjust to your actual user relation/columns
|
||||
->whereDoesntHave('ignoreMissingAirline')
|
||||
->with('user:id,name')
|
||||
->get(['id', 'flight_number', 'user_id']);
|
||||
|
||||
return $flights
|
||||
->map(function ($flight) {
|
||||
// Extract the 2-character IATA-style prefix (letters and/or digits)
|
||||
preg_match('/^([A-Za-z0-9]{2})\d+/', trim($flight->flight_number), $matches);
|
||||
|
||||
return [
|
||||
'id' => $flight->id,
|
||||
'code' => $matches[1] ?? null,
|
||||
'flight_number' => $flight->flight_number,
|
||||
'link' => "/u/{$flight->user->name}/flight/{$flight->id}",
|
||||
];
|
||||
})
|
||||
->filter(fn ($f) => $f['code'] !== null) // drop any that didn't match the pattern
|
||||
->filter(fn ($f) => $f['code'] !== null)
|
||||
->groupBy('code')
|
||||
->map(function ($group, $code) {
|
||||
return [
|
||||
'code' => $code,
|
||||
'flights' => $group->map(fn ($f) => [
|
||||
'id' => $f['id'],
|
||||
'flight_number' => $f['flight_number'],
|
||||
'link' => $f['link'],
|
||||
])->values()->all(),
|
||||
|
||||
@@ -72,7 +72,7 @@ class SettingsRegistry
|
||||
'type' => 'select',
|
||||
'label' => 'Default Page',
|
||||
'category' => 'FlightsGoneBy Settings',
|
||||
'default' => 'feed_first',
|
||||
'default' => 'profile',
|
||||
'options' => [
|
||||
['value' => 'feed_first', 'label' => 'My Feed if Following People, My Profile if Not'],
|
||||
['value' => 'profile', 'label' => 'My Profile'],
|
||||
@@ -155,7 +155,7 @@ class SettingsRegistry
|
||||
['value' => 'seat_type_id', 'label' => 'Seat Type'],
|
||||
['value' => 'seat_number', 'label' => 'Seat Number'],
|
||||
['value' => 'flight_reason_id', 'label' => 'Reason'],
|
||||
|
||||
['value' => 'note', 'label' => 'Note'],
|
||||
['value' => 'aircraft.display_name_short', 'label' => 'Aircraft Full Name'],
|
||||
['value' => 'class_seat_combined', 'label' => 'Class/Seat Type/Seat Number Combined'],
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user