| 1 | package Bracket::Controller::Region; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 4 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | my $PERFECT_BRACKET_MODE = 1; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | Bracket::Controller::Region - Edit/View Regional picks | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub save_picks : Local { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_picks: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my ($self, $c, $region, $player_id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $player_object = $c->model('DBIC::Player')->find({ id => $player_id }); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my $player_name = $player_object->first_name . ' ' . $player_object->last_name; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $c->stash->{player_id} = $player_id; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | $c->stash->{player_name} = $player_name; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $region_object = $c->model('DBIC::Region')->find($region); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $region_name = $region_object->name; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | $c->stash->{region} = $region; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $c->stash->{region_name} = $region_name; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my $params = $c->request->params; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # Do database insert | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | foreach my $pgame (keys %{$params}) { | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $pgame =~ m{p(\d+)}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $game = $1; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $team = ${$params}{$pgame}; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my ($pick) = $c->model('DBIC::Pick')->search({ player => $player_id, game => $game }); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if (defined $pick) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $pick->pick($team); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $pick->update; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $new_pick = | |||||||||||||||||||||||||||||||||||||||||
| 43 | $c->model('DBIC::Pick')->new({ player => $player_id, game => $game, pick => $team }); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $new_pick->insert; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $c->stash->{params} = $params; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $previous_user_id = $c->session->{previous_user_id}; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $c->response->redirect( | |||||||||||||||||||||||||||||||||||||||||
| 51 | $c->uri_for($c->controller('Player')->action_for('home')) | ||||||||||||||||||||||||||||||||||||||||||
| 52 | . "/${player_id}" | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub view : Local { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my ($self, $c, $region_id, $player_id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my @perfect_picks = $c->model('DBIC::Pick')->search({ player => 1 }); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my @player_picks = $c->model('DBIC::Pick')->search({ player => $player_id }); | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my %picks; | |||||||||||||||||||||||||||||||||||||||||
| 65 | my %class_for; | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $region_points = 0; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my @show_regions; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | foreach my $player_pick (@player_picks) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # Operate only on the current region | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ($player_pick->pick->region->id == $region_id) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # Compare player pick to actual winner for the perfect player bracket | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # Build the css class name accordingly | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my ($winning_pick) = | |||||||||||||||||||||||||||||||||||||||||
| 76 | $c->model('DBIC::Pick')->search({ player => 1, game => $player_pick->game->id }); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if (defined $winning_pick) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($winning_pick->pick->id == $player_pick->pick->id) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $class_for{ $player_pick->game->id } = 'in'; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # Formula to compute points for correct picks | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $points_for_pick = | |||||||||||||||||||||||||||||||||||||||||
| 83 | (5 + $player_pick->pick->seed * $player_pick->game->lower_seed) * | ||||||||||||||||||||||||||||||||||||||||||
| 84 | $player_pick->game->round; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $region_points += $points_for_pick; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $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 | 0 | ▶ | if ($player_pick->game->round >= $player_pick->pick->round_out) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # warn "round greater than round out: ", | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # $player_pick->game->round, ' and ', | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # $player_pick->pick->round_out; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $class_for{ $player_pick->game->id } = 'out'; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $class_for{ $player_pick->game->id } = 'pending'; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $picks{ $player_pick->game->id } = $player_pick->pick; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $c->stash->{class_for} = \%class_for; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $c->stash->{picks} = \%picks; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $c->stash->{region_points} = $region_points; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $player = $c->model('DBIC::Player')->find($player_id); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $c->stash->{player} = $player; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $region = $c->model('DBIC::Region')->find($region_id); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $c->stash->{region} = $region; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $c->stash->{teams} = $c->model('DBIC::Team')->search({region => $region_id}); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $c->stash->{regions} = $c->model('DBIC::Region')->search({},{order_by => 'id'}); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $c->stash->{show_regions} = \@show_regions; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $c->stash->{template} = 'region/view_region_status.tt'; | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub edit : Local { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edit: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my ($self, $c, $region, $player) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | # Restrict edits to user or admin role. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my @user_roles = $c->user->roles; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $c->go('/error_404') if (($player != $c->user->id) && !('admin' eq any(@user_roles))); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$player != $c->user->id and not "admin" eq any(@user_roles)
MC/DC0%0/2
$player != $c->user->id and not "admin" eq any(@user_roles)
$player != $c->user->id
not "admin" eq any(@user_roles)
Truth table0%0/3
A and not(B)
A= $player != $c->user->idB= not "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 | 0 | my @open_edit_ids = qw/ /; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $edit_allowed = 1 if ($c->user->id eq any(@open_edit_ids)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ( $c->stash->{is_game_time} && (!($c->stash->{is_admin} || $edit_allowed)) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$c->stash->{"is_game_time"} and not $c->stash->{"is_admin"} || $edit_allowed
$c->stash->{'is_admin'} || $edit_allowed
MC/DC0%0/3
$c->stash->{"is_game_time"} and not $c->stash->{"is_admin"} || $edit_allowed
$c->stash->{"is_game_time"}
$c->stash->{'is_admin'}
$edit_allowed
Truth table0%0/4
A and not(B || C)
A= $c->stash->{"is_game_time"}B= $c->stash->{'is_admin'}C= $edit_allowed
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $c->flash->{status_msg} = 'Regional edits are closed'; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $c->response->redirect($c->uri_for($c->controller('Player')->action_for('home'))); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | # Player picks | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my @picks = $c->model('DBIC::Pick')->search({ player => $player }); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my %picks; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | foreach my $pick (@picks) { | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $picks{ $pick->game->id } = $pick->pick; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $c->stash->{picks} = \%picks; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | # Player info | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $player_object = $c->model('DBIC::Player')->find($player); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $player_name = $player_object->first_name . ' ' . $player_object->last_name; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $c->stash->{player} = $player; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $c->stash->{player_name} = $player_name; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | # Region object | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $region_object = $c->model('DBIC::Region')->find($region); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $region_name = $region_object->name; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $c->stash->{region} = $region; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $c->stash->{region_name} = $region_name; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | # Teams | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $c->stash->{teams} = $c->model('DBIC::Team')->search({region => $region}); | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $c->stash->{template} = 'region/edit_region_picks.tt'; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||