line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bracket::Controller::Region; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
36844
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BEGIN { extends 'Catalyst::Controller' } |
5
|
|
|
|
|
|
|
use Perl6::Junction qw/ any /; |
6
|
|
|
|
|
|
|
use DateTime; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $PERFECT_BRACKET_MODE = 1; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Bracket::Controller::Region - Edit/View Regional picks |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub save_picks : Local { |
18
|
|
|
|
|
|
|
my ($self, $c, $region, $player_id) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $player_object = $c->model('DBIC::Player')->find({ id => $player_id }); |
21
|
|
|
|
|
|
|
my $player_name = $player_object->first_name . ' ' . $player_object->last_name; |
22
|
|
|
|
|
|
|
$c->stash->{player_id} = $player_id; |
23
|
|
|
|
|
|
|
$c->stash->{player_name} = $player_name; |
24
|
|
|
|
|
|
|
my $region_object = $c->model('DBIC::Region')->find($region); |
25
|
|
|
|
|
|
|
my $region_name = $region_object->name; |
26
|
|
|
|
|
|
|
$c->stash->{region} = $region; |
27
|
|
|
|
|
|
|
$c->stash->{region_name} = $region_name; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $params = $c->request->params; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Do database insert |
32
|
|
|
|
|
|
|
foreach my $pgame (keys %{$params}) { |
33
|
|
|
|
|
|
|
$pgame =~ m{p(\d+)}; |
34
|
|
|
|
|
|
|
my $game = $1; |
35
|
|
|
|
|
|
|
my $team = ${$params}{$pgame}; |
36
|
|
|
|
|
|
|
my ($pick) = $c->model('DBIC::Pick')->search({ player => $player_id, game => $game }); |
37
|
|
|
|
|
|
|
if (defined $pick) { |
38
|
|
|
|
|
|
|
$pick->pick($team); |
39
|
|
|
|
|
|
|
$pick->update; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
|
|
|
|
|
|
my $new_pick = |
43
|
|
|
|
|
|
|
$c->model('DBIC::Pick')->new({ player => $player_id, game => $game, pick => $team }); |
44
|
|
|
|
|
|
|
$new_pick->insert; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$c->stash->{params} = $params; |
49
|
|
|
|
|
|
|
my $previous_user_id = $c->session->{previous_user_id}; |
50
|
|
|
|
|
|
|
$c->response->redirect( |
51
|
|
|
|
|
|
|
$c->uri_for($c->controller('Player')->action_for('home')) |
52
|
|
|
|
|
|
|
. "/${player_id}" |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub view : Local { |
59
|
|
|
|
|
|
|
my ($self, $c, $region_id, $player_id) = @_; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my @perfect_picks = $c->model('DBIC::Pick')->search({ player => 1 }); |
62
|
|
|
|
|
|
|
my @player_picks = $c->model('DBIC::Pick')->search({ player => $player_id }); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my %picks; |
65
|
|
|
|
|
|
|
my %class_for; |
66
|
|
|
|
|
|
|
my $region_points = 0; |
67
|
|
|
|
|
|
|
my @show_regions; |
68
|
|
|
|
|
|
|
foreach my $player_pick (@player_picks) { |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Operate only on the current region |
71
|
|
|
|
|
|
|
if ($player_pick->pick->region->id == $region_id) { |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Compare player pick to actual winner for the perfect player bracket |
74
|
|
|
|
|
|
|
# Build the css class name accordingly |
75
|
|
|
|
|
|
|
my ($winning_pick) = |
76
|
|
|
|
|
|
|
$c->model('DBIC::Pick')->search({ player => 1, game => $player_pick->game->id }); |
77
|
|
|
|
|
|
|
if (defined $winning_pick) { |
78
|
|
|
|
|
|
|
if ($winning_pick->pick->id == $player_pick->pick->id) { |
79
|
|
|
|
|
|
|
$class_for{ $player_pick->game->id } = 'in'; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Formula to compute points for correct picks |
82
|
|
|
|
|
|
|
my $points_for_pick = |
83
|
|
|
|
|
|
|
(5 + $player_pick->pick->seed * $player_pick->game->lower_seed) * |
84
|
|
|
|
|
|
|
$player_pick->game->round; |
85
|
|
|
|
|
|
|
$region_points += $points_for_pick; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
|
|
|
|
|
|
$class_for{ $player_pick->game->id } = 'out'; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Need to determine if player pick has already been ousted in a |
94
|
|
|
|
|
|
|
# previous round using round_out variable. |
95
|
|
|
|
|
|
|
if ($player_pick->game->round >= $player_pick->pick->round_out) { |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# warn "round greater than round out: ", |
98
|
|
|
|
|
|
|
# $player_pick->game->round, ' and ', |
99
|
|
|
|
|
|
|
# $player_pick->pick->round_out; |
100
|
|
|
|
|
|
|
$class_for{ $player_pick->game->id } = 'out'; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
|
|
|
|
|
|
$class_for{ $player_pick->game->id } = 'pending'; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
$picks{ $player_pick->game->id } = $player_pick->pick; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
$c->stash->{class_for} = \%class_for; |
110
|
|
|
|
|
|
|
$c->stash->{picks} = \%picks; |
111
|
|
|
|
|
|
|
$c->stash->{region_points} = $region_points; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $player = $c->model('DBIC::Player')->find($player_id); |
114
|
|
|
|
|
|
|
$c->stash->{player} = $player; |
115
|
|
|
|
|
|
|
my $region = $c->model('DBIC::Region')->find($region_id); |
116
|
|
|
|
|
|
|
$c->stash->{region} = $region; |
117
|
|
|
|
|
|
|
$c->stash->{teams} = $c->model('DBIC::Team')->search({region => $region_id}); |
118
|
|
|
|
|
|
|
$c->stash->{regions} = $c->model('DBIC::Region')->search({},{order_by => 'id'}); |
119
|
|
|
|
|
|
|
$c->stash->{show_regions} = \@show_regions; |
120
|
|
|
|
|
|
|
$c->stash->{template} = 'region/view_region_status.tt'; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
return; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub edit : Local { |
126
|
|
|
|
|
|
|
my ($self, $c, $region, $player) = @_; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Restrict edits to user or admin role. |
129
|
|
|
|
|
|
|
my @user_roles = $c->user->roles; |
130
|
|
|
|
|
|
|
$c->go('/error_404') if (($player != $c->user->id) && !('admin' eq any(@user_roles))); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Go to home if edits are attempted after closing time |
133
|
|
|
|
|
|
|
# NOTE: Put a player's id on this list and they can make edits after the cut-off. |
134
|
|
|
|
|
|
|
my @open_edit_ids = qw/ /; |
135
|
|
|
|
|
|
|
my $edit_allowed = 1 if ($c->user->id eq any(@open_edit_ids)); |
136
|
|
|
|
|
|
|
if ( $c->stash->{is_game_time} && (!($c->stash->{is_admin} || $edit_allowed)) ) { |
137
|
|
|
|
|
|
|
$c->flash->{status_msg} = 'Regional edits are closed'; |
138
|
|
|
|
|
|
|
$c->response->redirect($c->uri_for($c->controller('Player')->action_for('home'))); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Player picks |
142
|
|
|
|
|
|
|
my @picks = $c->model('DBIC::Pick')->search({ player => $player }); |
143
|
|
|
|
|
|
|
my %picks; |
144
|
|
|
|
|
|
|
foreach my $pick (@picks) { |
145
|
|
|
|
|
|
|
$picks{ $pick->game->id } = $pick->pick; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
$c->stash->{picks} = \%picks; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Player info |
150
|
|
|
|
|
|
|
my $player_object = $c->model('DBIC::Player')->find($player); |
151
|
|
|
|
|
|
|
my $player_name = $player_object->first_name . ' ' . $player_object->last_name; |
152
|
|
|
|
|
|
|
$c->stash->{player} = $player; |
153
|
|
|
|
|
|
|
$c->stash->{player_name} = $player_name; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Region object |
156
|
|
|
|
|
|
|
my $region_object = $c->model('DBIC::Region')->find($region); |
157
|
|
|
|
|
|
|
my $region_name = $region_object->name; |
158
|
|
|
|
|
|
|
$c->stash->{region} = $region; |
159
|
|
|
|
|
|
|
$c->stash->{region_name} = $region_name; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# Teams |
162
|
|
|
|
|
|
|
$c->stash->{teams} = $c->model('DBIC::Team')->search({region => $region}); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$c->stash->{template} = 'region/edit_region_picks.tt'; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
return; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 AUTHOR |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
mateu x hunter |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 LICENSE |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify |
177
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |