1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Entity; |
4
|
|
|
|
5
|
|
|
use Obblm\Core\Entity\Traits\CoverTrait; |
6
|
|
|
use Obblm\Core\Entity\Traits\LogoTrait; |
7
|
|
|
use Obblm\Core\Entity\Traits\NameTrait; |
8
|
|
|
use Obblm\Core\Entity\Traits\RuleTrait; |
9
|
|
|
use Obblm\Core\Entity\Traits\TimeStampableTrait; |
10
|
|
|
use Obblm\Core\Helper\Rule\CanHaveRuleInterface; |
11
|
|
|
use Obblm\Core\Repository\TeamRepository; |
12
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
13
|
|
|
use Doctrine\Common\Collections\Collection; |
14
|
|
|
use Doctrine\Common\Collections\Criteria; |
15
|
|
|
use Doctrine\ORM\Mapping as ORM; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @ORM\Entity(repositoryClass=TeamRepository::class) |
19
|
|
|
* @ORM\Table(name="obblm_team") |
20
|
|
|
* @ORM\HasLifecycleCallbacks |
21
|
|
|
*/ |
22
|
|
|
class Team implements CanHaveRuleInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @ORM\Id() |
26
|
|
|
* @ORM\GeneratedValue() |
27
|
|
|
* @ORM\Column(type="integer") |
28
|
|
|
*/ |
29
|
|
|
private $id; |
30
|
|
|
|
31
|
|
|
use NameTrait, RuleTrait, LogoTrait, CoverTrait, TimeStampableTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\ManyToOne(targetEntity=Coach::class, inversedBy="teams") |
35
|
|
|
* @ORM\JoinColumn(nullable=false) |
36
|
|
|
*/ |
37
|
|
|
private $coach; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @ORM\Column(type="text", nullable=true) |
41
|
|
|
*/ |
42
|
|
|
private $anthem; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @ORM\Column(type="text", nullable=true) |
46
|
|
|
*/ |
47
|
|
|
private $fluff; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @ORM\Column(type="string", length=50) |
51
|
|
|
*/ |
52
|
|
|
private $roster; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @ORM\OneToMany(targetEntity=Player::class, fetch="EAGER", mappedBy="team", orphanRemoval=true, cascade={"persist", "remove"}) |
56
|
|
|
* @ORM\OrderBy({"number"="ASC"}) |
57
|
|
|
*/ |
58
|
|
|
private $players; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @ORM\Column(type="boolean") |
62
|
|
|
*/ |
63
|
|
|
private $ready = false; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @ORM\Column(type="boolean") |
67
|
|
|
*/ |
68
|
|
|
private $lockedByManagment = false; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @ORM\OneToMany(targetEntity=TeamVersion::class, fetch="EAGER", mappedBy="team", orphanRemoval=true, cascade={"persist", "remove"}) |
72
|
|
|
* @ORM\OrderBy({"id"="DESC"}) |
73
|
|
|
*/ |
74
|
|
|
private $versions; |
75
|
|
|
|
76
|
3 |
|
public function __construct() |
77
|
|
|
{ |
78
|
3 |
|
$this->players = new ArrayCollection(); |
79
|
3 |
|
$this->versions = new ArrayCollection(); |
80
|
3 |
|
} |
81
|
|
|
|
82
|
|
|
public function getId(): ?int |
83
|
|
|
{ |
84
|
|
|
return $this->id; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getCoach(): ?Coach |
88
|
|
|
{ |
89
|
|
|
return $this->coach; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function setCoach(?Coach $coach): self |
93
|
|
|
{ |
94
|
|
|
$this->coach = $coach; |
95
|
|
|
|
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getAnthem(): ?string |
100
|
|
|
{ |
101
|
|
|
return $this->anthem; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function setAnthem(?string $anthem): self |
105
|
|
|
{ |
106
|
|
|
$this->anthem = $anthem; |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getFluff(): ?string |
112
|
|
|
{ |
113
|
|
|
return $this->fluff; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function setFluff(?string $fluff): self |
117
|
|
|
{ |
118
|
|
|
$this->fluff = $fluff; |
119
|
|
|
|
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
2 |
|
public function getRoster(): ?string |
124
|
|
|
{ |
125
|
2 |
|
return $this->roster; |
126
|
|
|
} |
127
|
|
|
|
128
|
3 |
|
public function setRoster(string $roster): self |
129
|
|
|
{ |
130
|
3 |
|
$this->roster = $roster; |
131
|
|
|
|
132
|
3 |
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return Collection|Player[] |
137
|
|
|
*/ |
138
|
|
|
public function getPlayers(): Collection |
139
|
|
|
{ |
140
|
|
|
return $this->players; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return Collection|Player[] |
145
|
|
|
*/ |
146
|
1 |
|
public function getAvailablePlayers(): Collection |
147
|
|
|
{ |
148
|
1 |
|
$criteria = Criteria::create() |
149
|
1 |
|
->andWhere(Criteria::expr()->eq('dead', false)) |
150
|
1 |
|
->andWhere(Criteria::expr()->eq('fire', false)) |
151
|
1 |
|
->orderBy(['number' => 'ASC']) |
152
|
|
|
; |
153
|
1 |
|
return $this->players->matching($criteria); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function getAvailablePlayersSheet(): Collection |
157
|
|
|
{ |
158
|
|
|
// In want to have 16 players in the list, no less, no more |
159
|
|
|
$usedNumbers = []; |
160
|
|
|
$newPlayerList = $this->getAvailablePlayers(); |
161
|
|
|
foreach ($newPlayerList as $player) { |
162
|
|
|
$usedNumbers[$player->getNumber()] = $player; |
163
|
|
|
} |
164
|
|
|
for ($i=1; $i<=16; $i++) { |
165
|
|
|
if (!isset($usedNumbers[$i])) { |
166
|
|
|
$newPlayerList->add((new Player())->setNumber($i)); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
$criteria = Criteria::create(); |
170
|
|
|
$criteria->orderBy(['number' => 'ASC']); |
171
|
|
|
return $newPlayerList->matching($criteria); |
172
|
|
|
} |
173
|
|
|
|
174
|
1 |
|
public function addPlayer(Player $player): self |
175
|
|
|
{ |
176
|
1 |
|
if (!$this->players->contains($player)) { |
177
|
1 |
|
$this->players[] = $player; |
178
|
1 |
|
$player->setTeam($this); |
179
|
|
|
} |
180
|
|
|
|
181
|
1 |
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function removePlayer(Player $player): self |
185
|
|
|
{ |
186
|
|
|
if ($this->players->contains($player)) { |
187
|
|
|
$this->players->removeElement($player); |
188
|
|
|
// set the owning side to null (unless already changed) |
189
|
|
|
if ($player->getTeam() === $this) { |
190
|
|
|
$player->setTeam(null); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function getReady(): ?bool |
198
|
|
|
{ |
199
|
|
|
return $this->ready; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function isReady(): ?bool |
203
|
|
|
{ |
204
|
|
|
return $this->getReady(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function setReady(bool $ready): self |
208
|
|
|
{ |
209
|
|
|
$this->ready = $ready; |
210
|
|
|
|
211
|
|
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function getLockedByManagment(): ?bool |
215
|
|
|
{ |
216
|
|
|
return $this->lockedByManagment; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function isLockedByManagment(): ?bool |
220
|
|
|
{ |
221
|
|
|
return $this->getLockedByManagment(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function setLockedByManagment(bool $lockedByManagment): self |
225
|
|
|
{ |
226
|
|
|
$this->lockedByManagment = $lockedByManagment; |
227
|
|
|
|
228
|
|
|
return $this; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return Collection|TeamVersion[] |
233
|
|
|
*/ |
234
|
1 |
|
public function getVersions(): Collection |
235
|
|
|
{ |
236
|
1 |
|
return $this->versions; |
237
|
|
|
} |
238
|
|
|
|
239
|
1 |
|
public function addVersion(TeamVersion $version): self |
240
|
|
|
{ |
241
|
1 |
|
if (!$this->versions->contains($version)) { |
242
|
1 |
|
$this->versions[] = $version; |
243
|
1 |
|
$version->setTeam($this); |
244
|
|
|
} |
245
|
|
|
|
246
|
1 |
|
return $this; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
public function removeVersion(TeamVersion $version): self |
250
|
|
|
{ |
251
|
|
|
if ($this->versions->contains($version)) { |
252
|
|
|
$this->versions->removeElement($version); |
253
|
|
|
// set the owning side to null (unless already changed) |
254
|
|
|
if ($version->getTeam() === $this) { |
255
|
|
|
$version->setTeam(null); |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
return $this; |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|