1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Entity; |
4
|
|
|
|
5
|
|
|
use Obblm\Core\Entity\Traits\SidelinesTrait; |
6
|
|
|
use Obblm\Core\Entity\Traits\TeamEvolutionTrait; |
7
|
|
|
use Obblm\Core\Entity\Traits\TimeStampableTrait; |
8
|
|
|
use Obblm\Core\Repository\TeamVersionRepository; |
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
10
|
|
|
use Doctrine\Common\Collections\Collection; |
11
|
|
|
use Doctrine\Common\Collections\Criteria; |
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @ORM\Entity(repositoryClass=TeamVersionRepository::class) |
16
|
|
|
* @ORM\Table(name="obblm_team_version") |
17
|
|
|
* @ORM\HasLifecycleCallbacks |
18
|
|
|
*/ |
19
|
|
|
class TeamVersion |
20
|
|
|
{ |
21
|
|
|
use TimeStampableTrait, SidelinesTrait, TeamEvolutionTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ORM\Id |
25
|
|
|
* @ORM\GeneratedValue |
26
|
|
|
* @ORM\Column(type="integer") |
27
|
|
|
*/ |
28
|
|
|
private $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @ORM\ManyToOne(targetEntity=Team::class, fetch="EAGER", inversedBy="versions", cascade="persist") |
32
|
|
|
* @ORM\JoinColumn(nullable=false) |
33
|
|
|
*/ |
34
|
|
|
private $team; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @ORM\OneToMany(targetEntity=PlayerVersion::class, mappedBy="teamVersion", orphanRemoval=true, cascade={"persist", "remove"}) |
38
|
|
|
*/ |
39
|
|
|
private $playerVersions; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @ORM\Column(type="integer") |
43
|
|
|
*/ |
44
|
|
|
private $treasure = 0; |
45
|
|
|
|
46
|
2 |
|
public function __construct() |
47
|
|
|
{ |
48
|
2 |
|
$this->playerVersions = new ArrayCollection(); |
49
|
2 |
|
$this->apothecary = false; |
50
|
2 |
|
$this->rerolls = 0; |
51
|
2 |
|
$this->cheerleaders = 0; |
52
|
2 |
|
$this->assistants = 0; |
53
|
2 |
|
$this->popularity = 0; |
54
|
2 |
|
} |
55
|
|
|
|
56
|
|
|
public function getId(): ?int |
57
|
|
|
{ |
58
|
|
|
return $this->id; |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
public function getTeam(): ?Team |
62
|
|
|
{ |
63
|
2 |
|
return $this->team; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function setTeam(?Team $team): self |
67
|
|
|
{ |
68
|
1 |
|
$this->team = $team; |
69
|
|
|
|
70
|
1 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return Collection|PlayerVersion[] |
75
|
|
|
*/ |
76
|
|
|
public function getPlayerVersions(): Collection |
77
|
|
|
{ |
78
|
|
|
return $this->playerVersions; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return Collection|PlayerVersion[] |
83
|
|
|
*/ |
84
|
1 |
|
public function getNotDeadPlayerVersions(): Collection |
85
|
|
|
{ |
86
|
1 |
|
$criteria = Criteria::create() |
87
|
1 |
|
->andWhere(Criteria::expr()->eq('dead', false)) |
88
|
|
|
; |
89
|
1 |
|
return $this->playerVersions->matching($criteria); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return Collection|PlayerVersion[] |
94
|
|
|
*/ |
95
|
|
|
public function getAvailablePlayerVersions(): Collection |
96
|
|
|
{ |
97
|
|
|
$criteria = Criteria::create() |
98
|
|
|
->andWhere(Criteria::expr()->eq('dead', false)) |
99
|
|
|
; |
100
|
|
|
return $this->playerVersions->matching($criteria); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function addPlayerVersion(PlayerVersion $playerVersion): self |
104
|
|
|
{ |
105
|
|
|
if (!$this->playerVersions->contains($playerVersion)) { |
106
|
|
|
$this->playerVersions[] = $playerVersion; |
107
|
|
|
$playerVersion->setTeamVersion($this); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function removePlayerVersion(PlayerVersion $playerVersion): self |
114
|
|
|
{ |
115
|
|
|
if ($this->playerVersions->contains($playerVersion)) { |
116
|
|
|
$this->playerVersions->removeElement($playerVersion); |
117
|
|
|
// set the owning side to null (unless already changed) |
118
|
|
|
if ($playerVersion->getTeamVersion() === $this) { |
119
|
|
|
$playerVersion->setTeamVersion(null); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function getTreasure(): ?int |
127
|
|
|
{ |
128
|
|
|
return $this->treasure; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function setTreasure(int $treasure): self |
132
|
|
|
{ |
133
|
|
|
$this->treasure = $treasure; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function setUpdatedAtValue() |
139
|
|
|
{ |
140
|
|
|
$this->updatedAt = new \DateTime(); |
141
|
|
|
$this->getTeam()->setUpdatedAt(new \DateTime()); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|