1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\CoreBundle\Entity; |
6
|
|
|
|
7
|
|
|
use ApiPlatform\Metadata\ApiResource; |
8
|
|
|
use ApiPlatform\Metadata\ApiFilter; |
9
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter; |
10
|
|
|
use ApiPlatform\Metadata\Get; |
11
|
|
|
use ApiPlatform\Metadata\GetCollection; |
12
|
|
|
use ApiPlatform\Metadata\Link; |
13
|
|
|
use ApiPlatform\OpenApi\Model; |
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Doctrine\Common\Collections\Collection; |
16
|
|
|
use Doctrine\ORM\Mapping as ORM; |
17
|
|
|
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface; |
18
|
|
|
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait; |
19
|
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity; |
20
|
|
|
use Symfony\Component\Intl\Locale; |
21
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
22
|
|
|
use VideoGamesRecords\CoreBundle\Controller\Chart\GetFormData; |
23
|
|
|
use VideoGamesRecords\CoreBundle\Controller\Chart\Player\GetRanking; |
24
|
|
|
use VideoGamesRecords\CoreBundle\Controller\Chart\Player\GetRankingDisabled; |
25
|
|
|
use VideoGamesRecords\CoreBundle\Controller\Chart\Player\GetRankingPoints as PlayerGetRankingPoints; |
26
|
|
|
use VideoGamesRecords\CoreBundle\Controller\Chart\Team\GetRankingPoints as TeamGetRankingPoints; |
27
|
|
|
use VideoGamesRecords\CoreBundle\Repository\ChartRepository; |
28
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\IsDlcTrait; |
29
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\NbPostTrait; |
30
|
|
|
use VideoGamesRecords\CoreBundle\ValueObject\ChartStatus; |
31
|
|
|
|
32
|
|
|
#[ORM\Table(name:'vgr_chart')] |
33
|
|
|
#[ORM\Entity(repositoryClass: ChartRepository::class)] |
34
|
|
|
#[ORM\EntityListeners(["VideoGamesRecords\CoreBundle\EventListener\Entity\ChartListener"])] |
35
|
|
|
#[ORM\Index(name: "idx_lib_chart_fr", columns: ["lib_chart_fr"])] |
36
|
|
|
#[ORM\Index(name: "idx_lib_chart_en", columns: ["lib_chart_en"])] |
37
|
|
|
#[ORM\Index(name: "idx_status_player", columns: ["status_player"])] |
38
|
|
|
#[ORM\Index(name: "idx_status_team", columns: ["status_team"])] |
39
|
|
|
#[ApiResource( |
40
|
|
|
operations: [ |
41
|
|
|
new GetCollection(), |
42
|
|
|
new Get( |
43
|
|
|
normalizationContext: ['groups' => ['chart:read', 'chart:libs', 'chart-lib:read']] |
44
|
|
|
), |
45
|
|
|
new Get( |
46
|
|
|
uriTemplate: '/charts/{id}/form-data', |
47
|
|
|
controller: GetFormData::class, |
48
|
|
|
security: "is_granted('ROLE_PLAYER')", |
49
|
|
|
normalizationContext: ['groups' => [ |
50
|
|
|
'chart:read', 'chart:libs', 'chart-lib:read', |
51
|
|
|
'chart-lib:type', 'chart-type:read', |
52
|
|
|
'chart:group', 'group:read', |
53
|
|
|
'chart:player-charts', 'player-chart:read', 'player-chart:chart', |
54
|
|
|
'player-chart:libs', 'player-chart-lib:read', |
55
|
|
|
'player-chart:player', 'player-chart:platform', |
56
|
|
|
'player-chart:status', 'player-chart-status:read'] |
57
|
|
|
], |
58
|
|
|
openapi: new Model\Operation( |
59
|
|
|
summary: 'Fetch chart form data', |
60
|
|
|
description: 'Fetch chart form data' |
61
|
|
|
), |
62
|
|
|
), |
63
|
|
|
new Get( |
64
|
|
|
uriTemplate: '/charts/{id}/player-ranking', |
65
|
|
|
controller: GetRanking::class, |
66
|
|
|
normalizationContext: ['groups' => [ |
67
|
|
|
'player-chart:read', |
68
|
|
|
'player-chart:player', 'player:read', 'player:team', 'team-read', 'player:country', 'country:read', |
69
|
|
|
'player-chart:platform', 'platform:read', |
70
|
|
|
'player-chart:status', 'player-chart-status:read', |
71
|
|
|
'player-chart:proof', 'proof:read', 'prof:video', 'video-read', 'proof:picture', 'picture:read'] |
72
|
|
|
], |
73
|
|
|
openapi: new Model\Operation( |
74
|
|
|
summary: 'Retrieves the player chart leaderboard', |
75
|
|
|
description: 'Retrieves the player chart leaderboard' |
76
|
|
|
), |
77
|
|
|
), |
78
|
|
|
new Get( |
79
|
|
|
uriTemplate: '/charts/{id}/player-ranking-disabled', |
80
|
|
|
controller: GetRankingDisabled::class, |
81
|
|
|
normalizationContext: ['groups' => [ |
82
|
|
|
'player-chart:read', |
83
|
|
|
'player-chart:player', 'player:read', 'player:team', 'team-read', 'player:country', 'country:read', |
84
|
|
|
'player-chart:platform', 'platform;read', |
85
|
|
|
'player-chart:status', 'player-chart-status:read'] |
86
|
|
|
], |
87
|
|
|
openapi: new Model\Operation( |
88
|
|
|
summary: 'Retrieves the chart disabled scores', |
89
|
|
|
description: 'Retrieves the chart disabled scores', |
90
|
|
|
), |
91
|
|
|
), |
92
|
|
|
new Get( |
93
|
|
|
uriTemplate: '/charts/{id}/team-ranking-points', |
94
|
|
|
controller: TeamGetRankingPoints::class, |
95
|
|
|
normalizationContext: ['groups' => [ |
96
|
|
|
'team-chart:read', 'team-chart:team', 'team:read'] |
97
|
|
|
], |
98
|
|
|
openapi: new Model\Operation( |
99
|
|
|
summary: 'Retrieves the team chart leaderboard', |
100
|
|
|
description: 'Retrieves the team chart leaderboard' |
101
|
|
|
), |
102
|
|
|
openapiContext: [ |
103
|
|
|
'parameters' => [ |
104
|
|
|
[ |
105
|
|
|
'name' => 'maxRank', |
106
|
|
|
'in' => 'query', |
107
|
|
|
'type' => 'integer', |
108
|
|
|
'required' => false |
109
|
|
|
] |
110
|
|
|
] |
111
|
|
|
] |
112
|
|
|
), |
113
|
|
|
new Get( |
114
|
|
|
uriTemplate: '/charts/{id}/player-ranking-points', |
115
|
|
|
controller: PlayerGetRankingPoints::class, |
116
|
|
|
normalizationContext: ['groups' => [ |
117
|
|
|
'player-chart:read', 'player-chart:player', 'player:read', |
118
|
|
|
'player-team', 'team:read', |
119
|
|
|
'player-country', 'country:read'] |
120
|
|
|
], |
121
|
|
|
openapi: new Model\Operation( |
122
|
|
|
summary: 'Retrieves the team chart leaderboard', |
123
|
|
|
description: 'Retrieves the team chart leaderboard' |
124
|
|
|
), |
125
|
|
|
openapiContext: [ |
126
|
|
|
'parameters' => [ |
127
|
|
|
[ |
128
|
|
|
'name' => 'maxRank', |
129
|
|
|
'in' => 'query', |
130
|
|
|
'type' => 'integer', |
131
|
|
|
'required' => false |
132
|
|
|
], |
133
|
|
|
[ |
134
|
|
|
'name' => 'idTeam', |
135
|
|
|
'in' => 'query', |
136
|
|
|
'type' => 'integer', |
137
|
|
|
'required' => false |
138
|
|
|
] |
139
|
|
|
] |
140
|
|
|
] |
141
|
|
|
), |
142
|
|
|
], |
143
|
|
|
normalizationContext: ['groups' => ['chart:read']] |
144
|
|
|
)] |
145
|
|
|
#[ApiFilter( |
146
|
|
|
OrderFilter::class, |
147
|
|
|
properties: [ |
148
|
|
|
'id' => 'ASC', |
149
|
|
|
'libChartEn' => 'ASC', |
150
|
|
|
'libChartFr' => 'ASC', |
151
|
|
|
] |
152
|
|
|
)] |
153
|
|
|
class Chart implements SluggableInterface |
154
|
|
|
{ |
155
|
|
|
use TimestampableEntity; |
156
|
|
|
use SluggableTrait; |
157
|
|
|
use NbPostTrait; |
158
|
|
|
use IsDlcTrait; |
159
|
|
|
|
160
|
|
|
#[ORM\Id, ORM\Column, ORM\GeneratedValue] |
161
|
|
|
private ?int $id = null; |
162
|
|
|
|
163
|
|
|
#[Assert\Length(max: 255)] |
164
|
|
|
#[ORM\Column(length: 255, nullable: false)] |
165
|
|
|
private string $libChartEn = ''; |
166
|
|
|
|
167
|
|
|
#[Assert\Length(max: 255)] |
168
|
|
|
#[ORM\Column(length: 255, nullable: false)] |
169
|
|
|
private string $libChartFr = ''; |
170
|
|
|
|
171
|
|
|
#[ORM\Column(length: 30, nullable: false, options: ['default' => 'NORMAL'])] |
172
|
|
|
private string $statusPlayer = ChartStatus::NORMAL; |
173
|
|
|
|
174
|
|
|
#[ORM\Column(length: 30, nullable: false, options: ['default' => 'NORMAL'])] |
175
|
|
|
private string $statusTeam = ChartStatus::NORMAL; |
176
|
|
|
|
177
|
|
|
#[ORM\Column(nullable: false, options: ['default' => false])] |
178
|
|
|
private bool $isProofVideoOnly = false; |
179
|
|
|
|
180
|
|
|
#[Assert\NotNull] |
181
|
|
|
#[ORM\ManyToOne(targetEntity: Group::class, inversedBy: 'charts')] |
182
|
|
|
#[ORM\JoinColumn(name:'group_id', referencedColumnName:'id', nullable:false, onDelete:'CASCADE')] |
183
|
|
|
private Group $group; |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @var Collection<int, ChartLib> |
187
|
|
|
*/ |
188
|
|
|
#[ORM\OneToMany(targetEntity: ChartLib::class, cascade:['persist', 'remove'], mappedBy: 'chart', orphanRemoval: true)] |
189
|
|
|
private Collection $libs; |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @var Collection<int, PlayerChart> |
193
|
|
|
*/ |
194
|
|
|
#[ORM\OneToMany(targetEntity: PlayerChart::class, mappedBy: 'chart', fetch: 'EXTRA_LAZY')] |
195
|
|
|
private Collection $playerCharts; |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Shortcut to playerChart.rank = 1 |
199
|
|
|
*/ |
200
|
|
|
private ?PlayerChart $playerChart1 = null; |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Shortcut to playerChart.player = player |
204
|
|
|
*/ |
205
|
|
|
private ?PlayerChart $playerChartP = null; |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @var Collection<int, Proof> |
209
|
|
|
*/ |
210
|
|
|
#[ORM\OneToMany(targetEntity: Proof::class, cascade:['persist', 'remove'], mappedBy: 'chart', orphanRemoval: true)] |
211
|
|
|
private Collection $proofs; |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @var Collection<LostPosition> |
215
|
|
|
*/ |
216
|
|
|
#[ORM\OneToMany(targetEntity: LostPosition::class, mappedBy: 'chart')] |
217
|
|
|
private Collection $lostPositions; |
218
|
|
|
|
219
|
|
|
public function __construct() |
220
|
|
|
{ |
221
|
|
|
$this->libs = new ArrayCollection(); |
222
|
|
|
$this->playerCharts = new ArrayCollection(); |
223
|
|
|
$this->lostPositions = new ArrayCollection(); |
224
|
|
|
$this->proofs = new ArrayCollection(); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
public function __toString() |
228
|
|
|
{ |
229
|
|
|
return sprintf('%s [%s]', $this->getDefaultName(), $this->id); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
public function getDefaultName(): ?string |
233
|
|
|
{ |
234
|
|
|
return $this->libChartEn; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function getName(): ?string |
238
|
|
|
{ |
239
|
|
|
$locale = Locale::getDefault(); |
240
|
|
|
if ($locale == 'fr') { |
241
|
|
|
return $this->libChartFr; |
242
|
|
|
} else { |
243
|
|
|
return $this->libChartEn; |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function getCompleteName(string $locale = 'en'): string |
248
|
|
|
{ |
249
|
|
|
if ($locale == 'fr') { |
250
|
|
|
return $this->getGroup() |
251
|
|
|
->getGame() |
252
|
|
|
->getLibGameFr() . ' - ' . $this->getGroup() |
253
|
|
|
->getLibGroupFr() . ' - ' . $this->getLibChartFr(); |
254
|
|
|
} else { |
255
|
|
|
return $this->getGroup() |
256
|
|
|
->getGame() |
257
|
|
|
->getLibGameEn() . ' - ' . $this->getGroup() |
258
|
|
|
->getLibGroupEn() . ' - ' . $this->getLibChartEn(); |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
public function setId(int $id): void |
264
|
|
|
{ |
265
|
|
|
$this->id = $id; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
public function getId(): ?int |
269
|
|
|
{ |
270
|
|
|
return $this->id; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
public function setLibChartEn(string $libChartEn): void |
275
|
|
|
{ |
276
|
|
|
$this->libChartEn = $libChartEn; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
public function getLibChartEn(): string |
280
|
|
|
{ |
281
|
|
|
return $this->libChartEn; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
public function setLibChartFr(?string $libChartFr): void |
285
|
|
|
{ |
286
|
|
|
if ($libChartFr) { |
287
|
|
|
$this->libChartFr = $libChartFr; |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
public function getLibChartFr(): string |
292
|
|
|
{ |
293
|
|
|
return $this->libChartFr; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
public function setStatusPlayer(string $statusPlayer): void |
297
|
|
|
{ |
298
|
|
|
$this->statusPlayer = $statusPlayer; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
public function getStatusPlayer(): ChartStatus |
302
|
|
|
{ |
303
|
|
|
return new ChartStatus($this->statusPlayer); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
public function setStatusTeam(string $statusTeam): void |
307
|
|
|
{ |
308
|
|
|
$this->statusTeam = $statusTeam; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
public function getStatusTeam(): ChartStatus |
312
|
|
|
{ |
313
|
|
|
return new ChartStatus($this->statusTeam); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
public function getIsProofVideoOnly(): bool |
317
|
|
|
{ |
318
|
|
|
return $this->isProofVideoOnly; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
public function setIsProofVideoOnly(bool $isProofVideoOnly): void |
322
|
|
|
{ |
323
|
|
|
$this->isProofVideoOnly = $isProofVideoOnly; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
public function getPlayerCharts(): Collection |
327
|
|
|
{ |
328
|
|
|
return $this->playerCharts; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
public function addPlayerChart(PlayerChart $playerChart): void |
332
|
|
|
{ |
333
|
|
|
$this->playerCharts->add($playerChart); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
public function setGroup(Group $group = null): void |
337
|
|
|
{ |
338
|
|
|
$this->group = $group; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
public function getGroup(): Group |
342
|
|
|
{ |
343
|
|
|
return $this->group; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
public function addLib(ChartLib $lib): void |
347
|
|
|
{ |
348
|
|
|
$lib->setChart($this); |
349
|
|
|
$this->libs[] = $lib; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
public function removeLib(ChartLib $lib): void |
353
|
|
|
{ |
354
|
|
|
$this->libs->removeElement($lib); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
public function getLibs(): Collection |
358
|
|
|
{ |
359
|
|
|
return $this->libs; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
|
363
|
|
|
public function setPlayerChart1(?PlayerChart $playerChart1): void |
364
|
|
|
{ |
365
|
|
|
$this->playerChart1 = $playerChart1; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
public function getPlayerChart1(): ?PlayerChart |
369
|
|
|
{ |
370
|
|
|
return $this->playerChart1; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
public function setPlayerChartP(?PlayerChart $playerChartP): void |
374
|
|
|
{ |
375
|
|
|
$this->playerChartP = $playerChartP; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
public function getPlayerChartP(): ?PlayerChart |
379
|
|
|
{ |
380
|
|
|
return $this->playerChartP; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
public function getUrl(): string |
384
|
|
|
{ |
385
|
|
|
return sprintf( |
386
|
|
|
'%s-game-g%d/%s-group-g%d/%s-chart-c%d/index', |
387
|
|
|
$this->getGroup()->getGame()->getSlug(), |
388
|
|
|
$this->getGroup()->getGame()->getId(), |
389
|
|
|
$this->getGroup()->getSlug(), |
390
|
|
|
$this->getGroup()->getId(), |
391
|
|
|
$this->getSlug(), |
392
|
|
|
$this->getId() |
393
|
|
|
); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
public function getSluggableFields(): array |
397
|
|
|
{ |
398
|
|
|
return ['defaultName']; |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
|