Passed
Push — develop ( 226c06...3e3556 )
by BENARD
06:23
created

PlayerGame::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
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 DateTime;
16
use Doctrine\ORM\Mapping as ORM;
17
use VideoGamesRecords\CoreBundle\Repository\PlayerGameRepository;
18
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank0Trait;
19
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank1Trait;
20
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank2Trait;
21
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank3Trait;
22
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank4Trait;
23
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank5Trait;
24
use VideoGamesRecords\CoreBundle\Traits\Entity\Game\GameMethodsTrait;
25
use VideoGamesRecords\CoreBundle\Traits\Entity\NbChartProvenTrait;
26
use VideoGamesRecords\CoreBundle\Traits\Entity\NbChartProvenWithoutDlcTrait;
27
use VideoGamesRecords\CoreBundle\Traits\Entity\NbChartTrait;
28
use VideoGamesRecords\CoreBundle\Traits\Entity\NbChartWithoutDlcTrait;
29
use VideoGamesRecords\CoreBundle\Traits\Entity\NbEqualTrait;
30
use VideoGamesRecords\CoreBundle\Traits\Entity\Player\PlayerMethodsTrait;
31
use VideoGamesRecords\CoreBundle\Traits\Entity\PointChartTrait;
32
use VideoGamesRecords\CoreBundle\Traits\Entity\RankMedalTrait;
33
use VideoGamesRecords\CoreBundle\Traits\Entity\RankPointChartTrait;
34
35
#[ORM\Table(name:'vgr_player_game')]
36
#[ORM\Entity(repositoryClass: PlayerGameRepository::class)]
37
#[ApiResource(
38
    operations: [
39
        new GetCollection(),
40
        new Get()
41
    ],
42
    normalizationContext: ['groups' => ['player-game:read']]
43
)]
44
#[ApiFilter(
45
    SearchFilter::class,
46
    properties: [
47
        'player' => 'exact',
48
        'game' => 'exact',
49
        'game.platforms' => 'exact',
50
        'game.badge' => 'exact',
51
    ]
52
)]
53
#[ApiFilter(
54
    OrderFilter::class,
55
    properties: [
56
        'lastUpdate' => 'DESC',
57
        'rankPointChart' => 'ASC',
58
        'chartRank0' => 'DESC',
59
        'chartRank1' => 'DESC',
60
        'chartRank2' => 'DESC',
61
        'chartRank3' => 'DESC',
62
        'pointGame' => 'DESC',
63
        'nbChart' => 'DESC',
64
        'nbEqual' => 'ASC',
65
        'game.nbPlayer' => 'DESC',
66
        'game.libGameEn' => 'ASC',
67
        'game.libGameFr' => 'ASC',
68
    ]
69
)]
70
#[ApiFilter(
71
    GroupFilter::class,
72
    arguments: [
73
        'parameterName' => 'groups',
74
        'overrideDefaultGroups' => true,
75
        'whitelist' => [
76
            'player-game:read',
77
            'player-game:game', 'game:read',
78
            'game:platforms', 'platform:read',
79
        ]
80
    ]
81
)]
82
class PlayerGame
83
{
84
    use NbChartTrait;
85
    use NbChartWithoutDlcTrait;
86
    use NbChartProvenTrait;
87
    use NbChartProvenWithoutDlcTrait;
88
    use NbEqualTrait;
89
    use RankMedalTrait;
90
    use ChartRank0Trait;
91
    use ChartRank1Trait;
92
    use ChartRank2Trait;
93
    use ChartRank3Trait;
94
    use ChartRank4Trait;
95
    use ChartRank5Trait;
96
    use RankPointChartTrait;
97
    use PointChartTrait;
98
    use PlayerMethodsTrait;
99
    use GameMethodsTrait;
100
101
    #[ApiProperty(identifier: false)]
102
    #[ORM\Id]
103
    #[ORM\ManyToOne(targetEntity: Player::class, inversedBy: 'playerGame')]
104
    #[ORM\JoinColumn(name:'player_id', referencedColumnName:'id', nullable:false, onDelete:'CASCADE')]
105
    private Player $player;
106
107
    #[ApiProperty(identifier: false)]
108
    #[ORM\Id]
109
    #[ORM\ManyToOne(targetEntity: Game::class, inversedBy: 'playerGame', fetch: 'EAGER')]
110
    #[ORM\JoinColumn(name:'game_id', referencedColumnName:'id', nullable:false, onDelete:'CASCADE')]
111
    private Game $game;
112
113
    #[ORM\Column(nullable: false, options: ['default' => 0])]
114
    private int $pointChartWithoutDlc = 0;
115
116
    #[ORM\Column(nullable: false, options: ['default' => 0])]
117
    private int $pointGame = 0;
118
119
    #[ORM\Column(nullable: false)]
120
    private DateTime $lastUpdate;
121
122
    private $statuses;
123
124
125
    public function setPointChartWithoutDlc(int $pointChartWithoutDlc): void
126
    {
127
        $this->pointChartWithoutDlc = $pointChartWithoutDlc;
128
    }
129
130
    public function getPointChartWithoutDlc(): int
131
    {
132
        return $this->pointChartWithoutDlc;
133
    }
134
135
    public function setPointGame(int $pointGame): void
136
    {
137
        $this->pointGame = $pointGame;
138
    }
139
140
    public function getPointGame(): int
141
    {
142
        return $this->pointGame;
143
    }
144
145
    public function setLastUpdate(DateTime $lastUpdate): void
146
    {
147
        $this->lastUpdate = $lastUpdate;
148
    }
149
150
    public function getLastUpdate(): DateTime
151
    {
152
        return $this->lastUpdate;
153
    }
154
155
    public function setStatuses($statuses): void
156
    {
157
        $this->statuses = $statuses;
158
    }
159
160
    public function getStatuses()
161
    {
162
        return $this->statuses;
163
    }
164
165
    #[ApiProperty(identifier: true)]
166
    public function getId(): string
167
    {
168
        return sprintf('player=%d;game=%d', $this->player->getId(), $this->game->getId());
169
    }
170
}
171