/**
  * Handle the event.
  *
  * @param User $user
  *
  * @return void
  */
 public function handle(User $user)
 {
     if (DatabaseSeeder::isSeeding() || app()->environment('testing')) {
         return;
     }
     $list = $this->mailchimp->mailingList(env('MAILCHIMP_LIST_ID'));
     // We can't update an email address via the API, so we have to unsubscribe them
     if ($user->isDirty('email')) {
         $list->unsubscribe($user->getOriginal('email'));
     }
     // need to make sure their interests are up to date
     $interests = [];
     foreach (Role::whereNotNull('mailchimp_interest_id')->get() as $role) {
         $interests[$role->mailchimp_interest_id] = $user->isA($role->name);
     }
     // will add or update depending on whether the email addresses
     $list->updateSubscriber($user->email, $user->first_name, $user->last_name, $interests);
     // also do this for each group
     // group members don't get classified by interest
     foreach ($user->groups()->active()->get() as $group) {
         if ($group->settings->shouldUpdateSubscribers()) {
             /** @var Easychimp $mailchimp */
             $mailchimp = app(Easychimp::class, [$group->settings->mailchimpKey()]);
             $list = $mailchimp->mailingList($group->settings->mailchimpListId());
             if ($user->isDirty('email')) {
                 $list->unsubscribe($user->getOriginal('email'));
             }
             $list->updateSubscriber($user->email, $user->first_name, $user->last_name);
         }
     }
     $this->delete();
 }
 public static function boot()
 {
     parent::boot();
     // assign a guid for each model
     static::creating(function ($tournamentQuizmaster) {
         $tournamentQuizmaster->guid = Uuid::uuid4();
         return true;
     });
     // Make sure the user has the quizmaster role
     // Using a saved event since the user could be assigned
     // after the initial creation
     static::saved(function ($tournamentQuizmaster) {
         $user = $tournamentQuizmaster->user;
         // if no user is linked, try to find one
         if (is_null($user)) {
             $user = User::where('email', $tournamentQuizmaster->email)->first();
         }
         if (!is_null($user)) {
             // label the user as a quizmaster
             if ($user->isNotA(Role::QUIZMASTER)) {
                 $role = Role::where('name', Role::QUIZMASTER)->firstOrFail();
                 $user->assign($role);
             }
             // associate the user with the quizmaster
             if ($tournamentQuizmaster->user_id == null) {
                 $tournamentQuizmaster->update(['user_id' => $user->id]);
             }
         }
     });
 }
Example #3
0
 /**
  * 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']])]);
 }
 /**
  * Update the mailchimp ids so they match the staging list instead of production.
  */
 private function updateMailchimpIds()
 {
     Role::where('name', Role::LEAGUE_COORDINATOR)->update(['mailchimp_interest_id' => 'da431848e5']);
     Role::where('name', Role::HEAD_COACH)->update(['mailchimp_interest_id' => '8eb76f09f0']);
     Role::where('name', Role::COACH)->update(['mailchimp_interest_id' => 'd531b08cdb']);
     Role::where('name', Role::QUIZMASTER)->update(['mailchimp_interest_id' => 'bddc8cb120']);
     Role::where('name', Role::GUARDIAN)->update(['mailchimp_interest_id' => 'f29d2ce1ef']);
 }
Example #5
0
 /**
  * @return User
  */
 private function seedAdmin()
 {
     $address = Address::create(['name' => 'Home', 'address_one' => '11025 Eagles Cove Dr.', 'address_two' => null, 'latitude' => '38.2515659', 'longitude' => '-85.615241', 'city' => 'Louisville', 'state' => 'KY', 'zip_code' => '40241']);
     $director = User::create(['status' => User::STATUS_CONFIRMED, 'first_name' => 'Ben', 'last_name' => 'Director', 'email' => self::DIRECTOR_EMAIL, 'password' => bcrypt('changeme'), 'primary_address_id' => $address->id]);
     $director->addresses()->save($address);
     $role = Role::where('name', Role::ADMIN)->firstOrFail();
     $director->assign($role);
     return $director;
 }
Example #6
0
/**
 * @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;
}
Example #7
0
 /**
  * @param User  $guardian
  * @param array $attributes
  *
  * @return static
  */
 public function create(User $guardian, array $attributes)
 {
     $attributes['guardian_id'] = $guardian->id;
     DB::beginTransaction();
     $player = Player::create($attributes);
     if ($guardian->isNotA(Role::GUARDIAN)) {
         $role = Role::where('name', Role::GUARDIAN)->firstOrFail();
         $guardian->assign($role);
     }
     DB::commit();
     return $player;
 }
Example #8
0
 public static function boot()
 {
     parent::boot();
     //assign a guid for each user
     static::creating(function ($player) {
         $player->guid = Uuid::uuid4();
         return true;
     });
     static::deleting(function ($player) {
         $guardian = $player->guardian;
         // if it's the last player
         if ($guardian->players()->count() == 1 && $guardian->isAn(Role::GUARDIAN)) {
             $role = Role::where('name', Role::GUARDIAN)->firstOrFail();
             $guardian->retract($role);
         }
     });
 }
Example #9
0
 public function updateRoles(Request $request, $userId)
 {
     /** @var User $user */
     $user = User::with('roles')->findOrFail($userId);
     DB::transaction(function () use($request, $user) {
         $roleIds = $request->get('role', []);
         foreach (Role::editable()->get() as $role) {
             $hasRole = $user->isA($role->name);
             $shouldHaveRole = array_key_exists($role->id, $roleIds);
             if ($hasRole && $shouldHaveRole === false) {
                 $user->retract($role);
             } elseif ($hasRole === false && $shouldHaveRole) {
                 $user->assign($role);
             }
         }
     });
     return redirect('/admin/users/' . $userId)->withFlashSuccess('Your changes were saved');
 }
Example #10
0
 public function removeHeadCoach(User $user)
 {
     $user->groups()->detach($this->id);
     if ($user->groups()->count() == 0) {
         $role = Role::where('name', Role::HEAD_COACH)->firstOrFail();
         $user->retract($role);
     }
 }
Example #11
0
 /**
  * Update the mailchimp ids so they match the staging list instead of production.
  */
 private function updateMailchimpIds()
 {
     Role::where('name', Role::LEAGUE_COORDINATOR)->update(['mailchimp_interest_id' => '4548244911']);
     Role::where('name', Role::HEAD_COACH)->update(['mailchimp_interest_id' => 'cea4f8e0dd']);
     Role::where('name', Role::COACH)->update(['mailchimp_interest_id' => 'e11132acbf']);
     Role::where('name', Role::QUIZMASTER)->update(['mailchimp_interest_id' => 'e58faebc7c']);
     Role::where('name', Role::GUARDIAN)->update(['mailchimp_interest_id' => '295ac3a88c']);
 }
Example #12
0
 /**
  * Retract the given role from the model.
  *
  * @param \Silber\Bouncer\Database\Role|string $role
  *
  * @return $this
  */
 public function retract(Role $role)
 {
     if (DatabaseSeeder::isSeeding() === false && $role->hasMailchimpInterest()) {
         event('user.role.removed', [$this, $role]);
     }
     return $this->parentRetract($role);
 }
Example #13
0
 /**
  * @test
  */
 public function canEditRoles()
 {
     $guardian = User::whereEmail(DatabaseSeeder::GUARDIAN_EMAIL)->firstOrFail();
     $role = Role::where('name', Role::ADMIN)->firstOrFail();
     $this->visit('/admin/users/' . $guardian->id)->click('(add/remove)')->check('role[' . $role->id . ']')->press('Save')->see('Your changes were saved')->click('(add/remove)')->uncheck('role[' . $role->id . ']')->press('Save');
 }