1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\CoreBundle\Entity; |
6
|
|
|
|
7
|
|
|
use ApiPlatform\Metadata\ApiProperty; |
8
|
|
|
use ApiPlatform\Metadata\ApiResource; |
9
|
|
|
use ApiPlatform\Metadata\ApiFilter; |
10
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter; |
11
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; |
12
|
|
|
use ApiPlatform\Metadata\Get; |
13
|
|
|
use ApiPlatform\Metadata\GetCollection; |
14
|
|
|
use ApiPlatform\Serializer\Filter\GroupFilter; |
15
|
|
|
use Doctrine\ORM\Mapping as ORM; |
16
|
|
|
use VideoGamesRecords\CoreBundle\Repository\TeamGameRepository; |
17
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank0Trait; |
18
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank1Trait; |
19
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank2Trait; |
20
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank3Trait; |
21
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\NbEqualTrait; |
22
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\PointChartTrait; |
23
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\PointGameTrait; |
24
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\RankMedalTrait; |
25
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\RankPointChartTrait; |
26
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\RankPointGameTrait; |
27
|
|
|
|
28
|
|
|
#[ORM\Table(name:'vgr_team_game')] |
29
|
|
|
#[ORM\Entity(repositoryClass: TeamGameRepository::class)] |
30
|
|
|
#[ApiResource( |
31
|
|
|
operations: [ |
32
|
|
|
new GetCollection(), |
33
|
|
|
new Get() |
34
|
|
|
], |
35
|
|
|
normalizationContext: ['groups' => ['team-game:read']] |
36
|
|
|
)] |
37
|
|
|
#[ApiFilter( |
38
|
|
|
SearchFilter::class, |
39
|
|
|
properties: [ |
40
|
|
|
'team' => 'exact', |
41
|
|
|
'game' => 'exact', |
42
|
|
|
'game.badge' => 'exact', |
43
|
|
|
] |
44
|
|
|
)] |
45
|
|
|
#[ApiFilter( |
46
|
|
|
OrderFilter::class, |
47
|
|
|
properties: [ |
48
|
|
|
'rankPointChart' => 'ASC', |
49
|
|
|
'chartRank0' => 'DESC', |
50
|
|
|
'chartRank1' => 'DESC', |
51
|
|
|
'chartRank2' => 'DESC', |
52
|
|
|
'chartRank3' => 'DESC', |
53
|
|
|
'pointGame' => 'DESC', |
54
|
|
|
'nbEqual' => 'ASC', |
55
|
|
|
'game.nbTeam' => 'DESC', |
56
|
|
|
'game.libGameEn' => 'ASC', |
57
|
|
|
'game.libGameFr' => 'ASC' |
58
|
|
|
] |
59
|
|
|
)] |
60
|
|
|
#[ApiFilter( |
61
|
|
|
GroupFilter::class, |
62
|
|
|
arguments: [ |
63
|
|
|
'parameterName' => 'groups', |
64
|
|
|
'overrideDefaultGroups' => true, |
65
|
|
|
'whitelist' => [ |
66
|
|
|
'team-game:read', |
67
|
|
|
'team-game:game','game:read', |
68
|
|
|
'game:platforms', 'platform:read', |
69
|
|
|
] |
70
|
|
|
] |
71
|
|
|
)] |
72
|
|
|
class TeamGame |
73
|
|
|
{ |
74
|
|
|
use NbEqualTrait; |
75
|
|
|
use RankPointChartTrait; |
76
|
|
|
use PointChartTrait; |
77
|
|
|
//use RankPointGameTrait; |
78
|
|
|
use PointGameTrait; |
79
|
|
|
use RankMedalTrait; |
80
|
|
|
use ChartRank0Trait; |
81
|
|
|
use ChartRank1Trait; |
82
|
|
|
use ChartRank2Trait; |
83
|
|
|
use ChartRank3Trait; |
84
|
|
|
|
85
|
|
|
#[ApiProperty(identifier: false)] |
86
|
|
|
#[ORM\Id] |
87
|
|
|
#[ORM\ManyToOne(targetEntity: Team::class, inversedBy: 'teamGame')] |
88
|
|
|
#[ORM\JoinColumn(name:'team_id', referencedColumnName:'id', nullable:false, onDelete:'CASCADE')] |
89
|
|
|
private Team $team; |
90
|
|
|
|
91
|
|
|
#[ApiProperty(identifier: false)] |
92
|
|
|
#[ORM\Id] |
93
|
|
|
#[ORM\ManyToOne(targetEntity: Game::class, inversedBy: 'playerGame', fetch: 'EAGER')] |
94
|
|
|
#[ORM\JoinColumn(name:'game_id', referencedColumnName:'id', nullable:false, onDelete:'CASCADE')] |
95
|
|
|
private Game $game; |
96
|
|
|
|
97
|
|
|
public function setGame(Game $game): void |
98
|
|
|
{ |
99
|
|
|
$this->game = $game; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getGame(): Game |
103
|
|
|
{ |
104
|
|
|
return $this->game; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function setTeam(Team $team): void |
108
|
|
|
{ |
109
|
|
|
$this->team = $team; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getTeam(): Team |
113
|
|
|
{ |
114
|
|
|
return $this->team; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
#[ApiProperty(identifier: true)] |
118
|
|
|
public function getId(): string |
119
|
|
|
{ |
120
|
|
|
return sprintf('team=%d;game=%d', $this->team->getId(), $this->game->getId()); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|