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