Added Email Capability
This commit is contained in:
@@ -40,6 +40,22 @@ class Aircraft extends Model
|
||||
'787' => ['B788', 'B789', 'B78X'],
|
||||
];
|
||||
|
||||
public const array BOEING_737_VARIANTS = [
|
||||
'737-100' => ['B731'],
|
||||
'737-200' => ['B732'],
|
||||
'737-300' => ['B733'],
|
||||
'737-400' => ['B734'],
|
||||
'737-500' => ['B735'],
|
||||
'737-600' => ['B736'],
|
||||
'737-700' => ['B737', 'E737'],
|
||||
'737-800' => ['B738', 'P8'],
|
||||
'737-900' => ['B739'],
|
||||
'737 Max 7' => ['B37M'],
|
||||
'737 Max 8' => ['B38M'],
|
||||
'737 Max 9' => ['B39M'],
|
||||
'737 Max 10' => ['B3XM']
|
||||
];
|
||||
|
||||
public const array AIRBUS_FAMILIES = [
|
||||
'A300' => ['A30B', 'A300', 'A306'],
|
||||
'A310' => ['A310', 'A312', 'A313'],
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Alliance extends Model
|
||||
{
|
||||
|
||||
protected $table = 'alliances';
|
||||
|
||||
protected $fillable = [
|
||||
@@ -18,8 +19,25 @@ class Alliance extends Model
|
||||
'internal_name' => 'string',
|
||||
];
|
||||
|
||||
const ALLIANCE_CHALLENGES = [
|
||||
'star_alliance' => 'airlines_alliances.all_star_alliance',
|
||||
'oneworld' => 'airlines_alliances.all_oneworld',
|
||||
'vanilla_alliance' => 'airlines_alliances.all_vanilla_alliance',
|
||||
'skyteam' => 'airlines_alliances.all_skyteam',
|
||||
];
|
||||
|
||||
public function airlines(): HasMany
|
||||
{
|
||||
return $this->hasMany(Airline::class);
|
||||
}
|
||||
|
||||
public static function recalculateChallengeThresholds() : void {
|
||||
$alliances = Alliance::all();
|
||||
foreach ($alliances as $alliance) {
|
||||
$airlineCount = $alliance->airlines()->count();
|
||||
$challenge = self::ALLIANCE_CHALLENGES[$alliance->internal_name];
|
||||
Achievement::where('internal_name', $challenge)->update(['threshold' => $airlineCount]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+26
-2
@@ -13,11 +13,14 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use App\Traits\HasAchievements;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use NotificationChannels\WebPush\HasPushSubscriptions;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use App\Notifications\ResetPasswordNotification;
|
||||
|
||||
|
||||
#[Fillable(['name', 'email', 'password', 'distance_unit', 'settings'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
@@ -35,6 +38,22 @@ class User extends Authenticatable
|
||||
|
||||
protected $appends = ['resolved_settings'];
|
||||
|
||||
public function calculateAchievementsAndClearCache(): void
|
||||
{
|
||||
$this->clearCache();
|
||||
$this->calculateAchievements();
|
||||
}
|
||||
|
||||
public function clearCache(): void
|
||||
{
|
||||
Cache::forget("user_flights_{$this->id}");
|
||||
|
||||
$this
|
||||
->followers()
|
||||
->get()
|
||||
->each(fn ($follower) => Cache::forget("user_following_flights_{$follower->id}"));
|
||||
}
|
||||
|
||||
public function achievements(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserAchievement::class);
|
||||
@@ -83,6 +102,11 @@ class User extends Authenticatable
|
||||
});
|
||||
}
|
||||
|
||||
public function sendPasswordResetNotification($token): void
|
||||
{
|
||||
$this->notify(new ResetPasswordNotification($token));
|
||||
}
|
||||
|
||||
public function resolveRouteBinding($value, $field = null): ?User
|
||||
{
|
||||
return $this->where('name', 'ilike', $value)->firstOrFail();
|
||||
@@ -129,8 +153,8 @@ class User extends Authenticatable
|
||||
$today = now('UTC')->toDateString();
|
||||
|
||||
return match ($filter) {
|
||||
'departed' => $collection->filter(fn($f) => $f->departure_date <= $today)->values(),
|
||||
'upcoming' => $collection->filter(fn($f) => $f->departure_date > $today)->values(),
|
||||
'departed' => $collection->filter(fn($f) => Carbon::parse($f->departure_date)->toDateString() <= $today)->values(),
|
||||
'upcoming' => $collection->filter(fn($f) => Carbon::parse($f->departure_date)->toDateString() > $today)->values(),
|
||||
default => $collection,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user