Esempio n. 1
0
 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()]);
 }
Esempio n. 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     /** @var Group[] $groups */
     $groups = Group::active()->with('owner', 'meetingAddress')->get();
     DB::beginTransaction();
     $map = Map::findOrFail(Map::GROUPS);
     $activeLocations = [];
     foreach ($groups as $group) {
         /** @var Location $location */
         $location = $group->wordpressLocation();
         if ($group->isInactive()) {
             $location->delete();
         } else {
             if ($location == null) {
                 $location = app(Location::class);
             }
             $location->updateMarkerInformation($group);
             $location->save();
             $activeLocations[] = $location->location_id;
         }
     }
     $map->map_locations = $activeLocations;
     $map->save();
     DB::commit();
 }
 public function groupStats(Season $season)
 {
     return ['byProgram' => Group::whereHas('players', function (Builder $q) use($season) {
         $q->where('player_season.season_id', $season->id)->whereNull('player_season.inactive');
     })->with('program')->select('groups.program_id', DB::raw('count(groups.id) as total'))->groupBy('groups.program_id')->get(), 'byType' => Group::whereHas('players', function (Builder $q) use($season) {
         $q->where('player_season.season_id', $season->id)->whereNull('player_season.inactive');
     })->with('type')->select('groups.group_type_id', DB::raw('count(groups.id) as total'))->groupBy('groups.group_type_id')->get()];
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $groupId = $this->route('group');
     if (Auth::user()->isA(Role::HEAD_COACH)) {
         $groupId = Session::group()->id;
     }
     return Group::where('id', $groupId)->where('owner_id', Auth::id())->exists();
 }
Esempio n. 5
0
 public function averageGroupSize($playerCount) : int
 {
     $groupsWithPlayers = Group::active()->has('players')->count();
     if ($groupsWithPlayers > 0) {
         return round($playerCount / $groupsWithPlayers);
     }
     return 0;
 }
Esempio n. 6
0
 /**
  * @test
  */
 public function canAcceptGroupInvitations()
 {
     $group = Group::active()->firstOrFail();
     $invitation = Invitation::create(['type' => Invitation::TYPE_MANAGE_GROUP, 'inviter_id' => $group->owner_id, 'group_id' => $group->id]);
     $this->setupAsDirector();
     $this->visit('/invitation/' . $invitation->guid . '/accept')->followRedirects()->see('Invitation has been accepted')->assertSessionHas(\BibleBowl\Users\Auth\SessionManager::GROUP, $invitation->group->toArray());
     $invitation = Invitation::findOrFail($invitation->id);
     $this->assertEquals(Invitation::ACCEPTED, $invitation->status);
 }
Esempio n. 7
0
 /**
  * @param User  $owner
  * @param array $attributes
  *
  * @return static
  */
 public function create(User $owner, array $attributes)
 {
     $attributes['owner_id'] = $owner->id;
     DB::beginTransaction();
     $group = Group::create($attributes);
     $group->addHeadCoach($owner);
     DB::commit();
     return $group;
 }
Esempio n. 8
0
 public function outstandingRegistrationFees()
 {
     $outstandingAtLeast = Config::get('biblebowl.reminders.notify-office-of-outstanding-registration-payments-after');
     $relativeTime = $outstandingAtLeast . ' ago';
     $playersRegistrationUnpaidSince = new \Carbon\Carbon($relativeTime);
     return view('admin.groups.outstanding-registration-fees', ['unpaidSince' => $relativeTime, 'groups' => Group::hasPendingRegistrationPayments($playersRegistrationUnpaidSince)->with(['owner', 'program', 'players' => function ($q) {
         $q->orderBy('player_season.created_at', 'DESC');
         $q->limit(1);
     }])->orderBy('name', 'ASC')->get()]);
 }
Esempio n. 9
0
 /**
  * @test
  */
 public function canTransferOwnership()
 {
     $guardian = User::where('email', DatabaseSeeder::GUARDIAN_EMAIL)->firstOrFail();
     $this->assertTrue($guardian->isNotAn(Role::HEAD_COACH));
     $this->assertTrue($this->group->owner->isAn(Role::HEAD_COACH));
     $this->visit('/admin/groups/' . $this->group->id)->click('Transfer Ownership')->see('Transfer Ownership: ' . $this->group->name)->select($guardian->id, 'user_id')->press('Transfer')->see('Ownership has been transferred');
     Bouncer::refresh();
     $this->assertTrue($guardian->isAn(Role::HEAD_COACH));
     $this->assertTrue(Group::findOrFail($this->group->id)->isOwner($guardian));
 }
Esempio n. 10
0
 /**
  * @test
  */
 public function editIntegrationSettings()
 {
     $apiKey = md5(time()) . '-us1';
     $listId = '34adf2345wd';
     $this->visit('/group/' . $this->group()->id . '/settings/integrations')->check('mailchimp-enabled')->type($apiKey, 'mailchimp-key')->type($listId, 'mailchimp-list-id')->press('Save')->see('Your integration settings have been saved');
     $group = Group::findOrFail($this->group()->id);
     $this->assertTrue($group->settings->mailchimpEnabled());
     $this->assertEquals($apiKey, $group->settings->mailchimpKey());
     $this->assertEquals($listId, $group->settings->mailchimpListId());
 }
Esempio n. 11
0
 /**
  * @test
  */
 public function canRegisterPlayersForAllPrograms()
 {
     $nearbyGroup = Group::where('name', DatabaseSeeder::GROUP_NAME)->firstOrFail();
     $this->visit('/register/players')->see('David Webb')->see('Ethan Smith')->select('11', 'player[1][grade]')->select('10', 'player[2][grade]')->press('Continue')->dontSee('Submit Registration')->click('Join Beginner Group')->type('Southeast', 'q')->press('Search')->click('Register Later')->seePageIs('/register/summary')->see('Your Beginner players have been removed from this registration')->dontSee('Beginner Bible Bowl');
     // verify beginner players have been removed
     $beginner = Program::findOrFail(Program::BEGINNER);
     /** @var \BibleBowl\Seasons\GroupRegistration $registration */
     $registration = Session::seasonalGroupRegistration();
     $this->assertEquals(0, $registration->numberOfPlayers($beginner));
     $this->click('Join Teen Group')->click('#select-nearby-group-' . $nearbyGroup->id)->seePageIs('/register/summary')->see($nearbyGroup->name)->press('Submit Registration')->see('You must agree to the Terms of Participation')->check('terms_of_participation')->press('Submit Registration')->see('Your registration has been submitted!')->visit('/register/players')->dontSee('David Webb')->dontSee('Ethan Smith');
 }
Esempio n. 12
0
 /**
  * @test
  */
 public function canReorderPlayers()
 {
     $group = Group::findOrFail(2);
     $this->withSession([SessionManager::GROUP => $group->toArray()]);
     $teamSet = TeamSet::findOrFail(1);
     $team = $teamSet->teams->get(2);
     $startingPlayerOrder = [$team->players->first()->id, $team->players->get(1)->id];
     $this->post('/teams/' . $team->id . '/updateOrder', ['sortOrder' => [$startingPlayerOrder[1], $startingPlayerOrder[0]]])->assertResponseOk();
     $team = Team::findOrFail($team->id);
     $this->assertEquals($startingPlayerOrder[1], $team->players->first()->id);
     $this->assertEquals($startingPlayerOrder[0], $team->players->get(1)->id);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $remindGroupsOfPendingPaymentsAfter = config('biblebowl.reminders.remind-groups-of-pending-payments-after');
     $playersRegistrationUnpaidSince = new Carbon($remindGroupsOfPendingPaymentsAfter . ' ago');
     $groups = Group::hasPendingRegistrationPayments($playersRegistrationUnpaidSince)->get();
     foreach ($groups as $group) {
         foreach ($group->users as $user) {
             Mail::queue('emails.remind-groups-of-pending-payments', ['groupId' => $group->id], function (Message $message) use($group, $user) {
                 $message->to($user->email, $user->full_name)->subject('Registration Fee Reminder');
             });
         }
     }
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     if (Auth::user()->isNotA(Role::HEAD_COACH)) {
         return false;
     }
     $groupId = $this->route('group');
     if ($groupId == null) {
         $groupId = Session::group()->id;
     }
     return Group::where('id', $groupId)->whereHas('users', function (Builder $q) {
         $q->where('users.id', Auth::user()->id);
     })->exists();
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $notifyOfficeOfOutstandingPaymentsAfter = config('biblebowl.reminders.notify-office-of-outstanding-registration-payments-after');
     $relativeTime = $notifyOfficeOfOutstandingPaymentsAfter . ' ago';
     $playersRegistrationUnpaidSince = new Carbon($relativeTime);
     if (Group::hasPendingRegistrationPayments($playersRegistrationUnpaidSince)->count() > 0) {
         Mail::queue('emails.notify-office-of-outstanding-pending-payments', [], function (Message $message) {
             $message->to(Config::get('biblebowl.officeEmail'))->subject('Outstanding Registration Fees');
         });
     } else {
         Log::info('No groups have registration fees older than ' . $relativeTime);
     }
 }
 /**
  * @test
  */
 public function canRegisterWithGroupAndWithoutFees()
 {
     $this->setupAsGuardian();
     $this->simulateTransaction();
     $tournament = Tournament::firstOrFail();
     // Remove fees for quizmasters
     $tournament->participantFees()->where('participant_type_id', ParticipantType::ADULT)->update(['earlybird_fee' => 0, 'fee' => 0]);
     $group = Group::byProgram($tournament->program_id)->first();
     $this->visit('/tournaments/' . $tournament->slug . '/registration/spectator')->select($group->id, 'group_id')->press('Submit')->see('Your registration is complete');
     $spectator = Spectator::orderBy('id', 'desc')->first();
     $this->assertEquals($group->id, $spectator->group_id);
     // no payment was made, so we shouldn't have a receipt
     $this->assertNull($spectator->receipt_id);
 }
Esempio n. 17
0
 /**
  * Standalone registration is a Spectator that is registering
  * themselves, not the Head Coach registering on their behalf.
  */
 public function postStandaloneRegistration(StandaloneSpectatorRegistrationRequest $request, $slug, SpectatorRegistrationPaymentReceived $spectatorRegistrationPaymentReceived, SpectatorRegistrar $spectatorRegistrar)
 {
     $tournament = Tournament::where('slug', $slug)->firstOrFail();
     $spectator = $spectatorRegistrar->register($tournament, $request->except('_token'), Auth::user(), $request->get('group_id') ? Group::findOrFail($request->get('group_id')) : null);
     $spectatorRegistrationPaymentReceived->setSpectator($spectator);
     // registrations with fees go to the cart
     $fee = $tournament->fee($spectator->participant_type);
     if ($fee > 0) {
         $cart = Cart::clear();
         $cart->setPostPurchaseEvent($spectatorRegistrationPaymentReceived)->save();
         $cart->add($spectator->sku(), $fee, 1);
         return redirect('/cart');
     }
     return $spectatorRegistrationPaymentReceived->successStep();
 }
Esempio n. 18
0
 /**
  * Standalone registration is a Quizmaster that is registering
  * themselves, not the Head Coach registering on their behalf.
  */
 public function postStandaloneRegistration(StandaloneQuizmasterRegistrationRequest $request, $slug, QuizmasterRegistrationPaymentReceived $quizmasterRegistrationPaymentReceived, QuizmasterRegistrar $quizmasterRegistrar)
 {
     $tournament = Tournament::where('slug', $slug)->firstOrFail();
     $participantType = ParticipantType::findOrFail(ParticipantType::QUIZMASTER);
     $tournamentQuizmaster = $quizmasterRegistrar->register($tournament, $request->except('_token'), Auth::user(), $request->get('group_id') ? Group::findOrFail($request->get('group_id')) : null);
     $quizmasterRegistrationPaymentReceived->setTournamentQuizmaster($tournamentQuizmaster);
     // registrations with fees go to the cart
     $fee = $tournament->fee($participantType);
     if ($fee > 0) {
         $cart = Cart::clear();
         $cart->setPostPurchaseEvent($quizmasterRegistrationPaymentReceived)->save();
         $cart->add(TournamentQuizmaster::REGISTRATION_SKU, $fee, 1);
         return redirect('/cart');
     }
     return $quizmasterRegistrationPaymentReceived->successStep();
 }
 /**
  * @test
  */
 public function canRegisterWithGroupAndWithoutFees()
 {
     $this->setupAsGuardian();
     $this->simulateTransaction();
     $gamesQuizzedThisSeason = 'Fewer than 30';
     $tournament = Tournament::firstOrFail();
     // Remove fees for quizmasters
     $tournament->participantFees()->where('participant_type_id', ParticipantType::QUIZMASTER)->update(['earlybird_fee' => 0, 'fee' => 0]);
     $group = Group::byProgram($tournament->program_id)->first();
     $this->visit('/tournaments/' . $tournament->slug . '/registration/quizmaster')->select($group->id, 'group_id')->select($gamesQuizzedThisSeason, 'games_quizzed_this_season')->press('Submit')->see('Your quizmaster registration is complete');
     $quizmaster = TournamentQuizmaster::orderBy('id', 'desc')->first();
     $this->assertEquals($group->id, $quizmaster->group_id);
     // quizzing preferences saved
     $this->assertEquals($gamesQuizzedThisSeason, $quizmaster->quizzing_preferences->gamesQuizzedThisSeason());
     // no payment was made, so we shouldn't have a receipt
     $this->assertNull($quizmaster->receipt_id);
 }
 /**
  * @param array $groups
  */
 public function deactivateInactiveGroups($season)
 {
     $groupsToDeactivate = Group::active($season)->withoutActivePlayers($season)->get();
     // notify the group owner
     foreach ($groupsToDeactivate as $group) {
         $group->update(['inactive' => 1]);
         Mail::queue('emails.inactive-group-notification', ['group' => $group, 'season' => $season], function (Message $message) use($group) {
             $message->to($group->owner->email, $group->owner->full_name)->subject($group->name . ' Automatically Deactivated');
         });
     }
     // summarize impacted groups for the office
     $deactivatedGroups = $groupsToDeactivate->count();
     if ($deactivatedGroups > 0) {
         Mail::queue('emails.inactive-group-summary', ['groupIds' => $groupsToDeactivate->modelKeys()], function (Message $message) use($deactivatedGroups) {
             $message->to(config('biblebowl.officeEmail'))->subject('Group' . ($deactivatedGroups > 1 ? 's' : '') . ' Automatically Deactivated');
         });
     }
 }
Esempio n. 21
0
 public function sendUserInvite(UserInviteRequest $request)
 {
     $group = Group::findOrFail($request->route('group'));
     $user = User::where('email', $request->get('email'))->first();
     DB::beginTransaction();
     $recipientName = null;
     if (is_null($user)) {
         $recipientEmail = $request->get('email');
     } else {
         $recipientEmail = $user->email;
         $recipientName = $user->full_name;
     }
     $invitation = Invitation::create(['type' => Invitation::TYPE_MANAGE_GROUP, 'email' => is_null($user) ? $request->get('email') : null, 'user_id' => is_null($user) ? null : $user->id, 'inviter_id' => Auth::user()->id, 'group_id' => $group->id]);
     Mail::queue('emails.group-user-invitation', ['invitation' => $invitation, 'header' => 'Group Management Invitation', 'invitationText' => '<strong>' . Auth::user()->full_name . '</strong> has invited you to help manage the ' . $group->program->abbreviation . ' <strong>' . $group->name . '</strong> group.'], function (Message $message) use($recipientEmail, $recipientName) {
         $message->to($recipientEmail, $recipientName)->subject('Bible Bowl Group Management Invitation');
     });
     DB::commit();
     return redirect('/group/' . $group->id . '/settings/users')->withFlashSuccess('Invitation has been sent');
 }
Esempio n. 22
0
 /**
  * @return Group|null
  */
 public function getGroupToRegisterWith()
 {
     return Group::where('guid', $this->get(self::REGISTER_WITH_GROUP))->first();
 }
Esempio n. 23
0
 /**
  * @return Group[]
  */
 public function groups()
 {
     return Group::whereIn('id', array_values($this->attributes['groups']))->get();
 }
Esempio n. 24
0
 /**
  * @param       $name
  * @param null  $selected
  * @param array $options
  *
  * @return string
  */
 public function selectGroup(int $programId, $name, $selected = null, $options = [], $optional = false)
 {
     $availableGroups = Group::active()->byProgram($programId)->orderBy('name')->with('meetingAddress')->get();
     $groups = $optional ? ['' => ''] : [];
     foreach ($availableGroups as $group) {
         $groups[$group->id] = $group->name . ' - ' . $group->meetingAddress->city . ', ' . $group->meetingAddress->state;
     }
     return $this->select($name, $groups, $selected, $options);
 }
Esempio n. 25
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $isEditingExistingGroup = $this->route('group') > 0;
     return array_except(Group::validationRules($isEditingExistingGroup), ['program_id', 'owner_id']);
 }
Esempio n. 26
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     return Group::whereHas('users', function (Builder $q) {
         $q->where('id', Auth::user()->id);
     })->where('id', $this->route('group'))->count() > 0;
 }
    <?php 
// Serialized objects need to be re-instantiated in order
// to have a successful database connection
$programs = \BibleBowl\Program::orderBy('name', 'ASC')->get();
?>

    @include('emails.theme.header', [
        'header' => 'Automatically Deactivated Groups'
    ])

    @include('emails.theme.text-block', [
        'body' => '<p>Groups automatically become inactive when they end a season without any active players.  This time, <strong>'.count($groupIds).'</strong> met the criteria.  They have already been notified as well as provided instructions on how to reactivate their group or transfer the group ownership to another individual.  There\'s nothing you need to do, this is merely a notification that the following groups are now inactive.</p>'
    ])

    @foreach($programs as $program)
        <?php 
$groups = \BibleBowl\Group::whereIn('id', $groupIds)->where('program_id', $program->id)->with('owner')->get();
?>
        @if($groups->count() > 0)
            <?php 
$bulletedList = '';
foreach ($groups as $group) {
    $bulletedList .= '<li>' . $group->name . ' (' . $group->owner->full_name . ')</li>';
}
?>
            @include('emails.theme.text-block', [
                'body' => "<h4>".$program->name."</h4><ul>".$bulletedList.'</ul>'
            ])
        @endif
    @endforeach
@endsection
Esempio n. 28
0
 /**
  * Swap the current user's group for another.
  *
  * @param GroupCreatorOnlyRequest $request
  * @param                         $id
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function swap(GroupHeadCoachOnlyRequest $request, $id)
 {
     Session::setGroup(Group::findOrFail($id));
     return redirect('/dashboard');
 }
@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
Esempio n. 30
0
 public static function validationRules($groupAlreadyExists = false)
 {
     // Check to see if a group is a duplicate by looking at the location where they meet (zip code or city/state
     // and their program/name when the group is created
     Validator::extend('isnt_duplicate', function ($attribute, $value, $parameters, $validator) {
         $meetingAddress = Address::findOrFail($validator->getData()['meeting_address_id']);
         $group = Group::where('name', $value)->where('program_id', $validator->getData()['program_id'])->whereHas('meetingAddress', function ($query) use($meetingAddress) {
             $query->orWhere(function ($query) use($meetingAddress) {
                 $query->where('city', '=', $meetingAddress->city);
                 $query->where('state', '=', $meetingAddress->state);
             })->where('zip_code', '=', $meetingAddress->zip_code);
         })->first();
         return is_null($group);
     });
     return ['name' => 'required|max:128' . ($groupAlreadyExists ? '' : '|isnt_duplicate'), 'program_id' => 'required', 'owner_id' => 'required|exists:users,id', 'address_id' => 'required|exists:addresses,id'];
 }