Files
WebAPP/app/Models/Player.php
Rhino ad60e7a9f9 Spielerpositionen, Statistiken, Fahrgemeinschaften, Spielfeld-Visualisierung
- PlayerPosition Enum (7 Handball-Positionen) mit Label/ShortLabel
- Spielerstatistik pro Spiel (Tore, Würfe, TW-Paraden, Bemerkung)
- Position-Dropdown in Spieler-Editor und Event-Stats-Formular
- Statistik-Seite: TW zuerst, Trennlinie, Feldspieler, Position-Badges
- Spielfeld-SVG mit Ampel-Performance (grün/gelb/rot)
- Anklickbare Spieler im Spielfeld öffnen Detail-Modal
- Fahrgemeinschaften (Anbieten, Zuordnen, Zurückziehen)
- Übersetzungen in allen 6 Sprachen (de, en, pl, ru, ar, tr)
- .gitignore für Laravel hinzugefügt
- Demo-Daten mit Positionen und Statistiken

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 11:47:34 +01:00

81 lines
1.9 KiB
PHP
Executable File

<?php
namespace App\Models;
use App\Enums\PlayerPosition;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class Player extends Model
{
use SoftDeletes;
protected $fillable = [
'team_id',
'first_name',
'last_name',
'birth_year',
'jersey_number',
'position',
'is_active',
'photo_permission',
'notes',
'profile_picture',
];
protected function casts(): array
{
return [
'is_active' => 'boolean',
'photo_permission' => 'boolean',
'position' => PlayerPosition::class,
];
}
public function getFullNameAttribute(): string
{
return "{$this->first_name} {$this->last_name}";
}
public function team(): BelongsTo
{
return $this->belongsTo(Team::class);
}
public function parents(): BelongsToMany
{
return $this->belongsToMany(User::class, 'parent_player', 'player_id', 'parent_id')
->withPivot('relationship_label', 'created_at');
}
public function participations(): HasMany
{
return $this->hasMany(EventParticipant::class);
}
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public function getAvatarUrl(): ?string
{
if ($this->profile_picture) {
return asset('storage/' . $this->profile_picture);
}
return null;
}
public function getInitials(): string
{
return mb_strtoupper(mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1));
}
public function isRestorable(): bool
{
return $this->trashed() && $this->deleted_at->diffInDays(now()) < 7;
}
}