@@ -38,7 +38,7 @@ |
||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 41 | + * @return \Illuminate\Database\Eloquent\Relations\HasOne |
|
| 42 | 42 | */ |
| 43 | 43 | public function coach() |
| 44 | 44 | {
|
@@ -8,132 +8,132 @@ |
||
| 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 | - /** |
|
| 122 | - * @return array |
|
| 123 | - */ |
|
| 124 | - public static function getBest() |
|
| 125 | - {
|
|
| 126 | - $result = Match::selectRaw('winner_id as id, COUNT(*) as won')
|
|
| 127 | - ->whereNotNull('winner_id')->where('winner_id', '!=', 0)
|
|
| 128 | - ->orderByRaw('COUNT(*) DESC')->groupBy('winner_id')
|
|
| 129 | - ->take(20)->get()->keyBy('id')->toArray();
|
|
| 130 | - $teams = Team::whereIn('id', array_keys($result))->get()->toArray();
|
|
| 131 | - $result = array_map(function ($team) use ($result) {
|
|
| 132 | - $team['stats'] = $result[$team['id']]; |
|
| 133 | - return $team; |
|
| 134 | - }, $teams); |
|
| 121 | + /** |
|
| 122 | + * @return array |
|
| 123 | + */ |
|
| 124 | + public static function getBest() |
|
| 125 | + {
|
|
| 126 | + $result = Match::selectRaw('winner_id as id, COUNT(*) as won')
|
|
| 127 | + ->whereNotNull('winner_id')->where('winner_id', '!=', 0)
|
|
| 128 | + ->orderByRaw('COUNT(*) DESC')->groupBy('winner_id')
|
|
| 129 | + ->take(20)->get()->keyBy('id')->toArray();
|
|
| 130 | + $teams = Team::whereIn('id', array_keys($result))->get()->toArray();
|
|
| 131 | + $result = array_map(function ($team) use ($result) {
|
|
| 132 | + $team['stats'] = $result[$team['id']]; |
|
| 133 | + return $team; |
|
| 134 | + }, $teams); |
|
| 135 | 135 | |
| 136 | - return $result; |
|
| 137 | - } |
|
| 136 | + return $result; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | } |
| 140 | 140 | \ No newline at end of file |
@@ -128,7 +128,7 @@ |
||
| 128 | 128 | ->orderByRaw('COUNT(*) DESC')->groupBy('winner_id')
|
| 129 | 129 | ->take(20)->get()->keyBy('id')->toArray();
|
| 130 | 130 | $teams = Team::whereIn('id', array_keys($result))->get()->toArray();
|
| 131 | - $result = array_map(function ($team) use ($result) {
|
|
| 131 | + $result = array_map(function($team) use ($result) {
|
|
| 132 | 132 | $team['stats'] = $result[$team['id']]; |
| 133 | 133 | return $team; |
| 134 | 134 | }, $teams); |
@@ -9,48 +9,48 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Responder |
| 11 | 11 | {
|
| 12 | - /** |
|
| 13 | - * @param $content |
|
| 14 | - * @param $response |
|
| 15 | - * @param array $headers |
|
| 16 | - * @return mixed |
|
| 17 | - */ |
|
| 18 | - public static function getJsonResponse($content, $response, $headers = []) |
|
| 19 | - {
|
|
| 20 | - $headers['Content-Type'] = 'application/json'; |
|
| 21 | - return self::getResponse( |
|
| 22 | - $headers, |
|
| 23 | - $content, |
|
| 24 | - $response |
|
| 25 | - ); |
|
| 26 | - } |
|
| 12 | + /** |
|
| 13 | + * @param $content |
|
| 14 | + * @param $response |
|
| 15 | + * @param array $headers |
|
| 16 | + * @return mixed |
|
| 17 | + */ |
|
| 18 | + public static function getJsonResponse($content, $response, $headers = []) |
|
| 19 | + {
|
|
| 20 | + $headers['Content-Type'] = 'application/json'; |
|
| 21 | + return self::getResponse( |
|
| 22 | + $headers, |
|
| 23 | + $content, |
|
| 24 | + $response |
|
| 25 | + ); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param array $headers |
|
| 30 | - * @param $content |
|
| 31 | - * @param $response |
|
| 32 | - * @return mixed |
|
| 33 | - */ |
|
| 34 | - public static function getResponse($headers = [], $content, $response) |
|
| 35 | - {
|
|
| 36 | - $body = $response->getBody(); |
|
| 37 | - $body->write($content); |
|
| 38 | - $i = 0; |
|
| 39 | - foreach ($headers as $header => $value) {
|
|
| 40 | - if ($i === 0) {
|
|
| 41 | - $response = $response->withHeader( |
|
| 42 | - $header, |
|
| 43 | - $value |
|
| 44 | - ); |
|
| 45 | - } else {
|
|
| 46 | - $response = $response->withAddedHeader( |
|
| 47 | - $header, |
|
| 48 | - $value |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - $i++; |
|
| 52 | - } |
|
| 53 | - return $response->withBody($body); |
|
| 54 | - } |
|
| 28 | + /** |
|
| 29 | + * @param array $headers |
|
| 30 | + * @param $content |
|
| 31 | + * @param $response |
|
| 32 | + * @return mixed |
|
| 33 | + */ |
|
| 34 | + public static function getResponse($headers = [], $content, $response) |
|
| 35 | + {
|
|
| 36 | + $body = $response->getBody(); |
|
| 37 | + $body->write($content); |
|
| 38 | + $i = 0; |
|
| 39 | + foreach ($headers as $header => $value) {
|
|
| 40 | + if ($i === 0) {
|
|
| 41 | + $response = $response->withHeader( |
|
| 42 | + $header, |
|
| 43 | + $value |
|
| 44 | + ); |
|
| 45 | + } else {
|
|
| 46 | + $response = $response->withAddedHeader( |
|
| 47 | + $header, |
|
| 48 | + $value |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + $i++; |
|
| 52 | + } |
|
| 53 | + return $response->withBody($body); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |
@@ -9,104 +9,104 @@ |
||
| 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 | - /** |
|
| 41 | - * @return mixed |
|
| 42 | - */ |
|
| 43 | - public function lastMatches() |
|
| 44 | - {
|
|
| 45 | - return $this->hasMany(MatchPlayer::class) |
|
| 46 | - ->orderBy('updated_at', 'DESC')
|
|
| 47 | - ->limit(5); |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * @return mixed |
|
| 42 | + */ |
|
| 43 | + public function lastMatches() |
|
| 44 | + {
|
|
| 45 | + return $this->hasMany(MatchPlayer::class) |
|
| 46 | + ->orderBy('updated_at', 'DESC')
|
|
| 47 | + ->limit(5); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @return mixed |
|
| 52 | - */ |
|
| 53 | - public function goals() |
|
| 54 | - {
|
|
| 55 | - return $this->hasOne(MatchPlayer::class) |
|
| 56 | - ->selectRaw('player_id, sum(goals) as count')
|
|
| 57 | - ->groupBy('player_id');
|
|
| 58 | - } |
|
| 50 | + /** |
|
| 51 | + * @return mixed |
|
| 52 | + */ |
|
| 53 | + public function goals() |
|
| 54 | + {
|
|
| 55 | + return $this->hasOne(MatchPlayer::class) |
|
| 56 | + ->selectRaw('player_id, sum(goals) as count')
|
|
| 57 | + ->groupBy('player_id');
|
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @return mixed |
|
| 62 | - */ |
|
| 63 | - public function appearances() |
|
| 64 | - {
|
|
| 65 | - return $this->hasOne(MatchPlayer::class) |
|
| 66 | - ->selectRaw('player_id, count(match_id) as count')
|
|
| 67 | - ->groupBy('player_id');
|
|
| 68 | - } |
|
| 60 | + /** |
|
| 61 | + * @return mixed |
|
| 62 | + */ |
|
| 63 | + public function appearances() |
|
| 64 | + {
|
|
| 65 | + return $this->hasOne(MatchPlayer::class) |
|
| 66 | + ->selectRaw('player_id, count(match_id) as count')
|
|
| 67 | + ->groupBy('player_id');
|
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return mixed |
|
| 72 | - */ |
|
| 73 | - public function avg() |
|
| 74 | - {
|
|
| 75 | - return $this->hasOne(MatchPlayer::class) |
|
| 76 | - ->selectRaw('player_id, round(avg(vote),2) as avg')
|
|
| 77 | - ->groupBy('player_id');
|
|
| 78 | - } |
|
| 70 | + /** |
|
| 71 | + * @return mixed |
|
| 72 | + */ |
|
| 73 | + public function avg() |
|
| 74 | + {
|
|
| 75 | + return $this->hasOne(MatchPlayer::class) |
|
| 76 | + ->selectRaw('player_id, round(avg(vote),2) as avg')
|
|
| 77 | + ->groupBy('player_id');
|
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @param $query |
|
| 82 | - * @return mixed |
|
| 83 | - */ |
|
| 84 | - public function scopeStatistics($query) |
|
| 85 | - {
|
|
| 86 | - return $query->with( |
|
| 87 | - 'goals', |
|
| 88 | - 'appearances', |
|
| 89 | - 'avg', |
|
| 90 | - 'lastMatches', |
|
| 91 | - 'team' |
|
| 92 | - ); |
|
| 93 | - } |
|
| 80 | + /** |
|
| 81 | + * @param $query |
|
| 82 | + * @return mixed |
|
| 83 | + */ |
|
| 84 | + public function scopeStatistics($query) |
|
| 85 | + {
|
|
| 86 | + return $query->with( |
|
| 87 | + 'goals', |
|
| 88 | + 'appearances', |
|
| 89 | + 'avg', |
|
| 90 | + 'lastMatches', |
|
| 91 | + 'team' |
|
| 92 | + ); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @return array |
|
| 97 | - */ |
|
| 98 | - public static function getBest() |
|
| 99 | - {
|
|
| 100 | - $result = MatchPlayer::selectRaw( |
|
| 101 | - 'player_id, COUNT(*) as appearances ,AVG(vote) avg, SUM(goals) goals' |
|
| 102 | - )->where('goals', '>', 0)
|
|
| 103 | - ->orderByRaw('SUM(goals) DESC,COUNT(*) DESC')
|
|
| 104 | - ->groupBy('player_id')->take(20)->get()->keyBy('player_id')->toArray();
|
|
| 105 | - $players = Player::whereIn('id', array_keys($result))->get()->toArray();
|
|
| 106 | - $result = array_map(function ($player) use ($result) {
|
|
| 107 | - $player['stats'] = $result[$player['id']]; |
|
| 108 | - return $player; |
|
| 109 | - }, $players); |
|
| 110 | - return $result; |
|
| 111 | - } |
|
| 95 | + /** |
|
| 96 | + * @return array |
|
| 97 | + */ |
|
| 98 | + public static function getBest() |
|
| 99 | + {
|
|
| 100 | + $result = MatchPlayer::selectRaw( |
|
| 101 | + 'player_id, COUNT(*) as appearances ,AVG(vote) avg, SUM(goals) goals' |
|
| 102 | + )->where('goals', '>', 0)
|
|
| 103 | + ->orderByRaw('SUM(goals) DESC,COUNT(*) DESC')
|
|
| 104 | + ->groupBy('player_id')->take(20)->get()->keyBy('player_id')->toArray();
|
|
| 105 | + $players = Player::whereIn('id', array_keys($result))->get()->toArray();
|
|
| 106 | + $result = array_map(function ($player) use ($result) {
|
|
| 107 | + $player['stats'] = $result[$player['id']]; |
|
| 108 | + return $player; |
|
| 109 | + }, $players); |
|
| 110 | + return $result; |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | \ No newline at end of file |
@@ -103,7 +103,7 @@ |
||
| 103 | 103 | ->orderByRaw('SUM(goals) DESC,COUNT(*) DESC')
|
| 104 | 104 | ->groupBy('player_id')->take(20)->get()->keyBy('player_id')->toArray();
|
| 105 | 105 | $players = Player::whereIn('id', array_keys($result))->get()->toArray();
|
| 106 | - $result = array_map(function ($player) use ($result) {
|
|
| 106 | + $result = array_map(function($player) use ($result) {
|
|
| 107 | 107 | $player['stats'] = $result[$player['id']]; |
| 108 | 108 | return $player; |
| 109 | 109 | }, $players); |
@@ -15,187 +15,187 @@ |
||
| 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('/statistics', function ($request, $response, $args) {
|
| 36 | - return Responder::getJsonResponse( |
|
| 37 | - json_encode([ |
|
| 38 | - 'players' => Player::getBest(), |
|
| 39 | - 'teams' => Team::getBest() |
|
| 40 | - ]), |
|
| 41 | - $response |
|
| 42 | - ); |
|
| 36 | + return Responder::getJsonResponse( |
|
| 37 | + json_encode([ |
|
| 38 | + 'players' => Player::getBest(), |
|
| 39 | + 'teams' => Team::getBest() |
|
| 40 | + ]), |
|
| 41 | + $response |
|
| 42 | + ); |
|
| 43 | 43 | }); |
| 44 | 44 | |
| 45 | 45 | $api->get('/coaches', function ($request, $response, $args) {
|
| 46 | - return Responder::getJsonResponse( |
|
| 47 | - Coach::all(), |
|
| 48 | - $response |
|
| 49 | - ); |
|
| 46 | + return Responder::getJsonResponse( |
|
| 47 | + Coach::all(), |
|
| 48 | + $response |
|
| 49 | + ); |
|
| 50 | 50 | }); |
| 51 | 51 | |
| 52 | 52 | $api->get('/teams', function ($request, $response, $args) {
|
| 53 | - return Responder::getJsonResponse( |
|
| 54 | - Team::all(), |
|
| 55 | - $response |
|
| 56 | - ); |
|
| 53 | + return Responder::getJsonResponse( |
|
| 54 | + Team::all(), |
|
| 55 | + $response |
|
| 56 | + ); |
|
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | 59 | $api->get('/teams/{id}', function ($request, $response, $args) {
|
| 60 | - return Responder::getJsonResponse( |
|
| 61 | - Team::complete() |
|
| 62 | - ->where( |
|
| 63 | - [ |
|
| 64 | - 'id' => $args['id'] |
|
| 65 | - ] |
|
| 66 | - )->get(), |
|
| 67 | - $response |
|
| 68 | - ); |
|
| 60 | + return Responder::getJsonResponse( |
|
| 61 | + Team::complete() |
|
| 62 | + ->where( |
|
| 63 | + [ |
|
| 64 | + 'id' => $args['id'] |
|
| 65 | + ] |
|
| 66 | + )->get(), |
|
| 67 | + $response |
|
| 68 | + ); |
|
| 69 | 69 | }); |
| 70 | 70 | |
| 71 | 71 | $api->get('/teams/{id}/players', function ($request, $response, $args) {
|
| 72 | - return Responder::getJsonResponse( |
|
| 73 | - Team::with( |
|
| 74 | - 'roster' |
|
| 75 | - )->where( |
|
| 76 | - [ |
|
| 77 | - 'id' => $args['id'] |
|
| 78 | - ] |
|
| 79 | - )->get(), |
|
| 80 | - $response |
|
| 81 | - ); |
|
| 72 | + return Responder::getJsonResponse( |
|
| 73 | + Team::with( |
|
| 74 | + 'roster' |
|
| 75 | + )->where( |
|
| 76 | + [ |
|
| 77 | + 'id' => $args['id'] |
|
| 78 | + ] |
|
| 79 | + )->get(), |
|
| 80 | + $response |
|
| 81 | + ); |
|
| 82 | 82 | }); |
| 83 | 83 | |
| 84 | 84 | $api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) {
|
| 85 | - return Responder::getJsonResponse( |
|
| 86 | - Player::statistics()->where( |
|
| 87 | - [ |
|
| 88 | - 'id' => $args['playerId'], |
|
| 89 | - 'team_id' => $args['id'] |
|
| 90 | - ] |
|
| 91 | - )->get(), |
|
| 92 | - $response |
|
| 93 | - ); |
|
| 85 | + return Responder::getJsonResponse( |
|
| 86 | + Player::statistics()->where( |
|
| 87 | + [ |
|
| 88 | + 'id' => $args['playerId'], |
|
| 89 | + 'team_id' => $args['id'] |
|
| 90 | + ] |
|
| 91 | + )->get(), |
|
| 92 | + $response |
|
| 93 | + ); |
|
| 94 | 94 | }); |
| 95 | 95 | |
| 96 | 96 | $api->get('/teams/{id}/coach', function ($request, $response, $args) {
|
| 97 | - return Responder::getJsonResponse( |
|
| 98 | - Team::with( |
|
| 99 | - 'coach' |
|
| 100 | - )->where( |
|
| 101 | - [ |
|
| 102 | - 'id' => $args['id'] |
|
| 103 | - ] |
|
| 104 | - )->get(), |
|
| 105 | - $response |
|
| 106 | - ); |
|
| 97 | + return Responder::getJsonResponse( |
|
| 98 | + Team::with( |
|
| 99 | + 'coach' |
|
| 100 | + )->where( |
|
| 101 | + [ |
|
| 102 | + 'id' => $args['id'] |
|
| 103 | + ] |
|
| 104 | + )->get(), |
|
| 105 | + $response |
|
| 106 | + ); |
|
| 107 | 107 | }); |
| 108 | 108 | |
| 109 | 109 | $api->get('/leagues', function ($request, $response, $args) {
|
| 110 | - return Responder::getJsonResponse( |
|
| 111 | - League::all(), |
|
| 112 | - $response |
|
| 113 | - ); |
|
| 110 | + return Responder::getJsonResponse( |
|
| 111 | + League::all(), |
|
| 112 | + $response |
|
| 113 | + ); |
|
| 114 | 114 | }); |
| 115 | 115 | |
| 116 | 116 | $api->get('/leagues/{id}', function ($request, $response, $args) {
|
| 117 | - return Responder::getJsonResponse( |
|
| 118 | - League::with('rounds')
|
|
| 119 | - ->where( |
|
| 120 | - [ |
|
| 121 | - 'id' => $args['id'] |
|
| 122 | - ] |
|
| 123 | - )->first(), |
|
| 124 | - $response |
|
| 125 | - ); |
|
| 117 | + return Responder::getJsonResponse( |
|
| 118 | + League::with('rounds')
|
|
| 119 | + ->where( |
|
| 120 | + [ |
|
| 121 | + 'id' => $args['id'] |
|
| 122 | + ] |
|
| 123 | + )->first(), |
|
| 124 | + $response |
|
| 125 | + ); |
|
| 126 | 126 | }); |
| 127 | 127 | |
| 128 | 128 | $api->get('/leagues/{id}/rounds/{roundId}', function ($request, $response, $args) {
|
| 129 | - return Responder::getJsonResponse( |
|
| 130 | - LeagueRound::complete() |
|
| 131 | - ->where( |
|
| 132 | - [ |
|
| 133 | - 'id' => $args['roundId'], |
|
| 134 | - ] |
|
| 135 | - )->first(), |
|
| 136 | - $response |
|
| 137 | - ); |
|
| 129 | + return Responder::getJsonResponse( |
|
| 130 | + LeagueRound::complete() |
|
| 131 | + ->where( |
|
| 132 | + [ |
|
| 133 | + 'id' => $args['roundId'], |
|
| 134 | + ] |
|
| 135 | + )->first(), |
|
| 136 | + $response |
|
| 137 | + ); |
|
| 138 | 138 | }); |
| 139 | 139 | |
| 140 | 140 | $api->put('/leagues/{id}/rounds/{roundId}/simulate', function ($request, $response, $args) {
|
| 141 | - return Responder::getJsonResponse( |
|
| 142 | - MatchSimulator::simulateRound( |
|
| 143 | - $args['roundId'] |
|
| 144 | - ), |
|
| 145 | - $response |
|
| 146 | - ); |
|
| 141 | + return Responder::getJsonResponse( |
|
| 142 | + MatchSimulator::simulateRound( |
|
| 143 | + $args['roundId'] |
|
| 144 | + ), |
|
| 145 | + $response |
|
| 146 | + ); |
|
| 147 | 147 | }); |
| 148 | 148 | |
| 149 | 149 | $api->get('/matches', function ($request, $response, $args) {
|
| 150 | - return Responder::getJsonResponse( |
|
| 151 | - Match::teams()->get(), |
|
| 152 | - $response |
|
| 153 | - ); |
|
| 150 | + return Responder::getJsonResponse( |
|
| 151 | + Match::teams()->get(), |
|
| 152 | + $response |
|
| 153 | + ); |
|
| 154 | 154 | }); |
| 155 | 155 | |
| 156 | 156 | $api->post('/matches', function ($request, $response, $args) {
|
| 157 | - $json = $request->getBody(); |
|
| 158 | - $json = json_decode($json, true); |
|
| 159 | - return Responder::getJsonResponse( |
|
| 160 | - Match::create( |
|
| 161 | - $json |
|
| 162 | - ), |
|
| 163 | - $response |
|
| 164 | - ); |
|
| 157 | + $json = $request->getBody(); |
|
| 158 | + $json = json_decode($json, true); |
|
| 159 | + return Responder::getJsonResponse( |
|
| 160 | + Match::create( |
|
| 161 | + $json |
|
| 162 | + ), |
|
| 163 | + $response |
|
| 164 | + ); |
|
| 165 | 165 | }); |
| 166 | 166 | |
| 167 | 167 | $api->get('/matches/{id}', function ($request, $response, $args) {
|
| 168 | - return Responder::getJsonResponse( |
|
| 169 | - Match::complete() |
|
| 170 | - ->where( |
|
| 171 | - [ |
|
| 172 | - 'id' => $args['id'] |
|
| 173 | - ] |
|
| 174 | - )->first(), |
|
| 175 | - $response |
|
| 176 | - ); |
|
| 168 | + return Responder::getJsonResponse( |
|
| 169 | + Match::complete() |
|
| 170 | + ->where( |
|
| 171 | + [ |
|
| 172 | + 'id' => $args['id'] |
|
| 173 | + ] |
|
| 174 | + )->first(), |
|
| 175 | + $response |
|
| 176 | + ); |
|
| 177 | 177 | }); |
| 178 | 178 | |
| 179 | 179 | $api->get('/matches/{id}/result', function ($request, $response, $args) {
|
| 180 | - $result = MatchResult::complete() |
|
| 181 | - ->where( |
|
| 182 | - [ |
|
| 183 | - 'id' => $args['id'] |
|
| 184 | - ] |
|
| 185 | - )->first(); |
|
| 180 | + $result = MatchResult::complete() |
|
| 181 | + ->where( |
|
| 182 | + [ |
|
| 183 | + 'id' => $args['id'] |
|
| 184 | + ] |
|
| 185 | + )->first(); |
|
| 186 | 186 | |
| 187 | - return Responder::getJsonResponse( |
|
| 188 | - $result, |
|
| 189 | - $response |
|
| 190 | - ); |
|
| 187 | + return Responder::getJsonResponse( |
|
| 188 | + $result, |
|
| 189 | + $response |
|
| 190 | + ); |
|
| 191 | 191 | }); |
| 192 | 192 | |
| 193 | 193 | $api->put('/matches/{id}/simulate', function ($request, $response, $args) {
|
| 194 | - return Responder::getJsonResponse( |
|
| 195 | - MatchSimulator::simulateCompleteResult( |
|
| 196 | - $args['id'] |
|
| 197 | - ), |
|
| 198 | - $response |
|
| 199 | - ); |
|
| 194 | + return Responder::getJsonResponse( |
|
| 195 | + MatchSimulator::simulateCompleteResult( |
|
| 196 | + $args['id'] |
|
| 197 | + ), |
|
| 198 | + $response |
|
| 199 | + ); |
|
| 200 | 200 | }); |
| 201 | 201 | $api->run(); |
| 202 | 202 | \ No newline at end of file |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | $c = new \Slim\Container($configuration); |
| 23 | 23 | $api = new \Slim\App($c); |
| 24 | 24 | |
| 25 | -$api->get('/ping', function ($request, $response, $args) {
|
|
| 25 | +$api->get('/ping', function($request, $response, $args) {
|
|
| 26 | 26 | $jsonResp = json_encode( |
| 27 | 27 | [ |
| 28 | 28 | "status" => "service up", |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | return Responder::getJsonResponse($jsonResp, $response); |
| 33 | 33 | }); |
| 34 | 34 | |
| 35 | -$api->get('/statistics', function ($request, $response, $args) {
|
|
| 35 | +$api->get('/statistics', function($request, $response, $args) {
|
|
| 36 | 36 | return Responder::getJsonResponse( |
| 37 | 37 | json_encode([ |
| 38 | 38 | 'players' => Player::getBest(), |
@@ -42,21 +42,21 @@ discard block |
||
| 42 | 42 | ); |
| 43 | 43 | }); |
| 44 | 44 | |
| 45 | -$api->get('/coaches', function ($request, $response, $args) {
|
|
| 45 | +$api->get('/coaches', function($request, $response, $args) {
|
|
| 46 | 46 | return Responder::getJsonResponse( |
| 47 | 47 | Coach::all(), |
| 48 | 48 | $response |
| 49 | 49 | ); |
| 50 | 50 | }); |
| 51 | 51 | |
| 52 | -$api->get('/teams', function ($request, $response, $args) {
|
|
| 52 | +$api->get('/teams', function($request, $response, $args) {
|
|
| 53 | 53 | return Responder::getJsonResponse( |
| 54 | 54 | Team::all(), |
| 55 | 55 | $response |
| 56 | 56 | ); |
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | -$api->get('/teams/{id}', function ($request, $response, $args) {
|
|
| 59 | +$api->get('/teams/{id}', function($request, $response, $args) {
|
|
| 60 | 60 | return Responder::getJsonResponse( |
| 61 | 61 | Team::complete() |
| 62 | 62 | ->where( |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | ); |
| 69 | 69 | }); |
| 70 | 70 | |
| 71 | -$api->get('/teams/{id}/players', function ($request, $response, $args) {
|
|
| 71 | +$api->get('/teams/{id}/players', function($request, $response, $args) {
|
|
| 72 | 72 | return Responder::getJsonResponse( |
| 73 | 73 | Team::with( |
| 74 | 74 | 'roster' |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | ); |
| 82 | 82 | }); |
| 83 | 83 | |
| 84 | -$api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) {
|
|
| 84 | +$api->get('/teams/{id}/players/{playerId}', function($request, $response, $args) {
|
|
| 85 | 85 | return Responder::getJsonResponse( |
| 86 | 86 | Player::statistics()->where( |
| 87 | 87 | [ |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | ); |
| 94 | 94 | }); |
| 95 | 95 | |
| 96 | -$api->get('/teams/{id}/coach', function ($request, $response, $args) {
|
|
| 96 | +$api->get('/teams/{id}/coach', function($request, $response, $args) {
|
|
| 97 | 97 | return Responder::getJsonResponse( |
| 98 | 98 | Team::with( |
| 99 | 99 | 'coach' |
@@ -106,14 +106,14 @@ discard block |
||
| 106 | 106 | ); |
| 107 | 107 | }); |
| 108 | 108 | |
| 109 | -$api->get('/leagues', function ($request, $response, $args) {
|
|
| 109 | +$api->get('/leagues', function($request, $response, $args) {
|
|
| 110 | 110 | return Responder::getJsonResponse( |
| 111 | 111 | League::all(), |
| 112 | 112 | $response |
| 113 | 113 | ); |
| 114 | 114 | }); |
| 115 | 115 | |
| 116 | -$api->get('/leagues/{id}', function ($request, $response, $args) {
|
|
| 116 | +$api->get('/leagues/{id}', function($request, $response, $args) {
|
|
| 117 | 117 | return Responder::getJsonResponse( |
| 118 | 118 | League::with('rounds')
|
| 119 | 119 | ->where( |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | ); |
| 126 | 126 | }); |
| 127 | 127 | |
| 128 | -$api->get('/leagues/{id}/rounds/{roundId}', function ($request, $response, $args) {
|
|
| 128 | +$api->get('/leagues/{id}/rounds/{roundId}', function($request, $response, $args) {
|
|
| 129 | 129 | return Responder::getJsonResponse( |
| 130 | 130 | LeagueRound::complete() |
| 131 | 131 | ->where( |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | ); |
| 138 | 138 | }); |
| 139 | 139 | |
| 140 | -$api->put('/leagues/{id}/rounds/{roundId}/simulate', function ($request, $response, $args) {
|
|
| 140 | +$api->put('/leagues/{id}/rounds/{roundId}/simulate', function($request, $response, $args) {
|
|
| 141 | 141 | return Responder::getJsonResponse( |
| 142 | 142 | MatchSimulator::simulateRound( |
| 143 | 143 | $args['roundId'] |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | ); |
| 147 | 147 | }); |
| 148 | 148 | |
| 149 | -$api->get('/matches', function ($request, $response, $args) {
|
|
| 149 | +$api->get('/matches', function($request, $response, $args) {
|
|
| 150 | 150 | return Responder::getJsonResponse( |
| 151 | 151 | Match::teams()->get(), |
| 152 | 152 | $response |
| 153 | 153 | ); |
| 154 | 154 | }); |
| 155 | 155 | |
| 156 | -$api->post('/matches', function ($request, $response, $args) {
|
|
| 156 | +$api->post('/matches', function($request, $response, $args) {
|
|
| 157 | 157 | $json = $request->getBody(); |
| 158 | 158 | $json = json_decode($json, true); |
| 159 | 159 | return Responder::getJsonResponse( |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | ); |
| 165 | 165 | }); |
| 166 | 166 | |
| 167 | -$api->get('/matches/{id}', function ($request, $response, $args) {
|
|
| 167 | +$api->get('/matches/{id}', function($request, $response, $args) {
|
|
| 168 | 168 | return Responder::getJsonResponse( |
| 169 | 169 | Match::complete() |
| 170 | 170 | ->where( |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | ); |
| 177 | 177 | }); |
| 178 | 178 | |
| 179 | -$api->get('/matches/{id}/result', function ($request, $response, $args) {
|
|
| 179 | +$api->get('/matches/{id}/result', function($request, $response, $args) {
|
|
| 180 | 180 | $result = MatchResult::complete() |
| 181 | 181 | ->where( |
| 182 | 182 | [ |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | ); |
| 191 | 191 | }); |
| 192 | 192 | |
| 193 | -$api->put('/matches/{id}/simulate', function ($request, $response, $args) {
|
|
| 193 | +$api->put('/matches/{id}/simulate', function($request, $response, $args) {
|
|
| 194 | 194 | return Responder::getJsonResponse( |
| 195 | 195 | MatchSimulator::simulateCompleteResult( |
| 196 | 196 | $args['id'] |