@@ -13,118 +13,118 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class MatchResult extends DsManagerModel |
| 15 | 15 | {
|
| 16 | - /** |
|
| 17 | - * @var |
|
| 18 | - */ |
|
| 19 | - private $goalHome; |
|
| 20 | - /** |
|
| 21 | - * @var |
|
| 22 | - */ |
|
| 23 | - private $goalAway; |
|
| 24 | - /** |
|
| 25 | - * @var Team |
|
| 26 | - */ |
|
| 27 | - private $homeTeam; |
|
| 28 | - /** |
|
| 29 | - * @var Team |
|
| 30 | - */ |
|
| 31 | - private $awayTeam; |
|
| 16 | + /** |
|
| 17 | + * @var |
|
| 18 | + */ |
|
| 19 | + private $goalHome; |
|
| 20 | + /** |
|
| 21 | + * @var |
|
| 22 | + */ |
|
| 23 | + private $goalAway; |
|
| 24 | + /** |
|
| 25 | + * @var Team |
|
| 26 | + */ |
|
| 27 | + private $homeTeam; |
|
| 28 | + /** |
|
| 29 | + * @var Team |
|
| 30 | + */ |
|
| 31 | + private $awayTeam; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * MatchResult constructor. |
|
| 35 | - * @param $goalHome |
|
| 36 | - * @param $goalAway |
|
| 37 | - * @param Team $home |
|
| 38 | - * @param Team $away |
|
| 39 | - */ |
|
| 40 | - public function __construct($goalHome, $goalAway, Team $home, Team $away) |
|
| 41 | - {
|
|
| 42 | - $this->goalHome = $goalHome; |
|
| 43 | - $this->goalAway = $goalAway; |
|
| 44 | - $this->homeTeam = $home; |
|
| 45 | - $this->awayTeam = $away; |
|
| 46 | - } |
|
| 33 | + /** |
|
| 34 | + * MatchResult constructor. |
|
| 35 | + * @param $goalHome |
|
| 36 | + * @param $goalAway |
|
| 37 | + * @param Team $home |
|
| 38 | + * @param Team $away |
|
| 39 | + */ |
|
| 40 | + public function __construct($goalHome, $goalAway, Team $home, Team $away) |
|
| 41 | + {
|
|
| 42 | + $this->goalHome = $goalHome; |
|
| 43 | + $this->goalAway = $goalAway; |
|
| 44 | + $this->homeTeam = $home; |
|
| 45 | + $this->awayTeam = $away; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - public function getWinnerLoser() |
|
| 52 | - {
|
|
| 53 | - $isDraw = false; |
|
| 54 | - $winner = $this->awayTeam; |
|
| 55 | - $loser = $this->homeTeam; |
|
| 56 | - if ($this->goalAway == $this->goalHome) {
|
|
| 57 | - $isDraw = true; |
|
| 58 | - } else if ($this->goalHome < $this->goalAway) {
|
|
| 59 | - $winner = $this->awayTeam; |
|
| 60 | - $loser = $this->homeTeam; |
|
| 61 | - } |
|
| 62 | - return [ |
|
| 63 | - 'is_draw' => $isDraw, |
|
| 64 | - 'winner_id' => $winner->id, |
|
| 65 | - 'loser_id' => $loser->id |
|
| 66 | - ]; |
|
| 67 | - } |
|
| 48 | + /** |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + public function getWinnerLoser() |
|
| 52 | + {
|
|
| 53 | + $isDraw = false; |
|
| 54 | + $winner = $this->awayTeam; |
|
| 55 | + $loser = $this->homeTeam; |
|
| 56 | + if ($this->goalAway == $this->goalHome) {
|
|
| 57 | + $isDraw = true; |
|
| 58 | + } else if ($this->goalHome < $this->goalAway) {
|
|
| 59 | + $winner = $this->awayTeam; |
|
| 60 | + $loser = $this->homeTeam; |
|
| 61 | + } |
|
| 62 | + return [ |
|
| 63 | + 'is_draw' => $isDraw, |
|
| 64 | + 'winner_id' => $winner->id, |
|
| 65 | + 'loser_id' => $loser->id |
|
| 66 | + ]; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @return array |
|
| 71 | - */ |
|
| 72 | - public function toArray() |
|
| 73 | - {
|
|
| 74 | - $result = []; |
|
| 75 | - $result['home_team_id'] = $this->homeTeam->id; |
|
| 76 | - $result['away_team_id'] = $this->awayTeam->id; |
|
| 77 | - $result['goal_home'] = $this->goalHome; |
|
| 78 | - $result['goal_away'] = $this->goalAway; |
|
| 79 | - $result['info'] = $this->getWinnerLoser(); |
|
| 80 | - $result['info']['scorers'] = $this->getScorers(); |
|
| 81 | - $result['simulated'] = true; |
|
| 82 | - return $result; |
|
| 83 | - } |
|
| 84 | - /** |
|
| 85 | - * @return array |
|
| 86 | - */ |
|
| 87 | - private function getScorers() |
|
| 88 | - {
|
|
| 89 | - $scorers = [ |
|
| 90 | - 'home' => [], |
|
| 91 | - 'away' => [] |
|
| 92 | - ]; |
|
| 93 | - for ($i = 0; $i < $this->goalHome; $i++) {
|
|
| 94 | - $scorers['home'][] = $this->pickAScorer($this->homeTeam); |
|
| 95 | - } |
|
| 96 | - for ($i = 0; $i < $this->goalAway; $i++) {
|
|
| 97 | - $scorers['away'][] = $this->pickAScorer($this->awayTeam); |
|
| 98 | - } |
|
| 99 | - return $scorers; |
|
| 100 | - } |
|
| 69 | + /** |
|
| 70 | + * @return array |
|
| 71 | + */ |
|
| 72 | + public function toArray() |
|
| 73 | + {
|
|
| 74 | + $result = []; |
|
| 75 | + $result['home_team_id'] = $this->homeTeam->id; |
|
| 76 | + $result['away_team_id'] = $this->awayTeam->id; |
|
| 77 | + $result['goal_home'] = $this->goalHome; |
|
| 78 | + $result['goal_away'] = $this->goalAway; |
|
| 79 | + $result['info'] = $this->getWinnerLoser(); |
|
| 80 | + $result['info']['scorers'] = $this->getScorers(); |
|
| 81 | + $result['simulated'] = true; |
|
| 82 | + return $result; |
|
| 83 | + } |
|
| 84 | + /** |
|
| 85 | + * @return array |
|
| 86 | + */ |
|
| 87 | + private function getScorers() |
|
| 88 | + {
|
|
| 89 | + $scorers = [ |
|
| 90 | + 'home' => [], |
|
| 91 | + 'away' => [] |
|
| 92 | + ]; |
|
| 93 | + for ($i = 0; $i < $this->goalHome; $i++) {
|
|
| 94 | + $scorers['home'][] = $this->pickAScorer($this->homeTeam); |
|
| 95 | + } |
|
| 96 | + for ($i = 0; $i < $this->goalAway; $i++) {
|
|
| 97 | + $scorers['away'][] = $this->pickAScorer($this->awayTeam); |
|
| 98 | + } |
|
| 99 | + return $scorers; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * @param Team $team |
|
| 104 | - * @return Player |
|
| 105 | - */ |
|
| 106 | - private function pickAScorer(Team $team) |
|
| 107 | - {
|
|
| 108 | - $player = null; |
|
| 109 | - if (Randomizer::boolOnPercentage(70)) {
|
|
| 110 | - $roles = Config::get('modules.roles');
|
|
| 111 | - $forwards = array_splice($roles, count($roles) / 2); |
|
| 112 | - $pos = array_rand($forwards); |
|
| 113 | - unset($forwards[$pos]); |
|
| 114 | - $player = $team->getBestPlayerForRole($pos); |
|
| 115 | - while (empty($player)) {
|
|
| 116 | - if (!empty($forwards)) {
|
|
| 117 | - $pos = array_rand($forwards); |
|
| 118 | - unset($forwards[$pos]); |
|
| 119 | - $player = $team->getBestPlayerForRole($pos); |
|
| 120 | - } else {
|
|
| 121 | - $player = $team->roster[array_rand($team->roster)]; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } else {
|
|
| 125 | - $player = $team->roster[array_rand($team->roster)]; |
|
| 126 | - } |
|
| 127 | - return $player; |
|
| 128 | - } |
|
| 102 | + /** |
|
| 103 | + * @param Team $team |
|
| 104 | + * @return Player |
|
| 105 | + */ |
|
| 106 | + private function pickAScorer(Team $team) |
|
| 107 | + {
|
|
| 108 | + $player = null; |
|
| 109 | + if (Randomizer::boolOnPercentage(70)) {
|
|
| 110 | + $roles = Config::get('modules.roles');
|
|
| 111 | + $forwards = array_splice($roles, count($roles) / 2); |
|
| 112 | + $pos = array_rand($forwards); |
|
| 113 | + unset($forwards[$pos]); |
|
| 114 | + $player = $team->getBestPlayerForRole($pos); |
|
| 115 | + while (empty($player)) {
|
|
| 116 | + if (!empty($forwards)) {
|
|
| 117 | + $pos = array_rand($forwards); |
|
| 118 | + unset($forwards[$pos]); |
|
| 119 | + $player = $team->getBestPlayerForRole($pos); |
|
| 120 | + } else {
|
|
| 121 | + $player = $team->roster[array_rand($team->roster)]; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } else {
|
|
| 125 | + $player = $team->roster[array_rand($team->roster)]; |
|
| 126 | + } |
|
| 127 | + return $player; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | } |
| 131 | 131 | \ No newline at end of file |
@@ -10,22 +10,22 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Randomizer |
| 12 | 12 | {
|
| 13 | - /** |
|
| 14 | - * @param $percentage |
|
| 15 | - * @return bool |
|
| 16 | - */ |
|
| 17 | - public static function boolOnPercentage($percentage) |
|
| 18 | - {
|
|
| 19 | - return (rand(0, 100) < $percentage); |
|
| 20 | - } |
|
| 13 | + /** |
|
| 14 | + * @param $percentage |
|
| 15 | + * @return bool |
|
| 16 | + */ |
|
| 17 | + public static function boolOnPercentage($percentage) |
|
| 18 | + {
|
|
| 19 | + return (rand(0, 100) < $percentage); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param $skill |
|
| 24 | - * @return int |
|
| 25 | - */ |
|
| 26 | - public static function voteFromSkill($skill) |
|
| 27 | - {
|
|
| 28 | - return rand((2 * ($skill - 100) / 25), 10); |
|
| 29 | - } |
|
| 22 | + /** |
|
| 23 | + * @param $skill |
|
| 24 | + * @return int |
|
| 25 | + */ |
|
| 26 | + public static function voteFromSkill($skill) |
|
| 27 | + {
|
|
| 28 | + return rand((2 * ($skill - 100) / 25), 10); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | } |
| 32 | 32 | \ No newline at end of file |
@@ -9,70 +9,70 @@ |
||
| 9 | 9 | class Player extends DsManagerOrm |
| 10 | 10 | {
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $table = 'players'; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $table = 'players'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected $fillable = [ |
|
| 21 | - 'name', |
|
| 22 | - 'surname', |
|
| 23 | - 'age', |
|
| 24 | - 'nationality', |
|
| 25 | - 'skillAvg', |
|
| 26 | - 'wageReq', |
|
| 27 | - 'val', |
|
| 28 | - 'role', |
|
| 29 | - 'team_id' |
|
| 30 | - ]; |
|
| 17 | + /** |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected $fillable = [ |
|
| 21 | + 'name', |
|
| 22 | + 'surname', |
|
| 23 | + 'age', |
|
| 24 | + 'nationality', |
|
| 25 | + 'skillAvg', |
|
| 26 | + 'wageReq', |
|
| 27 | + 'val', |
|
| 28 | + 'role', |
|
| 29 | + 'team_id' |
|
| 30 | + ]; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 34 | - */ |
|
| 35 | - public function team() |
|
| 36 | - {
|
|
| 37 | - return $this->belongsTo(Team::class); |
|
| 38 | - } |
|
| 32 | + /** |
|
| 33 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 34 | + */ |
|
| 35 | + public function team() |
|
| 36 | + {
|
|
| 37 | + return $this->belongsTo(Team::class); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function lastMatches() |
|
| 41 | - {
|
|
| 42 | - return $this->hasMany(MatchPlayer::class) |
|
| 43 | - ->orderBy('updated_at', 'DESC')
|
|
| 44 | - ->limit(5); |
|
| 45 | - } |
|
| 40 | + public function lastMatches() |
|
| 41 | + {
|
|
| 42 | + return $this->hasMany(MatchPlayer::class) |
|
| 43 | + ->orderBy('updated_at', 'DESC')
|
|
| 44 | + ->limit(5); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function goals() |
|
| 48 | - {
|
|
| 49 | - return $this->hasOne(MatchPlayer::class) |
|
| 50 | - ->selectRaw('player_id, sum(goals) as count')
|
|
| 51 | - ->groupBy('player_id');
|
|
| 52 | - } |
|
| 47 | + public function goals() |
|
| 48 | + {
|
|
| 49 | + return $this->hasOne(MatchPlayer::class) |
|
| 50 | + ->selectRaw('player_id, sum(goals) as count')
|
|
| 51 | + ->groupBy('player_id');
|
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function appearances() |
|
| 55 | - {
|
|
| 56 | - return $this->hasOne(MatchPlayer::class) |
|
| 57 | - ->selectRaw('player_id, count(match_id) as count')
|
|
| 58 | - ->groupBy('player_id');
|
|
| 59 | - } |
|
| 54 | + public function appearances() |
|
| 55 | + {
|
|
| 56 | + return $this->hasOne(MatchPlayer::class) |
|
| 57 | + ->selectRaw('player_id, count(match_id) as count')
|
|
| 58 | + ->groupBy('player_id');
|
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function avg() |
|
| 62 | - {
|
|
| 63 | - return $this->hasOne(MatchPlayer::class) |
|
| 64 | - ->selectRaw('player_id, round(avg(vote),2) as avg')
|
|
| 65 | - ->groupBy('player_id');
|
|
| 66 | - } |
|
| 61 | + public function avg() |
|
| 62 | + {
|
|
| 63 | + return $this->hasOne(MatchPlayer::class) |
|
| 64 | + ->selectRaw('player_id, round(avg(vote),2) as avg')
|
|
| 65 | + ->groupBy('player_id');
|
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function scopeStatistics($query) |
|
| 69 | - {
|
|
| 70 | - return $query->with( |
|
| 71 | - 'goals', |
|
| 72 | - 'appearances', |
|
| 73 | - 'avg', |
|
| 74 | - 'lastMatches', |
|
| 75 | - 'team' |
|
| 76 | - ); |
|
| 77 | - } |
|
| 68 | + public function scopeStatistics($query) |
|
| 69 | + {
|
|
| 70 | + return $query->with( |
|
| 71 | + 'goals', |
|
| 72 | + 'appearances', |
|
| 73 | + 'avg', |
|
| 74 | + 'lastMatches', |
|
| 75 | + 'team' |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | \ No newline at end of file |
@@ -3,20 +3,20 @@ |
||
| 3 | 3 | |
| 4 | 4 | class ATeamsSeeder |
| 5 | 5 | { |
| 6 | - function run() |
|
| 7 | - { |
|
| 8 | - $teamNumber = 16; |
|
| 9 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
| 10 | - for ($i = 1; $i <= $teamNumber; $i++) { |
|
| 11 | - $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
| 12 | - $teamArray = $team->toArray(); |
|
| 13 | - $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
| 14 | - foreach ($teamArray['roster'] as $player) { |
|
| 15 | - $player['team_id'] = $teamO->id; |
|
| 16 | - \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
| 17 | - } |
|
| 18 | - $teamArray['coach']['team_id'] = $teamO->id; |
|
| 19 | - \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
| 20 | - } |
|
| 21 | - } |
|
| 6 | + function run() |
|
| 7 | + { |
|
| 8 | + $teamNumber = 16; |
|
| 9 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
| 10 | + for ($i = 1; $i <= $teamNumber; $i++) { |
|
| 11 | + $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
| 12 | + $teamArray = $team->toArray(); |
|
| 13 | + $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
| 14 | + foreach ($teamArray['roster'] as $player) { |
|
| 15 | + $player['team_id'] = $teamO->id; |
|
| 16 | + \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
| 17 | + } |
|
| 18 | + $teamArray['coach']['team_id'] = $teamO->id; |
|
| 19 | + \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | \ No newline at end of file |
@@ -9,46 +9,46 @@ |
||
| 9 | 9 | |
| 10 | 10 | class A001LeaguesSeeder |
| 11 | 11 | { |
| 12 | - function run() |
|
| 13 | - { |
|
| 14 | - $leagues = [ |
|
| 15 | - 'friendly' => 16, |
|
| 16 | - 'europa league' => 8 |
|
| 17 | - ]; |
|
| 18 | - $teams = Team::all()->toArray(); |
|
| 19 | - foreach ($leagues as $league => $teamsNum) { |
|
| 12 | + function run() |
|
| 13 | + { |
|
| 14 | + $leagues = [ |
|
| 15 | + 'friendly' => 16, |
|
| 16 | + 'europa league' => 8 |
|
| 17 | + ]; |
|
| 18 | + $teams = Team::all()->toArray(); |
|
| 19 | + foreach ($leagues as $league => $teamsNum) { |
|
| 20 | 20 | |
| 21 | - $teamCopy = $teams; |
|
| 22 | - $league = League::create( |
|
| 23 | - [ |
|
| 24 | - 'name' => $league, |
|
| 25 | - 'teams' => $teamsNum |
|
| 26 | - ] |
|
| 27 | - ); |
|
| 21 | + $teamCopy = $teams; |
|
| 22 | + $league = League::create( |
|
| 23 | + [ |
|
| 24 | + 'name' => $league, |
|
| 25 | + 'teams' => $teamsNum |
|
| 26 | + ] |
|
| 27 | + ); |
|
| 28 | 28 | |
| 29 | - //Create Rounds |
|
| 30 | - shuffle($teamCopy); |
|
| 31 | - $teamCopy = array_splice($teamCopy, 0, $teamsNum); |
|
| 32 | - $rounds = LeagueFixtureGenerator::generate($teamCopy); |
|
| 33 | - foreach ($rounds as $i => $round) { |
|
| 29 | + //Create Rounds |
|
| 30 | + shuffle($teamCopy); |
|
| 31 | + $teamCopy = array_splice($teamCopy, 0, $teamsNum); |
|
| 32 | + $rounds = LeagueFixtureGenerator::generate($teamCopy); |
|
| 33 | + foreach ($rounds as $i => $round) { |
|
| 34 | 34 | |
| 35 | - $leagueRound = LeagueRound::create( |
|
| 36 | - [ |
|
| 37 | - 'league_id' => $league->id, |
|
| 38 | - 'day' => $i + 1 |
|
| 39 | - ] |
|
| 40 | - ); |
|
| 35 | + $leagueRound = LeagueRound::create( |
|
| 36 | + [ |
|
| 37 | + 'league_id' => $league->id, |
|
| 38 | + 'day' => $i + 1 |
|
| 39 | + ] |
|
| 40 | + ); |
|
| 41 | 41 | |
| 42 | - foreach ($round as $match) { |
|
| 43 | - $newMatch = Match::create( |
|
| 44 | - [ |
|
| 45 | - 'home_team_id' => $match['home_team_id'], |
|
| 46 | - 'away_team_id' => $match['away_team_id'], |
|
| 47 | - 'league_round_id' => $leagueRound->id |
|
| 48 | - ] |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - } |
|
| 42 | + foreach ($round as $match) { |
|
| 43 | + $newMatch = Match::create( |
|
| 44 | + [ |
|
| 45 | + 'home_team_id' => $match['home_team_id'], |
|
| 46 | + 'away_team_id' => $match['away_team_id'], |
|
| 47 | + 'league_round_id' => $leagueRound->id |
|
| 48 | + ] |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | } |
| 55 | 55 | \ No newline at end of file |
@@ -5,19 +5,19 @@ |
||
| 5 | 5 | |
| 6 | 6 | class CreateLeaguesTable |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Run the migrations. |
|
| 10 | - * |
|
| 11 | - * @return void |
|
| 12 | - */ |
|
| 13 | - public function run() |
|
| 14 | - { |
|
| 15 | - Capsule::schema()->dropIfExists('leagues'); |
|
| 16 | - Capsule::schema()->create('leagues', function (Blueprint $table) { |
|
| 17 | - $table->increments('id'); |
|
| 18 | - $table->string('name'); |
|
| 19 | - $table->unsignedTinyInteger('teams')->default(2); |
|
| 20 | - $table->timestamps(); |
|
| 21 | - }); |
|
| 22 | - } |
|
| 8 | + /** |
|
| 9 | + * Run the migrations. |
|
| 10 | + * |
|
| 11 | + * @return void |
|
| 12 | + */ |
|
| 13 | + public function run() |
|
| 14 | + { |
|
| 15 | + Capsule::schema()->dropIfExists('leagues'); |
|
| 16 | + Capsule::schema()->create('leagues', function (Blueprint $table) { |
|
| 17 | + $table->increments('id'); |
|
| 18 | + $table->string('name'); |
|
| 19 | + $table->unsignedTinyInteger('teams')->default(2); |
|
| 20 | + $table->timestamps(); |
|
| 21 | + }); |
|
| 22 | + } |
|
| 23 | 23 | } |
@@ -8,24 +8,24 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class League extends DsManagerOrm |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 14 | - protected $table = 'leagues'; |
|
| 11 | + /** |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | + protected $table = 'leagues'; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - protected $fillable = [ |
|
| 20 | - 'name', |
|
| 21 | - 'teams' |
|
| 22 | - ]; |
|
| 16 | + /** |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + protected $fillable = [ |
|
| 20 | + 'name', |
|
| 21 | + 'teams' |
|
| 22 | + ]; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 26 | - */ |
|
| 27 | - public function rounds() |
|
| 28 | - { |
|
| 29 | - return $this->hasMany(LeagueRound::class); |
|
| 30 | - } |
|
| 24 | + /** |
|
| 25 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 26 | + */ |
|
| 27 | + public function rounds() |
|
| 28 | + { |
|
| 29 | + return $this->hasMany(LeagueRound::class); |
|
| 30 | + } |
|
| 31 | 31 | } |
| 32 | 32 | \ No newline at end of file |
@@ -5,28 +5,28 @@ |
||
| 5 | 5 | |
| 6 | 6 | class LeagueFixtureGenerator |
| 7 | 7 | { |
| 8 | - public static function generate(array $teams) |
|
| 9 | - { |
|
| 10 | - $numTeams = count($teams); |
|
| 11 | - $numRounds = ($numTeams - 1); |
|
| 12 | - $halfSize = $numTeams / 2; |
|
| 8 | + public static function generate(array $teams) |
|
| 9 | + { |
|
| 10 | + $numTeams = count($teams); |
|
| 11 | + $numRounds = ($numTeams - 1); |
|
| 12 | + $halfSize = $numTeams / 2; |
|
| 13 | 13 | |
| 14 | - $away = array_splice($teams, $halfSize); |
|
| 15 | - $home = $teams; |
|
| 16 | - $rounds = []; |
|
| 17 | - for ($i = 0; $i < $numRounds; $i++) { |
|
| 18 | - $homeCount = count($home); |
|
| 19 | - for ($j = 0; $j < $homeCount; $j++) { |
|
| 20 | - $rounds[$i][$j]["home_team_id"] = $home[$j]['id']; |
|
| 21 | - $rounds[$i][$j]["away_team_id"] = $away[$j]['id']; |
|
| 22 | - } |
|
| 23 | - if (count($home) + count($away) - 1 > 2) { |
|
| 24 | - $spliced = array_splice($home, 1, 1); |
|
| 25 | - $shifted = array_shift($spliced); |
|
| 26 | - array_unshift($away, $shifted); |
|
| 27 | - array_push($home, array_pop($away)); |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - return $rounds; |
|
| 31 | - } |
|
| 14 | + $away = array_splice($teams, $halfSize); |
|
| 15 | + $home = $teams; |
|
| 16 | + $rounds = []; |
|
| 17 | + for ($i = 0; $i < $numRounds; $i++) { |
|
| 18 | + $homeCount = count($home); |
|
| 19 | + for ($j = 0; $j < $homeCount; $j++) { |
|
| 20 | + $rounds[$i][$j]["home_team_id"] = $home[$j]['id']; |
|
| 21 | + $rounds[$i][$j]["away_team_id"] = $away[$j]['id']; |
|
| 22 | + } |
|
| 23 | + if (count($home) + count($away) - 1 > 2) { |
|
| 24 | + $spliced = array_splice($home, 1, 1); |
|
| 25 | + $shifted = array_shift($spliced); |
|
| 26 | + array_unshift($away, $shifted); |
|
| 27 | + array_push($home, array_pop($away)); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + return $rounds; |
|
| 31 | + } |
|
| 32 | 32 | } |
| 33 | 33 | \ No newline at end of file |
@@ -5,24 +5,24 @@ |
||
| 5 | 5 | |
| 6 | 6 | class CreateLeagueTeamsTable |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Run the migrations. |
|
| 10 | - * |
|
| 11 | - * @return void |
|
| 12 | - */ |
|
| 13 | - public function run() |
|
| 14 | - { |
|
| 15 | - Capsule::schema()->dropIfExists('league_teams'); |
|
| 16 | - Capsule::schema()->create('league_teams', function (Blueprint $table) { |
|
| 17 | - $table->increments('id'); |
|
| 18 | - $table->integer('league_id'); |
|
| 19 | - $table->integer('team_id'); |
|
| 20 | - $table->unsignedTinyInteger('points')->default(0); |
|
| 21 | - $table->unsignedTinyInteger('played')->default(0); |
|
| 22 | - $table->unsignedTinyInteger('won')->default(0); |
|
| 23 | - $table->unsignedTinyInteger('draw')->default(0); |
|
| 24 | - $table->unsignedTinyInteger('lost')->default(0); |
|
| 25 | - $table->timestamps(); |
|
| 26 | - }); |
|
| 27 | - } |
|
| 8 | + /** |
|
| 9 | + * Run the migrations. |
|
| 10 | + * |
|
| 11 | + * @return void |
|
| 12 | + */ |
|
| 13 | + public function run() |
|
| 14 | + { |
|
| 15 | + Capsule::schema()->dropIfExists('league_teams'); |
|
| 16 | + Capsule::schema()->create('league_teams', function (Blueprint $table) { |
|
| 17 | + $table->increments('id'); |
|
| 18 | + $table->integer('league_id'); |
|
| 19 | + $table->integer('team_id'); |
|
| 20 | + $table->unsignedTinyInteger('points')->default(0); |
|
| 21 | + $table->unsignedTinyInteger('played')->default(0); |
|
| 22 | + $table->unsignedTinyInteger('won')->default(0); |
|
| 23 | + $table->unsignedTinyInteger('draw')->default(0); |
|
| 24 | + $table->unsignedTinyInteger('lost')->default(0); |
|
| 25 | + $table->timestamps(); |
|
| 26 | + }); |
|
| 27 | + } |
|
| 28 | 28 | } |