| 1 | package Bracket::Controller::Final4; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | BEGIN { extends 'Catalyst::Controller' } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Perl6::Junction qw/ any /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Data::Dumper::Concise; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | Bracket::Controller::Final4 - Edit/View Final 4 Picks | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =cut | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | my %region_winner_picks = ( | |||||||||||||||||||||||||||
| 14 | 1 => 15, | ||||||||||||||||||||||||||||
| 15 | 2 => 30, | ||||||||||||||||||||||||||||
| 16 | 3 => 45, | ||||||||||||||||||||||||||||
| 17 | 4 => 60, | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub make : Local { | ||||||||||||||||||||||||||
|
Subroutine
make: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 0 | my ($self, $c, $player_id) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # Restrict edits to user or admin role. | ||||||||||||||||||||||||||||
| 24 | 0 | my @user_roles = $c->user->roles; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | $c->go('/error_404') if (($player_id != $c->user->id) && !('admin' eq any(@user_roles))); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$player_id != $c->user->id and not "admin" eq any(@user_roles)
MC/DC0%0/2
$player_id != $c->user->id and not "admin" eq any(@user_roles)
$player_id != $c->user->id
not "admin" eq any(@user_roles)
Truth table0%0/3
A and not(B)
A= $player_id != $c->user->idB= not "admin" eq any(@user_roles)
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my $player = $c->model('DBIC::Player')->find($player_id); | |||||||||||||||||||||||||||
| 28 | 0 | $c->stash->{player} = $player; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Get the player's regional winner picks. Later we deal w/ whether they actually won or not. | ||||||||||||||||||||||||||||
| 31 | # region_id => game_id | ||||||||||||||||||||||||||||
| 32 | 0 | foreach my $region_id (keys %region_winner_picks) { | |||||||||||||||||||||||||||
| 33 | 0 | my $region_name = 'region' . "_${region_id}"; | |||||||||||||||||||||||||||
| 34 | 0 | my $game = $region_winner_picks{$region_id}; | |||||||||||||||||||||||||||
| 35 | 0 | $c->stash->{$region_name} = | |||||||||||||||||||||||||||
| 36 | $c->model('DBIC::Pick')->search({ player => $player_id, game => $game })->first; | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Get all player picks for loading when in edit of existing picks mode | ||||||||||||||||||||||||||||
| 40 | 0 | my @picks = $c->model('DBIC::Pick')->search({ player => $player_id }); | |||||||||||||||||||||||||||
| 41 | 0 | my %picks; | |||||||||||||||||||||||||||
| 42 | 0 | foreach my $pick (@picks) { | |||||||||||||||||||||||||||
| 43 | 0 | $picks{ $pick->game->id } = $pick->pick; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | $c->stash->{picks} = \%picks; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Create Class for Final Four Teams | ||||||||||||||||||||||||||||
| 48 | 0 | my %class_for; | |||||||||||||||||||||||||||
| 49 | 0 | foreach my $player_pick (@picks) { | |||||||||||||||||||||||||||
| 50 | 0 | my ($winning_pick) = | |||||||||||||||||||||||||||
| 51 | $c->model('DBIC::Pick')->search({ player => 1, game => $player_pick->game->id }); | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (defined $winning_pick) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($winning_pick->pick->id == $player_pick->pick->id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | $class_for{ $player_pick->game->id } = 'in'; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||
| 57 | 0 | $class_for{ $player_pick->game->id } = 'out'; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($player_pick->game->round >= $player_pick->pick->round_out) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | #if ($player_pick->game == 63) { | ||||||||||||||||||||||||||||
| 64 | # warn "round: " . $player_pick->game->round . "\n"; | ||||||||||||||||||||||||||||
| 65 | # warn "round_out: " . $player_pick->pick->round_out . "\n"; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | #} | ||||||||||||||||||||||||||||
| 68 | 0 | $class_for{ $player_pick->game->id } = 'out'; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||
| 71 | 0 | $class_for{ $player_pick->game->id } = 'pending'; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 0 | $c->stash->{class_for} = \%class_for; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Inform to load final 4 javascript | ||||||||||||||||||||||||||||
| 78 | 0 | $c->stash->{final_4_javascript} = 1; | |||||||||||||||||||||||||||
| 79 | 0 | $c->stash->{template} = 'final4/make_final4_picks.tt'; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | return; | |||||||||||||||||||||||||||
| 82 | 4 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub save_picks : Local { | ||||||||||||||||||||||||||
|
Subroutine
save_picks: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 0 | my ($self, $c, $player_id) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my $player = $c->model('DBIC::Player')->find($player_id); | |||||||||||||||||||||||||||
| 88 | 0 | $c->stash->{player} = $player; | |||||||||||||||||||||||||||
| 89 | 0 | $c->stash->{player_id} = $player_id; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $params = $c->request->params; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # Do database insert | ||||||||||||||||||||||||||||
| 94 | 0 | foreach my $pgame (keys %{$params}) { | |||||||||||||||||||||||||||
| 95 | 0 | $pgame =~ m{p(\d+)}; | |||||||||||||||||||||||||||
| 96 | 0 | my $game_id = $1; | |||||||||||||||||||||||||||
| 97 | 0 | my $team_id = ${$params}{$pgame}; | |||||||||||||||||||||||||||
| 98 | 0 | my ($pick) = $c->model('DBIC::Pick')->search({ player => $player_id, game => $game_id }); | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | if (defined $pick) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | $pick->pick($team_id); | |||||||||||||||||||||||||||
| 101 | 0 | $pick->update; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | else { | ||||||||||||||||||||||||||||
| 104 | 0 | my $new_pick = $c->model('DBIC::Pick')->new( | |||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | player => $player_id, | ||||||||||||||||||||||||||||
| 107 | game => $game_id, | ||||||||||||||||||||||||||||
| 108 | pick => $team_id | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||
| 111 | 0 | $new_pick->insert; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 0 | $c->stash->{params} = $params; | |||||||||||||||||||||||||||
| 115 | 0 | $c->response->redirect( | |||||||||||||||||||||||||||
| 116 | $c->uri_for($c->controller('Player')->action_for('home')) | ||||||||||||||||||||||||||||
| 117 | . "/${player_id}" | ||||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | return; | |||||||||||||||||||||||||||
| 121 | 4 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub view : Local { | ||||||||||||||||||||||||||
|
Subroutine
view: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 0 | my ($self, $c, $player_id) = @_; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | my $player = $c->model('DBIC::Player')->find($player_id); | |||||||||||||||||||||||||||
| 127 | 0 | $c->stash->{player} = $player; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # Get the player's regional winner picks. | ||||||||||||||||||||||||||||
| 130 | 0 | foreach my $region_id (keys %region_winner_picks) { | |||||||||||||||||||||||||||
| 131 | 0 | my $region_name = 'region' . "_${region_id}"; | |||||||||||||||||||||||||||
| 132 | 0 | my $game = $region_winner_picks{$region_id}; | |||||||||||||||||||||||||||
| 133 | 0 | $c->stash->{$region_name} = | |||||||||||||||||||||||||||
| 134 | $c->model('DBIC::Pick')->search({ player => $player_id, game => $game })->first; | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # Get all player picks for loading when in edit of existing picks mode | ||||||||||||||||||||||||||||
| 138 | 0 | my @picks = $c->model('DBIC::Pick')->search({ player => $player_id }); | |||||||||||||||||||||||||||
| 139 | 0 | my %picks; | |||||||||||||||||||||||||||
| 140 | 0 | foreach my $pick (@picks) { | |||||||||||||||||||||||||||
| 141 | 0 | $picks{ $pick->game->id } = $pick->pick; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 0 | $c->stash->{picks} = \%picks; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # Create Class for Final Four Teams | ||||||||||||||||||||||||||||
| 146 | 0 | my %class_for; | |||||||||||||||||||||||||||
| 147 | 0 | foreach my $player_pick (@picks) { | |||||||||||||||||||||||||||
| 148 | 0 | my ($winning_pick) = | |||||||||||||||||||||||||||
| 149 | $c->model('DBIC::Pick')->search({ player => 1, game => $player_pick->game->id }); | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (defined $winning_pick) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ($winning_pick->pick->id == $player_pick->pick->id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 0 | $class_for{ $player_pick->game->id } = 'in'; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | else { | ||||||||||||||||||||||||||||
| 155 | 0 | $class_for{ $player_pick->game->id } = 'out'; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | else { | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ($player_pick->game->round >= $player_pick->pick->round_out) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | $class_for{ $player_pick->game->id } = 'out'; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | else { | ||||||||||||||||||||||||||||
| 163 | 0 | $class_for{ $player_pick->game->id } = 'pending'; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 0 | $c->stash->{class_for} = \%class_for; | |||||||||||||||||||||||||||
| 168 | 0 | $c->stash->{regions} = $c->model('DBIC::Region')->search({},{order_by => 'id'}); | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | # Turn off javascript | ||||||||||||||||||||||||||||
| 171 | 0 | $c->stash->{no_javascript} = 1; | |||||||||||||||||||||||||||
| 172 | 0 | $c->stash->{template} = 'final4/view_final4_picks.tt'; | |||||||||||||||||||||||||||
| 173 | 0 | return; | |||||||||||||||||||||||||||
| 174 | 4 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | mateu x hunter | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | This library is free software, you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 183 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 4 | 1; | |||||||||||||||||||||||||||