|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TournamentGenerator; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use InvalidArgumentException; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class that identifies a team and holds the scores from the whole tournament. |
|
10
|
|
|
* |
|
11
|
|
|
* @author Tomáš Vojík <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* @since 0.1 |
|
14
|
|
|
* @package TournamentGenerator |
|
15
|
|
|
*/ |
|
16
|
|
|
class Team extends Base |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string $name The name of the team |
|
21
|
|
|
* @var string|int $id The unique identifier of the team |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var array[] Associative array of results in each group |
|
26
|
|
|
* @details [ |
|
27
|
|
|
* * groupId => [ |
|
28
|
|
|
* * * "group" => Group, # GROUP OBJECT |
|
29
|
|
|
* * * "points" => int 0, # NUMBER OF POINTS ACQUIRED |
|
30
|
|
|
* * * "score" => int 0, # SUM OF SCORE ACQUIRED |
|
31
|
|
|
* * * "wins" => int 0, # NUMBER OF WINS |
|
32
|
|
|
* * * "draws" => int 0, # NUMBER OF DRAWS |
|
33
|
|
|
* * * "losses" => int 0, # NUMBER OF LOSSES |
|
34
|
|
|
* * * "second" => int 0, # NUMBER OF TIMES BEING SECOND (ONLY FOR INGAME OPTION OF 3 OR 4) |
|
35
|
|
|
* * * "third" => int 0 # NUMBER OF TIMES BEING THIRD (ONLY FOR INGAME OPTION OF 4) |
|
36
|
|
|
* * ] |
|
37
|
|
|
* ] |
|
38
|
|
|
*/ |
|
39
|
|
|
public array $groupResults = []; |
|
40
|
|
|
/** @var Game[] $games A list of games played by this team */ |
|
41
|
|
|
protected array $games = []; |
|
42
|
|
|
/** @var array $gamesWith Multi-dimensional associative array of number of games together with other teams */ |
|
43
|
|
|
protected array $gamesWith = []; |
|
44
|
|
|
/** @var int $sumPoints Sum of all points acquired through the whole tournament */ |
|
45
|
|
|
protected int $sumPoints = 0; |
|
46
|
|
|
/** @var int $sumScore Sum of all score acquired through the whole tournament */ |
|
47
|
|
|
protected int $sumScore = 0; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Initiates a team class |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $name Name of the team |
|
53
|
|
|
* @param string|int $id Unique identifier of the team |
|
54
|
|
|
* |
|
55
|
|
|
* @throws InvalidArgumentException if the provided argument id is not of type 'null' or 'string' or 'int' |
|
56
|
|
|
*/ |
|
57
|
147 |
|
public function __construct(string $name = 'team', $id = null) { |
|
58
|
147 |
|
$this->setName($name); |
|
59
|
147 |
|
$this->setId($id ?? uniqid('', false)); |
|
60
|
147 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Gets team statistics from the given group without the group object |
|
64
|
|
|
* |
|
65
|
|
|
* @param string|int $groupId Unique identifier of the group to get its results |
|
66
|
|
|
* |
|
67
|
|
|
* @return array All the statistics including points, score, wins, draws, losses, times being second, times being third |
|
68
|
|
|
* @throws Exception if the group with given groupId doesn't exist |
|
69
|
|
|
* |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function getGamesInfo($groupId) : array { |
|
72
|
1 |
|
return array_filter($this->getGroupResults($groupId), static function($k) { |
|
73
|
1 |
|
return $k !== 'group'; |
|
74
|
1 |
|
}, ARRAY_FILTER_USE_KEY); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Gets team statistics from the given group |
|
79
|
|
|
* |
|
80
|
|
|
* @param string|int|null $groupId Unique identifier of the group to get its results |
|
81
|
|
|
* |
|
82
|
|
|
* @return array All the statistics including points, score, wins, draws, losses, times being second, times being third if the group id is set or all the statistics |
|
83
|
|
|
* @throws Exception if the group with given groupId doesn't exist |
|
84
|
|
|
* |
|
85
|
|
|
*/ |
|
86
|
8 |
|
public function getGroupResults($groupId = null) : array { |
|
87
|
8 |
|
if (isset($groupId)) { |
|
88
|
6 |
|
if (!isset($this->groupResults[$groupId])) { |
|
89
|
1 |
|
throw new Exception('Trying to get nonexistent group results ('.$groupId.')'); |
|
90
|
|
|
} |
|
91
|
5 |
|
return $this->groupResults[$groupId]; |
|
92
|
|
|
} |
|
93
|
2 |
|
return $this->groupResults; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Creates a new data-array to store statistics for a new group |
|
98
|
|
|
* |
|
99
|
|
|
* Resets the statistics if the group was already added |
|
100
|
|
|
* |
|
101
|
|
|
* @param Group $group A group object to add its results |
|
102
|
|
|
* |
|
103
|
|
|
* @return $this |
|
104
|
|
|
*/ |
|
105
|
107 |
|
public function addGroupResults(Group $group) : Team { |
|
106
|
107 |
|
$this->groupResults[$group->getId()] = [ |
|
107
|
107 |
|
'group' => $group, |
|
108
|
107 |
|
'points' => 0, |
|
109
|
107 |
|
'score' => 0, |
|
110
|
107 |
|
'wins' => 0, |
|
111
|
107 |
|
'draws' => 0, |
|
112
|
107 |
|
'losses' => 0, |
|
113
|
107 |
|
'second' => 0, |
|
114
|
107 |
|
'third' => 0 |
|
115
|
|
|
]; |
|
116
|
107 |
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Adds a record of a game with another team in a group |
|
121
|
|
|
* |
|
122
|
|
|
* @param Team $team A team that played with this team |
|
123
|
|
|
* @param Group $group A group that the teams were playing in |
|
124
|
|
|
* |
|
125
|
|
|
* @return $this |
|
126
|
|
|
*/ |
|
127
|
100 |
|
public function addGameWith(Team $team, Group $group) : Team { |
|
128
|
100 |
|
if (!isset($this->gamesWith[$group->getId()][$team->getId()])) { |
|
129
|
100 |
|
$this->gamesWith[$group->getId()][$team->getId()] = 0; |
|
130
|
|
|
} |
|
131
|
100 |
|
$this->gamesWith[$group->getId()][$team->getId()]++; |
|
132
|
100 |
|
return $this; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Gets a record of a game with another team or teams |
|
137
|
|
|
* |
|
138
|
|
|
* @param Team|null $team A team to get the games with |
|
139
|
|
|
* @param Group|null $group A group from where to get the games |
|
140
|
|
|
* |
|
141
|
|
|
* @return array|int The number of games played with a team in a group if both arguments are given, array of all games with all teams from a group if only group is given, array of games with team from all groups if only a team argument is given or all games with all teams from all groups if no argument is given |
|
142
|
|
|
*/ |
|
143
|
3 |
|
public function getGameWith(Team $team = null, Group $group = null) { |
|
144
|
3 |
|
if (isset($group)) { |
|
145
|
3 |
|
if (isset($team)) { |
|
146
|
3 |
|
return $this->gamesWith[$group->getId()][$team->getId()]; |
|
147
|
|
|
} |
|
148
|
3 |
|
return $this->gamesWith[$group->getId()]; |
|
149
|
|
|
} |
|
150
|
2 |
|
if (isset($team)) { |
|
151
|
1 |
|
$return = []; |
|
152
|
1 |
|
foreach ($this->gamesWith as $id => $games) { |
|
153
|
1 |
|
$filter = array_filter($games, static function($key) use ($team) { |
|
154
|
1 |
|
return $key === $team->getId(); |
|
155
|
1 |
|
}, ARRAY_FILTER_USE_KEY); |
|
156
|
1 |
|
if (count($filter) > 0) { |
|
157
|
1 |
|
$return[$id] = $filter; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
1 |
|
return $return; |
|
161
|
|
|
} |
|
162
|
1 |
|
return $this->gamesWith; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Adds a group to a team and creates an array for all games to be played |
|
167
|
|
|
* |
|
168
|
|
|
* @param Group $group A group to add |
|
169
|
|
|
* |
|
170
|
|
|
* @return $this |
|
171
|
|
|
*/ |
|
172
|
1 |
|
public function addGroup(Group $group) : Team { |
|
173
|
1 |
|
if (!isset($this->games[$group->getId()])) { |
|
174
|
1 |
|
$this->games[$group->getId()] = []; |
|
175
|
|
|
} |
|
176
|
1 |
|
return $this; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Adds a game to this team |
|
181
|
|
|
* |
|
182
|
|
|
* @param Game $game A game to add |
|
183
|
|
|
* |
|
184
|
|
|
* @return $this |
|
185
|
|
|
*/ |
|
186
|
100 |
|
public function addGame(Game $game) : Team { |
|
187
|
100 |
|
$group = $game->getGroup(); |
|
188
|
100 |
|
if (!isset($this->games[$group->getId()])) { |
|
189
|
100 |
|
$this->games[$group->getId()] = []; |
|
190
|
|
|
} |
|
191
|
100 |
|
$this->games[$group->getId()][] = $game; |
|
192
|
100 |
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Gets all game from given group |
|
197
|
|
|
* |
|
198
|
|
|
* @param Group|null $group A group to get its game from |
|
199
|
|
|
* @param string|int|null $groupId An id of group to get its game from |
|
200
|
|
|
* |
|
201
|
|
|
* @return array Games from a group or all games if both arguments are null |
|
202
|
|
|
*/ |
|
203
|
4 |
|
public function getGames(?Group $group = null, $groupId = null) { |
|
204
|
4 |
|
if (!is_null($group) && isset($this->games[$group->getId()])) { |
|
205
|
1 |
|
return $this->games[$group->getId()]; |
|
206
|
|
|
} |
|
207
|
4 |
|
if (isset($groupId, $this->games[$groupId])) { |
|
208
|
3 |
|
return $this->games[$groupId]; |
|
209
|
|
|
} |
|
210
|
1 |
|
return $this->games; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Gets all points that the team has acquired through the tournament |
|
215
|
|
|
* |
|
216
|
|
|
* @return int Sum of the points acquired |
|
217
|
|
|
*/ |
|
218
|
5 |
|
public function getSumPoints() : int { |
|
219
|
5 |
|
return $this->sumPoints; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Gets all score that the team has acquired through the tournament |
|
224
|
|
|
* |
|
225
|
|
|
* @return int Sum of the score acquired |
|
226
|
|
|
*/ |
|
227
|
5 |
|
public function getSumScore() : int { |
|
228
|
5 |
|
return $this->sumScore; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Adds a win to the team |
|
233
|
|
|
* |
|
234
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
235
|
|
|
* |
|
236
|
|
|
* @return $this |
|
237
|
|
|
* @throws Exception if the group results have not been added |
|
238
|
|
|
* |
|
239
|
|
|
* @uses Group::getWinPoints() to retrieve the points to add |
|
240
|
|
|
* |
|
241
|
|
|
*/ |
|
242
|
73 |
|
public function addWin(string $groupId = '') : Team { |
|
243
|
73 |
|
if (!isset($this->groupResults[$groupId])) { |
|
244
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
245
|
|
|
} |
|
246
|
72 |
|
$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getWinPoints(); |
|
247
|
72 |
|
$this->sumPoints += $this->groupResults[$groupId]['group']->getWinPoints(); |
|
248
|
72 |
|
$this->groupResults[$groupId]['wins']++; |
|
249
|
72 |
|
return $this; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Remove a win from the team |
|
254
|
|
|
* |
|
255
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
256
|
|
|
* |
|
257
|
|
|
* @return $this |
|
258
|
|
|
* @throws Exception if the group results have not been added |
|
259
|
|
|
* |
|
260
|
|
|
* @uses Group::getWinPoints() to retrieve the points to add |
|
261
|
|
|
* |
|
262
|
|
|
*/ |
|
263
|
20 |
|
public function removeWin(string $groupId = '') : Team { |
|
264
|
20 |
|
if (!isset($this->groupResults[$groupId])) { |
|
265
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
266
|
|
|
} |
|
267
|
19 |
|
$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getWinPoints(); |
|
268
|
19 |
|
$this->sumPoints -= $this->groupResults[$groupId]['group']->getWinPoints(); |
|
269
|
19 |
|
$this->groupResults[$groupId]['wins']--; |
|
270
|
19 |
|
return $this; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* Adds a draw to the team |
|
275
|
|
|
* |
|
276
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
277
|
|
|
* |
|
278
|
|
|
* @return $this |
|
279
|
|
|
* @throws Exception if the group results have not been added |
|
280
|
|
|
* |
|
281
|
|
|
* @uses Group::getDrawPoints() to retrieve the points to add |
|
282
|
|
|
* |
|
283
|
|
|
*/ |
|
284
|
15 |
|
public function addDraw(string $groupId = '') : Team { |
|
285
|
15 |
|
if (!isset($this->groupResults[$groupId])) { |
|
286
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
287
|
|
|
} |
|
288
|
14 |
|
$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getDrawPoints(); |
|
289
|
14 |
|
$this->sumPoints += $this->groupResults[$groupId]['group']->getDrawPoints(); |
|
290
|
14 |
|
$this->groupResults[$groupId]['draws']++; |
|
291
|
14 |
|
return $this; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* Remove a draw from the team |
|
296
|
|
|
* |
|
297
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
298
|
|
|
* |
|
299
|
|
|
* @return $this |
|
300
|
|
|
* @throws Exception if the group results have not been added |
|
301
|
|
|
* |
|
302
|
|
|
* @uses Group::getDrawPoints() to retrieve the points to add |
|
303
|
|
|
* |
|
304
|
|
|
*/ |
|
305
|
2 |
|
public function removeDraw(string $groupId = '') : Team { |
|
306
|
2 |
|
if (!isset($this->groupResults[$groupId])) { |
|
307
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
308
|
|
|
} |
|
309
|
1 |
|
$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getDrawPoints(); |
|
310
|
1 |
|
$this->sumPoints -= $this->groupResults[$groupId]['group']->getDrawPoints(); |
|
311
|
1 |
|
$this->groupResults[$groupId]['draws']--; |
|
312
|
1 |
|
return $this; |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* Adds a loss to the team |
|
317
|
|
|
* |
|
318
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
319
|
|
|
* |
|
320
|
|
|
* @return $this |
|
321
|
|
|
* @throws Exception if the group results have not been added |
|
322
|
|
|
* |
|
323
|
|
|
* @uses Group::getLossPoints() to retrieve the points to add |
|
324
|
|
|
* |
|
325
|
|
|
*/ |
|
326
|
73 |
|
public function addLoss(string $groupId = '') : Team { |
|
327
|
73 |
|
if (!isset($this->groupResults[$groupId])) { |
|
328
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
329
|
|
|
} |
|
330
|
72 |
|
$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getLostPoints(); |
|
331
|
72 |
|
$this->sumPoints += $this->groupResults[$groupId]['group']->getLostPoints(); |
|
332
|
72 |
|
$this->groupResults[$groupId]['losses']++; |
|
333
|
72 |
|
return $this; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* Remove a loss from the team |
|
338
|
|
|
* |
|
339
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
340
|
|
|
* |
|
341
|
|
|
* @return $this |
|
342
|
|
|
* @throws Exception if the group results have not been added |
|
343
|
|
|
* |
|
344
|
|
|
* @uses Group::getLossPoints() to retrieve the points to add |
|
345
|
|
|
* |
|
346
|
|
|
*/ |
|
347
|
20 |
|
public function removeLoss(string $groupId = '') : Team { |
|
348
|
20 |
|
if (!isset($this->groupResults[$groupId])) { |
|
349
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
350
|
|
|
} |
|
351
|
19 |
|
$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getLostPoints(); |
|
352
|
19 |
|
$this->sumPoints -= $this->groupResults[$groupId]['group']->getLostPoints(); |
|
353
|
19 |
|
$this->groupResults[$groupId]['losses']--; |
|
354
|
19 |
|
return $this; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* Add points for being second to the team |
|
359
|
|
|
* |
|
360
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
361
|
|
|
* |
|
362
|
|
|
* @return $this |
|
363
|
|
|
* @throws Exception if the group results have not been added |
|
364
|
|
|
* |
|
365
|
|
|
* @uses Group::getSecondPoints() to retrieve the points to add |
|
366
|
|
|
* |
|
367
|
|
|
*/ |
|
368
|
11 |
|
public function addSecond(string $groupId = '') : Team { |
|
369
|
11 |
|
if (!isset($this->groupResults[$groupId])) { |
|
370
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
371
|
|
|
} |
|
372
|
10 |
|
$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getSecondPoints(); |
|
373
|
10 |
|
$this->sumPoints += $this->groupResults[$groupId]['group']->getSecondPoints(); |
|
374
|
10 |
|
$this->groupResults[$groupId]['second']++; |
|
375
|
10 |
|
return $this; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* Remove points for being second from the team |
|
380
|
|
|
* |
|
381
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
382
|
|
|
* |
|
383
|
|
|
* @return $this |
|
384
|
|
|
* @throws Exception if the group results have not been added |
|
385
|
|
|
* |
|
386
|
|
|
* @uses Group::getSecondPoints() to retrieve the points to add |
|
387
|
|
|
* |
|
388
|
|
|
*/ |
|
389
|
3 |
|
public function removeSecond(string $groupId = '') : Team { |
|
390
|
3 |
|
if (!isset($this->groupResults[$groupId])) { |
|
391
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
392
|
|
|
} |
|
393
|
2 |
|
$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getSecondPoints(); |
|
394
|
2 |
|
$this->sumPoints -= $this->groupResults[$groupId]['group']->getSecondPoints(); |
|
395
|
2 |
|
$this->groupResults[$groupId]['second']--; |
|
396
|
2 |
|
return $this; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* Add points for being third to the team |
|
401
|
|
|
* |
|
402
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
403
|
|
|
* |
|
404
|
|
|
* @return $this |
|
405
|
|
|
* @throws Exception if the group results have not been added |
|
406
|
|
|
* |
|
407
|
|
|
* @uses Group::getThirdPoints() to retrieve the points to add |
|
408
|
|
|
* |
|
409
|
|
|
*/ |
|
410
|
10 |
|
public function addThird(string $groupId = '') : Team { |
|
411
|
10 |
|
if (!isset($this->groupResults[$groupId])) { |
|
412
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
413
|
|
|
} |
|
414
|
9 |
|
$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getThirdPoints(); |
|
415
|
9 |
|
$this->sumPoints += $this->groupResults[$groupId]['group']->getThirdPoints(); |
|
416
|
9 |
|
$this->groupResults[$groupId]['third']++; |
|
417
|
9 |
|
return $this; |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
/** |
|
421
|
|
|
* Remove points for being third from the team |
|
422
|
|
|
* |
|
423
|
|
|
* @param string|int|null $groupId An id of group to add the results from |
|
424
|
|
|
* |
|
425
|
|
|
* @return $this |
|
426
|
|
|
* @throws Exception if the group results have not been added |
|
427
|
|
|
* |
|
428
|
|
|
* @uses Group::getThirdPoints() to retrieve the points to add |
|
429
|
|
|
* |
|
430
|
|
|
*/ |
|
431
|
2 |
|
public function removeThird(string $groupId = '') : Team { |
|
432
|
2 |
|
if (!isset($this->groupResults[$groupId])) { |
|
433
|
1 |
|
throw new Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
434
|
|
|
} |
|
435
|
1 |
|
$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getThirdPoints(); |
|
436
|
1 |
|
$this->sumPoints -= $this->groupResults[$groupId]['group']->getThirdPoints(); |
|
437
|
1 |
|
$this->groupResults[$groupId]['third']--; |
|
438
|
1 |
|
return $this; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
/** |
|
442
|
|
|
* Calculate all the points acquired from given group ids |
|
443
|
|
|
* |
|
444
|
|
|
* @param array $groupIds Array of group ids |
|
445
|
|
|
* |
|
446
|
|
|
* @return int Sum of the points or sum of all points if argument is empty |
|
447
|
|
|
*/ |
|
448
|
45 |
|
public function sumPoints(array $groupIds = []) : int { |
|
449
|
45 |
|
if (count($groupIds) === 0) { |
|
450
|
1 |
|
return $this->sumPoints; |
|
451
|
|
|
} |
|
452
|
44 |
|
$sum = 0; |
|
453
|
44 |
|
foreach ($groupIds as $gid) { |
|
454
|
44 |
|
$sum += $this->groupResults[$gid]['points'] ?? 0; |
|
455
|
|
|
} |
|
456
|
44 |
|
return $sum; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
/** |
|
460
|
|
|
* Calculate all score acquired from given group ids |
|
461
|
|
|
* |
|
462
|
|
|
* @param array $groupIds Array of group ids |
|
463
|
|
|
* |
|
464
|
|
|
* @return int Sum of score or sum of all score if argument is empty |
|
465
|
|
|
*/ |
|
466
|
29 |
|
public function sumScore(array $groupIds = []) : int { |
|
467
|
29 |
|
if (count($groupIds) === 0) { |
|
468
|
1 |
|
return $this->sumScore; |
|
469
|
|
|
} |
|
470
|
28 |
|
$sum = 0; |
|
471
|
28 |
|
foreach ($groupIds as $gid) { |
|
472
|
28 |
|
$sum += $this->groupResults[$gid]['score'] ?? 0; |
|
473
|
|
|
} |
|
474
|
28 |
|
return $sum; |
|
475
|
|
|
} |
|
476
|
|
|
|
|
477
|
|
|
/** |
|
478
|
|
|
* Adds score to the total sum |
|
479
|
|
|
* |
|
480
|
|
|
* @param int $score Score to add |
|
481
|
|
|
* |
|
482
|
|
|
* @return $this |
|
483
|
|
|
*/ |
|
484
|
75 |
|
public function addScore(int $score) : Team { |
|
485
|
75 |
|
$this->sumScore += $score; |
|
486
|
75 |
|
return $this; |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
/** |
|
490
|
|
|
* Removes score to the total sum |
|
491
|
|
|
* |
|
492
|
|
|
* @param int $score Score to add |
|
493
|
|
|
* |
|
494
|
|
|
* @return $this |
|
495
|
|
|
*/ |
|
496
|
21 |
|
public function removeScore(int $score) : Team { |
|
497
|
21 |
|
$this->sumScore -= $score; |
|
498
|
21 |
|
return $this; |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
/** |
|
502
|
|
|
* Adds points to the total sum |
|
503
|
|
|
* |
|
504
|
|
|
* @param int $points Points to add |
|
505
|
|
|
* |
|
506
|
|
|
* @return $this |
|
507
|
|
|
*/ |
|
508
|
18 |
|
public function addPoints(int $points) : Team { |
|
509
|
18 |
|
$this->sumPoints += $points; |
|
510
|
18 |
|
return $this; |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
/** |
|
514
|
|
|
* Removes points to the total sum |
|
515
|
|
|
* |
|
516
|
|
|
* @param int $points Points to remove |
|
517
|
|
|
* |
|
518
|
|
|
* @return $this |
|
519
|
|
|
*/ |
|
520
|
1 |
|
public function removePoints(int $points) : Team { |
|
521
|
1 |
|
$this->sumPoints -= $points; |
|
522
|
1 |
|
return $this; |
|
523
|
|
|
} |
|
524
|
|
|
} |
|
525
|
|
|
|