- 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>
854 lines
40 KiB
PHP
Executable File
854 lines
40 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Enums\CateringStatus;
|
|
use App\Enums\EventStatus;
|
|
use App\Enums\EventType;
|
|
use App\Enums\ParticipantStatus;
|
|
use App\Enums\PlayerPosition;
|
|
use App\Enums\UserRole;
|
|
use App\Models\ActivityLog;
|
|
use App\Models\Comment;
|
|
use App\Models\Event;
|
|
use App\Models\EventCarpool;
|
|
use App\Models\EventCarpoolPassenger;
|
|
use App\Models\EventCatering;
|
|
use App\Models\EventParticipant;
|
|
use App\Models\EventPlayerStat;
|
|
use App\Models\EventTimekeeper;
|
|
use App\Models\Faq;
|
|
use App\Models\Location;
|
|
use App\Models\Player;
|
|
use App\Models\Team;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class DemoDataSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$admin = $this->seedAdmin();
|
|
$coach = $this->seedCoach();
|
|
$parentRep = $this->seedParentRep();
|
|
$team = $this->seedTeam($coach);
|
|
|
|
$data = $this->playerData();
|
|
$parentUsers = $this->seedParentUsers($data);
|
|
$players = $this->seedPlayers($data, $team);
|
|
$this->seedParentPlayerRelations($data, $players, $parentUsers);
|
|
$this->assignParentRepChild($parentRep, $players);
|
|
|
|
$locations = $this->seedLocations();
|
|
$events = $this->seedEvents($team, $admin, $locations);
|
|
$this->seedParticipants($events, $players, $admin, $parentUsers);
|
|
$this->seedCatering($events, $parentUsers);
|
|
$this->seedTimekeepers($events, $parentUsers);
|
|
$this->seedComments($events, $admin, $coach, $parentUsers);
|
|
$this->seedPlayerStats($events, $players);
|
|
$this->seedCarpools($events, $parentUsers, $players);
|
|
$this->seedFaqs($admin);
|
|
$this->seedActivityLogs($admin, $coach, $team, $events);
|
|
$this->seedSoftDeletedRecords($team);
|
|
}
|
|
|
|
// ─── Admin ─────────────────────────────────────────────
|
|
|
|
private function seedAdmin(): User
|
|
{
|
|
// Wenn bereits ein Admin existiert (z.B. durch Installer erstellt), diesen nutzen
|
|
$existing = User::where('role', UserRole::Admin)->first();
|
|
if ($existing) {
|
|
return $existing;
|
|
}
|
|
|
|
return User::updateOrCreate(
|
|
['email' => env('ADMIN_EMAIL', 'admin@handball.local')],
|
|
[
|
|
'name' => 'Charles Xavier',
|
|
'password' => env('ADMIN_PASSWORD', 'admin1234'),
|
|
'role' => UserRole::Admin,
|
|
'is_active' => true,
|
|
]
|
|
);
|
|
}
|
|
|
|
// ─── Trainer ───────────────────────────────────────────
|
|
|
|
private function seedCoach(): User
|
|
{
|
|
return User::firstOrCreate(
|
|
['email' => 'trainer@handball.local'],
|
|
[
|
|
'name' => 'Nick Fury',
|
|
'password' => Hash::make('trainer1234'),
|
|
'role' => UserRole::Coach,
|
|
'is_active' => true,
|
|
'phone' => '0171-1234567',
|
|
]
|
|
);
|
|
}
|
|
|
|
// ─── Elternvertretung ──────────────────────────────────
|
|
|
|
private function seedParentRep(): User
|
|
{
|
|
return User::firstOrCreate(
|
|
['email' => 'elternvertretung@handball.local'],
|
|
[
|
|
'name' => 'Peggy Carter',
|
|
'password' => Hash::make('eltern1234'),
|
|
'role' => UserRole::ParentRep,
|
|
'is_active' => true,
|
|
'phone' => '0172-9876543',
|
|
]
|
|
);
|
|
}
|
|
|
|
// ─── Team ──────────────────────────────────────────────
|
|
|
|
private function seedTeam(User $coach): Team
|
|
{
|
|
$team = Team::firstOrCreate(
|
|
['name' => 'Mannschaft I'],
|
|
['year_group' => '2017/2018', 'is_active' => true]
|
|
);
|
|
|
|
// Coach via team_user pivot zuweisen
|
|
DB::table('team_user')->updateOrInsert(
|
|
['team_id' => $team->id, 'user_id' => $coach->id],
|
|
['created_at' => now()]
|
|
);
|
|
|
|
return $team;
|
|
}
|
|
|
|
// ─── Datenstruktur ─────────────────────────────────────
|
|
|
|
private function playerData(): array
|
|
{
|
|
// [Kind-Vorname, Nachname, [[Eltern-Vorname, Geschlecht], ...]]
|
|
// Mix aus Disney-, Marvel- und DC-Universum
|
|
return [
|
|
// ── Marvel ──────────────────────────────
|
|
['Peter', 'Parker', [['Mary', 'w']]],
|
|
['Morgan', 'Stark', [['Tony', 'm'], ['Pepper', 'w']]],
|
|
['Cooper', 'Barton', [['Clint', 'm'], ['Laura', 'w']]],
|
|
['Kamala', 'Khan', [['Muneeba', 'w']]],
|
|
['Cassie', 'Lang', [['Scott', 'm']]],
|
|
['Natasha', 'Romanoff', [['Alexei', 'm']]],
|
|
['Wanda', 'Maximoff', [['Natalya', 'w']]],
|
|
['Loki', 'Odinson', [['Frigga', 'w']]],
|
|
['Groot', 'Guardian', [['Rocket', 'm']]],
|
|
// ── DC ──────────────────────────────────
|
|
['Damian', 'Wayne', [['Bruce', 'm'], ['Talia', 'w']]],
|
|
['Jon', 'Kent', [['Clark', 'm'], ['Lois', 'w']]],
|
|
['Barbara', 'Gordon', [['James', 'm']]],
|
|
['Wally', 'West', [['Iris', 'w']]],
|
|
['Arthur', 'Curry', [['Atlanna', 'w']]],
|
|
['Diana', 'Prince', [['Hippolyta', 'w']]],
|
|
['Oliver', 'Queen', [['Moira', 'w']]],
|
|
['Kara', 'Danvers', [['Eliza', 'w']]],
|
|
['Garfield', 'Logan', [['Marie', 'w']]],
|
|
// ── Disney ──────────────────────────────
|
|
['Simba', 'Pride', [['Sarabi', 'w']]],
|
|
['Elsa', 'Arendelle', [['Iduna', 'w']]],
|
|
['Rapunzel', 'Corona', [['Arianna', 'w']]],
|
|
['Moana', 'Motunui', [['Sina', 'w']]],
|
|
['Nemo', 'Reef', [['Marlin', 'm']]],
|
|
['Dash', 'Parr', [['Helen', 'w']]],
|
|
['Raya', 'Kumandra', [['Benja', 'm']]],
|
|
['Mirabel', 'Madrigal', [['Julieta', 'w']]],
|
|
['Riley', 'Andersen', [['Jill', 'w']]],
|
|
];
|
|
}
|
|
|
|
// ─── Eltern-Benutzer ───────────────────────────────────
|
|
|
|
private function seedParentUsers(array $data): array
|
|
{
|
|
$hashedPassword = Hash::make('eltern1234');
|
|
$parentUsers = [];
|
|
$phones = [
|
|
'Mary Parker' => '0151-1111111',
|
|
'Tony Stark' => '0152-2222222',
|
|
'Sarabi Pride' => '0153-3333333',
|
|
'Scott Lang' => '0154-4444444',
|
|
];
|
|
|
|
foreach ($data as [$childFirst, $lastName, $parents]) {
|
|
foreach ($parents as [$parentFirst, $gender]) {
|
|
$fullName = "{$parentFirst} {$lastName}";
|
|
if (isset($parentUsers[$fullName])) {
|
|
continue;
|
|
}
|
|
$email = $this->makeEmail($parentFirst, $lastName);
|
|
$user = User::firstOrCreate(
|
|
['email' => $email],
|
|
[
|
|
'name' => $fullName,
|
|
'password' => $hashedPassword,
|
|
'role' => UserRole::User,
|
|
'is_active' => true,
|
|
'phone' => $phones[$fullName] ?? null,
|
|
]
|
|
);
|
|
$parentUsers[$fullName] = $user;
|
|
}
|
|
}
|
|
|
|
return $parentUsers;
|
|
}
|
|
|
|
// ─── Spieler ───────────────────────────────────────────
|
|
|
|
private function seedPlayers(array $data, Team $team): array
|
|
{
|
|
// Positionsverteilung: Index → Position
|
|
$positions = [
|
|
0 => PlayerPosition::Torwart,
|
|
1 => PlayerPosition::LinksAussen,
|
|
2 => PlayerPosition::RueckraumMitte,
|
|
3 => PlayerPosition::RueckraumLinks,
|
|
4 => PlayerPosition::RechtsAussen,
|
|
5 => PlayerPosition::RueckraumRechts,
|
|
6 => PlayerPosition::Kreislaeufer,
|
|
7 => PlayerPosition::LinksAussen,
|
|
8 => PlayerPosition::RechtsAussen,
|
|
9 => PlayerPosition::RueckraumLinks,
|
|
10 => PlayerPosition::RueckraumMitte,
|
|
11 => PlayerPosition::RueckraumRechts,
|
|
12 => PlayerPosition::Kreislaeufer,
|
|
13 => PlayerPosition::Torwart, // Ersatz-TW
|
|
];
|
|
|
|
$players = [];
|
|
$jerseyNr = 1;
|
|
foreach ($data as $idx => [$childFirst, $lastName, $parents]) {
|
|
$player = Player::firstOrCreate(
|
|
['first_name' => $childFirst, 'last_name' => $lastName, 'team_id' => $team->id],
|
|
[
|
|
'birth_year' => $jerseyNr % 2 === 0 ? 2017 : 2018,
|
|
'jersey_number' => $jerseyNr,
|
|
'is_active' => true,
|
|
'photo_permission' => true,
|
|
'position' => $positions[$idx] ?? null,
|
|
]
|
|
);
|
|
// Position auch bei bestehenden Spielern setzen
|
|
if ($player->position === null && isset($positions[$idx])) {
|
|
$player->update(['position' => $positions[$idx]]);
|
|
}
|
|
$players["{$childFirst} {$lastName}"] = $player;
|
|
$jerseyNr++;
|
|
}
|
|
|
|
return $players;
|
|
}
|
|
|
|
// ─── Eltern-Kind-Zuordnungen ───────────────────────────
|
|
// ACHTUNG: parent_player hat KEIN updated_at → DB::table()->updateOrInsert()
|
|
|
|
private function seedParentPlayerRelations(array $data, array $players, array $parentUsers): void
|
|
{
|
|
foreach ($data as [$childFirst, $lastName, $parents]) {
|
|
$player = $players["{$childFirst} {$lastName}"];
|
|
foreach ($parents as [$parentFirst, $gender]) {
|
|
$user = $parentUsers["{$parentFirst} {$lastName}"];
|
|
DB::table('parent_player')->updateOrInsert(
|
|
['parent_id' => $user->id, 'player_id' => $player->id],
|
|
['relationship_label' => $gender === 'm' ? 'Vater' : 'Mutter', 'created_at' => now()]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
// ─── Elternvertretung Kind zuweisen ────────────────────
|
|
|
|
private function assignParentRepChild(User $parentRep, array $players): void
|
|
{
|
|
$firstPlayer = reset($players);
|
|
DB::table('parent_player')->updateOrInsert(
|
|
['parent_id' => $parentRep->id, 'player_id' => $firstPlayer->id],
|
|
['relationship_label' => 'Elternvertretung', 'created_at' => now()]
|
|
);
|
|
}
|
|
|
|
// ─── Orte ──────────────────────────────────────────────
|
|
|
|
private function seedLocations(): array
|
|
{
|
|
return [
|
|
Location::firstOrCreate(
|
|
['name' => 'Sporthalle Musterstadt'],
|
|
['address_text' => 'Schulstraße 12, 12345 Musterstadt', 'location_lat' => 50.1109, 'location_lng' => 8.6821]
|
|
),
|
|
Location::firstOrCreate(
|
|
['name' => 'Sporthalle Nachbarort'],
|
|
['address_text' => 'Am Sportpark 5, 12346 Nachbarort', 'location_lat' => 50.1205, 'location_lng' => 8.7100]
|
|
),
|
|
Location::firstOrCreate(
|
|
['name' => 'Turnierzentrum Landeshauptstadt'],
|
|
['address_text' => 'Sportplatzweg 1, 60000 Landeshauptstadt', 'location_lat' => 50.1155, 'location_lng' => 8.6842]
|
|
),
|
|
];
|
|
}
|
|
|
|
// ─── Events ────────────────────────────────────────────
|
|
|
|
private function seedEvents(Team $team, User $admin, array $locations): array
|
|
{
|
|
$events = [];
|
|
|
|
// 0: Training (vergangen)
|
|
$events[] = Event::updateOrCreate(
|
|
['title' => 'Training Dienstag', 'team_id' => $team->id, 'start_at' => now()->subDays(3)->setTime(17, 0)],
|
|
[
|
|
'type' => EventType::Training,
|
|
'end_at' => now()->subDays(3)->setTime(18, 30),
|
|
'status' => EventStatus::Published,
|
|
'location_name' => $locations[0]->name,
|
|
'address_text' => $locations[0]->address_text,
|
|
'location_lat' => $locations[0]->location_lat,
|
|
'location_lng' => $locations[0]->location_lng,
|
|
'description_html' => '<p>Reguläres Training. Bitte <strong>Hallenschuhe</strong> und ausreichend Trinken mitbringen.</p>',
|
|
'created_by' => $admin->id,
|
|
]
|
|
);
|
|
|
|
// 1: Training (Zukunft)
|
|
$events[] = Event::updateOrCreate(
|
|
['title' => 'Training nächste Woche', 'team_id' => $team->id, 'start_at' => now()->next('Tuesday')->setTime(17, 0)],
|
|
[
|
|
'type' => EventType::Training,
|
|
'end_at' => now()->next('Tuesday')->setTime(18, 30),
|
|
'status' => EventStatus::Published,
|
|
'location_name' => $locations[0]->name,
|
|
'address_text' => $locations[0]->address_text,
|
|
'location_lat' => $locations[0]->location_lat,
|
|
'location_lng' => $locations[0]->location_lng,
|
|
'min_players' => 12,
|
|
'min_catering' => 1,
|
|
'min_timekeepers' => 1,
|
|
'description_html' => '<p>Training mit Schwerpunkt Passspiel. Bitte pünktlich kommen!</p>',
|
|
'created_by' => $admin->id,
|
|
]
|
|
);
|
|
|
|
// 2: Heimspiel (vergangen, mit Ergebnis)
|
|
$events[] = Event::updateOrCreate(
|
|
['title' => 'Heimspiel vs. TSV Beispielburg', 'team_id' => $team->id, 'start_at' => now()->subWeek()->previous('Saturday')->setTime(10, 0)],
|
|
[
|
|
'type' => EventType::HomeGame,
|
|
'end_at' => now()->subWeek()->previous('Saturday')->setTime(12, 0),
|
|
'status' => EventStatus::Published,
|
|
'location_name' => $locations[0]->name,
|
|
'address_text' => $locations[0]->address_text,
|
|
'location_lat' => $locations[0]->location_lat,
|
|
'location_lng' => $locations[0]->location_lng,
|
|
'opponent' => 'TSV Beispielburg',
|
|
'score_home' => 15,
|
|
'score_away' => 12,
|
|
'min_players' => 10,
|
|
'min_catering' => 2,
|
|
'min_timekeepers' => 2,
|
|
'description_html' => '<p>Unser erstes Heimspiel der Rückrunde! Bitte <strong>30 Minuten vor Anpfiff</strong> da sein.</p><ul><li>Trikots werden gestellt</li><li>Eltern bitte Kuchen mitbringen</li></ul>',
|
|
'created_by' => $admin->id,
|
|
]
|
|
);
|
|
|
|
// 3: Auswärtsspiel (Zukunft)
|
|
$events[] = Event::updateOrCreate(
|
|
['title' => 'Auswärtsspiel beim SC Nachbarort', 'team_id' => $team->id, 'start_at' => now()->addWeeks(2)->next('Saturday')->setTime(11, 0)],
|
|
[
|
|
'type' => EventType::AwayGame,
|
|
'end_at' => now()->addWeeks(2)->next('Saturday')->setTime(13, 0),
|
|
'status' => EventStatus::Published,
|
|
'location_name' => $locations[1]->name,
|
|
'address_text' => $locations[1]->address_text,
|
|
'location_lat' => $locations[1]->location_lat,
|
|
'location_lng' => $locations[1]->location_lng,
|
|
'opponent' => 'SC Nachbarort',
|
|
'min_players' => 10,
|
|
'description_html' => '<p>Auswärtsspiel — Fahrgemeinschaften bitte abstimmen. Treffpunkt 10:00 am Vereinsheim.</p>',
|
|
'created_by' => $admin->id,
|
|
]
|
|
);
|
|
|
|
// 4: Turnier (Zukunft)
|
|
$events[] = Event::updateOrCreate(
|
|
['title' => 'Nikolaus-Turnier Sportverein', 'team_id' => $team->id, 'start_at' => now()->addWeeks(3)->next('Sunday')->setTime(9, 0)],
|
|
[
|
|
'type' => EventType::Tournament,
|
|
'end_at' => now()->addWeeks(3)->next('Sunday')->setTime(16, 0),
|
|
'status' => EventStatus::Published,
|
|
'location_name' => $locations[2]->name,
|
|
'address_text' => $locations[2]->address_text,
|
|
'location_lat' => $locations[2]->location_lat,
|
|
'location_lng' => $locations[2]->location_lng,
|
|
'min_players' => 12,
|
|
'min_catering' => 3,
|
|
'min_timekeepers' => 2,
|
|
'description_html' => '<p>Ganztages-Turnier mit 8 Mannschaften. Bitte <strong>Lunchpaket</strong> einpacken.</p><h3>Zeitplan</h3><ul><li>09:00 Eintreffen</li><li>09:30 Erstes Spiel</li><li>ca. 16:00 Siegerehrung</li></ul>',
|
|
'created_by' => $admin->id,
|
|
]
|
|
);
|
|
|
|
// 5: Besprechung (Zukunft)
|
|
$events[] = Event::updateOrCreate(
|
|
['title' => 'Elternabend Rückrunden-Planung', 'team_id' => $team->id, 'start_at' => now()->addWeeks(4)->next('Wednesday')->setTime(19, 30)],
|
|
[
|
|
'type' => EventType::Meeting,
|
|
'end_at' => now()->addWeeks(4)->next('Wednesday')->setTime(21, 0),
|
|
'status' => EventStatus::Published,
|
|
'location_name' => 'Vereinsheim TV Musterstadt',
|
|
'address_text' => 'Vereinsweg 1, 12345 Musterstadt',
|
|
'min_players' => 10,
|
|
'description_html' => '<p>Themen:</p><ul><li>Rückrunden-Spielplan</li><li>Trikot-Bestellung</li><li>Fahrgemeinschaften</li><li>Eltern-Catering-Plan</li></ul>',
|
|
'created_by' => $admin->id,
|
|
]
|
|
);
|
|
|
|
// 6: Abgesagtes Training
|
|
$events[] = Event::updateOrCreate(
|
|
['title' => 'Training Donnerstag (entfällt!)', 'team_id' => $team->id, 'start_at' => now()->next('Thursday')->setTime(17, 0)],
|
|
[
|
|
'type' => EventType::Training,
|
|
'end_at' => now()->next('Thursday')->setTime(18, 30),
|
|
'status' => EventStatus::Cancelled,
|
|
'location_name' => $locations[0]->name,
|
|
'address_text' => $locations[0]->address_text,
|
|
'description_html' => '<p>Fällt wegen Hallensperrung aus. Nächstes Training wie gewohnt am Dienstag.</p>',
|
|
'created_by' => $admin->id,
|
|
]
|
|
);
|
|
|
|
// 7: Entwurf
|
|
$events[] = Event::updateOrCreate(
|
|
['title' => 'Freundschaftsspiel (in Planung)', 'team_id' => $team->id, 'start_at' => now()->addWeeks(5)->next('Saturday')->setTime(10, 0)],
|
|
[
|
|
'type' => EventType::HomeGame,
|
|
'end_at' => now()->addWeeks(5)->next('Saturday')->setTime(12, 0),
|
|
'status' => EventStatus::Draft,
|
|
'location_name' => $locations[0]->name,
|
|
'address_text' => $locations[0]->address_text,
|
|
'location_lat' => $locations[0]->location_lat,
|
|
'location_lng' => $locations[0]->location_lng,
|
|
'opponent' => 'TBD',
|
|
'description_html' => '<p>Freundschaftsspiel — Gegner und Uhrzeit werden noch festgelegt.</p>',
|
|
'created_by' => $admin->id,
|
|
]
|
|
);
|
|
|
|
return $events;
|
|
}
|
|
|
|
// ─── Teilnehmer ────────────────────────────────────────
|
|
// ACHTUNG: set_by_user_id ist NOT NULL → immer explizit setzen
|
|
|
|
private function seedParticipants(array $events, array $players, User $admin, array $parentUsers): void
|
|
{
|
|
$parentList = array_values($parentUsers);
|
|
$playerList = array_values($players);
|
|
|
|
// Statusverteilungen pro Event-Index: [Ja, Nein, Rest=Offen]
|
|
$distributions = [
|
|
0 => [22, 3], // Training vergangen
|
|
1 => [15, 5], // Training Zukunft
|
|
2 => [18, 4], // Heimspiel
|
|
3 => [12, 3], // Auswärtsspiel
|
|
4 => [20, 2], // Turnier
|
|
6 => [5, 2], // Abgesagt
|
|
];
|
|
|
|
$sampleNotes = [
|
|
'Komme direkt aus der Schule',
|
|
'Wird eventuell 10 Min. später',
|
|
'Bringt eigene Trinkflasche mit',
|
|
];
|
|
|
|
foreach ($distributions as $eventIdx => $dist) {
|
|
$event = $events[$eventIdx];
|
|
[$yesCount, $noCount] = $dist;
|
|
|
|
foreach (array_values($playerList) as $i => $player) {
|
|
if ($i < $yesCount) {
|
|
$status = ParticipantStatus::Yes;
|
|
} elseif ($i < $yesCount + $noCount) {
|
|
$status = ParticipantStatus::No;
|
|
} else {
|
|
$status = ParticipantStatus::Unknown;
|
|
}
|
|
|
|
$setByUserId = isset($parentList[$i]) ? $parentList[$i]->id : $admin->id;
|
|
$respondedAt = $status !== ParticipantStatus::Unknown ? now()->subHours(rand(1, 72)) : null;
|
|
$note = ($status === ParticipantStatus::Yes && $i < count($sampleNotes)) ? $sampleNotes[$i] : null;
|
|
|
|
$participant = EventParticipant::firstOrNew(
|
|
['event_id' => $event->id, 'player_id' => $player->id]
|
|
);
|
|
$participant->status = $status;
|
|
$participant->set_by_user_id = $setByUserId;
|
|
$participant->responded_at = $respondedAt;
|
|
$participant->note = $note;
|
|
$participant->save();
|
|
}
|
|
}
|
|
|
|
// Besprechung (Index 5): User-basierte Teilnehmer
|
|
$meeting = $events[5];
|
|
$meeting->syncMeetingParticipants($admin->id);
|
|
|
|
$meetingParticipants = EventParticipant::where('event_id', $meeting->id)->get();
|
|
foreach ($meetingParticipants->take(10) as $idx => $p) {
|
|
$p->status = $idx < 7 ? ParticipantStatus::Yes : ParticipantStatus::No;
|
|
$p->set_by_user_id = $p->user_id ?? $admin->id;
|
|
$p->responded_at = now()->subHours(rand(1, 24));
|
|
$p->save();
|
|
}
|
|
}
|
|
|
|
// ─── Catering ──────────────────────────────────────────
|
|
// Kein Catering bei AwayGame und Meeting
|
|
|
|
private function seedCatering(array $events, array $parentUsers): void
|
|
{
|
|
$p = array_values($parentUsers);
|
|
|
|
$entries = [
|
|
[$events[2]->id, $p[0]->id, CateringStatus::Yes, 'Bringe Marmorkuchen mit'],
|
|
[$events[2]->id, $p[1]->id, CateringStatus::Yes, 'Bringe Obst und Wasser mit'],
|
|
[$events[2]->id, $p[2]->id, CateringStatus::No, 'Kann leider nicht'],
|
|
[$events[1]->id, $p[3]->id, CateringStatus::Yes, 'Belegte Brötchen'],
|
|
[$events[1]->id, $p[4]->id, CateringStatus::Unknown, null],
|
|
[$events[4]->id, $p[5]->id, CateringStatus::Yes, 'Kuchen und Muffins'],
|
|
[$events[4]->id, $p[6]->id, CateringStatus::Yes, 'Getränke'],
|
|
[$events[4]->id, $p[7]->id, CateringStatus::No, null],
|
|
];
|
|
|
|
foreach ($entries as [$eventId, $userId, $status, $note]) {
|
|
$c = EventCatering::where('event_id', $eventId)->where('user_id', $userId)->first();
|
|
if (!$c) {
|
|
$c = new EventCatering(['event_id' => $eventId]);
|
|
$c->user_id = $userId;
|
|
}
|
|
$c->status = $status;
|
|
$c->note = $note;
|
|
$c->save();
|
|
}
|
|
}
|
|
|
|
// ─── Zeitnehmer ────────────────────────────────────────
|
|
// EventTimekeeper nutzt CateringStatus-Enum
|
|
|
|
private function seedTimekeepers(array $events, array $parentUsers): void
|
|
{
|
|
$p = array_values($parentUsers);
|
|
|
|
$entries = [
|
|
[$events[2]->id, $p[10]->id, CateringStatus::Yes],
|
|
[$events[2]->id, $p[11]->id, CateringStatus::Yes],
|
|
[$events[1]->id, $p[12]->id, CateringStatus::Yes],
|
|
[$events[1]->id, $p[13]->id, CateringStatus::No],
|
|
[$events[4]->id, $p[14]->id, CateringStatus::Yes],
|
|
[$events[4]->id, $p[15]->id, CateringStatus::Unknown],
|
|
];
|
|
|
|
foreach ($entries as [$eventId, $userId, $status]) {
|
|
$t = EventTimekeeper::where('event_id', $eventId)->where('user_id', $userId)->first();
|
|
if (!$t) {
|
|
$t = new EventTimekeeper(['event_id' => $eventId]);
|
|
$t->user_id = $userId;
|
|
}
|
|
$t->status = $status;
|
|
$t->save();
|
|
}
|
|
}
|
|
|
|
// ─── Kommentare ────────────────────────────────────────
|
|
|
|
private function seedComments(array $events, User $admin, User $coach, array $parentUsers): void
|
|
{
|
|
$p = array_values($parentUsers);
|
|
|
|
// Heimspiel (Index 2): 4 Kommentare
|
|
Comment::updateOrCreate(
|
|
['event_id' => $events[2]->id, 'user_id' => $p[0]->id, 'body' => 'Können wir Fahrgemeinschaften bilden?'],
|
|
['created_at' => now()->subDays(5)->subHours(5)]
|
|
);
|
|
Comment::updateOrCreate(
|
|
['event_id' => $events[2]->id, 'user_id' => $admin->id, 'body' => 'Gute Idee! Bitte untereinander absprechen.'],
|
|
['created_at' => now()->subDays(5)->subHours(3)]
|
|
);
|
|
Comment::updateOrCreate(
|
|
['event_id' => $events[2]->id, 'user_id' => $p[3]->id, 'body' => 'Wir können 3 Kinder mitnehmen.'],
|
|
['created_at' => now()->subDays(5)->subHours(2)]
|
|
);
|
|
Comment::updateOrCreate(
|
|
['event_id' => $events[2]->id, 'user_id' => $coach->id, 'body' => 'Denkt bitte an die Trikots!'],
|
|
['created_at' => now()->subDays(5)->subHour()]
|
|
);
|
|
|
|
// Training Zukunft (Index 1): 2 Kommentare
|
|
Comment::updateOrCreate(
|
|
['event_id' => $events[1]->id, 'user_id' => $p[5]->id, 'body' => 'Kann jemand mein Kind abholen? Bin auf Dienstreise.'],
|
|
['created_at' => now()->subHours(12)]
|
|
);
|
|
Comment::updateOrCreate(
|
|
['event_id' => $events[1]->id, 'user_id' => $p[8]->id, 'body' => 'Klar, kein Problem! Bringe sie mit.'],
|
|
['created_at' => now()->subHours(10)]
|
|
);
|
|
|
|
// Turnier (Index 4): 2 Kommentare
|
|
Comment::updateOrCreate(
|
|
['event_id' => $events[4]->id, 'user_id' => $admin->id, 'body' => 'Zeitplan folgt nächste Woche.'],
|
|
['created_at' => now()->subDays(1)]
|
|
);
|
|
Comment::updateOrCreate(
|
|
['event_id' => $events[4]->id, 'user_id' => $p[2]->id, 'body' => 'Gibt es vor Ort Essen zu kaufen oder sollen wir selber was mitbringen?'],
|
|
['created_at' => now()->subHours(6)]
|
|
);
|
|
|
|
// Besprechung (Index 5): 1 Kommentar
|
|
Comment::updateOrCreate(
|
|
['event_id' => $events[5]->id, 'user_id' => $p[1]->id, 'body' => 'Wird es eine Tagesordnung geben?'],
|
|
['created_at' => now()->subHours(2)]
|
|
);
|
|
|
|
// 1 gelöschter Kommentar (manuelles Soft-Delete via deleted_at + deleted_by)
|
|
$deleted = Comment::updateOrCreate(
|
|
['event_id' => $events[2]->id, 'user_id' => $p[15]->id, 'body' => 'Dieser Kommentar wurde von einem Admin entfernt.'],
|
|
['created_at' => now()->subDays(6)]
|
|
);
|
|
if (! $deleted->isDeleted()) {
|
|
$deleted->update([
|
|
'deleted_at' => now()->subDays(4),
|
|
'deleted_by' => $admin->id,
|
|
]);
|
|
}
|
|
}
|
|
|
|
// ─── Spielerstatistiken ─────────────────────────────────
|
|
// Heimspiel (Index 2, Ergebnis 15:12) — Stats für zugesagte Spieler
|
|
|
|
private function seedPlayerStats(array $events, array $players): void
|
|
{
|
|
$homeGame = $events[2]; // Heimspiel vs. TSV Beispielburg (15:12)
|
|
$playerList = array_values($players);
|
|
|
|
// Nur die ersten 18 Spieler haben beim Heimspiel zugesagt (siehe seedParticipants)
|
|
$statsData = [
|
|
// [index, is_goalkeeper, gk_saves, gk_shots, goals, shots, note, position]
|
|
[0, true, 8, 20, 0, 0, 'Starke Leistung im Tor', 'torwart'],
|
|
[1, false, null, null, 3, 6, 'Drei Tempogegenstöße', 'links_aussen'],
|
|
[2, false, null, null, 2, 5, 'Guter Aufbau', 'rueckraum_mitte'],
|
|
[3, false, null, null, 2, 4, null, 'rueckraum_links'],
|
|
[4, false, null, null, 1, 3, 'Schnelle Beine', 'rechts_aussen'],
|
|
[5, false, null, null, 2, 5, null, 'rueckraum_rechts'],
|
|
[6, false, null, null, 1, 2, 'Erste Tore der Saison!', 'kreislaeufer'],
|
|
[7, false, null, null, 1, 4, null, 'links_aussen'],
|
|
[8, false, null, null, 1, 3, null, 'rechts_aussen'],
|
|
[9, false, null, null, 1, 2, null, 'rueckraum_links'],
|
|
[10, false, null, null, 1, 3, 'Stark in der Abwehr', 'rueckraum_mitte'],
|
|
[11, false, null, null, 0, 2, null, 'rueckraum_rechts'],
|
|
[12, false, null, null, 0, 1, null, 'kreislaeufer'],
|
|
[13, false, null, null, 0, 1, null, 'torwart'],
|
|
[14, false, null, null, 0, 2, 'Erste Spielminuten', null],
|
|
[15, false, null, null, 0, 0, null, null],
|
|
[16, false, null, null, 0, 1, null, null],
|
|
[17, false, null, null, 0, 0, null, null],
|
|
];
|
|
|
|
foreach ($statsData as [$idx, $isGk, $gkSaves, $gkShots, $goals, $shots, $note, $position]) {
|
|
if (!isset($playerList[$idx])) {
|
|
continue;
|
|
}
|
|
EventPlayerStat::updateOrCreate(
|
|
['event_id' => $homeGame->id, 'player_id' => $playerList[$idx]->id],
|
|
[
|
|
'is_goalkeeper' => $isGk,
|
|
'goalkeeper_saves' => $gkSaves,
|
|
'goalkeeper_shots' => $gkShots,
|
|
'goals' => $goals,
|
|
'shots' => $shots,
|
|
'note' => $note,
|
|
'position' => $position,
|
|
]
|
|
);
|
|
}
|
|
}
|
|
|
|
// ─── Fahrgemeinschaften ──────────────────────────────────
|
|
// Auswärtsspiel (Index 3) + Turnier (Index 4)
|
|
|
|
private function seedCarpools(array $events, array $parentUsers, array $players): void
|
|
{
|
|
$p = array_values($parentUsers);
|
|
$pl = array_values($players);
|
|
|
|
// Auswärtsspiel (Index 3): 2 Fahrgemeinschaften
|
|
$carpool1 = EventCarpool::where('event_id', $events[3]->id)->where('user_id', $p[0]->id)->first();
|
|
if (!$carpool1) {
|
|
$carpool1 = new EventCarpool(['event_id' => $events[3]->id, 'seats' => 3, 'note' => 'Treffpunkt Parkplatz, 9:30 Uhr']);
|
|
$carpool1->user_id = $p[0]->id;
|
|
$carpool1->save();
|
|
}
|
|
|
|
// 2 Kinder zuordnen
|
|
foreach ([0, 1] as $childIdx) {
|
|
if (isset($pl[$childIdx])) {
|
|
$pass = EventCarpoolPassenger::where('carpool_id', $carpool1->id)->where('player_id', $pl[$childIdx]->id)->first();
|
|
if (!$pass) {
|
|
$pass = new EventCarpoolPassenger(['carpool_id' => $carpool1->id, 'player_id' => $pl[$childIdx]->id]);
|
|
$pass->added_by = $p[0]->id;
|
|
$pass->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
$carpool2 = EventCarpool::where('event_id', $events[3]->id)->where('user_id', $p[2]->id)->first();
|
|
if (!$carpool2) {
|
|
$carpool2 = new EventCarpool(['event_id' => $events[3]->id, 'seats' => 2, 'note' => 'Abfahrt 9:15 Uhr ab Vereinsheim']);
|
|
$carpool2->user_id = $p[2]->id;
|
|
$carpool2->save();
|
|
}
|
|
|
|
// Voll belegt — 2 Kinder
|
|
foreach ([2, 3] as $childIdx) {
|
|
if (isset($pl[$childIdx])) {
|
|
$pass = EventCarpoolPassenger::where('carpool_id', $carpool2->id)->where('player_id', $pl[$childIdx]->id)->first();
|
|
if (!$pass) {
|
|
$pass = new EventCarpoolPassenger(['carpool_id' => $carpool2->id, 'player_id' => $pl[$childIdx]->id]);
|
|
$pass->added_by = $p[2]->id;
|
|
$pass->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Turnier (Index 4): 1 Fahrgemeinschaft
|
|
$carpool3 = EventCarpool::where('event_id', $events[4]->id)->where('user_id', $p[5]->id)->first();
|
|
if (!$carpool3) {
|
|
$carpool3 = new EventCarpool(['event_id' => $events[4]->id, 'seats' => 4, 'note' => 'Großer Van, Abfahrt 8:00 Uhr']);
|
|
$carpool3->user_id = $p[5]->id;
|
|
$carpool3->save();
|
|
}
|
|
|
|
// 1 Kind zugeordnet
|
|
if (isset($pl[5])) {
|
|
$pass = EventCarpoolPassenger::where('carpool_id', $carpool3->id)->where('player_id', $pl[5]->id)->first();
|
|
if (!$pass) {
|
|
$pass = new EventCarpoolPassenger(['carpool_id' => $carpool3->id, 'player_id' => $pl[5]->id]);
|
|
$pass->added_by = $p[5]->id;
|
|
$pass->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
// ─── FAQs ──────────────────────────────────────────────
|
|
|
|
private function seedFaqs(User $admin): void
|
|
{
|
|
$faqs = [
|
|
['title' => 'Wie melde ich mein Kind für ein Event an?', 'content_html' => '<p>Gehe auf die Event-Detailseite und klicke bei deinem Kind auf "Zusagen". Du kannst den Status jederzeit ändern.</p>', 'sort_order' => 1],
|
|
['title' => 'Wie funktioniert das Catering?', 'content_html' => '<p>Bei Heimspielen und Turnieren wird Catering organisiert. Du kannst auf der Event-Seite angeben, ob du etwas mitbringst und was genau.</p>', 'sort_order' => 2],
|
|
['title' => 'Was ist ein Zeitnehmer?', 'content_html' => '<p>Bei Heimspielen werden Zeitnehmer benötigt, die die Spieluhr bedienen. Pro Spiel brauchen wir mindestens 2 Zeitnehmer aus den Reihen der Eltern.</p>', 'sort_order' => 3],
|
|
];
|
|
|
|
foreach ($faqs as $data) {
|
|
$existing = Faq::where('title', $data['title'])->first();
|
|
if (! $existing) {
|
|
$faq = new Faq([
|
|
'title' => $data['title'],
|
|
'content_html' => $data['content_html'],
|
|
'sort_order' => $data['sort_order'],
|
|
]);
|
|
$faq->created_by = $admin->id;
|
|
$faq->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
// ─── Aktivitätslog ─────────────────────────────────────
|
|
// ActivityLog: $timestamps = false, created_at muss explizit gesetzt werden
|
|
|
|
private function seedActivityLogs(User $admin, User $coach, Team $team, array $events): void
|
|
{
|
|
$base = now()->subDays(7);
|
|
|
|
$logs = [
|
|
['user_id' => $admin->id, 'action' => 'install', 'description' => 'App wurde installiert', 'ip_address' => '127.0.0.1', 'created_at' => $base],
|
|
['user_id' => $admin->id, 'action' => 'login', 'description' => 'Admin hat sich eingeloggt', 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addHour()],
|
|
['user_id' => $admin->id, 'action' => 'created', 'model_type' => 'Team', 'model_id' => $team->id, 'description' => "Team '{$team->name}' erstellt", 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addHours(2)],
|
|
['user_id' => $admin->id, 'action' => 'created', 'model_type' => 'Event', 'model_id' => $events[0]->id, 'description' => "Event '{$events[0]->title}' erstellt", 'properties' => ['new' => ['title' => $events[0]->title, 'type' => 'training']], 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addHours(3)],
|
|
['user_id' => $admin->id, 'action' => 'updated', 'model_type' => 'Event', 'model_id' => $events[2]->id, 'description' => "Event '{$events[2]->title}' bearbeitet", 'properties' => ['old' => ['min_players' => null], 'new' => ['min_players' => 10]], 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addHours(4)],
|
|
['user_id' => $admin->id, 'action' => 'updated', 'model_type' => 'Setting', 'description' => 'Einstellungen aktualisiert', 'properties' => ['old' => ['app_name' => 'Handball App'], 'new' => ['app_name' => 'Demo Handball']], 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addDay()],
|
|
['user_id' => $coach->id, 'action' => 'login', 'description' => 'Trainer hat sich eingeloggt', 'ip_address' => '192.168.1.50', 'created_at' => $base->copy()->addDays(2)],
|
|
['user_id' => $admin->id, 'action' => 'created', 'model_type' => 'Player', 'model_id' => 1, 'description' => 'Spieler erstellt', 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addDays(2)->addHour()],
|
|
['user_id' => $admin->id, 'action' => 'updated', 'model_type' => 'User', 'model_id' => $coach->id, 'description' => "Rolle von '{$coach->name}' geändert", 'properties' => ['old' => ['role' => 'user'], 'new' => ['role' => 'coach']], 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addDays(3)],
|
|
['user_id' => $admin->id, 'action' => 'updated', 'model_type' => 'Event', 'model_id' => $events[6]->id, 'description' => 'Event abgesagt', 'properties' => ['old' => ['status' => 'published'], 'new' => ['status' => 'cancelled']], 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addDays(4)],
|
|
['user_id' => $admin->id, 'action' => 'deleted', 'model_type' => 'User', 'description' => 'Benutzer gelöscht (Soft-Delete)', 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addDays(5)],
|
|
['user_id' => $admin->id, 'action' => 'created', 'model_type' => 'File', 'description' => 'Datei "Regelwerk_Handball.pdf" hochgeladen', 'ip_address' => '127.0.0.1', 'created_at' => $base->copy()->addDays(6)],
|
|
];
|
|
|
|
foreach ($logs as $log) {
|
|
$exists = ActivityLog::where('description', $log['description'])
|
|
->where('created_at', $log['created_at'])
|
|
->exists();
|
|
|
|
if (! $exists) {
|
|
ActivityLog::create($log);
|
|
}
|
|
}
|
|
}
|
|
|
|
// ─── Soft-Deleted Records ──────────────────────────────
|
|
|
|
private function seedSoftDeletedRecords(Team $team): void
|
|
{
|
|
// Gelöschter User (3 Tage, im restaurierbaren 7-Tage-Fenster)
|
|
$deletedUser = User::withTrashed()->firstOrCreate(
|
|
['email' => 'geloescht@handball.local'],
|
|
[
|
|
'name' => 'Thaddeus Ross',
|
|
'password' => Hash::make('geloescht1234'),
|
|
'role' => UserRole::User,
|
|
'is_active' => true,
|
|
]
|
|
);
|
|
if (! $deletedUser->trashed()) {
|
|
$deletedUser->delete();
|
|
User::withTrashed()->where('id', $deletedUser->id)
|
|
->update(['deleted_at' => now()->subDays(3)]);
|
|
}
|
|
|
|
// Gelöschter Spieler (2 Tage, im restaurierbaren 7-Tage-Fenster)
|
|
$deletedPlayer = Player::withTrashed()->firstOrCreate(
|
|
['first_name' => 'Bucky', 'last_name' => 'Barnes', 'team_id' => $team->id],
|
|
[
|
|
'birth_year' => 2017,
|
|
'is_active' => true,
|
|
'photo_permission' => false,
|
|
]
|
|
);
|
|
if (! $deletedPlayer->trashed()) {
|
|
$deletedPlayer->delete();
|
|
Player::withTrashed()->where('id', $deletedPlayer->id)
|
|
->update(['deleted_at' => now()->subDays(2)]);
|
|
}
|
|
}
|
|
|
|
// ─── Helper ────────────────────────────────────────────
|
|
|
|
private function makeEmail(string $first, string $last): string
|
|
{
|
|
$map = ['ß' => 'ss', 'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue',
|
|
'Ä' => 'ae', 'Ö' => 'oe', 'Ü' => 'ue'];
|
|
$f = mb_strtolower(strtr($first, $map));
|
|
$l = mb_strtolower(strtr($last, $map));
|
|
|
|
return "{$f}.{$l}@handball.local";
|
|
}
|
|
}
|