1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Entity; |
4
|
|
|
|
5
|
|
|
use ApiPlatform\Core\Annotation\ApiFilter; |
6
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; |
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
10
|
|
|
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface; |
11
|
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity; |
12
|
|
|
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait; |
13
|
|
|
use Symfony\Component\Intl\Locale; |
14
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
15
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\IsDlcTrait; |
16
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\IsRankTrait; |
17
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\NbChartTrait; |
18
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\NbPlayerTrait; |
19
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\NbPostTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Group |
23
|
|
|
* |
24
|
|
|
* @ORM\Table( |
25
|
|
|
* name="vgr_group", |
26
|
|
|
* indexes={ |
27
|
|
|
* @ORM\Index(name="idx_libGroupFr", columns={"libGroupFr"}), |
28
|
|
|
* @ORM\Index(name="idx_libGroupEn", columns={"libGroupEn"}) |
29
|
|
|
* } |
30
|
|
|
* ) |
31
|
|
|
* @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\GroupRepository") |
32
|
|
|
* @ORM\EntityListeners({"VideoGamesRecords\CoreBundle\EventListener\Entity\GroupListener"}) |
33
|
|
|
* @ApiFilter( |
34
|
|
|
* OrderFilter::class, |
35
|
|
|
* properties={ |
36
|
|
|
* "id":"ASC", |
37
|
|
|
* "libGroupEn" : "ASC", |
38
|
|
|
* "libGroupFr" : "ASC", |
39
|
|
|
* }, |
40
|
|
|
* arguments={"orderParameterName"="order"} |
41
|
|
|
* ) |
42
|
|
|
*/ |
43
|
|
|
class Group implements SluggableInterface |
44
|
|
|
{ |
45
|
|
|
use TimestampableEntity; |
46
|
|
|
use SluggableTrait; |
47
|
|
|
use NbChartTrait; |
48
|
|
|
use NbPostTrait; |
49
|
|
|
use NbPlayerTrait; |
50
|
|
|
use IsRankTrait; |
51
|
|
|
use IsDlcTrait; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ORM\Column(name="id", type="integer") |
55
|
|
|
* @ORM\Id |
56
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
57
|
|
|
*/ |
58
|
|
|
protected ?int $id = null; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Assert\Length(max="255") |
62
|
|
|
* @ORM\Column(name="libGroupEn", type="string", length=255, nullable=false) |
63
|
|
|
*/ |
64
|
|
|
private string $libGroupEn = ''; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Assert\Length(max="255") |
68
|
|
|
* @ORM\Column(name="libGroupFr", type="string", length=255, nullable=false) |
69
|
|
|
*/ |
70
|
|
|
private string $libGroupFr = ''; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Assert\NotNull |
74
|
|
|
* @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Game", inversedBy="groups") |
75
|
|
|
* @ORM\JoinColumns({ |
76
|
|
|
* @ORM\JoinColumn(name="idGame", referencedColumnName="id", nullable=false) |
77
|
|
|
* }) |
78
|
|
|
*/ |
79
|
|
|
private Game $game; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var Collection<Chart> |
83
|
|
|
* @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\Chart", mappedBy="group",cascade={"persist"}) |
84
|
|
|
*/ |
85
|
|
|
private Collection $charts; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Constructor |
89
|
|
|
*/ |
90
|
|
|
public function __construct() |
91
|
|
|
{ |
92
|
|
|
$this->charts = new ArrayCollection(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function __toString() |
99
|
|
|
{ |
100
|
|
|
return sprintf('%s [%s]', $this->getDefaultName(), $this->id); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function getDefaultName(): string |
107
|
|
|
{ |
108
|
|
|
return $this->libGroupEn; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string|null |
113
|
|
|
*/ |
114
|
|
|
public function getName(): ?string |
115
|
|
|
{ |
116
|
|
|
$locale = Locale::getDefault(); |
117
|
|
|
if ($locale == 'fr') { |
118
|
|
|
return $this->libGroupFr; |
119
|
|
|
} else { |
120
|
|
|
return $this->libGroupEn; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set idGroup |
126
|
|
|
* @param integer $id |
127
|
|
|
* @return $this |
128
|
|
|
*/ |
129
|
|
|
public function setId(int $id): Group |
130
|
|
|
{ |
131
|
|
|
$this->id = $id; |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get idGroup |
137
|
|
|
* @return int|null |
138
|
|
|
*/ |
139
|
|
|
public function getId(): ?int |
140
|
|
|
{ |
141
|
|
|
return $this->id; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param string $libGroupEn |
146
|
|
|
* @return $this |
147
|
|
|
*/ |
148
|
|
|
public function setLibGroupEn(string $libGroupEn): Group |
149
|
|
|
{ |
150
|
|
|
$this->libGroupEn = $libGroupEn; |
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
public function getLibGroupEn(): string |
158
|
|
|
{ |
159
|
|
|
return $this->libGroupEn; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param ?string $libGroupFr |
164
|
|
|
* @return $this |
165
|
|
|
*/ |
166
|
|
|
public function setLibGroupFr(?string $libGroupFr): Group |
167
|
|
|
{ |
168
|
|
|
if ($libGroupFr) { |
169
|
|
|
$this->libGroupFr = $libGroupFr; |
170
|
|
|
} |
171
|
|
|
return $this; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return string |
176
|
|
|
*/ |
177
|
|
|
public function getLibGroupFr(): string |
178
|
|
|
{ |
179
|
|
|
return $this->libGroupFr; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Set Game |
184
|
|
|
* @param Game|null $game |
185
|
|
|
* @return $this |
186
|
|
|
*/ |
187
|
|
|
public function setGame(Game $game = null): Group |
188
|
|
|
{ |
189
|
|
|
$this->game = $game; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Get game |
196
|
|
|
* @return Game |
197
|
|
|
*/ |
198
|
|
|
public function getGame(): Game |
199
|
|
|
{ |
200
|
|
|
return $this->game; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param Chart $chart |
205
|
|
|
* @return $this |
206
|
|
|
*/ |
207
|
|
|
public function addChart(Chart $chart): Group |
208
|
|
|
{ |
209
|
|
|
$this->charts[] = $chart; |
210
|
|
|
return $this; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param Chart $chart |
215
|
|
|
*/ |
216
|
|
|
public function removeChart(Chart $chart): void |
217
|
|
|
{ |
218
|
|
|
$this->charts->removeElement($chart); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return Collection |
223
|
|
|
*/ |
224
|
|
|
public function getCharts(): Collection |
225
|
|
|
{ |
226
|
|
|
return $this->charts; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Returns an array of the fields used to generate the slug. |
231
|
|
|
* |
232
|
|
|
* @return string[] |
233
|
|
|
*/ |
234
|
|
|
public function getSluggableFields(): array |
235
|
|
|
{ |
236
|
|
|
return ['defaultName']; |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|