/** * @param User $owner * @param Season $season * @param array $attributes * * @return static */ public function create(User $owner, Season $season, array $attributes, array $eventTypes, array $participantTypes) { $attributes['creator_id'] = $owner->id; $attributes['season_id'] = $season->id; // don't prefix with season if the name already contains the year (20xx) if (str_contains($attributes['name'], '20') == false) { $attributes['slug'] = $season->name . ' ' . $attributes['name']; } else { $attributes['slug'] = $attributes['name']; } DB::beginTransaction(); $tournament = Tournament::create($attributes); // add fees foreach ($participantTypes as $typeId => $registration) { $tournament->participantFees()->create(['participant_type_id' => $typeId, 'requires_registration' => isset($registration['requireRegistration']) ? (bool) $registration['requireRegistration'] : false, 'fee' => is_numeric($registration['fee']) ? $registration['fee'] : null, 'earlybird_fee' => is_numeric($registration['earlybird_fee']) ? $registration['earlybird_fee'] : null, 'onsite_fee' => is_numeric($registration['onsite_fee']) ? $registration['onsite_fee'] : null]); } // add events foreach ($eventTypes as $eventTypeId) { $tournament->events()->create(['event_type_id' => $eventTypeId]); } DB::commit(); return $tournament; }
private function seedTournament($director) { $tournamentName = 'My Test Tournament'; $tournament = Tournament::create(['program_id' => Program::TEEN, 'slug' => $this->season->name . ' ' . $tournamentName, 'season_id' => $this->season->id, 'name' => $tournamentName, 'start' => Carbon::now()->addMonths(5)->format('m/d/Y'), 'end' => Carbon::now()->addMonths(7)->format('m/d/Y'), 'registration_start' => Carbon::now()->subMonths(3)->format('m/d/Y'), 'registration_end' => Carbon::now()->addDays(4)->format('m/d/Y'), 'creator_id' => $director->id, 'details' => '<h3>Nearby Hotels</h3><p>There are a few nearby:</p><ul><li>Option #1</li></ul>', 'max_teams' => 64, 'lock_teams' => Carbon::now()->addMonths(3)->addWeeks(2)->format('m/d/Y'), 'earlybird_ends' => Carbon::now()->addMonths(3)->format('m/d/Y')]); $tournament->events()->create(['event_type_id' => EventType::ROUND_ROBIN, 'price_per_participant' => '25.00']); $tournament->events()->create(['event_type_id' => EventType::DOUBLE_ELIMINATION, 'price_per_participant' => '35.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::PLAYER, 'requires_registration' => 1, 'fee' => '15.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::TEAM, 'requires_registration' => 1, 'earlybird_fee' => '50.00', 'fee' => '75.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::QUIZMASTER, 'requires_registration' => 1, 'fee' => '30.00', 'onsite_fee' => '40.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::ADULT, 'requires_registration' => 1, 'fee' => '30.00', 'onsite_fee' => '40.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::FAMILY, 'requires_registration' => 1, 'fee' => '60.00', 'onsite_fee' => '75.00']); $groupId = 2; $tournament->tournamentQuizmasters()->create(['group_id' => $groupId, 'first_name' => 'Keith', 'last_name' => 'Webb', 'email' => '*****@*****.**', 'gender' => 'M']); $user = User::where('email', self::QUIZMASTER_EMAIL)->first(); $receipt = $this->seedReceipt($user); $tournament->tournamentQuizmasters()->create(['group_id' => $groupId, 'receipt_id' => $receipt->id, 'first_name' => 'Warner', 'last_name' => 'Jackson', 'email' => '*****@*****.**', 'gender' => 'F']); // guest spectators $director = User::where('email', self::DIRECTOR_EMAIL)->first(); $tournament->spectators()->create(['group_id' => $groupId, 'receipt_id' => $receipt->id, 'first_name' => 'Sarah', 'last_name' => 'Jones', 'shirt_size' => 'L', 'email' => '*****@*****.**', 'gender' => 'F', 'address_id' => $director->primary_address_id]); $tournament->spectators()->create(['group_id' => $groupId, 'first_name' => 'Jonathan', 'last_name' => 'Wicker', 'shirt_size' => 'L', 'email' => '*****@*****.**', 'gender' => 'M', 'address_id' => $director->primary_address_id]); // family spectators $tournament->spectators()->create(['group_id' => $groupId, 'user_id' => $director->id, 'receipt_id' => $receipt->id, 'spouse_first_name' => 'Michelle', 'spouse_gender' => 'F', 'spouse_shirt_size' => 'M']); $spectator = $tournament->spectators()->create(['group_id' => $groupId, 'first_name' => 'Clark', 'last_name' => 'Larkson', 'shirt_size' => 'XL', 'email' => '*****@*****.**', 'gender' => 'M', 'spouse_first_name' => 'Lucy', 'spouse_gender' => 'F', 'spouse_shirt_size' => 'M']); $spectator->minors()->create(['name' => 'Jonathan', 'age' => '6', 'shirt_size' => 'YS', 'gender' => 'M']); $spectator->minors()->create(['name' => 'Christine', 'age' => '12', 'shirt_size' => 'YM', 'gender' => 'F']); }