1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Entity; |
4
|
|
|
|
5
|
|
|
use Obblm\Core\Helper\Rule\CanHaveRuleInterface; |
6
|
|
|
use Obblm\Core\Repository\TeamRepository; |
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Doctrine\Common\Collections\Criteria; |
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @ORM\Entity(repositoryClass=TeamRepository::class) |
14
|
|
|
* @ORM\Table(name="obblm_team") |
15
|
|
|
*/ |
16
|
|
|
class Team implements CanHaveRuleInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @ORM\Id() |
20
|
|
|
* @ORM\GeneratedValue() |
21
|
|
|
* @ORM\Column(type="integer") |
22
|
|
|
*/ |
23
|
|
|
private $id; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @ORM\Column(type="string", length=255) |
27
|
|
|
*/ |
28
|
|
|
private $name; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @ORM\ManyToOne(targetEntity=Coach::class, inversedBy="teams") |
32
|
|
|
* @ORM\JoinColumn(nullable=false) |
33
|
|
|
*/ |
34
|
|
|
private $coach; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @ORM\ManyToOne(targetEntity=Rule::class, inversedBy="teams") |
38
|
|
|
*/ |
39
|
|
|
private $rule; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @ORM\Column(type="text", nullable=true) |
43
|
|
|
*/ |
44
|
|
|
private $anthem; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @ORM\Column(type="text", nullable=true) |
48
|
|
|
*/ |
49
|
|
|
private $fluff; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @ORM\Column(type="string", length=50) |
53
|
|
|
*/ |
54
|
|
|
private $roster; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @ORM\OneToMany(targetEntity=Player::class, fetch="EAGER", mappedBy="team", orphanRemoval=true, cascade={"persist", "remove"}) |
58
|
|
|
* @ORM\OrderBy({"number"="ASC"}) |
59
|
|
|
*/ |
60
|
|
|
private $players; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @ORM\Column(type="string", nullable=true) |
64
|
|
|
*/ |
65
|
|
|
private $logoFilename; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @ORM\Column(type="string", nullable=true) |
69
|
|
|
*/ |
70
|
|
|
private $logoMimeType; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @ORM\Column(type="string", nullable=true) |
74
|
|
|
*/ |
75
|
|
|
private $coverFilename; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @ORM\Column(type="string", nullable=true) |
79
|
|
|
*/ |
80
|
|
|
private $coverMimeType; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @ORM\Column(type="boolean") |
84
|
|
|
*/ |
85
|
|
|
private $ready = false; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @ORM\Column(type="boolean") |
89
|
|
|
*/ |
90
|
|
|
private $lockedByManagment = false; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @ORM\OneToMany(targetEntity=TeamVersion::class, fetch="EAGER", mappedBy="team", orphanRemoval=true, cascade={"persist", "remove"}) |
94
|
|
|
* @ORM\OrderBy({"id"="DESC"}) |
95
|
|
|
*/ |
96
|
|
|
private $versions; |
97
|
|
|
|
98
|
3 |
|
public function __construct() |
99
|
|
|
{ |
100
|
3 |
|
$this->players = new ArrayCollection(); |
101
|
3 |
|
$this->versions = new ArrayCollection(); |
102
|
3 |
|
} |
103
|
|
|
|
104
|
|
|
public function getId(): ?int |
105
|
|
|
{ |
106
|
|
|
return $this->id; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getName(): ?string |
110
|
|
|
{ |
111
|
|
|
return $this->name; |
112
|
|
|
} |
113
|
|
|
|
114
|
2 |
|
public function setName(string $name): self |
115
|
|
|
{ |
116
|
2 |
|
$this->name = $name; |
117
|
|
|
|
118
|
2 |
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getCoach(): ?Coach |
122
|
|
|
{ |
123
|
|
|
return $this->coach; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function setCoach(?Coach $coach): self |
127
|
|
|
{ |
128
|
|
|
$this->coach = $coach; |
129
|
|
|
|
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
2 |
|
public function getRule(): ?Rule |
134
|
|
|
{ |
135
|
2 |
|
return $this->rule; |
136
|
|
|
} |
137
|
|
|
|
138
|
3 |
|
public function setRule(?Rule $rule): self |
139
|
|
|
{ |
140
|
3 |
|
$this->rule = $rule; |
141
|
|
|
|
142
|
3 |
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function getAnthem(): ?string |
146
|
|
|
{ |
147
|
|
|
return $this->anthem; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function setAnthem(?string $anthem): self |
151
|
|
|
{ |
152
|
|
|
$this->anthem = $anthem; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getFluff(): ?string |
158
|
|
|
{ |
159
|
|
|
return $this->fluff; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function setFluff(?string $fluff): self |
163
|
|
|
{ |
164
|
|
|
$this->fluff = $fluff; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
2 |
|
public function getRoster(): ?string |
170
|
|
|
{ |
171
|
2 |
|
return $this->roster; |
172
|
|
|
} |
173
|
|
|
|
174
|
3 |
|
public function setRoster(string $roster): self |
175
|
|
|
{ |
176
|
3 |
|
$this->roster = $roster; |
177
|
|
|
|
178
|
3 |
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return Collection|Player[] |
183
|
|
|
*/ |
184
|
|
|
public function getPlayers(): Collection |
185
|
|
|
{ |
186
|
|
|
return $this->players; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return Collection|Player[] |
191
|
|
|
*/ |
192
|
|
|
public function getAvailablePlayers(): Collection |
193
|
|
|
{ |
194
|
|
|
$criteria = Criteria::create() |
195
|
|
|
->andWhere(Criteria::expr()->eq('dead', false)) |
196
|
|
|
->andWhere(Criteria::expr()->eq('fire', false)) |
197
|
|
|
->orderBy(['number' => 'ASC']) |
198
|
|
|
; |
199
|
|
|
return $this->players->matching($criteria); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function getAvailablePlayersSheet(): Collection |
203
|
|
|
{ |
204
|
|
|
// In want to have 16 players in the list, no less, no more |
205
|
|
|
$usedNumbers = []; |
206
|
|
|
$newPlayerList = $this->getAvailablePlayers(); |
207
|
|
|
foreach ($newPlayerList as $player) { |
208
|
|
|
$usedNumbers[$player->getNumber()] = $player; |
209
|
|
|
} |
210
|
|
|
for ($i=1; $i<=16; $i++) { |
211
|
|
|
if (!isset($usedNumbers[$i])) { |
212
|
|
|
$newPlayerList->add((new Player())->setNumber($i)); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
$criteria = Criteria::create(); |
216
|
|
|
$criteria->orderBy(['number' => 'ASC']); |
217
|
|
|
return $newPlayerList->matching($criteria); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function addPlayer(Player $player): self |
221
|
|
|
{ |
222
|
|
|
if (!$this->players->contains($player)) { |
223
|
|
|
$this->players[] = $player; |
224
|
|
|
$player->setTeam($this); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
public function removePlayer(Player $player): self |
231
|
|
|
{ |
232
|
|
|
if ($this->players->contains($player)) { |
233
|
|
|
$this->players->removeElement($player); |
234
|
|
|
// set the owning side to null (unless already changed) |
235
|
|
|
if ($player->getTeam() === $this) { |
236
|
|
|
$player->setTeam(null); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
return $this; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function getLogoFilename(): ?string |
244
|
|
|
{ |
245
|
|
|
return $this->logoFilename; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function setLogoFilename(?string $logoFilename): self |
249
|
|
|
{ |
250
|
|
|
$this->logoFilename = $logoFilename; |
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function getLogoMimeType(): ?string |
255
|
|
|
{ |
256
|
|
|
return $this->logoMimeType; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public function setLogoMimeType(?string $logoMimeType): self |
260
|
|
|
{ |
261
|
|
|
$this->logoMimeType = $logoMimeType; |
262
|
|
|
return $this; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
public function getCoverFilename(): ?string |
266
|
|
|
{ |
267
|
|
|
return $this->coverFilename; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function setCoverFilename(?string $coverFilename): self |
271
|
|
|
{ |
272
|
|
|
$this->coverFilename = $coverFilename; |
273
|
|
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
public function getCoverMimeType(): ?string |
277
|
|
|
{ |
278
|
|
|
return $this->coverMimeType; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
public function setCoverMimeType(?string $coverMimeType): self |
282
|
|
|
{ |
283
|
|
|
$this->coverMimeType = $coverMimeType; |
284
|
|
|
return $this; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public function getReady(): ?bool |
288
|
|
|
{ |
289
|
|
|
return $this->ready; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
public function isReady(): ?bool |
293
|
|
|
{ |
294
|
|
|
return $this->getReady(); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
public function setReady(bool $ready): self |
298
|
|
|
{ |
299
|
|
|
$this->ready = $ready; |
300
|
|
|
|
301
|
|
|
return $this; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public function getLockedByManagment(): ?bool |
305
|
|
|
{ |
306
|
|
|
return $this->lockedByManagment; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
public function isLockedByManagment(): ?bool |
310
|
|
|
{ |
311
|
|
|
return $this->getLockedByManagment(); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
public function setLockedByManagment(bool $lockedByManagment): self |
315
|
|
|
{ |
316
|
|
|
$this->lockedByManagment = $lockedByManagment; |
317
|
|
|
|
318
|
|
|
return $this; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* @return Collection|TeamVersion[] |
323
|
|
|
*/ |
324
|
|
|
public function getVersions(): Collection |
325
|
|
|
{ |
326
|
|
|
return $this->versions; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
public function addVersion(TeamVersion $version): self |
330
|
|
|
{ |
331
|
|
|
if (!$this->versions->contains($version)) { |
332
|
|
|
$this->versions[] = $version; |
333
|
|
|
$version->setTeam($this); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
return $this; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
public function removeVersion(TeamVersion $version): self |
340
|
|
|
{ |
341
|
|
|
if ($this->versions->contains($version)) { |
342
|
|
|
$this->versions->removeElement($version); |
343
|
|
|
// set the owning side to null (unless already changed) |
344
|
|
|
if ($version->getTeam() === $this) { |
345
|
|
|
$version->setTeam(null); |
346
|
|
|
} |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
return $this; |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
|