@@ -15,190 +15,190 @@ |
||
| 15 | 15 | use \App\Lib\DsManager\Models\Orm\Coach; |
| 16 | 16 | |
| 17 | 17 | $configuration = [ |
| 18 | - 'settings' => [ |
|
| 19 | - 'displayErrorDetails' => true, |
|
| 20 | - ], |
|
| 18 | + 'settings' => [ |
|
| 19 | + 'displayErrorDetails' => true, |
|
| 20 | + ], |
|
| 21 | 21 | ]; |
| 22 | 22 | $c = new \Slim\Container($configuration); |
| 23 | 23 | $api = new \Slim\App($c); |
| 24 | 24 | |
| 25 | 25 | $api->get('/ping', function ($request, $response, $args) {
|
| 26 | - $jsonResp = json_encode( |
|
| 27 | - [ |
|
| 28 | - "status" => "service up", |
|
| 29 | - "message" => "in a bottle" |
|
| 30 | - ] |
|
| 31 | - ); |
|
| 32 | - return Responder::getJsonResponse($jsonResp, $response); |
|
| 26 | + $jsonResp = json_encode( |
|
| 27 | + [ |
|
| 28 | + "status" => "service up", |
|
| 29 | + "message" => "in a bottle" |
|
| 30 | + ] |
|
| 31 | + ); |
|
| 32 | + return Responder::getJsonResponse($jsonResp, $response); |
|
| 33 | 33 | }); |
| 34 | 34 | |
| 35 | 35 | $api->get('/players', function ($request, $response, $args) {
|
| 36 | - $json = json_encode(Player::all()); |
|
| 37 | - return Responder::getJsonResponse($json, $response); |
|
| 36 | + $json = json_encode(Player::all()); |
|
| 37 | + return Responder::getJsonResponse($json, $response); |
|
| 38 | 38 | }); |
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | $api->get('/players/{id}', function ($request, $response, $args) {
|
| 42 | - return Responder::getJsonResponse( |
|
| 43 | - Player::findOrFail($args['id']), |
|
| 44 | - $response |
|
| 45 | - ); |
|
| 42 | + return Responder::getJsonResponse( |
|
| 43 | + Player::findOrFail($args['id']), |
|
| 44 | + $response |
|
| 45 | + ); |
|
| 46 | 46 | }); |
| 47 | 47 | |
| 48 | 48 | $api->get('/coaches', function ($request, $response, $args) {
|
| 49 | - return Responder::getJsonResponse( |
|
| 50 | - Coach::all(), |
|
| 51 | - $response |
|
| 52 | - ); |
|
| 49 | + return Responder::getJsonResponse( |
|
| 50 | + Coach::all(), |
|
| 51 | + $response |
|
| 52 | + ); |
|
| 53 | 53 | }); |
| 54 | 54 | |
| 55 | 55 | $api->get('/teams', function ($request, $response, $args) {
|
| 56 | - return Responder::getJsonResponse( |
|
| 57 | - Team::all(), |
|
| 58 | - $response |
|
| 59 | - ); |
|
| 56 | + return Responder::getJsonResponse( |
|
| 57 | + Team::all(), |
|
| 58 | + $response |
|
| 59 | + ); |
|
| 60 | 60 | }); |
| 61 | 61 | |
| 62 | 62 | $api->get('/teams/{id}', function ($request, $response, $args) {
|
| 63 | - return Responder::getJsonResponse( |
|
| 64 | - Team::complete() |
|
| 65 | - ->where( |
|
| 66 | - [ |
|
| 67 | - 'id' => $args['id'] |
|
| 68 | - ] |
|
| 69 | - )->get(), |
|
| 70 | - $response |
|
| 71 | - ); |
|
| 63 | + return Responder::getJsonResponse( |
|
| 64 | + Team::complete() |
|
| 65 | + ->where( |
|
| 66 | + [ |
|
| 67 | + 'id' => $args['id'] |
|
| 68 | + ] |
|
| 69 | + )->get(), |
|
| 70 | + $response |
|
| 71 | + ); |
|
| 72 | 72 | }); |
| 73 | 73 | |
| 74 | 74 | $api->get('/teams/{id}/players', function ($request, $response, $args) {
|
| 75 | - return Responder::getJsonResponse( |
|
| 76 | - Team::with( |
|
| 77 | - 'roster' |
|
| 78 | - )->where( |
|
| 79 | - [ |
|
| 80 | - 'id' => $args['id'] |
|
| 81 | - ] |
|
| 82 | - )->get(), |
|
| 83 | - $response |
|
| 84 | - ); |
|
| 75 | + return Responder::getJsonResponse( |
|
| 76 | + Team::with( |
|
| 77 | + 'roster' |
|
| 78 | + )->where( |
|
| 79 | + [ |
|
| 80 | + 'id' => $args['id'] |
|
| 81 | + ] |
|
| 82 | + )->get(), |
|
| 83 | + $response |
|
| 84 | + ); |
|
| 85 | 85 | }); |
| 86 | 86 | |
| 87 | 87 | $api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) {
|
| 88 | - return Responder::getJsonResponse( |
|
| 89 | - Player::statistics()->where( |
|
| 90 | - [ |
|
| 91 | - 'id' => $args['playerId'], |
|
| 92 | - 'team_id' => $args['id'] |
|
| 93 | - ] |
|
| 94 | - )->get(), |
|
| 95 | - $response |
|
| 96 | - ); |
|
| 88 | + return Responder::getJsonResponse( |
|
| 89 | + Player::statistics()->where( |
|
| 90 | + [ |
|
| 91 | + 'id' => $args['playerId'], |
|
| 92 | + 'team_id' => $args['id'] |
|
| 93 | + ] |
|
| 94 | + )->get(), |
|
| 95 | + $response |
|
| 96 | + ); |
|
| 97 | 97 | }); |
| 98 | 98 | |
| 99 | 99 | $api->get('/teams/{id}/coach', function ($request, $response, $args) {
|
| 100 | - return Responder::getJsonResponse( |
|
| 101 | - Team::with( |
|
| 102 | - 'coach' |
|
| 103 | - )->where( |
|
| 104 | - [ |
|
| 105 | - 'id' => $args['id'] |
|
| 106 | - ] |
|
| 107 | - )->get(), |
|
| 108 | - $response |
|
| 109 | - ); |
|
| 100 | + return Responder::getJsonResponse( |
|
| 101 | + Team::with( |
|
| 102 | + 'coach' |
|
| 103 | + )->where( |
|
| 104 | + [ |
|
| 105 | + 'id' => $args['id'] |
|
| 106 | + ] |
|
| 107 | + )->get(), |
|
| 108 | + $response |
|
| 109 | + ); |
|
| 110 | 110 | }); |
| 111 | 111 | |
| 112 | 112 | $api->get('/leagues', function ($request, $response, $args) {
|
| 113 | - return Responder::getJsonResponse( |
|
| 114 | - League::all(), |
|
| 115 | - $response |
|
| 116 | - ); |
|
| 113 | + return Responder::getJsonResponse( |
|
| 114 | + League::all(), |
|
| 115 | + $response |
|
| 116 | + ); |
|
| 117 | 117 | }); |
| 118 | 118 | |
| 119 | 119 | $api->get('/leagues/{id}', function ($request, $response, $args) {
|
| 120 | - return Responder::getJsonResponse( |
|
| 121 | - League::with('rounds')
|
|
| 122 | - ->where( |
|
| 123 | - [ |
|
| 124 | - 'id' => $args['id'] |
|
| 125 | - ] |
|
| 126 | - )->first(), |
|
| 127 | - $response |
|
| 128 | - ); |
|
| 120 | + return Responder::getJsonResponse( |
|
| 121 | + League::with('rounds')
|
|
| 122 | + ->where( |
|
| 123 | + [ |
|
| 124 | + 'id' => $args['id'] |
|
| 125 | + ] |
|
| 126 | + )->first(), |
|
| 127 | + $response |
|
| 128 | + ); |
|
| 129 | 129 | }); |
| 130 | 130 | |
| 131 | 131 | $api->get('/leagues/{id}/rounds/{roundId}', function ($request, $response, $args) {
|
| 132 | - return Responder::getJsonResponse( |
|
| 133 | - LeagueRound::complete() |
|
| 134 | - ->where( |
|
| 135 | - [ |
|
| 136 | - 'id' => $args['roundId'], |
|
| 137 | - ] |
|
| 138 | - )->first(), |
|
| 139 | - $response |
|
| 140 | - ); |
|
| 132 | + return Responder::getJsonResponse( |
|
| 133 | + LeagueRound::complete() |
|
| 134 | + ->where( |
|
| 135 | + [ |
|
| 136 | + 'id' => $args['roundId'], |
|
| 137 | + ] |
|
| 138 | + )->first(), |
|
| 139 | + $response |
|
| 140 | + ); |
|
| 141 | 141 | }); |
| 142 | 142 | |
| 143 | 143 | $api->put('/leagues/{id}/rounds/{roundId}/simulate', function ($request, $response, $args) {
|
| 144 | - return Responder::getJsonResponse( |
|
| 145 | - MatchSimulator::simulateRound( |
|
| 146 | - $args['roundId'] |
|
| 147 | - ), |
|
| 148 | - $response |
|
| 149 | - ); |
|
| 144 | + return Responder::getJsonResponse( |
|
| 145 | + MatchSimulator::simulateRound( |
|
| 146 | + $args['roundId'] |
|
| 147 | + ), |
|
| 148 | + $response |
|
| 149 | + ); |
|
| 150 | 150 | }); |
| 151 | 151 | |
| 152 | 152 | $api->get('/matches', function ($request, $response, $args) {
|
| 153 | - return Responder::getJsonResponse( |
|
| 154 | - Match::teams()->get(), |
|
| 155 | - $response |
|
| 156 | - ); |
|
| 153 | + return Responder::getJsonResponse( |
|
| 154 | + Match::teams()->get(), |
|
| 155 | + $response |
|
| 156 | + ); |
|
| 157 | 157 | }); |
| 158 | 158 | |
| 159 | 159 | $api->post('/matches', function ($request, $response, $args) {
|
| 160 | - $json = $request->getBody(); |
|
| 161 | - $json = json_decode($json, true); |
|
| 162 | - return Responder::getJsonResponse( |
|
| 163 | - Match::create( |
|
| 164 | - $json |
|
| 165 | - ), |
|
| 166 | - $response |
|
| 167 | - ); |
|
| 160 | + $json = $request->getBody(); |
|
| 161 | + $json = json_decode($json, true); |
|
| 162 | + return Responder::getJsonResponse( |
|
| 163 | + Match::create( |
|
| 164 | + $json |
|
| 165 | + ), |
|
| 166 | + $response |
|
| 167 | + ); |
|
| 168 | 168 | }); |
| 169 | 169 | |
| 170 | 170 | $api->get('/matches/{id}', function ($request, $response, $args) {
|
| 171 | - return Responder::getJsonResponse( |
|
| 172 | - Match::complete() |
|
| 173 | - ->where( |
|
| 174 | - [ |
|
| 175 | - 'id' => $args['id'] |
|
| 176 | - ] |
|
| 177 | - )->first(), |
|
| 178 | - $response |
|
| 179 | - ); |
|
| 171 | + return Responder::getJsonResponse( |
|
| 172 | + Match::complete() |
|
| 173 | + ->where( |
|
| 174 | + [ |
|
| 175 | + 'id' => $args['id'] |
|
| 176 | + ] |
|
| 177 | + )->first(), |
|
| 178 | + $response |
|
| 179 | + ); |
|
| 180 | 180 | }); |
| 181 | 181 | |
| 182 | 182 | $api->get('/matches/{id}/result', function ($request, $response, $args) {
|
| 183 | - $result = MatchResult::complete() |
|
| 184 | - ->where( |
|
| 185 | - [ |
|
| 186 | - 'id' => $args['id'] |
|
| 187 | - ] |
|
| 188 | - )->first(); |
|
| 183 | + $result = MatchResult::complete() |
|
| 184 | + ->where( |
|
| 185 | + [ |
|
| 186 | + 'id' => $args['id'] |
|
| 187 | + ] |
|
| 188 | + )->first(); |
|
| 189 | 189 | |
| 190 | - return Responder::getJsonResponse( |
|
| 191 | - $result, |
|
| 192 | - $response |
|
| 193 | - ); |
|
| 190 | + return Responder::getJsonResponse( |
|
| 191 | + $result, |
|
| 192 | + $response |
|
| 193 | + ); |
|
| 194 | 194 | }); |
| 195 | 195 | |
| 196 | 196 | $api->put('/matches/{id}/simulate', function ($request, $response, $args) {
|
| 197 | - return Responder::getJsonResponse( |
|
| 198 | - MatchSimulator::simulateCompleteResult( |
|
| 199 | - $args['id'] |
|
| 200 | - ), |
|
| 201 | - $response |
|
| 202 | - ); |
|
| 197 | + return Responder::getJsonResponse( |
|
| 198 | + MatchSimulator::simulateCompleteResult( |
|
| 199 | + $args['id'] |
|
| 200 | + ), |
|
| 201 | + $response |
|
| 202 | + ); |
|
| 203 | 203 | }); |
| 204 | 204 | $api->run(); |
| 205 | 205 | \ No newline at end of file |
@@ -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 |
@@ -9,74 +9,74 @@ |
||
| 9 | 9 | class Match extends DsManagerOrm |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $table = 'matches'; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $table = 'matches'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected $fillable = [ |
|
| 21 | - 'home_team_id', |
|
| 22 | - 'away_team_id', |
|
| 23 | - 'league_round_id' |
|
| 24 | - ]; |
|
| 17 | + /** |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected $fillable = [ |
|
| 21 | + 'home_team_id', |
|
| 22 | + 'away_team_id', |
|
| 23 | + 'league_round_id' |
|
| 24 | + ]; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $hidden = [ |
|
| 30 | - 'home_team_id', |
|
| 31 | - 'away_team_id', |
|
| 32 | - 'created_at', |
|
| 33 | - 'updated_at', |
|
| 34 | - 'winner_id', |
|
| 35 | - 'loser_id', |
|
| 36 | - 'is_draw', |
|
| 37 | - ]; |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $hidden = [ |
|
| 30 | + 'home_team_id', |
|
| 31 | + 'away_team_id', |
|
| 32 | + 'created_at', |
|
| 33 | + 'updated_at', |
|
| 34 | + 'winner_id', |
|
| 35 | + 'loser_id', |
|
| 36 | + 'is_draw', |
|
| 37 | + ]; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - protected $casts = [ |
|
| 43 | - 'simulated' => 'boolean' |
|
| 44 | - ]; |
|
| 39 | + /** |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + protected $casts = [ |
|
| 43 | + 'simulated' => 'boolean' |
|
| 44 | + ]; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 48 | - */ |
|
| 49 | - public function homeTeam() |
|
| 50 | - { |
|
| 51 | - return $this->belongsTo(Team::class, 'home_team_id'); |
|
| 52 | - } |
|
| 46 | + /** |
|
| 47 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 48 | + */ |
|
| 49 | + public function homeTeam() |
|
| 50 | + { |
|
| 51 | + return $this->belongsTo(Team::class, 'home_team_id'); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 56 | - */ |
|
| 57 | - public function awayTeam() |
|
| 58 | - { |
|
| 59 | - return $this->belongsTo(Team::class, 'away_team_id'); |
|
| 60 | - } |
|
| 54 | + /** |
|
| 55 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 56 | + */ |
|
| 57 | + public function awayTeam() |
|
| 58 | + { |
|
| 59 | + return $this->belongsTo(Team::class, 'away_team_id'); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function scopeTeams($query) |
|
| 63 | - { |
|
| 64 | - return $query->with( |
|
| 65 | - 'homeTeam', |
|
| 66 | - 'awayTeam' |
|
| 67 | - ); |
|
| 68 | - } |
|
| 62 | + public function scopeTeams($query) |
|
| 63 | + { |
|
| 64 | + return $query->with( |
|
| 65 | + 'homeTeam', |
|
| 66 | + 'awayTeam' |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - public function scopeComplete($query) |
|
| 71 | - { |
|
| 72 | - return $query->with( |
|
| 73 | - 'homeTeam', |
|
| 74 | - 'homeTeam.roster', |
|
| 75 | - 'homeTeam.coach', |
|
| 76 | - 'awayTeam', |
|
| 77 | - 'awayTeam.roster', |
|
| 78 | - 'awayTeam.coach' |
|
| 79 | - ); |
|
| 80 | - } |
|
| 70 | + public function scopeComplete($query) |
|
| 71 | + { |
|
| 72 | + return $query->with( |
|
| 73 | + 'homeTeam', |
|
| 74 | + 'homeTeam.roster', |
|
| 75 | + 'homeTeam.coach', |
|
| 76 | + 'awayTeam', |
|
| 77 | + 'awayTeam.roster', |
|
| 78 | + 'awayTeam.coach' |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -8,114 +8,114 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Team extends DsManagerOrm |
| 10 | 10 | {
|
| 11 | - /** |
|
| 12 | - * |
|
| 13 | - */ |
|
| 14 | - const PLAYED_LIMIT = 5; |
|
| 15 | - /** |
|
| 16 | - * |
|
| 17 | - */ |
|
| 18 | - const FUTURE_LIMIT = 3; |
|
| 19 | - /** |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $table = 'teams'; |
|
| 11 | + /** |
|
| 12 | + * |
|
| 13 | + */ |
|
| 14 | + const PLAYED_LIMIT = 5; |
|
| 15 | + /** |
|
| 16 | + * |
|
| 17 | + */ |
|
| 18 | + const FUTURE_LIMIT = 3; |
|
| 19 | + /** |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $table = 'teams'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected $fillable = [ |
|
| 28 | - 'name', |
|
| 29 | - 'nationality' |
|
| 30 | - ]; |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $fillable = [ |
|
| 28 | + 'name', |
|
| 29 | + 'nationality' |
|
| 30 | + ]; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 34 | - */ |
|
| 35 | - public function roster() |
|
| 36 | - {
|
|
| 37 | - return $this->hasMany(Player::class); |
|
| 38 | - } |
|
| 32 | + /** |
|
| 33 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 34 | + */ |
|
| 35 | + public function roster() |
|
| 36 | + {
|
|
| 37 | + return $this->hasMany(Player::class); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 42 | - */ |
|
| 43 | - public function coach() |
|
| 44 | - {
|
|
| 45 | - return $this->hasOne(Coach::class); |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 42 | + */ |
|
| 43 | + public function coach() |
|
| 44 | + {
|
|
| 45 | + return $this->hasOne(Coach::class); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @return mixed |
|
| 50 | - */ |
|
| 51 | - public function playedMatchesHome() |
|
| 52 | - {
|
|
| 53 | - return $this->hasMany( |
|
| 54 | - MatchResult::class, |
|
| 55 | - 'home_team_id' |
|
| 56 | - )->where('simulated', true)
|
|
| 57 | - ->orderBy('updated_at', 'DESC')
|
|
| 58 | - ->limit(self::PLAYED_LIMIT); |
|
| 59 | - } |
|
| 48 | + /** |
|
| 49 | + * @return mixed |
|
| 50 | + */ |
|
| 51 | + public function playedMatchesHome() |
|
| 52 | + {
|
|
| 53 | + return $this->hasMany( |
|
| 54 | + MatchResult::class, |
|
| 55 | + 'home_team_id' |
|
| 56 | + )->where('simulated', true)
|
|
| 57 | + ->orderBy('updated_at', 'DESC')
|
|
| 58 | + ->limit(self::PLAYED_LIMIT); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @return mixed |
|
| 63 | - */ |
|
| 64 | - public function futureMatchesHome() |
|
| 65 | - {
|
|
| 66 | - return $this->hasMany( |
|
| 67 | - MatchResult::class, |
|
| 68 | - 'home_team_id' |
|
| 69 | - )->where('simulated', false)
|
|
| 70 | - ->orderBy('updated_at', 'DESC')
|
|
| 71 | - ->limit(self::FUTURE_LIMIT); |
|
| 72 | - } |
|
| 61 | + /** |
|
| 62 | + * @return mixed |
|
| 63 | + */ |
|
| 64 | + public function futureMatchesHome() |
|
| 65 | + {
|
|
| 66 | + return $this->hasMany( |
|
| 67 | + MatchResult::class, |
|
| 68 | + 'home_team_id' |
|
| 69 | + )->where('simulated', false)
|
|
| 70 | + ->orderBy('updated_at', 'DESC')
|
|
| 71 | + ->limit(self::FUTURE_LIMIT); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return mixed |
|
| 76 | - */ |
|
| 77 | - public function playedMatchesAway() |
|
| 78 | - {
|
|
| 79 | - return $this->hasMany( |
|
| 80 | - MatchResult::class, |
|
| 81 | - 'away_team_id' |
|
| 82 | - )->where('simulated', true)
|
|
| 83 | - ->orderBy('updated_at', 'DESC')
|
|
| 84 | - ->limit(self::PLAYED_LIMIT); |
|
| 85 | - } |
|
| 74 | + /** |
|
| 75 | + * @return mixed |
|
| 76 | + */ |
|
| 77 | + public function playedMatchesAway() |
|
| 78 | + {
|
|
| 79 | + return $this->hasMany( |
|
| 80 | + MatchResult::class, |
|
| 81 | + 'away_team_id' |
|
| 82 | + )->where('simulated', true)
|
|
| 83 | + ->orderBy('updated_at', 'DESC')
|
|
| 84 | + ->limit(self::PLAYED_LIMIT); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @return mixed |
|
| 89 | - */ |
|
| 90 | - public function futureMatchesAway() |
|
| 91 | - {
|
|
| 92 | - return $this->hasMany( |
|
| 93 | - MatchResult::class, |
|
| 94 | - 'away_team_id' |
|
| 95 | - )->where('simulated', false)
|
|
| 96 | - ->orderBy('updated_at', 'DESC')
|
|
| 97 | - ->limit(self::FUTURE_LIMIT); |
|
| 98 | - } |
|
| 87 | + /** |
|
| 88 | + * @return mixed |
|
| 89 | + */ |
|
| 90 | + public function futureMatchesAway() |
|
| 91 | + {
|
|
| 92 | + return $this->hasMany( |
|
| 93 | + MatchResult::class, |
|
| 94 | + 'away_team_id' |
|
| 95 | + )->where('simulated', false)
|
|
| 96 | + ->orderBy('updated_at', 'DESC')
|
|
| 97 | + ->limit(self::FUTURE_LIMIT); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @param $query |
|
| 103 | - * @return mixed |
|
| 104 | - */ |
|
| 105 | - public function scopeComplete($query) |
|
| 106 | - {
|
|
| 107 | - return $query->with( |
|
| 108 | - 'roster', |
|
| 109 | - 'coach', |
|
| 110 | - 'playedMatchesHome', |
|
| 111 | - 'playedMatchesHome.awayTeam', |
|
| 112 | - 'futureMatchesHome', |
|
| 113 | - 'futureMatchesHome.awayTeam', |
|
| 114 | - 'playedMatchesAway', |
|
| 115 | - 'playedMatchesAway.homeTeam', |
|
| 116 | - 'futureMatchesAway', |
|
| 117 | - 'futureMatchesAway.homeTeam' |
|
| 118 | - ); |
|
| 119 | - } |
|
| 101 | + /** |
|
| 102 | + * @param $query |
|
| 103 | + * @return mixed |
|
| 104 | + */ |
|
| 105 | + public function scopeComplete($query) |
|
| 106 | + {
|
|
| 107 | + return $query->with( |
|
| 108 | + 'roster', |
|
| 109 | + 'coach', |
|
| 110 | + 'playedMatchesHome', |
|
| 111 | + 'playedMatchesHome.awayTeam', |
|
| 112 | + 'futureMatchesHome', |
|
| 113 | + 'futureMatchesHome.awayTeam', |
|
| 114 | + 'playedMatchesAway', |
|
| 115 | + 'playedMatchesAway.homeTeam', |
|
| 116 | + 'futureMatchesAway', |
|
| 117 | + 'futureMatchesAway.homeTeam' |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | } |
| 122 | 122 | \ No newline at end of file |
@@ -9,52 +9,52 @@ |
||
| 9 | 9 | class MatchPlayer extends DsManagerOrm |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $table = 'match_players'; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected $fillable = [ |
|
| 21 | - 'match_id', |
|
| 22 | - 'team_id', |
|
| 23 | - 'player_id', |
|
| 24 | - 'goals', |
|
| 25 | - 'vote' |
|
| 26 | - ]; |
|
| 27 | - |
|
| 28 | - protected $casts = [ |
|
| 29 | - 'vote' => 'integer', |
|
| 30 | - 'goals' => 'integer' |
|
| 31 | - ]; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 35 | - */ |
|
| 36 | - public function player() |
|
| 37 | - { |
|
| 38 | - return $this->belongsTo(Player::class, 'player_id'); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 43 | - */ |
|
| 44 | - public function team() |
|
| 45 | - { |
|
| 46 | - return $this->belongsTo(Team::class, 'team_id'); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param $query |
|
| 51 | - * @return mixed |
|
| 52 | - */ |
|
| 53 | - public function scopeComplete($query){ |
|
| 54 | - return $query->with( |
|
| 55 | - 'team', |
|
| 56 | - 'player' |
|
| 57 | - ); |
|
| 58 | - } |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $table = 'match_players'; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected $fillable = [ |
|
| 21 | + 'match_id', |
|
| 22 | + 'team_id', |
|
| 23 | + 'player_id', |
|
| 24 | + 'goals', |
|
| 25 | + 'vote' |
|
| 26 | + ]; |
|
| 27 | + |
|
| 28 | + protected $casts = [ |
|
| 29 | + 'vote' => 'integer', |
|
| 30 | + 'goals' => 'integer' |
|
| 31 | + ]; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 35 | + */ |
|
| 36 | + public function player() |
|
| 37 | + { |
|
| 38 | + return $this->belongsTo(Player::class, 'player_id'); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 43 | + */ |
|
| 44 | + public function team() |
|
| 45 | + { |
|
| 46 | + return $this->belongsTo(Team::class, 'team_id'); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param $query |
|
| 51 | + * @return mixed |
|
| 52 | + */ |
|
| 53 | + public function scopeComplete($query){ |
|
| 54 | + return $query->with( |
|
| 55 | + 'team', |
|
| 56 | + 'player' |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | } |
| 61 | 61 | \ No newline at end of file |
@@ -10,139 +10,139 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class MatchResult extends Match |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var array |
|
| 15 | - */ |
|
| 16 | - protected $fillable = [ |
|
| 17 | - 'goal_home', |
|
| 18 | - 'goal_away', |
|
| 19 | - 'simulated', |
|
| 20 | - 'winner_id', |
|
| 21 | - 'loser_id', |
|
| 22 | - 'is_draw' |
|
| 23 | - ]; |
|
| 13 | + /** |
|
| 14 | + * @var array |
|
| 15 | + */ |
|
| 16 | + protected $fillable = [ |
|
| 17 | + 'goal_home', |
|
| 18 | + 'goal_away', |
|
| 19 | + 'simulated', |
|
| 20 | + 'winner_id', |
|
| 21 | + 'loser_id', |
|
| 22 | + 'is_draw' |
|
| 23 | + ]; |
|
| 24 | 24 | |
| 25 | - protected $hidden = [ |
|
| 26 | - 'home_team_id', |
|
| 27 | - 'away_team_id', |
|
| 28 | - 'winner_id', |
|
| 29 | - 'loser_id', |
|
| 30 | - 'is_draw', |
|
| 31 | - 'created_at', |
|
| 32 | - 'updated_at' |
|
| 33 | - ]; |
|
| 25 | + protected $hidden = [ |
|
| 26 | + 'home_team_id', |
|
| 27 | + 'away_team_id', |
|
| 28 | + 'winner_id', |
|
| 29 | + 'loser_id', |
|
| 30 | + 'is_draw', |
|
| 31 | + 'created_at', |
|
| 32 | + 'updated_at' |
|
| 33 | + ]; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $casts = [ |
|
| 39 | - 'simulated' => 'boolean' |
|
| 40 | - ]; |
|
| 35 | + /** |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $casts = [ |
|
| 39 | + 'simulated' => 'boolean' |
|
| 40 | + ]; |
|
| 41 | 41 | |
| 42 | - public static function resolveAttributes(array $attributes, $matchId) |
|
| 43 | - { |
|
| 44 | - self::generateAppearances( |
|
| 45 | - [ |
|
| 46 | - $attributes['home_team_id'], |
|
| 47 | - $attributes['away_team_id'] |
|
| 48 | - ], |
|
| 49 | - $matchId |
|
| 50 | - ); |
|
| 51 | - $attributes = self::setResult($attributes); |
|
| 52 | - if (array_key_exists('info', $attributes)) { |
|
| 53 | - if (array_key_exists('scorers', $attributes['info'])) { |
|
| 54 | - foreach ($attributes['info']['scorers']['home'] as $scorerHome) { |
|
| 55 | - self::addScorer($matchId, $attributes['home_team_id'], $scorerHome->id); |
|
| 56 | - } |
|
| 57 | - foreach ($attributes['info']['scorers']['away'] as $scorerAway) { |
|
| 58 | - self::addScorer($matchId, $attributes['away_team_id'], $scorerAway->id); |
|
| 59 | - } |
|
| 60 | - unset($attributes['info']['scorers']); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - unset($attributes['info']); |
|
| 64 | - return $attributes; |
|
| 65 | - } |
|
| 42 | + public static function resolveAttributes(array $attributes, $matchId) |
|
| 43 | + { |
|
| 44 | + self::generateAppearances( |
|
| 45 | + [ |
|
| 46 | + $attributes['home_team_id'], |
|
| 47 | + $attributes['away_team_id'] |
|
| 48 | + ], |
|
| 49 | + $matchId |
|
| 50 | + ); |
|
| 51 | + $attributes = self::setResult($attributes); |
|
| 52 | + if (array_key_exists('info', $attributes)) { |
|
| 53 | + if (array_key_exists('scorers', $attributes['info'])) { |
|
| 54 | + foreach ($attributes['info']['scorers']['home'] as $scorerHome) { |
|
| 55 | + self::addScorer($matchId, $attributes['home_team_id'], $scorerHome->id); |
|
| 56 | + } |
|
| 57 | + foreach ($attributes['info']['scorers']['away'] as $scorerAway) { |
|
| 58 | + self::addScorer($matchId, $attributes['away_team_id'], $scorerAway->id); |
|
| 59 | + } |
|
| 60 | + unset($attributes['info']['scorers']); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + unset($attributes['info']); |
|
| 64 | + return $attributes; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - private static function addScorer($matchId, $teamId, $playerId) |
|
| 68 | - { |
|
| 69 | - $scorer = MatchPlayer::where( |
|
| 70 | - [ |
|
| 71 | - 'match_id' => $matchId, |
|
| 72 | - 'team_id' => $teamId, |
|
| 73 | - 'player_id' => $playerId |
|
| 74 | - ] |
|
| 75 | - )->first(); |
|
| 76 | - if (!empty($scorer)) { |
|
| 77 | - $scorer->goals = $scorer->goals + 1; |
|
| 78 | - $scorer->vote = $scorer->vote <= 9 ? $scorer->vote + rand(0, 1) : $scorer->vote; |
|
| 79 | - $scorer->save(); |
|
| 80 | - } else { |
|
| 81 | - MatchPlayer::create( |
|
| 82 | - [ |
|
| 83 | - 'match_id' => $matchId, |
|
| 84 | - 'team_id' => $teamId, |
|
| 85 | - 'player_id' => $playerId, |
|
| 86 | - 'goals' => 1 |
|
| 87 | - ] |
|
| 88 | - ); |
|
| 89 | - } |
|
| 90 | - } |
|
| 67 | + private static function addScorer($matchId, $teamId, $playerId) |
|
| 68 | + { |
|
| 69 | + $scorer = MatchPlayer::where( |
|
| 70 | + [ |
|
| 71 | + 'match_id' => $matchId, |
|
| 72 | + 'team_id' => $teamId, |
|
| 73 | + 'player_id' => $playerId |
|
| 74 | + ] |
|
| 75 | + )->first(); |
|
| 76 | + if (!empty($scorer)) { |
|
| 77 | + $scorer->goals = $scorer->goals + 1; |
|
| 78 | + $scorer->vote = $scorer->vote <= 9 ? $scorer->vote + rand(0, 1) : $scorer->vote; |
|
| 79 | + $scorer->save(); |
|
| 80 | + } else { |
|
| 81 | + MatchPlayer::create( |
|
| 82 | + [ |
|
| 83 | + 'match_id' => $matchId, |
|
| 84 | + 'team_id' => $teamId, |
|
| 85 | + 'player_id' => $playerId, |
|
| 86 | + 'goals' => 1 |
|
| 87 | + ] |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - private static function generateAppearances( |
|
| 93 | - $teamIds, |
|
| 94 | - $matchId |
|
| 95 | - ) |
|
| 96 | - { |
|
| 97 | - foreach ($teamIds as $id) { |
|
| 98 | - $players = Player::where('team_id', $id)->get()->random(11); |
|
| 99 | - foreach ($players as $player) { |
|
| 100 | - MatchPlayer::create( |
|
| 101 | - [ |
|
| 102 | - 'match_id' => $matchId, |
|
| 103 | - 'team_id' => $id, |
|
| 104 | - 'player_id' => $player->id, |
|
| 105 | - 'vote' => Randomizer::voteFromSkill($player->skillAvg) |
|
| 106 | - ] |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - } |
|
| 92 | + private static function generateAppearances( |
|
| 93 | + $teamIds, |
|
| 94 | + $matchId |
|
| 95 | + ) |
|
| 96 | + { |
|
| 97 | + foreach ($teamIds as $id) { |
|
| 98 | + $players = Player::where('team_id', $id)->get()->random(11); |
|
| 99 | + foreach ($players as $player) { |
|
| 100 | + MatchPlayer::create( |
|
| 101 | + [ |
|
| 102 | + 'match_id' => $matchId, |
|
| 103 | + 'team_id' => $id, |
|
| 104 | + 'player_id' => $player->id, |
|
| 105 | + 'vote' => Randomizer::voteFromSkill($player->skillAvg) |
|
| 106 | + ] |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - private static function setResult($attributes) |
|
| 113 | - { |
|
| 114 | - $toExtract = [ |
|
| 115 | - 'winner_id' => 'winner_id', |
|
| 116 | - 'loser_id' => 'loser_id', |
|
| 117 | - 'is_draw' => 'is_draw' |
|
| 118 | - ]; |
|
| 119 | - if (array_key_exists('info', $attributes)) { |
|
| 120 | - foreach ($toExtract as $key => $attr) { |
|
| 121 | - $attributes[$attr] = $attributes['info'][$key]; |
|
| 122 | - unset($attributes['info'][$key]); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - return $attributes; |
|
| 126 | - } |
|
| 112 | + private static function setResult($attributes) |
|
| 113 | + { |
|
| 114 | + $toExtract = [ |
|
| 115 | + 'winner_id' => 'winner_id', |
|
| 116 | + 'loser_id' => 'loser_id', |
|
| 117 | + 'is_draw' => 'is_draw' |
|
| 118 | + ]; |
|
| 119 | + if (array_key_exists('info', $attributes)) { |
|
| 120 | + foreach ($toExtract as $key => $attr) { |
|
| 121 | + $attributes[$attr] = $attributes['info'][$key]; |
|
| 122 | + unset($attributes['info'][$key]); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + return $attributes; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - public function scorers() |
|
| 129 | - { |
|
| 130 | - return $this->belongsToMany( |
|
| 131 | - Player::class, |
|
| 132 | - 'match_players', |
|
| 133 | - 'match_id' |
|
| 134 | - )->withPivot( |
|
| 135 | - 'team_id', |
|
| 136 | - 'goals' |
|
| 137 | - )->where( |
|
| 138 | - 'goals', '>', 0 |
|
| 139 | - ); |
|
| 140 | - } |
|
| 128 | + public function scorers() |
|
| 129 | + { |
|
| 130 | + return $this->belongsToMany( |
|
| 131 | + Player::class, |
|
| 132 | + 'match_players', |
|
| 133 | + 'match_id' |
|
| 134 | + )->withPivot( |
|
| 135 | + 'team_id', |
|
| 136 | + 'goals' |
|
| 137 | + )->where( |
|
| 138 | + 'goals', '>', 0 |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - public function scopeComplete($query) |
|
| 143 | - { |
|
| 144 | - return parent::scopeComplete($query)->with('scorers'); |
|
| 145 | - } |
|
| 142 | + public function scopeComplete($query) |
|
| 143 | + { |
|
| 144 | + return parent::scopeComplete($query)->with('scorers'); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | } |
| 149 | 149 | \ No newline at end of file |
@@ -5,27 +5,27 @@ |
||
| 5 | 5 | |
| 6 | 6 | class CreateMatchTable |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Run the migrations. |
|
| 10 | - * |
|
| 11 | - * @return void |
|
| 12 | - */ |
|
| 13 | - public function run() |
|
| 14 | - { |
|
| 15 | - Capsule::schema()->dropIfExists('matches'); |
|
| 16 | - Capsule::schema()->create('matches', function (Blueprint $table) { |
|
| 17 | - $table->increments('id'); |
|
| 18 | - $table->integer('league_round_id')->nullable(); |
|
| 19 | - $table->integer('home_team_id'); |
|
| 20 | - $table->integer('goal_home')->default(0); |
|
| 21 | - $table->integer('away_team_id'); |
|
| 22 | - $table->integer('goal_away')->default(0); |
|
| 23 | - $table->boolean('is_draw')->default(false); |
|
| 24 | - $table->integer('winner_id')->default(null); |
|
| 25 | - $table->integer('loser_id')->default(null); |
|
| 26 | - $table->boolean('simulated')->default(false); |
|
| 27 | - $table->date('match_date')->default(\Carbon\Carbon::now()); |
|
| 28 | - $table->timestamps(); |
|
| 29 | - }); |
|
| 30 | - } |
|
| 8 | + /** |
|
| 9 | + * Run the migrations. |
|
| 10 | + * |
|
| 11 | + * @return void |
|
| 12 | + */ |
|
| 13 | + public function run() |
|
| 14 | + { |
|
| 15 | + Capsule::schema()->dropIfExists('matches'); |
|
| 16 | + Capsule::schema()->create('matches', function (Blueprint $table) { |
|
| 17 | + $table->increments('id'); |
|
| 18 | + $table->integer('league_round_id')->nullable(); |
|
| 19 | + $table->integer('home_team_id'); |
|
| 20 | + $table->integer('goal_home')->default(0); |
|
| 21 | + $table->integer('away_team_id'); |
|
| 22 | + $table->integer('goal_away')->default(0); |
|
| 23 | + $table->boolean('is_draw')->default(false); |
|
| 24 | + $table->integer('winner_id')->default(null); |
|
| 25 | + $table->integer('loser_id')->default(null); |
|
| 26 | + $table->boolean('simulated')->default(false); |
|
| 27 | + $table->date('match_date')->default(\Carbon\Carbon::now()); |
|
| 28 | + $table->timestamps(); |
|
| 29 | + }); |
|
| 30 | + } |
|
| 31 | 31 | } |