@@ -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 | } |
@@ -8,74 +8,74 @@ |
||
| 8 | 8 | { |
| 9 | 9 | |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @group Helpers |
|
| 13 | - * @group FixtureGenerator |
|
| 14 | - * @group generatefixture |
|
| 15 | - */ |
|
| 16 | - public function testFixtureGenerator() |
|
| 17 | - { |
|
| 18 | - $teams = \App\Lib\DsManager\Models\Orm\Team::all(); |
|
| 19 | - $rounds = \App\Lib\DsManager\Helpers\LeagueFixtureGenerator::generate( |
|
| 20 | - $teams->toArray() |
|
| 21 | - ); |
|
| 22 | - //Number of rounds |
|
| 23 | - $this->assertCount($teams->count() - 1, $rounds); |
|
| 24 | - //Matches for each round |
|
| 25 | - foreach ($rounds as $round) { |
|
| 26 | - $this->assertCount($teams->count() / 2, $round); |
|
| 27 | - } |
|
| 28 | - } |
|
| 11 | + /** |
|
| 12 | + * @group Helpers |
|
| 13 | + * @group FixtureGenerator |
|
| 14 | + * @group generatefixture |
|
| 15 | + */ |
|
| 16 | + public function testFixtureGenerator() |
|
| 17 | + { |
|
| 18 | + $teams = \App\Lib\DsManager\Models\Orm\Team::all(); |
|
| 19 | + $rounds = \App\Lib\DsManager\Helpers\LeagueFixtureGenerator::generate( |
|
| 20 | + $teams->toArray() |
|
| 21 | + ); |
|
| 22 | + //Number of rounds |
|
| 23 | + $this->assertCount($teams->count() - 1, $rounds); |
|
| 24 | + //Matches for each round |
|
| 25 | + foreach ($rounds as $round) { |
|
| 26 | + $this->assertCount($teams->count() / 2, $round); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @group Helpers |
|
| 32 | - * @group MatchSimulator |
|
| 33 | - */ |
|
| 34 | - public function testMatchSimulator() |
|
| 35 | - { |
|
| 36 | - $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
| 37 | - [ |
|
| 38 | - 'simulated' => false |
|
| 39 | - ] |
|
| 40 | - )->get()->random(1); |
|
| 41 | - $this->assertNotEmpty($match); |
|
| 42 | - $result = \App\Lib\DsManager\Helpers\MatchSimulator::simulateCompleteResult($match->id); |
|
| 43 | - $this->assertNotEmpty($result); |
|
| 44 | - $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
| 45 | - [ |
|
| 46 | - 'id' => $match->id, |
|
| 47 | - 'simulated' => true |
|
| 48 | - ] |
|
| 49 | - )->first(); |
|
| 50 | - $this->assertNotEmpty($match); |
|
| 51 | - } |
|
| 30 | + /** |
|
| 31 | + * @group Helpers |
|
| 32 | + * @group MatchSimulator |
|
| 33 | + */ |
|
| 34 | + public function testMatchSimulator() |
|
| 35 | + { |
|
| 36 | + $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
| 37 | + [ |
|
| 38 | + 'simulated' => false |
|
| 39 | + ] |
|
| 40 | + )->get()->random(1); |
|
| 41 | + $this->assertNotEmpty($match); |
|
| 42 | + $result = \App\Lib\DsManager\Helpers\MatchSimulator::simulateCompleteResult($match->id); |
|
| 43 | + $this->assertNotEmpty($result); |
|
| 44 | + $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
| 45 | + [ |
|
| 46 | + 'id' => $match->id, |
|
| 47 | + 'simulated' => true |
|
| 48 | + ] |
|
| 49 | + )->first(); |
|
| 50 | + $this->assertNotEmpty($match); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @group Helpers |
|
| 55 | - * @group RoundSimulator |
|
| 56 | - */ |
|
| 57 | - public function testRoundSimulator() |
|
| 58 | - { |
|
| 59 | - $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
| 60 | - [ |
|
| 61 | - 'simulated' => false |
|
| 62 | - ] |
|
| 63 | - )->whereNotNull( |
|
| 64 | - 'league_round_id' |
|
| 65 | - )->get()->random(1); |
|
| 66 | - $this->assertNotEmpty($match); |
|
| 67 | - $result = \App\Lib\DsManager\Helpers\MatchSimulator::simulateRound($match->league_round_id); |
|
| 68 | - $this->assertNotEmpty($result); |
|
| 69 | - $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
| 70 | - [ |
|
| 71 | - 'id' => $match->id, |
|
| 72 | - 'simulated' => true |
|
| 73 | - ] |
|
| 74 | - )->first(); |
|
| 75 | - $this->assertNotEmpty($match); |
|
| 76 | - $round = \App\Lib\DsManager\Models\Orm\LeagueRound::find($match->league_round_id); |
|
| 77 | - $this->assertNotEmpty($round); |
|
| 78 | - $this->assertTrue($round->simulated); |
|
| 79 | - } |
|
| 53 | + /** |
|
| 54 | + * @group Helpers |
|
| 55 | + * @group RoundSimulator |
|
| 56 | + */ |
|
| 57 | + public function testRoundSimulator() |
|
| 58 | + { |
|
| 59 | + $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
| 60 | + [ |
|
| 61 | + 'simulated' => false |
|
| 62 | + ] |
|
| 63 | + )->whereNotNull( |
|
| 64 | + 'league_round_id' |
|
| 65 | + )->get()->random(1); |
|
| 66 | + $this->assertNotEmpty($match); |
|
| 67 | + $result = \App\Lib\DsManager\Helpers\MatchSimulator::simulateRound($match->league_round_id); |
|
| 68 | + $this->assertNotEmpty($result); |
|
| 69 | + $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
| 70 | + [ |
|
| 71 | + 'id' => $match->id, |
|
| 72 | + 'simulated' => true |
|
| 73 | + ] |
|
| 74 | + )->first(); |
|
| 75 | + $this->assertNotEmpty($match); |
|
| 76 | + $round = \App\Lib\DsManager\Models\Orm\LeagueRound::find($match->league_round_id); |
|
| 77 | + $this->assertNotEmpty($round); |
|
| 78 | + $this->assertTrue($round->simulated); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | } |
@@ -5,20 +5,20 @@ |
||
| 5 | 5 | |
| 6 | 6 | class CreateLeagueRoundsTable |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Run the migrations. |
|
| 10 | - * |
|
| 11 | - * @return void |
|
| 12 | - */ |
|
| 13 | - public function run() |
|
| 14 | - { |
|
| 15 | - Capsule::schema()->dropIfExists('league_rounds'); |
|
| 16 | - Capsule::schema()->create('league_rounds', function (Blueprint $table) { |
|
| 17 | - $table->increments('id'); |
|
| 18 | - $table->integer('league_id'); |
|
| 19 | - $table->boolean('simulated')->default(false); |
|
| 20 | - $table->integer('day')->default(0); |
|
| 21 | - $table->timestamps(); |
|
| 22 | - }); |
|
| 23 | - } |
|
| 8 | + /** |
|
| 9 | + * Run the migrations. |
|
| 10 | + * |
|
| 11 | + * @return void |
|
| 12 | + */ |
|
| 13 | + public function run() |
|
| 14 | + { |
|
| 15 | + Capsule::schema()->dropIfExists('league_rounds'); |
|
| 16 | + Capsule::schema()->create('league_rounds', function (Blueprint $table) { |
|
| 17 | + $table->increments('id'); |
|
| 18 | + $table->integer('league_id'); |
|
| 19 | + $table->boolean('simulated')->default(false); |
|
| 20 | + $table->integer('day')->default(0); |
|
| 21 | + $table->timestamps(); |
|
| 22 | + }); |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -9,54 +9,54 @@ |
||
| 9 | 9 | class LeagueRound extends DsManagerOrm |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $table = 'league_rounds'; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected $fillable = [ |
|
| 21 | - 'league_id', |
|
| 22 | - 'day', |
|
| 23 | - 'simulated' |
|
| 24 | - ]; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $casts = [ |
|
| 30 | - 'simulated' => 'boolean' |
|
| 31 | - ]; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return \Illuminate\Database\Eloquent\Relations\HasOne |
|
| 35 | - */ |
|
| 36 | - public function league() |
|
| 37 | - { |
|
| 38 | - return $this->belongsTo(League::class); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 43 | - */ |
|
| 44 | - public function matches() |
|
| 45 | - { |
|
| 46 | - return $this->hasMany(Match::class); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param $query |
|
| 51 | - * @return mixed |
|
| 52 | - */ |
|
| 53 | - public function scopeComplete($query) |
|
| 54 | - { |
|
| 55 | - return $query->with( |
|
| 56 | - 'league', |
|
| 57 | - 'matches', |
|
| 58 | - 'matches.homeTeam', |
|
| 59 | - 'matches.AwayTeam' |
|
| 60 | - ); |
|
| 61 | - } |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $table = 'league_rounds'; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected $fillable = [ |
|
| 21 | + 'league_id', |
|
| 22 | + 'day', |
|
| 23 | + 'simulated' |
|
| 24 | + ]; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $casts = [ |
|
| 30 | + 'simulated' => 'boolean' |
|
| 31 | + ]; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return \Illuminate\Database\Eloquent\Relations\HasOne |
|
| 35 | + */ |
|
| 36 | + public function league() |
|
| 37 | + { |
|
| 38 | + return $this->belongsTo(League::class); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 43 | + */ |
|
| 44 | + public function matches() |
|
| 45 | + { |
|
| 46 | + return $this->hasMany(Match::class); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param $query |
|
| 51 | + * @return mixed |
|
| 52 | + */ |
|
| 53 | + public function scopeComplete($query) |
|
| 54 | + { |
|
| 55 | + return $query->with( |
|
| 56 | + 'league', |
|
| 57 | + 'matches', |
|
| 58 | + 'matches.homeTeam', |
|
| 59 | + 'matches.AwayTeam' |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | \ No newline at end of file |
@@ -15,129 +15,129 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class MatchSimulator |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @param $roundId |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - public static function simulateRound($roundId) |
|
| 23 | - { |
|
| 24 | - $result = self::getCompleteRound($roundId); |
|
| 25 | - if (!empty($result) |
|
| 26 | - && |
|
| 27 | - !$result->simulated |
|
| 28 | - ) { |
|
| 29 | - $matches = Match::where( |
|
| 30 | - [ |
|
| 31 | - 'league_round_id' => $roundId |
|
| 32 | - ] |
|
| 33 | - )->get(); |
|
| 34 | - foreach ($matches as $match) { |
|
| 35 | - self::simulateSimpleResult($match->id)->toArray(); |
|
| 36 | - } |
|
| 37 | - LeagueRound::find($roundId)->update(['simulated' => true]); |
|
| 38 | - $result = self::getCompleteRound($roundId); |
|
| 39 | - } |
|
| 40 | - return $result; |
|
| 41 | - } |
|
| 18 | + /** |
|
| 19 | + * @param $roundId |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + public static function simulateRound($roundId) |
|
| 23 | + { |
|
| 24 | + $result = self::getCompleteRound($roundId); |
|
| 25 | + if (!empty($result) |
|
| 26 | + && |
|
| 27 | + !$result->simulated |
|
| 28 | + ) { |
|
| 29 | + $matches = Match::where( |
|
| 30 | + [ |
|
| 31 | + 'league_round_id' => $roundId |
|
| 32 | + ] |
|
| 33 | + )->get(); |
|
| 34 | + foreach ($matches as $match) { |
|
| 35 | + self::simulateSimpleResult($match->id)->toArray(); |
|
| 36 | + } |
|
| 37 | + LeagueRound::find($roundId)->update(['simulated' => true]); |
|
| 38 | + $result = self::getCompleteRound($roundId); |
|
| 39 | + } |
|
| 40 | + return $result; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param $matchId |
|
| 45 | - * @return mixed |
|
| 46 | - */ |
|
| 47 | - public static function simulateCompleteResult($matchId) |
|
| 48 | - { |
|
| 49 | - $result = self::getCompleteResult($matchId); |
|
| 50 | - if (!empty($result) |
|
| 51 | - && !$result->simulated |
|
| 52 | - && self::simulate($matchId) === 1 |
|
| 53 | - ) { |
|
| 54 | - $result = self::getCompleteResult($matchId); |
|
| 55 | - } |
|
| 56 | - return $result; |
|
| 57 | - } |
|
| 43 | + /** |
|
| 44 | + * @param $matchId |
|
| 45 | + * @return mixed |
|
| 46 | + */ |
|
| 47 | + public static function simulateCompleteResult($matchId) |
|
| 48 | + { |
|
| 49 | + $result = self::getCompleteResult($matchId); |
|
| 50 | + if (!empty($result) |
|
| 51 | + && !$result->simulated |
|
| 52 | + && self::simulate($matchId) === 1 |
|
| 53 | + ) { |
|
| 54 | + $result = self::getCompleteResult($matchId); |
|
| 55 | + } |
|
| 56 | + return $result; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param $matchId |
|
| 61 | - * @return mixed |
|
| 62 | - */ |
|
| 63 | - public static function simulateSimpleResult($matchId) |
|
| 64 | - { |
|
| 65 | - $result = self::getSimpleResult($matchId); |
|
| 66 | - if (!empty($result) |
|
| 67 | - && !$result->simulated |
|
| 68 | - && self::simulate($matchId) === 1 |
|
| 69 | - ) { |
|
| 70 | - $result = self::getSimpleResult($matchId); |
|
| 71 | - } |
|
| 72 | - return $result; |
|
| 73 | - } |
|
| 59 | + /** |
|
| 60 | + * @param $matchId |
|
| 61 | + * @return mixed |
|
| 62 | + */ |
|
| 63 | + public static function simulateSimpleResult($matchId) |
|
| 64 | + { |
|
| 65 | + $result = self::getSimpleResult($matchId); |
|
| 66 | + if (!empty($result) |
|
| 67 | + && !$result->simulated |
|
| 68 | + && self::simulate($matchId) === 1 |
|
| 69 | + ) { |
|
| 70 | + $result = self::getSimpleResult($matchId); |
|
| 71 | + } |
|
| 72 | + return $result; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @param $matchId |
|
| 77 | - * @return mixed |
|
| 78 | - */ |
|
| 79 | - private static function simulate($matchId) |
|
| 80 | - { |
|
| 81 | - $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
| 82 | - MatchOrm::complete() |
|
| 83 | - ->where( |
|
| 84 | - [ |
|
| 85 | - 'id' => $matchId |
|
| 86 | - ] |
|
| 87 | - )->first()->toArray() |
|
| 88 | - ); |
|
| 89 | - $matchResult = $match->simulate()->toArray(); |
|
| 90 | - $result = MatchResult::where( |
|
| 91 | - [ |
|
| 92 | - 'id' => $matchId |
|
| 93 | - ] |
|
| 94 | - )->update( |
|
| 95 | - MatchResult::resolveAttributes( |
|
| 96 | - $matchResult, |
|
| 97 | - $matchId |
|
| 98 | - ) |
|
| 99 | - ); |
|
| 100 | - return $result; |
|
| 101 | - } |
|
| 75 | + /** |
|
| 76 | + * @param $matchId |
|
| 77 | + * @return mixed |
|
| 78 | + */ |
|
| 79 | + private static function simulate($matchId) |
|
| 80 | + { |
|
| 81 | + $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
| 82 | + MatchOrm::complete() |
|
| 83 | + ->where( |
|
| 84 | + [ |
|
| 85 | + 'id' => $matchId |
|
| 86 | + ] |
|
| 87 | + )->first()->toArray() |
|
| 88 | + ); |
|
| 89 | + $matchResult = $match->simulate()->toArray(); |
|
| 90 | + $result = MatchResult::where( |
|
| 91 | + [ |
|
| 92 | + 'id' => $matchId |
|
| 93 | + ] |
|
| 94 | + )->update( |
|
| 95 | + MatchResult::resolveAttributes( |
|
| 96 | + $matchResult, |
|
| 97 | + $matchId |
|
| 98 | + ) |
|
| 99 | + ); |
|
| 100 | + return $result; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @param $matchId |
|
| 106 | - * @return MatchResult |
|
| 107 | - */ |
|
| 108 | - private static function getCompleteResult($matchId) |
|
| 109 | - { |
|
| 110 | - return MatchResult::complete()->where( |
|
| 111 | - [ |
|
| 112 | - 'id' => $matchId |
|
| 113 | - ] |
|
| 114 | - )->first(); |
|
| 115 | - } |
|
| 104 | + /** |
|
| 105 | + * @param $matchId |
|
| 106 | + * @return MatchResult |
|
| 107 | + */ |
|
| 108 | + private static function getCompleteResult($matchId) |
|
| 109 | + { |
|
| 110 | + return MatchResult::complete()->where( |
|
| 111 | + [ |
|
| 112 | + 'id' => $matchId |
|
| 113 | + ] |
|
| 114 | + )->first(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @param $matchId |
|
| 119 | - * @return MatchResult |
|
| 120 | - */ |
|
| 121 | - private static function getSimpleResult($matchId) |
|
| 122 | - { |
|
| 123 | - return MatchResult::teams()->where( |
|
| 124 | - [ |
|
| 125 | - 'id' => $matchId |
|
| 126 | - ] |
|
| 127 | - )->first(); |
|
| 128 | - } |
|
| 117 | + /** |
|
| 118 | + * @param $matchId |
|
| 119 | + * @return MatchResult |
|
| 120 | + */ |
|
| 121 | + private static function getSimpleResult($matchId) |
|
| 122 | + { |
|
| 123 | + return MatchResult::teams()->where( |
|
| 124 | + [ |
|
| 125 | + 'id' => $matchId |
|
| 126 | + ] |
|
| 127 | + )->first(); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @param $roundId |
|
| 132 | - * @return mixed |
|
| 133 | - */ |
|
| 134 | - private static function getCompleteRound($roundId) |
|
| 135 | - { |
|
| 136 | - return LeagueRound::complete()->where( |
|
| 137 | - [ |
|
| 138 | - 'id' => $roundId |
|
| 139 | - ] |
|
| 140 | - )->first(); |
|
| 141 | - } |
|
| 130 | + /** |
|
| 131 | + * @param $roundId |
|
| 132 | + * @return mixed |
|
| 133 | + */ |
|
| 134 | + private static function getCompleteRound($roundId) |
|
| 135 | + { |
|
| 136 | + return LeagueRound::complete()->where( |
|
| 137 | + [ |
|
| 138 | + 'id' => $roundId |
|
| 139 | + ] |
|
| 140 | + )->first(); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | } |
| 144 | 144 | \ No newline at end of file |