public function setupAsHeadCoach() { $this->headCoach = User::where('email', DatabaseSeeder::HEAD_COACH_EMAIL)->first(); $this->group = Group::where('name', DatabaseSeeder::GROUP_NAME)->first(); $this->season = Season::orderBy('id', 'DESC')->first(); $this->actingAs($this->headCoach)->withSession([SessionManager::GROUP => $this->group->toArray(), SessionManager::SEASON => $this->season->toArray()]); }
/** * Run the database seeds. * * @return void */ public function run() { Season::create(['name' => date('Y') . '-' . (date('y') + 1)]); Program::create(['name' => 'Beginner Bible Bowl', 'abbreviation' => 'Beginner', 'slug' => 'beginner', 'registration_fee' => '25.00', 'min_grade' => 2, 'max_grade' => 5]); Program::create(['name' => 'Teen Bible Bowl', 'abbreviation' => 'Teen', 'slug' => 'teen', 'registration_fee' => '35.00', 'min_grade' => 6, 'max_grade' => 12]); GroupType::create(['name' => 'Christian School']); GroupType::create(['name' => 'Homeschool']); GroupType::create(['name' => 'Church']); GroupType::create(['name' => 'Other']); ParticipantType::create(['name' => 'Team']); ParticipantType::create(['name' => 'Player']); ParticipantType::create(['name' => 'Quizmaster']); ParticipantType::create(['name' => 'Spectator - Adult', 'description' => 'Single adult']); ParticipantType::create(['name' => 'Spectator - Family', 'description' => 'Up to 2 adults and children who are not players']); EventType::create(['participant_type_id' => ParticipantType::TEAM, 'name' => 'Round Robin']); EventType::create(['participant_type_id' => ParticipantType::PLAYER, 'name' => 'Quote Bee']); EventType::create(['participant_type_id' => ParticipantType::TEAM, 'name' => 'Double Elimination']); EventType::create(['participant_type_id' => ParticipantType::PLAYER, 'name' => 'BuzzOff']); EventType::create(['participant_type_id' => ParticipantType::PLAYER, 'name' => 'King of the Hill']); Bouncer::allow(Role::ADMIN)->to([Ability::VIEW_REPORTS, Ability::MANAGE_ROLES, Ability::MANAGE_USERS, Ability::MANAGE_GROUPS, Ability::MANAGE_PLAYERS, Ability::CREATE_TOURNAMENTS, Ability::SWITCH_ACCOUNTS, Ability::MANAGE_SETTINGS]); Bouncer::allow(Role::BOARD_MEMBER)->to(Ability::VIEW_REPORTS); Bouncer::allow(Role::HEAD_COACH)->to([Ability::MANAGE_ROSTER, Ability::MANAGE_TEAMS]); Role::create(['name' => Role::COACH, 'mailchimp_interest_id' => '29a52dd6fc']); Role::create(['name' => Role::LEAGUE_COORDINATOR, 'mailchimp_interest_id' => '9b90dc8bdd']); Role::create(['name' => Role::QUIZMASTER, 'mailchimp_interest_id' => 'fe3a183033']); Bouncer::allow(Role::QUIZMASTER); Bouncer::allow(Role::GUARDIAN)->to(Ability::REGISTER_PLAYERS); Role::where('name', Role::HEAD_COACH)->update(['mailchimp_interest_id' => 'be4c459134']); Role::where('name', Role::GUARDIAN)->update(['mailchimp_interest_id' => '0f83e0f312']); $howDidYouHearAbout = RegistrationSurveyQuestion::create(['question' => 'How did you hear about Bible Bowl?', 'order' => 1]); $howDidYouHearAbout->answers()->saveMany([app(RegistrationSurveyAnswer::class, [['answer' => 'Friend', 'order' => '1']]), app(RegistrationSurveyAnswer::class, [['answer' => 'Church brochure/bulletin', 'order' => '2']]), app(RegistrationSurveyAnswer::class, [['answer' => 'Homeschool convention', 'order' => '3']]), app(RegistrationSurveyAnswer::class, [['answer' => 'TV', 'order' => '4']]), app(RegistrationSurveyAnswer::class, [['answer' => 'Web Advertisement', 'order' => '5']]), app(RegistrationSurveyAnswer::class, [['answer' => 'Internet', 'order' => '6']]), app(RegistrationSurveyAnswer::class, [['answer' => 'Other', 'order' => '7']])]); $mostInfluential = RegistrationSurveyQuestion::create(['question' => 'Which of the following were most influential in your decision to join Bible Bowl?', 'order' => 2]); $mostInfluential->answers()->saveMany([app(RegistrationSurveyAnswer::class, [['answer' => "Friend's recommendation", 'order' => '1']]), app(RegistrationSurveyAnswer::class, [['answer' => 'Attending a practice/demo/meeting', 'order' => '2']]), app(RegistrationSurveyAnswer::class, [['answer' => 'Learning about it on the web site', 'order' => '3']]), app(RegistrationSurveyAnswer::class, [['answer' => 'Homeschool curriculum potential', 'order' => '4']]), app(RegistrationSurveyAnswer::class, [['answer' => 'Other', 'order' => '5']])]); }
/** * @return \Illuminate\View\View */ public function getRegistrationSurveys(Request $request, SurveyMetricsRepository $metrics) { $seasons = Season::orderBy('id', 'DESC')->get(); $currentSeason = $request->has('seasonId') ? Season::findOrFail($request->get('seasonId')) : $seasons->first(); $questions = []; foreach (RegistrationSurveyQuestion::orderBy('order')->get() as $question) { $questions[$question->id] = ['question' => $question, 'metrics' => $metrics->byQuestion($question, $currentSeason)]; } return view('admin.reports.registration-surveys', ['currentSeason' => $currentSeason, 'seasons' => $seasons, 'questions' => $questions]); }
private function seedGroupWithPlayers(GroupCreator $groupCreator, User $headCoach, Address $address, $groupName, $guardianLat, $guardianLng) { $group = $groupCreator->create($headCoach, ['name' => $groupName, 'group_type_id' => GroupType::CHURCH, 'program_id' => Program::TEEN, 'address_id' => $address->id, 'meeting_address_id' => $address->id]); $shirtSizes = ['S', 'YS', 'M', 'L', 'YL', 'YM']; $guardian = seedGuardian([], ['latitude' => $guardianLat, 'longitude' => $guardianLng]); for ($x = 0; $x <= 2; $x++) { $player = seedPlayer($guardian); $this->season->players()->attach($player->id, ['group_id' => $group->id, 'grade' => rand(6, 12), 'shirt_size' => $shirtSizes[array_rand($shirtSizes)]]); } // Seed inactive player $player = seedPlayer($guardian); $this->season->players()->attach($player->id, ['inactive' => Carbon::now()->toDateTimeString(), 'group_id' => $group->id, 'grade' => rand(6, 12), 'shirt_size' => $shirtSizes[array_rand($shirtSizes)]]); }
public function handle(Login $login) { // skip when an admin is logging in as this user if (!Session::canSwitchToAdmin()) { $login->user->updateLastLogin(); } // current session is the most recent Session::setSeason(Season::current()->first()); // if user is a coach set current "Group" upon login if ($login->user->isA(Role::HEAD_COACH) && $login->user->groups->count() > 0) { Session::setGroup($login->user->groups->first()); } }
public function register(Season $season, User $guardian, GroupRegistration $registration) { DB::beginTransaction(); foreach ($registration->groups() as $group) { foreach ($registration->playerInfo($group->program) as $playerId => $playerData) { $playerData['group_id'] = $group->id; $season->players()->attach($playerId, $playerData); } // Since this email is queued, we need to get pivot data now and include it with $players // because once it actually gets processed $players won't be an object making it more // difficult to fetch this data $players = []; $grades = []; $shirtSizes = []; foreach ($registration->players($group->program) as $player) { $player->full_name = $player->full_name; $grades[$player->id] = $registration->grade($player->id); $shirtSizes[$player->id] = $registration->shirtSize($player->id); $players[] = $player; } // setting this value so that it's available in the toArray() so queued mail can use it $guardian->full_name = $guardian->full_name; /** @var User $user */ foreach ($group->users()->with('roles')->get() as $user) { if ($user->isA(Role::HEAD_COACH) && $user->settings->shouldBeNotifiedWhenUserJoinsGroup()) { Mail::queue('emails.group-registration-notification', ['groupId' => $group->id, 'guardian' => $guardian, 'players' => $players, 'grades' => $grades, 'shirtSizes' => $shirtSizes], function (Message $message) use($group, $user, $players) { $message->to($user->email, $user->full_name)->subject('New ' . $group->name . ' Registration' . (count($players) > 1 ? 's' : '')); }); } } $this->registrationConfirmation->send($guardian, $group, $registration); } DB::commit(); event('players.registered.with.group', [$group, $guardian]); return $group; }
private function seedGroupWithPlayers(GroupCreator $groupCreator, User $headCoach, Address $address) { $group = $groupCreator->create($headCoach, ['name' => self::GROUP_NAME, 'group_type_id' => GroupType::CHURCH, 'program_id' => Program::TEEN, 'address_id' => $address->id, 'meeting_address_id' => $address->id]); $shirtSizes = ['S', 'YS', 'M', 'L', 'YL', 'YM']; $guardian = seedGuardian([], ['latitude' => '38.301815', 'longitude' => '-85.597701']); for ($x = 0; $x <= 2; $x++) { $player = seedPlayer($guardian); $this->season->players()->attach($player->id, ['group_id' => $group->id, 'grade' => rand(6, 12), 'shirt_size' => $shirtSizes[array_rand($shirtSizes)], 'created_at' => Carbon::now()->subWeeks('10')->toDateTimeString()]); } // Seed inactive player $player = seedPlayer($guardian); $player->update(['first_name' => 'Inactive', 'first_name' => 'Joe']); $this->season->players()->attach($player->id, ['inactive' => Carbon::now()->toDateTimeString(), 'group_id' => $group->id, 'grade' => rand(6, 12), 'shirt_size' => $shirtSizes[array_rand($shirtSizes)]]); return $group; }
/** * @test */ public function guardianCantAlwaysEditBirthday() { /** @var Player $player */ $player = $this->guardian->players()->first(); $player->birthday = Carbon::now()->format('m/d/Y'); $this->assertTrue($player->seasons()->count() == 0); // admins can edit $user = Mockery::mock(User::class); $user->shouldReceive('isA')->andReturn(true); $this->assertTrue($player->isBirthdayEditable($user)); $user = Mockery::mock(User::class); $user->shouldReceive('isA')->andReturn(false); // can't edit after a few months $player->created_at = Carbon::now()->subMonths(4)->subDays(2); $this->assertFalse($player->isBirthdayEditable($user)); // can't edit after first season $player->created_at = Carbon::now(); Season::current()->first()->players()->attach($player->id, ['grade' => '11', 'shirt_size' => 'M', 'group_id' => 1]); $this->assertTrue($player->isBirthdayEditable($user)); }
/** * Execute the console command. * * @return mixed */ public function fire(AutomatedGroupDeactivator $groupDeactivator) { /** @var Carbon $endDate */ $endDate = Setting::seasonEnd(); /** @var Carbon $startDate */ $startDate = Setting::seasonStart(); $nextSeasonName = $startDate->format('Y-') . $startDate->addYear()->format('y'); // notify the office before the season rotates $rotateInDays = 7; if ($endDate->isBirthday(Carbon::now()->addDays($rotateInDays))) { Mail::queue('emails.season-rotate-notification', ['willRotateOn' => $endDate->toFormattedDateString(), 'nextSeasonName' => $nextSeasonName, 'programs' => Program::orderBy('name', 'ASC')->get()], function (Message $message) use($nextSeasonName, $rotateInDays) { $message->to(config('biblebowl.officeEmail'))->subject('The ' . $nextSeasonName . ' season begins in ' . $rotateInDays . ' days'); }); } // rotate the season if ($endDate->isBirthday()) { /* @var Season $season */ Season::firstOrCreate(['name' => $nextSeasonName]); // since the season rotated today, deactivate inactive groups from last season $lastSeason = Season::orderBy('id', 'DESC')->skip(1)->first(); $groupDeactivator->deactivateInactiveGroups($lastSeason); } }
@extends('emails.simple') @section('body') <?php // Serialized objects need to be re-instantiated in order // to have a successful database connection $group = \BibleBowl\Group::findOrFail($groupId); $season = \BibleBowl\Season::current()->first(); $players = $group->players()->pendingRegistrationPayment($season)->get(); $bulletedList = ''; foreach ($players as $player) { $bulletedList .= '<li>' . $player->full_name . '</li>'; } ?> @include('emails.theme.header', [ 'header' => 'Registration Fee Reminder' ]) @include('emails.theme.text-block', [ 'body' => '<p><strong>'.$group->name.'</strong> has <strong>'.count($players).'</strong> player(s) with outstanding '.$group->program->name.' registration fees. Please '.EmailTemplate::link(url('/'), 'login to your Bible Bowl account').' and click "Pay Now" to pay their fees.</p>' ]) @include('emails.theme.text-block', [ 'body' => '<p>Players are more than welcome to try out Bible Bowl for a brief period. If they try it out and decide not to play, please login and mark them as "Inactive" in your '.EmailTemplate::link(url('/roster'), 'player roster').' to avoid future emails.</p>' ]) @include('emails.theme.text-block', [ 'body' => "<p>Here's a list of players with outstanding fees:</p><ul>".$bulletedList.'</ul>' ]) @endsection
public function activate(Season $season) { $season->players()->wherePivot('season_id', $season->id)->updateExistingPivot($this->id, ['inactive' => null]); }
public function setSeason(Season $season) { $this->season = $season; $this->set(self::SEASON, $season->toArray()); }
public function byQuestion(RegistrationSurveyQuestion $question, Season $season) : array { return $question->surveys()->select(DB::raw('count(registration_surveys.id) as total'), 'answer')->groupBy('answer_id')->whereBetween('registration_surveys.created_at', [$season->start(), $season->end()])->get()->toArray(); }
public function historicalPlayerSummaryByProgram() { return Season::orderBy('seasons.created_at', 'DESC')->addSelect('seasons.*', DB::raw('(SELECT COUNT(player_id) FROM player_season INNER JOIN `groups` ON (`groups`.id = player_season.group_id AND `groups`.program_id = ' . Program::BEGINNER . ') WHERE season_id = seasons.id AND player_season.inactive IS NULL) as beginner_count'), DB::raw('(SELECT COUNT(player_id) FROM player_season INNER JOIN `groups` ON (`groups`.id = player_season.group_id AND `groups`.program_id = ' . Program::BEGINNER . ') WHERE season_id = seasons.id AND player_season.inactive IS NOT NULL) as beginner_quitters_count'), DB::raw('(SELECT COUNT(player_id) FROM player_season INNER JOIN `groups` ON (`groups`.id = player_season.group_id AND `groups`.program_id = ' . Program::TEEN . ') WHERE season_id = seasons.id AND player_season.inactive IS NULL) as teen_count'), DB::raw('(SELECT COUNT(player_id) FROM player_season INNER JOIN `groups` ON (`groups`.id = player_season.group_id AND `groups`.program_id = ' . Program::TEEN . ') WHERE season_id = seasons.id AND player_season.inactive IS NOT NULL) as teen_quitters_count'))->limit(5)->get(); }
/** * Show the parent/guardian a summary of their registration. * * @return \Illuminate\View\View */ public function summary() { return view('seasons.registration.summary')->withSeason(Season::current()->first())->withRegistration(Session::seasonalGroupRegistration()); }
| Here you may define all of your model factories. Model factories give | you a convenient way to create models for testing and seeding your | database. Just tell the factory how a default model should look. | */ $factory->define(User::class, function (Generator $faker) { return ['status' => User::STATUS_CONFIRMED, 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'email' => $faker->email, 'phone' => $faker->phoneNumber, 'password' => str_random(10), 'remember_token' => str_random(10)]; }); $factory->define(Player::class, function (Generator $faker) { return ['first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'gender' => rand(0, 1) ? 'M' : 'F', 'birthday' => $faker->dateTimeBetween('-18 years', '-9 years')->format('m/d/Y')]; }); $factory->define(Address::class, function (Generator $faker) { return ['name' => 'Home', 'address_one' => $faker->buildingNumber . ' ' . $faker->streetName . ' ' . $faker->streetSuffix, 'address_two' => rand(0, 5) ? $faker->secondaryAddress : null, 'latitude' => $faker->latitude, 'longitude' => $faker->longitude, 'city' => $faker->city, 'state' => $faker->stateAbbr, 'zip_code' => $faker->postcode]; }); $factory->define(Tournament::class, function (Generator $faker) { return ['name' => $faker->word, 'program_id' => Program::TEEN, 'season_id' => Season::current()->id, 'start' => Carbon::now()->addMonth(1), 'end' => Carbon::now()->addDays(14), 'registration_start' => Carbon::now()->subMonth(1), 'registration_end' => Carbon::now()->subDays(14), 'creator_id' => User::where('email', DatabaseSeeder::DIRECTOR_EMAIL)->first()->id]; }); /** * @return User */ function seedGuardian($attrs = [], $addressAttrs = []) { $address = factory(Address::class)->create($addressAttrs); $attrs['primary_address_id'] = $address->id; $user = factory(User::class)->create($attrs); $address->user_id = $user->id; $address->save(); $role = Role::where('name', Role::GUARDIAN)->firstOrFail(); $user->assign($role); return $user; }
public function setupAsDirector() { $this->director = User::where('email', DatabaseSeeder::DIRECTOR_EMAIL)->first(); $this->season = Season::orderBy('id', 'DESC')->first(); $this->actingAs($this->director)->withSession([SessionManager::SEASON => $this->season->toArray()]); }
public function setupAsGuardian() { $this->guardian = User::where('email', DatabaseSeeder::GUARDIAN_EMAIL)->first(); $this->season = Season::orderBy('id', 'DESC')->first(); $this->actingAs($this->guardian)->withSession([SessionManager::SEASON => $this->season->toArray()]); }