| 1 | package Bracket::Controller::Admin; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | BEGIN { extends 'Catalyst::Controller' } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use Perl6::Junction qw/ any /; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | =head1 Name | ||||||||||||
| 8 | |||||||||||||
| 9 | Bracket::Controller::Admin - Functions for admin users. | ||||||||||||
| 10 | |||||||||||||
| 11 | =head1 Description | ||||||||||||
| 12 | |||||||||||||
| 13 | Controller for admin functions: | ||||||||||||
| 14 | |||||||||||||
| 15 | * Update player points | ||||||||||||
| 16 | * Mark the round teams go out | ||||||||||||
| 17 | * Check which wins are by a lower seed | ||||||||||||
| 18 | |||||||||||||
| 19 | =head1 Methods | ||||||||||||
| 20 | |||||||||||||
| 21 | =cut | ||||||||||||
| 22 | |||||||||||||
| 23 | 0 | ▶ | sub auto : Private { | ||||||||||
|
Subroutine
auto: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 24 | 0 | my ($self, $c) = @_; | |||||||||||
| 25 | |||||||||||||
| 26 | # Restrict controller to admin role | ||||||||||||
| 27 | 0 | my @user_roles = $c->user->roles; | |||||||||||
| 28 | |||||||||||||
| 29 | 0 | ▶ | if (!$c->stash->{is_admin}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | 0 | $c->go('/error_404'); | |||||||||||
| 31 | 0 | return 0; | |||||||||||
| 32 | } | ||||||||||||
| 33 | 0 | else { return 1; } | |||||||||||
| 34 | 4 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | |||||||||||||
| 36 | 0 | ▶ | sub update_player_points : Global { | ||||||||||
|
Subroutine
update_player_points: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||
| 37 | 0 | my ($self, $c) = @_; | |||||||||||
| 38 | |||||||||||||
| 39 | 0 | $c->stash->{template} = 'player/all_home.tt'; | |||||||||||
| 40 | 0 | my @players = $c->model('DBIC::Player')->all; | |||||||||||
| 41 | |||||||||||||
| 42 | # Get player scores | ||||||||||||
| 43 | 0 | foreach my $player (@players) { | |||||||||||
| 44 | |||||||||||||
| 45 | # Avoid non active players | ||||||||||||
| 46 | 0 | ▶ | next if $player->active == 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | |||||||||||||
| 48 | # Get total points, and regional points | ||||||||||||
| 49 | 0 | my $points_ref = $c->forward('player_points', [ $player->id ]); | |||||||||||
| 50 | 0 | ▶ | $player->points($points_ref->[0] || 0); | ||||||||||
|
Condition0%0/2
$points_ref->[0] || 0
MC/DC0%0/1
$points_ref->[0] || 0
$points_ref->[0]
Truth table0%0/2
A
A= $points_ref->[0]
| |||||||||||||
| 51 | 0 | $player->update; | |||||||||||
| 52 | 0 | foreach my $region_id (1 .. 4) { | |||||||||||
| 53 | my $region_score = $c->model('DBIC::RegionScore')->update_or_create( | ||||||||||||
| 54 | { | ||||||||||||
| 55 | player => $player->id, | ||||||||||||
| 56 | region => $region_id, | ||||||||||||
| 57 | 0 | ▶ | points => $points_ref->[1]->{$region_id} || 0 | ||||||||||
|
Condition0%0/2
$points_ref->[1]{$region_id} || 0
MC/DC0%0/1
$points_ref->[1]{$region_id} || 0
$points_ref->[1]{$region_id}
Truth table0%0/2
A
A= $points_ref->[1]{$region_id}
| |||||||||||||
| 58 | } | ||||||||||||
| 59 | ); | ||||||||||||
| 60 | 0 | $region_score->update; | |||||||||||
| 61 | } | ||||||||||||
| 62 | } | ||||||||||||
| 63 | 0 | $c->stash->{players} = \@players; | |||||||||||
| 64 | 0 | $c->flash->{status_msg} = 'Scores Updated'; | |||||||||||
| 65 | 0 | $c->response->redirect($c->uri_for($c->controller('Player')->action_for('all'))); | |||||||||||
| 66 | 0 | return; | |||||||||||
| 67 | 4 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 68 | |||||||||||||
| 69 | 0 | ▶ | sub player_points : Private { | ||||||||||
|
Subroutine
player_points: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||
| 70 | 0 | my ($self, $c, $player) = @_; | |||||||||||
| 71 | |||||||||||||
| 72 | # Determine player total running score. | ||||||||||||
| 73 | 0 | my @player_picks = $c->model('DBIC::Pick')->search({ player => $player }); | |||||||||||
| 74 | 0 | my $total_player_points = 0; | |||||||||||
| 75 | 0 | my $points_for_region; | |||||||||||
| 76 | 0 | foreach my $player_pick (@player_picks) { | |||||||||||
| 77 | |||||||||||||
| 78 | # Compare player pick to actual winner for the perfect player bracket | ||||||||||||
| 79 | # Build the css class name accordingly | ||||||||||||
| 80 | 0 | my ($winning_pick) = | |||||||||||
| 81 | $c->model('DBIC::Pick')->search({ player => 1, game => $player_pick->game->id }); | ||||||||||||
| 82 | 0 | ▶ | if (defined $winning_pick) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | 0 | ▶ | if ($winning_pick->pick->id == $player_pick->pick->id) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | |||||||||||||
| 85 | # Compute points for correct pick | ||||||||||||
| 86 | # Formula | ||||||||||||
| 87 | 0 | my $points_for_pick = | |||||||||||
| 88 | (5 + $player_pick->pick->seed * $player_pick->game->lower_seed); | ||||||||||||
| 89 | |||||||||||||
| 90 | # Championship game has round multiplier of 10. | ||||||||||||
| 91 | 0 | ▶ | if ($player_pick->game->round == 6) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | 0 | $points_for_pick *= 10; | |||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | # All other games have round multiplier of round number. | ||||||||||||
| 96 | else { | ||||||||||||
| 97 | 0 | $points_for_pick *= $player_pick->game->round; | |||||||||||
| 98 | } | ||||||||||||
| 99 | 0 | $total_player_points += $points_for_pick; | |||||||||||
| 100 | 0 | $points_for_region->{ $player_pick->pick->region->id } += $points_for_pick; | |||||||||||
| 101 | } | ||||||||||||
| 102 | } | ||||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | 0 | return [ $total_player_points, $points_for_region ]; | |||||||||||
| 106 | 4 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 107 | |||||||||||||
| 108 | # Quality Assurance to check that lower seeds are marked correctly. | ||||||||||||
| 109 | 0 | ▶ | sub qa : Global { | ||||||||||
|
Subroutine
qa: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 110 | 0 | my ($self, $c) = @_; | |||||||||||
| 111 | 0 | my @played_games = $c->model('DBIC::Pick')->search({ player => 1 }, { order_by => 'game' }); | |||||||||||
| 112 | 0 | $c->stash->{played_games} = \@played_games; | |||||||||||
| 113 | 0 | $c->stash->{template} = 'admin/lower_seeds.tt'; | |||||||||||
| 114 | 4 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 115 | |||||||||||||
| 116 | 0 | ▶ | sub update_points : Global { | ||||||||||
|
Subroutine
update_points: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 117 | 0 | my ($self, $c) = @_; | |||||||||||
| 118 | 0 | my @points = $c->model('DBIC')->update_points; | |||||||||||
| 119 | 0 | $c->flash->{status_msg} = 'Scores Updated'; | |||||||||||
| 120 | 0 | $c->response->redirect($c->uri_for($c->controller('Player')->action_for('all'))); | |||||||||||
| 121 | 0 | return; | |||||||||||
| 122 | 4 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 123 | |||||||||||||
| 124 | =head2 round_out | ||||||||||||
| 125 | |||||||||||||
| 126 | Mark the round teams go out. | ||||||||||||
| 127 | |||||||||||||
| 128 | =cut | ||||||||||||
| 129 | |||||||||||||
| 130 | 0 | ▶ | sub round_out : Global : ActionClass('REST') { | ||||||||||
|
Subroutine
round_out: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 131 | 0 | my ($self, $c) = @_; | |||||||||||
| 132 | |||||||||||||
| 133 | 0 | $c->stash->{template} = 'admin/round_out.tt'; | |||||||||||
| 134 | 0 | my @teams = $c->model('DBIC::Team')->all; | |||||||||||
| 135 | 0 | $c->stash(teams => \@teams); | |||||||||||
| 136 | 4 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 137 | |||||||||||||
| 138 | 0 | ▶ | sub round_out_GET {} | ||||||||||
|
Subroutine
round_out_GET: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 139 | |||||||||||||
| 140 | 0 | ▶ | sub round_out_POST { | ||||||||||
|
Subroutine
round_out_POST: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 141 | 0 | my ($self, $c) = @_; | |||||||||||
| 142 | |||||||||||||
| 143 | 0 | foreach my $team (@{$c->stash->{teams}}) { | |||||||||||
| 144 | 0 | $team->update({ round_out => $c->request->body_parameters->{$team->id} }); | |||||||||||
| 145 | } | ||||||||||||
| 146 | } | ||||||||||||
| 147 | |||||||||||||
| 148 | =head2 round_out_unmarked | ||||||||||||
| 149 | |||||||||||||
| 150 | Show only the teams that havent' been marked out yet. | ||||||||||||
| 151 | |||||||||||||
| 152 | =cut | ||||||||||||
| 153 | |||||||||||||
| 154 | 0 | ▶ | sub round_out_unmarked : Global : ActionClass('REST') { | ||||||||||
|
Subroutine
round_out_unmarked: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 155 | 0 | my ($self, $c) = @_; | |||||||||||
| 156 | 0 | $c->stash->{template} = 'admin/round_out_unmarked.tt'; | |||||||||||
| 157 | 0 | my @teams = $c->model('DBIC::Team')->search({round_out => 7})->all; | |||||||||||
| 158 | 0 | $c->stash(teams => \@teams); | |||||||||||
| 159 | 4 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 160 | 0 | ▶ | sub round_out_unmarked_GET {} | ||||||||||
|
Subroutine
round_out_unmarked_GET: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 161 | |||||||||||||
| 162 | 0 | ▶ | sub round_out_unmarked_POST { | ||||||||||
|
Subroutine
round_out_unmarked_POST: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 163 | 0 | my ($self, $c) = @_; | |||||||||||
| 164 | |||||||||||||
| 165 | 0 | foreach my $team (@{$c->stash->{teams}}) { | |||||||||||
| 166 | 0 | $team->update({ round_out => $c->request->body_parameters->{$team->id} }); | |||||||||||
| 167 | } | ||||||||||||
| 168 | 0 | $c->response->redirect($c->uri_for($c->controller('Player')->action_for('home'))); | |||||||||||
| 169 | 0 | return; | |||||||||||
| 170 | } | ||||||||||||
| 171 | |||||||||||||
| 172 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 173 | 4 | 1 | |||||||||||