1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Entity; |
4
|
|
|
|
5
|
|
|
use ApiPlatform\Core\Annotation\ApiFilter; |
6
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
7
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter; |
8
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; |
9
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; |
10
|
|
|
use ApiPlatform\Core\Serializer\Filter\GroupFilter; |
11
|
|
|
use DateTime; |
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
13
|
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity; |
14
|
|
|
use VideoGamesRecords\CoreBundle\Contracts\BadgeInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* PlayerGame |
18
|
|
|
* |
19
|
|
|
* @ORM\Table(name="vgr_player_badge") |
20
|
|
|
* @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\PlayerBadgeRepository") |
21
|
|
|
* @ApiFilter( |
22
|
|
|
* SearchFilter::class, |
23
|
|
|
* properties={ |
24
|
|
|
* "player": "exact", |
25
|
|
|
* "player": "exact", |
26
|
|
|
* "badge": "exact", |
27
|
|
|
* "badge.type": "exact", |
28
|
|
|
* } |
29
|
|
|
*) |
30
|
|
|
* @ApiFilter(DateFilter::class, properties={"ended_at": DateFilter::INCLUDE_NULL_BEFORE_AND_AFTER}) |
31
|
|
|
* @ApiResource(attributes={"order"={"badge.type", "badge.value"}}) |
32
|
|
|
* @ApiFilter( |
33
|
|
|
* GroupFilter::class, |
34
|
|
|
* arguments={ |
35
|
|
|
* "parameterName": "groups", |
36
|
|
|
* "overrideDefaultGroups": true, |
37
|
|
|
* "whitelist": {"playerBadge.read","playerBadge.badge","playerBadge.player","player.read.mini", "badge.read", "badge.game"} |
38
|
|
|
* } |
39
|
|
|
* ) |
40
|
|
|
* @ApiFilter( |
41
|
|
|
* OrderFilter::class, |
42
|
|
|
* properties={ |
43
|
|
|
* "id":"ASC", |
44
|
|
|
* "createdAt":"ASC", |
45
|
|
|
* "mbOrder":"ASC", |
46
|
|
|
* }, |
47
|
|
|
* arguments={"orderParameterName"="order"} |
48
|
|
|
* ) |
49
|
|
|
*/ |
50
|
|
|
class PlayerBadge implements BadgeInterface |
51
|
|
|
{ |
52
|
|
|
use TimestampableEntity; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @ORM\Column(name="id", type="integer") |
56
|
|
|
* @ORM\Id |
57
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
58
|
|
|
*/ |
59
|
|
|
private ?int $id = null; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @ORM\Column(name="ended_at", type="datetime", nullable=true) |
63
|
|
|
*/ |
64
|
|
|
private ?DateTime $ended_at = null; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @ORM\Column(name="mbOrder", type="integer", nullable=true, options={"default":0}) |
68
|
|
|
*/ |
69
|
|
|
private ?int $mbOrder = null; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Player") |
73
|
|
|
* @ORM\JoinColumns({ |
74
|
|
|
* @ORM\JoinColumn(name="idPlayer", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
75
|
|
|
* }) |
76
|
|
|
*/ |
77
|
|
|
private Player $player; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Badge", fetch="EAGER") |
81
|
|
|
* @ORM\JoinColumns({ |
82
|
|
|
* @ORM\JoinColumn(name="idBadge", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
83
|
|
|
* }) |
84
|
|
|
*/ |
85
|
|
|
private Badge $badge; |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Set id |
90
|
|
|
* |
91
|
|
|
* @param integer $id |
92
|
|
|
* @return $this |
93
|
|
|
*/ |
94
|
|
|
public function setId(int $id): static |
95
|
|
|
{ |
96
|
|
|
$this->id = $id; |
97
|
|
|
|
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get id |
103
|
|
|
* |
104
|
|
|
* @return integer |
105
|
|
|
*/ |
106
|
|
|
public function getId(): ?int |
107
|
|
|
{ |
108
|
|
|
return $this->id; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set ended_at |
113
|
|
|
* |
114
|
|
|
* @param DateTime $ended_at |
115
|
|
|
* @return $this |
116
|
|
|
*/ |
117
|
|
|
public function setEndedAt(DateTime $ended_at): static |
118
|
|
|
{ |
119
|
|
|
$this->ended_at = $ended_at; |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get ended_at |
126
|
|
|
* |
127
|
|
|
* @return DateTime |
128
|
|
|
*/ |
129
|
|
|
public function getEndedAt(): ?DateTime |
130
|
|
|
{ |
131
|
|
|
return $this->ended_at; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Set mbOrder |
136
|
|
|
* |
137
|
|
|
* @param integer $mbOrder |
138
|
|
|
* @return $this |
139
|
|
|
*/ |
140
|
|
|
public function setMbOrder(int $mbOrder): static |
141
|
|
|
{ |
142
|
|
|
$this->mbOrder = $mbOrder; |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Get mbOrder |
149
|
|
|
* |
150
|
|
|
* @return integer |
151
|
|
|
*/ |
152
|
|
|
public function getMbOrder(): ?int |
153
|
|
|
{ |
154
|
|
|
return $this->mbOrder; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set badge |
159
|
|
|
* |
160
|
|
|
* @param Badge $badge |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
|
|
public function setBadge(Badge $badge): static |
164
|
|
|
{ |
165
|
|
|
$this->badge = $badge; |
166
|
|
|
|
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Get badge |
172
|
|
|
* |
173
|
|
|
* @return Badge |
174
|
|
|
*/ |
175
|
|
|
public function getBadge(): Badge |
176
|
|
|
{ |
177
|
|
|
return $this->badge; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Set player |
183
|
|
|
* @param Player $player |
184
|
|
|
* @return $this |
185
|
|
|
*/ |
186
|
|
|
public function setPlayer(Player $player): static |
187
|
|
|
{ |
188
|
|
|
$this->player = $player; |
189
|
|
|
|
190
|
|
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Get player |
195
|
|
|
* |
196
|
|
|
* @return Player |
197
|
|
|
*/ |
198
|
|
|
public function getPlayer(): Player |
199
|
|
|
{ |
200
|
|
|
return $this->player; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
public function __toString(): string |
205
|
|
|
{ |
206
|
|
|
return sprintf('%s # %s ', $this->getPlayer()->getPseudo(), $this->getBadge()->__toString()); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|