@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace App\Lib\DsManager\Models; |
4 | 4 | |
5 | -use App\Lib\DsManager\Helpers\Randomizer; |
|
5 | +use App\Lib\DsManager\Helpers\Randomizer; |
|
6 | 6 | use App\Lib\Helpers\Config; |
7 | 7 | |
8 | 8 |
@@ -11,164 +11,164 @@ |
||
11 | 11 | */ |
12 | 12 | class Match extends DsManagerModel |
13 | 13 | { |
14 | - /** |
|
15 | - * @var Team |
|
16 | - */ |
|
17 | - private $homeTeam; |
|
18 | - /** |
|
19 | - * @var Team |
|
20 | - */ |
|
21 | - private $awayTeam; |
|
22 | - |
|
23 | - /** |
|
24 | - * Match constructor. |
|
25 | - * @param Team $home |
|
26 | - * @param Team $away |
|
27 | - */ |
|
28 | - public function __construct(Team $home, Team $away) |
|
29 | - { |
|
30 | - $this->homeTeam = $home; |
|
31 | - $this->awayTeam = $away; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @return MatchResult |
|
36 | - */ |
|
37 | - public function simulate() |
|
38 | - { |
|
39 | - $homePoints = $this->homeTeam->getAvgSkill(); |
|
40 | - $awayPoints = $this->awayTeam->getAvgSkill(); |
|
41 | - |
|
42 | - $homePoints += $this->malusModule( |
|
43 | - $this->homeTeam->coach->favouriteModule, |
|
44 | - $this->homeTeam->playersPerRoleArray() |
|
45 | - ); |
|
46 | - $awayPoints += $this->malusModule( |
|
47 | - $this->awayTeam->coach->favouriteModule, |
|
48 | - $this->awayTeam->playersPerRoleArray() |
|
49 | - ); |
|
50 | - |
|
51 | - $goalHome = 0; |
|
52 | - $goalAway = 0; |
|
53 | - |
|
54 | - if (Randomizer::boolOnPercentage(80)) { |
|
55 | - if (($homePoints - $awayPoints) < 0) { |
|
56 | - $goalAway = ($awayPoints - $homePoints) % 6; |
|
57 | - $goalHome += $this->chance(); |
|
58 | - $goalAway += $this->chance(); |
|
59 | - $goalHome += $this->bonusHome(); |
|
60 | - } else { |
|
61 | - $goalHome = ($homePoints - $awayPoints) % 6; |
|
62 | - $goalAway += $this->chance(); |
|
63 | - $goalHome += $this->bonusHome(); |
|
64 | - } |
|
65 | - } else { |
|
66 | - $goalHome += $this->chance(); |
|
67 | - $goalAway += $this->chance(); |
|
68 | - $goalHome += $this->bonusHome(); |
|
69 | - } |
|
70 | - $goalHome += $this->bonusAge($this->homeTeam); |
|
71 | - $goalAway += $this->bonusAge($this->awayTeam); |
|
72 | - |
|
73 | - //Bonus on Good GoalKeeper |
|
74 | - $goalies = $this->homeTeam->getBestPlayerForRole("GK"); |
|
75 | - $goalAway -= $this->bonusGoalKeeper($goalies); |
|
76 | - $goalies = $this->awayTeam->getBestPlayerForRole("GK"); |
|
77 | - $goalHome -= $this->bonusGoalKeeper($goalies); |
|
78 | - // |
|
79 | - $homeModule = new Module($this->homeTeam->coach->favouriteModule); |
|
80 | - $awayModule = new Module($this->awayTeam->coach->favouriteModule); |
|
81 | - if ($homeModule->isOffensive()) { |
|
82 | - $goalHome += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
|
83 | - $goalAway += Randomizer::boolOnPercentage(20) ? 1 : 0; |
|
84 | - } |
|
85 | - if ($awayModule->isOffensive()) { |
|
86 | - $goalAway += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
|
87 | - $goalHome += Randomizer::boolOnPercentage(20) ? 1 : 0; |
|
88 | - } |
|
89 | - if ($awayModule->isDefensive()) { |
|
90 | - $goalHome -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
|
91 | - } |
|
92 | - if ($homeModule->isDefensive()) { |
|
93 | - $goalAway -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
|
94 | - } |
|
95 | - $goalHome = $goalHome < 0 ? 0 : $goalHome; |
|
96 | - $goalAway = $goalAway < 0 ? 0 : $goalAway; |
|
97 | - return new MatchResult($goalHome, $goalAway, $this->homeTeam, $this->awayTeam); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param Team $team |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - private function bonusAge(Team $team) |
|
105 | - { |
|
106 | - if ($team->getAvgAge() > 29 || $team->getAvgAge() < 24) { |
|
107 | - return $this->chance(); |
|
108 | - } |
|
109 | - return 0; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @param $goalkeeper |
|
114 | - * @return int |
|
115 | - */ |
|
116 | - private function bonusGoalKeeper($goalkeeper) |
|
117 | - { |
|
118 | - $skillGoalkeeper = empty($goalkeeper) ? 1 : $goalkeeper->skillAvg; |
|
119 | - return (Randomizer::boolOnPercentage($skillGoalkeeper) ? 1 : 0); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @return int |
|
124 | - */ |
|
125 | - private function chance() |
|
126 | - { |
|
127 | - return rand(0, 3); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return int |
|
132 | - */ |
|
133 | - private function bonusHome() |
|
134 | - { |
|
135 | - return Randomizer::boolOnPercentage(66) ? 1 : 0; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @param $moduleString |
|
140 | - * @param $playersRoleArray |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - private function malusModule($moduleString, $playersRoleArray) |
|
144 | - { |
|
145 | - $module = new Module($moduleString); |
|
146 | - if ($module->isApplicableToArray($playersRoleArray)) { |
|
147 | - return rand(1, 10); |
|
148 | - } else { |
|
149 | - return (-1) * rand(1, 10); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param array $ormMatchArray |
|
155 | - * @return Match |
|
156 | - */ |
|
157 | - public static function fromArray($ormMatchArray = []) |
|
158 | - { |
|
159 | - $homeTeam = Team::fromArray($ormMatchArray['home_team']); |
|
160 | - $awayTeam = Team::fromArray($ormMatchArray['away_team']); |
|
161 | - return new Match($homeTeam, $awayTeam); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @return mixed |
|
166 | - */ |
|
167 | - function toArray() |
|
168 | - { |
|
169 | - $result = []; |
|
170 | - $result['home_team_id'] = $this->homeTeam->id; |
|
171 | - $result['away_team_id'] = $this->awayTeam->id; |
|
172 | - return $result; |
|
173 | - } |
|
14 | + /** |
|
15 | + * @var Team |
|
16 | + */ |
|
17 | + private $homeTeam; |
|
18 | + /** |
|
19 | + * @var Team |
|
20 | + */ |
|
21 | + private $awayTeam; |
|
22 | + |
|
23 | + /** |
|
24 | + * Match constructor. |
|
25 | + * @param Team $home |
|
26 | + * @param Team $away |
|
27 | + */ |
|
28 | + public function __construct(Team $home, Team $away) |
|
29 | + { |
|
30 | + $this->homeTeam = $home; |
|
31 | + $this->awayTeam = $away; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @return MatchResult |
|
36 | + */ |
|
37 | + public function simulate() |
|
38 | + { |
|
39 | + $homePoints = $this->homeTeam->getAvgSkill(); |
|
40 | + $awayPoints = $this->awayTeam->getAvgSkill(); |
|
41 | + |
|
42 | + $homePoints += $this->malusModule( |
|
43 | + $this->homeTeam->coach->favouriteModule, |
|
44 | + $this->homeTeam->playersPerRoleArray() |
|
45 | + ); |
|
46 | + $awayPoints += $this->malusModule( |
|
47 | + $this->awayTeam->coach->favouriteModule, |
|
48 | + $this->awayTeam->playersPerRoleArray() |
|
49 | + ); |
|
50 | + |
|
51 | + $goalHome = 0; |
|
52 | + $goalAway = 0; |
|
53 | + |
|
54 | + if (Randomizer::boolOnPercentage(80)) { |
|
55 | + if (($homePoints - $awayPoints) < 0) { |
|
56 | + $goalAway = ($awayPoints - $homePoints) % 6; |
|
57 | + $goalHome += $this->chance(); |
|
58 | + $goalAway += $this->chance(); |
|
59 | + $goalHome += $this->bonusHome(); |
|
60 | + } else { |
|
61 | + $goalHome = ($homePoints - $awayPoints) % 6; |
|
62 | + $goalAway += $this->chance(); |
|
63 | + $goalHome += $this->bonusHome(); |
|
64 | + } |
|
65 | + } else { |
|
66 | + $goalHome += $this->chance(); |
|
67 | + $goalAway += $this->chance(); |
|
68 | + $goalHome += $this->bonusHome(); |
|
69 | + } |
|
70 | + $goalHome += $this->bonusAge($this->homeTeam); |
|
71 | + $goalAway += $this->bonusAge($this->awayTeam); |
|
72 | + |
|
73 | + //Bonus on Good GoalKeeper |
|
74 | + $goalies = $this->homeTeam->getBestPlayerForRole("GK"); |
|
75 | + $goalAway -= $this->bonusGoalKeeper($goalies); |
|
76 | + $goalies = $this->awayTeam->getBestPlayerForRole("GK"); |
|
77 | + $goalHome -= $this->bonusGoalKeeper($goalies); |
|
78 | + // |
|
79 | + $homeModule = new Module($this->homeTeam->coach->favouriteModule); |
|
80 | + $awayModule = new Module($this->awayTeam->coach->favouriteModule); |
|
81 | + if ($homeModule->isOffensive()) { |
|
82 | + $goalHome += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
|
83 | + $goalAway += Randomizer::boolOnPercentage(20) ? 1 : 0; |
|
84 | + } |
|
85 | + if ($awayModule->isOffensive()) { |
|
86 | + $goalAway += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
|
87 | + $goalHome += Randomizer::boolOnPercentage(20) ? 1 : 0; |
|
88 | + } |
|
89 | + if ($awayModule->isDefensive()) { |
|
90 | + $goalHome -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
|
91 | + } |
|
92 | + if ($homeModule->isDefensive()) { |
|
93 | + $goalAway -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
|
94 | + } |
|
95 | + $goalHome = $goalHome < 0 ? 0 : $goalHome; |
|
96 | + $goalAway = $goalAway < 0 ? 0 : $goalAway; |
|
97 | + return new MatchResult($goalHome, $goalAway, $this->homeTeam, $this->awayTeam); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param Team $team |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + private function bonusAge(Team $team) |
|
105 | + { |
|
106 | + if ($team->getAvgAge() > 29 || $team->getAvgAge() < 24) { |
|
107 | + return $this->chance(); |
|
108 | + } |
|
109 | + return 0; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @param $goalkeeper |
|
114 | + * @return int |
|
115 | + */ |
|
116 | + private function bonusGoalKeeper($goalkeeper) |
|
117 | + { |
|
118 | + $skillGoalkeeper = empty($goalkeeper) ? 1 : $goalkeeper->skillAvg; |
|
119 | + return (Randomizer::boolOnPercentage($skillGoalkeeper) ? 1 : 0); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @return int |
|
124 | + */ |
|
125 | + private function chance() |
|
126 | + { |
|
127 | + return rand(0, 3); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return int |
|
132 | + */ |
|
133 | + private function bonusHome() |
|
134 | + { |
|
135 | + return Randomizer::boolOnPercentage(66) ? 1 : 0; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @param $moduleString |
|
140 | + * @param $playersRoleArray |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + private function malusModule($moduleString, $playersRoleArray) |
|
144 | + { |
|
145 | + $module = new Module($moduleString); |
|
146 | + if ($module->isApplicableToArray($playersRoleArray)) { |
|
147 | + return rand(1, 10); |
|
148 | + } else { |
|
149 | + return (-1) * rand(1, 10); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param array $ormMatchArray |
|
155 | + * @return Match |
|
156 | + */ |
|
157 | + public static function fromArray($ormMatchArray = []) |
|
158 | + { |
|
159 | + $homeTeam = Team::fromArray($ormMatchArray['home_team']); |
|
160 | + $awayTeam = Team::fromArray($ormMatchArray['away_team']); |
|
161 | + return new Match($homeTeam, $awayTeam); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @return mixed |
|
166 | + */ |
|
167 | + function toArray() |
|
168 | + { |
|
169 | + $result = []; |
|
170 | + $result['home_team_id'] = $this->homeTeam->id; |
|
171 | + $result['away_team_id'] = $this->awayTeam->id; |
|
172 | + return $result; |
|
173 | + } |
|
174 | 174 | } |
175 | 175 | \ No newline at end of file |
@@ -3,20 +3,20 @@ |
||
3 | 3 | |
4 | 4 | class BMatchesSeeder |
5 | 5 | { |
6 | - function run() |
|
7 | - { |
|
8 | - $teams = \App\Lib\DsManager\Models\Orm\Team::all()->toArray(); |
|
9 | - $halfTheTeams = count($teams) / 2; |
|
10 | - $chunks = array_chunk($teams, $halfTheTeams); |
|
11 | - $teamsSlice1 = $chunks[0]; |
|
12 | - $teamsSlice2 = $chunks[1]; |
|
13 | - for ($i = 0; $i < $halfTheTeams; $i++) { |
|
14 | - \App\Lib\DsManager\Models\Orm\Match::create( |
|
15 | - [ |
|
16 | - 'home_team_id' => $teamsSlice1[$i]['id'], |
|
17 | - 'away_team_id' => $teamsSlice2[$i]['id'] |
|
18 | - ] |
|
19 | - ); |
|
20 | - } |
|
21 | - } |
|
6 | + function run() |
|
7 | + { |
|
8 | + $teams = \App\Lib\DsManager\Models\Orm\Team::all()->toArray(); |
|
9 | + $halfTheTeams = count($teams) / 2; |
|
10 | + $chunks = array_chunk($teams, $halfTheTeams); |
|
11 | + $teamsSlice1 = $chunks[0]; |
|
12 | + $teamsSlice2 = $chunks[1]; |
|
13 | + for ($i = 0; $i < $halfTheTeams; $i++) { |
|
14 | + \App\Lib\DsManager\Models\Orm\Match::create( |
|
15 | + [ |
|
16 | + 'home_team_id' => $teamsSlice1[$i]['id'], |
|
17 | + 'away_team_id' => $teamsSlice2[$i]['id'] |
|
18 | + ] |
|
19 | + ); |
|
20 | + } |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -5,24 +5,24 @@ |
||
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('home_team_id'); |
|
19 | - $table->integer('goal_home')->default(0); |
|
20 | - $table->integer('away_team_id'); |
|
21 | - $table->integer('goal_away')->default(0); |
|
22 | - $table->boolean('simulated')->default(false); |
|
23 | - $table->text('info')->nullable(); |
|
24 | - $table->date('match_date')->default(\Carbon\Carbon::now()); |
|
25 | - $table->timestamps(); |
|
26 | - }); |
|
27 | - } |
|
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('home_team_id'); |
|
19 | + $table->integer('goal_home')->default(0); |
|
20 | + $table->integer('away_team_id'); |
|
21 | + $table->integer('goal_away')->default(0); |
|
22 | + $table->boolean('simulated')->default(false); |
|
23 | + $table->text('info')->nullable(); |
|
24 | + $table->date('match_date')->default(\Carbon\Carbon::now()); |
|
25 | + $table->timestamps(); |
|
26 | + }); |
|
27 | + } |
|
28 | 28 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function run() |
14 | 14 | { |
15 | 15 | Capsule::schema()->dropIfExists('matches'); |
16 | - Capsule::schema()->create('matches', function (Blueprint $table) { |
|
16 | + Capsule::schema()->create('matches', function(Blueprint $table) { |
|
17 | 17 | $table->increments('id'); |
18 | 18 | $table->integer('home_team_id'); |
19 | 19 | $table->integer('goal_home')->default(0); |
@@ -9,62 +9,62 @@ |
||
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 | - ]; |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected $fillable = [ |
|
21 | + 'home_team_id', |
|
22 | + 'away_team_id' |
|
23 | + ]; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $hidden = [ |
|
29 | - 'home_team_id', |
|
30 | - 'away_team_id', |
|
31 | - 'created_at', |
|
32 | - 'updated_at', |
|
33 | - 'info' |
|
34 | - ]; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $hidden = [ |
|
29 | + 'home_team_id', |
|
30 | + 'away_team_id', |
|
31 | + 'created_at', |
|
32 | + 'updated_at', |
|
33 | + 'info' |
|
34 | + ]; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $casts = [ |
|
40 | - 'simulated' => 'boolean' |
|
41 | - ]; |
|
36 | + /** |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $casts = [ |
|
40 | + 'simulated' => 'boolean' |
|
41 | + ]; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
45 | - */ |
|
46 | - public function homeTeam() |
|
47 | - { |
|
48 | - return $this->belongsTo(Team::class, 'home_team_id'); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
45 | + */ |
|
46 | + public function homeTeam() |
|
47 | + { |
|
48 | + return $this->belongsTo(Team::class, 'home_team_id'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
53 | - */ |
|
54 | - public function awayTeam() |
|
55 | - { |
|
56 | - return $this->belongsTo(Team::class, 'away_team_id'); |
|
57 | - } |
|
51 | + /** |
|
52 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
53 | + */ |
|
54 | + public function awayTeam() |
|
55 | + { |
|
56 | + return $this->belongsTo(Team::class, 'away_team_id'); |
|
57 | + } |
|
58 | 58 | |
59 | - public function scopeComplete($query){ |
|
60 | - return $query->with( |
|
61 | - 'homeTeam', |
|
62 | - 'homeTeam.roster', |
|
63 | - 'homeTeam.coach', |
|
64 | - 'awayTeam', |
|
65 | - 'awayTeam.roster', |
|
66 | - 'awayTeam.coach' |
|
67 | - ); |
|
68 | - } |
|
59 | + public function scopeComplete($query){ |
|
60 | + return $query->with( |
|
61 | + 'homeTeam', |
|
62 | + 'homeTeam.roster', |
|
63 | + 'homeTeam.coach', |
|
64 | + 'awayTeam', |
|
65 | + 'awayTeam.roster', |
|
66 | + 'awayTeam.coach' |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | \ No newline at end of file |
@@ -56,7 +56,7 @@ |
||
56 | 56 | return $this->belongsTo(Team::class, 'away_team_id'); |
57 | 57 | } |
58 | 58 | |
59 | - public function scopeComplete($query){ |
|
59 | + public function scopeComplete($query) { |
|
60 | 60 | return $query->with( |
61 | 61 | 'homeTeam', |
62 | 62 | 'homeTeam.roster', |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | $c = new \Slim\Container($configuration); |
18 | 18 | $api = new \Slim\App($c); |
19 | 19 | |
20 | -$api->get('/ping', function ($request, $response, $args) { |
|
20 | +$api->get('/ping', function($request, $response, $args) { |
|
21 | 21 | $jsonResp = json_encode( |
22 | 22 | [ |
23 | 23 | "status" => "service up", |
@@ -28,34 +28,34 @@ discard block |
||
28 | 28 | return Responder::getJsonResponse($jsonResp, $response); |
29 | 29 | }); |
30 | 30 | |
31 | -$api->get('/players', function ($request, $response, $args) { |
|
31 | +$api->get('/players', function($request, $response, $args) { |
|
32 | 32 | $json = json_encode(Player::all()); |
33 | 33 | return Responder::getJsonResponse($json, $response); |
34 | 34 | }); |
35 | 35 | |
36 | 36 | |
37 | -$api->get('/players/{id}', function ($request, $response, $args) { |
|
37 | +$api->get('/players/{id}', function($request, $response, $args) { |
|
38 | 38 | return Responder::getJsonResponse( |
39 | 39 | Player::findOrFail($args['id']), |
40 | 40 | $response |
41 | 41 | ); |
42 | 42 | }); |
43 | 43 | |
44 | -$api->get('/coaches', function ($request, $response, $args) { |
|
44 | +$api->get('/coaches', function($request, $response, $args) { |
|
45 | 45 | return Responder::getJsonResponse( |
46 | 46 | Coach::all(), |
47 | 47 | $response |
48 | 48 | ); |
49 | 49 | }); |
50 | 50 | |
51 | -$api->get('/teams', function ($request, $response, $args) { |
|
51 | +$api->get('/teams', function($request, $response, $args) { |
|
52 | 52 | return Responder::getJsonResponse( |
53 | 53 | Team::all(), |
54 | 54 | $response |
55 | 55 | ); |
56 | 56 | }); |
57 | 57 | |
58 | -$api->get('/teams/{id}', function ($request, $response, $args) { |
|
58 | +$api->get('/teams/{id}', function($request, $response, $args) { |
|
59 | 59 | return Responder::getJsonResponse( |
60 | 60 | Team::with( |
61 | 61 | 'roster', |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | ); |
70 | 70 | }); |
71 | 71 | |
72 | -$api->get('/teams/{id}/players', function ($request, $response, $args) { |
|
72 | +$api->get('/teams/{id}/players', function($request, $response, $args) { |
|
73 | 73 | return Responder::getJsonResponse( |
74 | 74 | Team::with( |
75 | 75 | 'roster' |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ); |
83 | 83 | }); |
84 | 84 | |
85 | -$api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) { |
|
85 | +$api->get('/teams/{id}/players/{playerId}', function($request, $response, $args) { |
|
86 | 86 | return Responder::getJsonResponse( |
87 | 87 | Player::where( |
88 | 88 | [ |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | ); |
95 | 95 | }); |
96 | 96 | |
97 | -$api->get('/teams/{id}/coach', function ($request, $response, $args) { |
|
97 | +$api->get('/teams/{id}/coach', function($request, $response, $args) { |
|
98 | 98 | return Responder::getJsonResponse( |
99 | 99 | Team::with( |
100 | 100 | 'coach' |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ); |
108 | 108 | }); |
109 | 109 | |
110 | -$api->get('/matches', function ($request, $response, $args) { |
|
110 | +$api->get('/matches', function($request, $response, $args) { |
|
111 | 111 | return Responder::getJsonResponse( |
112 | 112 | \App\Lib\DsManager\Models\Orm\Match::with( |
113 | 113 | 'homeTeam', |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ); |
118 | 118 | }); |
119 | 119 | |
120 | -$api->post('/matches', function ($request, $response, $args) { |
|
120 | +$api->post('/matches', function($request, $response, $args) { |
|
121 | 121 | $json = $request->getBody(); |
122 | 122 | $json = json_decode($json, true); |
123 | 123 | return Responder::getJsonResponse( |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | ); |
129 | 129 | }); |
130 | 130 | |
131 | -$api->get('/matches/{id}', function ($request, $response, $args) { |
|
131 | +$api->get('/matches/{id}', function($request, $response, $args) { |
|
132 | 132 | return Responder::getJsonResponse( |
133 | 133 | \App\Lib\DsManager\Models\Orm\Match::with( |
134 | 134 | 'homeTeam', |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | ); |
147 | 147 | }); |
148 | 148 | |
149 | -$api->get('/matches/{id}/result', function ($request, $response, $args) { |
|
149 | +$api->get('/matches/{id}/result', function($request, $response, $args) { |
|
150 | 150 | $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
151 | 151 | ->where( |
152 | 152 | [ |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | ); |
161 | 161 | }); |
162 | 162 | |
163 | -$api->put('/matches/{id}/simulate', function ($request, $response, $args) { |
|
163 | +$api->put('/matches/{id}/simulate', function($request, $response, $args) { |
|
164 | 164 | $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
165 | 165 | ->where( |
166 | 166 | [ |
@@ -10,189 +10,189 @@ |
||
10 | 10 | use \App\Lib\DsManager\Models\Orm\Coach; |
11 | 11 | |
12 | 12 | $configuration = [ |
13 | - 'settings' => [ |
|
14 | - 'displayErrorDetails' => true, |
|
15 | - ], |
|
13 | + 'settings' => [ |
|
14 | + 'displayErrorDetails' => true, |
|
15 | + ], |
|
16 | 16 | ]; |
17 | 17 | $c = new \Slim\Container($configuration); |
18 | 18 | $api = new \Slim\App($c); |
19 | 19 | |
20 | 20 | $api->get('/ping', function ($request, $response, $args) { |
21 | - $jsonResp = json_encode( |
|
22 | - [ |
|
23 | - "status" => "service up", |
|
24 | - "message" => "in a bottle" |
|
25 | - ] |
|
26 | - ); |
|
27 | - return Responder::getJsonResponse($jsonResp, $response); |
|
21 | + $jsonResp = json_encode( |
|
22 | + [ |
|
23 | + "status" => "service up", |
|
24 | + "message" => "in a bottle" |
|
25 | + ] |
|
26 | + ); |
|
27 | + return Responder::getJsonResponse($jsonResp, $response); |
|
28 | 28 | }); |
29 | 29 | |
30 | 30 | $api->get('/players', function ($request, $response, $args) { |
31 | - $json = json_encode(Player::all()); |
|
32 | - return Responder::getJsonResponse($json, $response); |
|
31 | + $json = json_encode(Player::all()); |
|
32 | + return Responder::getJsonResponse($json, $response); |
|
33 | 33 | }); |
34 | 34 | |
35 | 35 | |
36 | 36 | $api->get('/players/{id}', function ($request, $response, $args) { |
37 | - return Responder::getJsonResponse( |
|
38 | - Player::findOrFail($args['id']), |
|
39 | - $response |
|
40 | - ); |
|
37 | + return Responder::getJsonResponse( |
|
38 | + Player::findOrFail($args['id']), |
|
39 | + $response |
|
40 | + ); |
|
41 | 41 | }); |
42 | 42 | |
43 | 43 | $api->get('/coaches', function ($request, $response, $args) { |
44 | - return Responder::getJsonResponse( |
|
45 | - Coach::all(), |
|
46 | - $response |
|
47 | - ); |
|
44 | + return Responder::getJsonResponse( |
|
45 | + Coach::all(), |
|
46 | + $response |
|
47 | + ); |
|
48 | 48 | }); |
49 | 49 | |
50 | 50 | $api->get('/teams', function ($request, $response, $args) { |
51 | - return Responder::getJsonResponse( |
|
52 | - Team::all(), |
|
53 | - $response |
|
54 | - ); |
|
51 | + return Responder::getJsonResponse( |
|
52 | + Team::all(), |
|
53 | + $response |
|
54 | + ); |
|
55 | 55 | }); |
56 | 56 | |
57 | 57 | $api->get('/teams/{id}', function ($request, $response, $args) { |
58 | - return Responder::getJsonResponse( |
|
59 | - Team::complete() |
|
60 | - ->where( |
|
61 | - [ |
|
62 | - 'id' => $args['id'] |
|
63 | - ] |
|
64 | - )->get(), |
|
65 | - $response |
|
66 | - ); |
|
58 | + return Responder::getJsonResponse( |
|
59 | + Team::complete() |
|
60 | + ->where( |
|
61 | + [ |
|
62 | + 'id' => $args['id'] |
|
63 | + ] |
|
64 | + )->get(), |
|
65 | + $response |
|
66 | + ); |
|
67 | 67 | }); |
68 | 68 | |
69 | 69 | $api->get('/teams/{id}/players', function ($request, $response, $args) { |
70 | - return Responder::getJsonResponse( |
|
71 | - Team::with( |
|
72 | - 'roster' |
|
73 | - )->where( |
|
74 | - [ |
|
75 | - 'id' => $args['id'] |
|
76 | - ] |
|
77 | - )->get(), |
|
78 | - $response |
|
79 | - ); |
|
70 | + return Responder::getJsonResponse( |
|
71 | + Team::with( |
|
72 | + 'roster' |
|
73 | + )->where( |
|
74 | + [ |
|
75 | + 'id' => $args['id'] |
|
76 | + ] |
|
77 | + )->get(), |
|
78 | + $response |
|
79 | + ); |
|
80 | 80 | }); |
81 | 81 | |
82 | 82 | $api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) { |
83 | - return Responder::getJsonResponse( |
|
84 | - Player::statistics()->where( |
|
85 | - [ |
|
86 | - 'id' => $args['playerId'], |
|
87 | - 'team_id' => $args['id'] |
|
88 | - ] |
|
89 | - )->get(), |
|
90 | - $response |
|
91 | - ); |
|
83 | + return Responder::getJsonResponse( |
|
84 | + Player::statistics()->where( |
|
85 | + [ |
|
86 | + 'id' => $args['playerId'], |
|
87 | + 'team_id' => $args['id'] |
|
88 | + ] |
|
89 | + )->get(), |
|
90 | + $response |
|
91 | + ); |
|
92 | 92 | }); |
93 | 93 | |
94 | 94 | $api->get('/teams/{id}/coach', function ($request, $response, $args) { |
95 | - return Responder::getJsonResponse( |
|
96 | - Team::with( |
|
97 | - 'coach' |
|
98 | - )->where( |
|
99 | - [ |
|
100 | - 'id' => $args['id'] |
|
101 | - ] |
|
102 | - )->get(), |
|
103 | - $response |
|
104 | - ); |
|
95 | + return Responder::getJsonResponse( |
|
96 | + Team::with( |
|
97 | + 'coach' |
|
98 | + )->where( |
|
99 | + [ |
|
100 | + 'id' => $args['id'] |
|
101 | + ] |
|
102 | + )->get(), |
|
103 | + $response |
|
104 | + ); |
|
105 | 105 | }); |
106 | 106 | |
107 | 107 | $api->get('/matches', function ($request, $response, $args) { |
108 | - return Responder::getJsonResponse( |
|
109 | - \App\Lib\DsManager\Models\Orm\Match::with( |
|
110 | - 'homeTeam', |
|
111 | - 'awayTeam' |
|
112 | - )->get(), |
|
113 | - $response |
|
114 | - ); |
|
108 | + return Responder::getJsonResponse( |
|
109 | + \App\Lib\DsManager\Models\Orm\Match::with( |
|
110 | + 'homeTeam', |
|
111 | + 'awayTeam' |
|
112 | + )->get(), |
|
113 | + $response |
|
114 | + ); |
|
115 | 115 | }); |
116 | 116 | |
117 | 117 | $api->post('/matches', function ($request, $response, $args) { |
118 | - $json = $request->getBody(); |
|
119 | - $json = json_decode($json, true); |
|
120 | - return Responder::getJsonResponse( |
|
121 | - \App\Lib\DsManager\Models\Orm\Match::create( |
|
122 | - $json |
|
123 | - ), |
|
124 | - $response |
|
125 | - ); |
|
118 | + $json = $request->getBody(); |
|
119 | + $json = json_decode($json, true); |
|
120 | + return Responder::getJsonResponse( |
|
121 | + \App\Lib\DsManager\Models\Orm\Match::create( |
|
122 | + $json |
|
123 | + ), |
|
124 | + $response |
|
125 | + ); |
|
126 | 126 | }); |
127 | 127 | |
128 | 128 | $api->get('/matches/{id}', function ($request, $response, $args) { |
129 | - return Responder::getJsonResponse( |
|
130 | - \App\Lib\DsManager\Models\Orm\Match::complete() |
|
131 | - ->where( |
|
132 | - [ |
|
133 | - 'id' => $args['id'] |
|
134 | - ] |
|
135 | - )->first(), |
|
136 | - $response |
|
137 | - ); |
|
129 | + return Responder::getJsonResponse( |
|
130 | + \App\Lib\DsManager\Models\Orm\Match::complete() |
|
131 | + ->where( |
|
132 | + [ |
|
133 | + 'id' => $args['id'] |
|
134 | + ] |
|
135 | + )->first(), |
|
136 | + $response |
|
137 | + ); |
|
138 | 138 | }); |
139 | 139 | |
140 | 140 | $api->get('/matches/{id}/result', function ($request, $response, $args) { |
141 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
142 | - ->where( |
|
143 | - [ |
|
144 | - 'id' => $args['id'] |
|
145 | - ] |
|
146 | - )->first(); |
|
147 | - |
|
148 | - return Responder::getJsonResponse( |
|
149 | - $result, |
|
150 | - $response |
|
151 | - ); |
|
141 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
142 | + ->where( |
|
143 | + [ |
|
144 | + 'id' => $args['id'] |
|
145 | + ] |
|
146 | + )->first(); |
|
147 | + |
|
148 | + return Responder::getJsonResponse( |
|
149 | + $result, |
|
150 | + $response |
|
151 | + ); |
|
152 | 152 | }); |
153 | 153 | |
154 | 154 | $api->put('/matches/{id}/simulate', function ($request, $response, $args) { |
155 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
156 | - ->where( |
|
157 | - [ |
|
158 | - 'id' => $args['id'] |
|
159 | - ] |
|
160 | - )->first(); |
|
161 | - |
|
162 | - if (!empty($result) && !$result->simulated) { |
|
163 | - //simulate match |
|
164 | - $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
165 | - \App\Lib\DsManager\Models\Orm\Match::complete() |
|
166 | - ->where( |
|
167 | - [ |
|
168 | - 'id' => $args['id'] |
|
169 | - ] |
|
170 | - )->first()->toArray() |
|
171 | - ); |
|
172 | - $matchResult = $match->simulate()->toArray(); |
|
173 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::where( |
|
174 | - [ |
|
175 | - 'id' => $args['id'] |
|
176 | - ] |
|
177 | - )->update( |
|
178 | - \App\Lib\DsManager\Models\Orm\MatchResult::resolveAttributes( |
|
179 | - $matchResult, |
|
180 | - $args['id'] |
|
181 | - ) |
|
182 | - ); |
|
183 | - if ($result === 1) { |
|
184 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
185 | - ->where( |
|
186 | - [ |
|
187 | - 'id' => $args['id'] |
|
188 | - ] |
|
189 | - )->first(); |
|
190 | - } |
|
191 | - |
|
192 | - } |
|
193 | - return Responder::getJsonResponse( |
|
194 | - $result, |
|
195 | - $response |
|
196 | - ); |
|
155 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
156 | + ->where( |
|
157 | + [ |
|
158 | + 'id' => $args['id'] |
|
159 | + ] |
|
160 | + )->first(); |
|
161 | + |
|
162 | + if (!empty($result) && !$result->simulated) { |
|
163 | + //simulate match |
|
164 | + $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
165 | + \App\Lib\DsManager\Models\Orm\Match::complete() |
|
166 | + ->where( |
|
167 | + [ |
|
168 | + 'id' => $args['id'] |
|
169 | + ] |
|
170 | + )->first()->toArray() |
|
171 | + ); |
|
172 | + $matchResult = $match->simulate()->toArray(); |
|
173 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::where( |
|
174 | + [ |
|
175 | + 'id' => $args['id'] |
|
176 | + ] |
|
177 | + )->update( |
|
178 | + \App\Lib\DsManager\Models\Orm\MatchResult::resolveAttributes( |
|
179 | + $matchResult, |
|
180 | + $args['id'] |
|
181 | + ) |
|
182 | + ); |
|
183 | + if ($result === 1) { |
|
184 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
185 | + ->where( |
|
186 | + [ |
|
187 | + 'id' => $args['id'] |
|
188 | + ] |
|
189 | + )->first(); |
|
190 | + } |
|
191 | + |
|
192 | + } |
|
193 | + return Responder::getJsonResponse( |
|
194 | + $result, |
|
195 | + $response |
|
196 | + ); |
|
197 | 197 | }); |
198 | 198 | $api->run(); |
199 | 199 | \ No newline at end of file |
@@ -74,10 +74,10 @@ |
||
74 | 74 | 'ro_MD', |
75 | 75 | 'tr_TR' |
76 | 76 | ], |
77 | - 'rosters' => [ |
|
78 | - 'min' => 11, |
|
79 | - 'max' => 18 |
|
80 | - ], |
|
77 | + 'rosters' => [ |
|
78 | + 'min' => 11, |
|
79 | + 'max' => 18 |
|
80 | + ], |
|
81 | 81 | ]; |
82 | 82 | |
83 | 83 |
@@ -8,101 +8,101 @@ |
||
8 | 8 | { |
9 | 9 | |
10 | 10 | |
11 | - /** |
|
12 | - * @group OrmModels |
|
13 | - * @group PlayerOrm |
|
14 | - */ |
|
15 | - public function testPlayerOrmGetSet() |
|
16 | - { |
|
17 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
18 | - $playerM = $rndFiller->getPlayer(); |
|
19 | - $arrayPl = $playerM->toArray(); |
|
20 | - $playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl); |
|
21 | - $this->assertNotEmpty($playerO); |
|
11 | + /** |
|
12 | + * @group OrmModels |
|
13 | + * @group PlayerOrm |
|
14 | + */ |
|
15 | + public function testPlayerOrmGetSet() |
|
16 | + { |
|
17 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
18 | + $playerM = $rndFiller->getPlayer(); |
|
19 | + $arrayPl = $playerM->toArray(); |
|
20 | + $playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl); |
|
21 | + $this->assertNotEmpty($playerO); |
|
22 | 22 | |
23 | - $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray()); |
|
24 | - $this->assertNotEmpty($newPlayer); |
|
25 | - } |
|
23 | + $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray()); |
|
24 | + $this->assertNotEmpty($newPlayer); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @group OrmModels |
|
29 | - * @group CoachOrm |
|
30 | - */ |
|
31 | - public function testCoachOrmGetSet() |
|
32 | - { |
|
33 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
34 | - $coach = $rndFiller->getCoach(); |
|
35 | - $arrayPl = $coach->toArray(); |
|
36 | - $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl); |
|
37 | - $this->assertNotEmpty($coachO); |
|
27 | + /** |
|
28 | + * @group OrmModels |
|
29 | + * @group CoachOrm |
|
30 | + */ |
|
31 | + public function testCoachOrmGetSet() |
|
32 | + { |
|
33 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
34 | + $coach = $rndFiller->getCoach(); |
|
35 | + $arrayPl = $coach->toArray(); |
|
36 | + $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl); |
|
37 | + $this->assertNotEmpty($coachO); |
|
38 | 38 | |
39 | - $newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray()); |
|
40 | - $this->assertNotEmpty($newCoach); |
|
41 | - } |
|
39 | + $newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray()); |
|
40 | + $this->assertNotEmpty($newCoach); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @group OrmModels |
|
45 | - * @group TeamOrm |
|
46 | - */ |
|
47 | - public function testTeamOrm() |
|
48 | - { |
|
49 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
50 | - $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
51 | - $teamArray = $team->toArray(); |
|
52 | - $this->assertNotEmpty($team); |
|
53 | - $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
54 | - $this->assertNotEmpty($teamArray); |
|
55 | - $this->assertNotEmpty($teamArray['roster']); |
|
56 | - foreach ($teamArray['roster'] as $player) { |
|
57 | - $player['team_id'] = $teamO->id; |
|
58 | - $playerO = \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
59 | - $this->assertNotEmpty($playerO); |
|
60 | - } |
|
61 | - $teamArray['coach']['team_id'] = $teamO->id; |
|
62 | - $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
63 | - $this->assertNotEmpty($coachO); |
|
43 | + /** |
|
44 | + * @group OrmModels |
|
45 | + * @group TeamOrm |
|
46 | + */ |
|
47 | + public function testTeamOrm() |
|
48 | + { |
|
49 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
50 | + $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
51 | + $teamArray = $team->toArray(); |
|
52 | + $this->assertNotEmpty($team); |
|
53 | + $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
54 | + $this->assertNotEmpty($teamArray); |
|
55 | + $this->assertNotEmpty($teamArray['roster']); |
|
56 | + foreach ($teamArray['roster'] as $player) { |
|
57 | + $player['team_id'] = $teamO->id; |
|
58 | + $playerO = \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
59 | + $this->assertNotEmpty($playerO); |
|
60 | + } |
|
61 | + $teamArray['coach']['team_id'] = $teamO->id; |
|
62 | + $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
63 | + $this->assertNotEmpty($coachO); |
|
64 | 64 | |
65 | - $this->assertNotEmpty( |
|
66 | - \App\Lib\DsManager\Models\Orm\Team::with( |
|
67 | - 'roster' |
|
68 | - )->with( |
|
69 | - 'coach' |
|
70 | - )->where( |
|
71 | - [ |
|
72 | - 'id' => $teamO->id |
|
73 | - ] |
|
74 | - )->get()->toArray() |
|
75 | - ); |
|
76 | - } |
|
65 | + $this->assertNotEmpty( |
|
66 | + \App\Lib\DsManager\Models\Orm\Team::with( |
|
67 | + 'roster' |
|
68 | + )->with( |
|
69 | + 'coach' |
|
70 | + )->where( |
|
71 | + [ |
|
72 | + 'id' => $teamO->id |
|
73 | + ] |
|
74 | + )->get()->toArray() |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @group Match |
|
80 | - * @group createnewmatch |
|
81 | - */ |
|
82 | - public function testCreateNewMatch() |
|
83 | - { |
|
84 | - $teams = \App\Lib\DsManager\Models\Orm\Team::with( |
|
85 | - 'roster', |
|
86 | - 'coach' |
|
87 | - )->get(); |
|
88 | - $this->assertNotNull($teams); |
|
89 | - $teams = $teams->toArray(); |
|
90 | - $homeIndex = array_rand($teams); |
|
91 | - $teamHome = $teams[$homeIndex]; |
|
92 | - unset($teams[$homeIndex]); |
|
93 | - $teamAway = $teams[array_rand($teams)]; |
|
94 | - $this->assertNotNull($teamHome); |
|
95 | - $this->assertNotNull($teamAway); |
|
96 | - $matchO = \App\Lib\DsManager\Models\Orm\Match::create( |
|
97 | - [ |
|
98 | - 'home_team_id' => $teamHome['id'], |
|
99 | - 'away_team_id' => $teamAway['id'] |
|
100 | - ] |
|
101 | - ); |
|
102 | - $this->assertNotNull($matchO); |
|
103 | - $matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first(); |
|
104 | - $this->assertNotNull($matchNew); |
|
105 | - $match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray()); |
|
106 | - $this->assertNotNull($match); |
|
107 | - } |
|
78 | + /** |
|
79 | + * @group Match |
|
80 | + * @group createnewmatch |
|
81 | + */ |
|
82 | + public function testCreateNewMatch() |
|
83 | + { |
|
84 | + $teams = \App\Lib\DsManager\Models\Orm\Team::with( |
|
85 | + 'roster', |
|
86 | + 'coach' |
|
87 | + )->get(); |
|
88 | + $this->assertNotNull($teams); |
|
89 | + $teams = $teams->toArray(); |
|
90 | + $homeIndex = array_rand($teams); |
|
91 | + $teamHome = $teams[$homeIndex]; |
|
92 | + unset($teams[$homeIndex]); |
|
93 | + $teamAway = $teams[array_rand($teams)]; |
|
94 | + $this->assertNotNull($teamHome); |
|
95 | + $this->assertNotNull($teamAway); |
|
96 | + $matchO = \App\Lib\DsManager\Models\Orm\Match::create( |
|
97 | + [ |
|
98 | + 'home_team_id' => $teamHome['id'], |
|
99 | + 'away_team_id' => $teamAway['id'] |
|
100 | + ] |
|
101 | + ); |
|
102 | + $this->assertNotNull($matchO); |
|
103 | + $matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first(); |
|
104 | + $this->assertNotNull($matchNew); |
|
105 | + $match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray()); |
|
106 | + $this->assertNotNull($match); |
|
107 | + } |
|
108 | 108 | } |
@@ -3,20 +3,20 @@ |
||
3 | 3 | |
4 | 4 | class ATeamsSeeder |
5 | 5 | { |
6 | - function run() |
|
7 | - { |
|
8 | - $teamNumber = 16; |
|
9 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
10 | - for ($i = 1; $i <= $teamNumber; $i++) { |
|
11 | - $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
12 | - $teamArray = $team->toArray(); |
|
13 | - $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
14 | - foreach ($teamArray['roster'] as $player) { |
|
15 | - $player['team_id'] = $teamO->id; |
|
16 | - \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
17 | - } |
|
18 | - $teamArray['coach']['team_id'] = $teamO->id; |
|
19 | - \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
20 | - } |
|
21 | - } |
|
6 | + function run() |
|
7 | + { |
|
8 | + $teamNumber = 16; |
|
9 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
10 | + for ($i = 1; $i <= $teamNumber; $i++) { |
|
11 | + $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
12 | + $teamArray = $team->toArray(); |
|
13 | + $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
14 | + foreach ($teamArray['roster'] as $player) { |
|
15 | + $player['team_id'] = $teamO->id; |
|
16 | + \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
17 | + } |
|
18 | + $teamArray['coach']['team_id'] = $teamO->id; |
|
19 | + \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
20 | + } |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -8,45 +8,45 @@ |
||
8 | 8 | */ |
9 | 9 | class Team extends DsManagerOrm |
10 | 10 | { |
11 | - /** |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - protected $table = 'teams'; |
|
11 | + /** |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + protected $table = 'teams'; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $fillable = [ |
|
20 | - 'name', |
|
21 | - 'nationality' |
|
22 | - ]; |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $fillable = [ |
|
20 | + 'name', |
|
21 | + 'nationality' |
|
22 | + ]; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
26 | - */ |
|
27 | - public function roster() |
|
28 | - { |
|
29 | - return $this->hasMany(Player::class); |
|
30 | - } |
|
24 | + /** |
|
25 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
26 | + */ |
|
27 | + public function roster() |
|
28 | + { |
|
29 | + return $this->hasMany(Player::class); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
34 | - */ |
|
35 | - public function coach() |
|
36 | - { |
|
37 | - return $this->hasOne(Coach::class); |
|
38 | - } |
|
32 | + /** |
|
33 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
34 | + */ |
|
35 | + public function coach() |
|
36 | + { |
|
37 | + return $this->hasOne(Coach::class); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param $query |
|
42 | - * @return mixed |
|
43 | - */ |
|
44 | - public function scopeComplete($query) |
|
45 | - { |
|
46 | - return $query->with( |
|
47 | - 'roster', |
|
48 | - 'coach' |
|
49 | - ); |
|
50 | - } |
|
40 | + /** |
|
41 | + * @param $query |
|
42 | + * @return mixed |
|
43 | + */ |
|
44 | + public function scopeComplete($query) |
|
45 | + { |
|
46 | + return $query->with( |
|
47 | + 'roster', |
|
48 | + 'coach' |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | } |
53 | 53 | \ No newline at end of file |