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
|
|
|
* "badge": "exact", |
26
|
|
|
* "badge.type": "exact", |
27
|
|
|
* } |
28
|
|
|
*) |
29
|
|
|
* @ApiFilter(DateFilter::class, properties={"ended_at": DateFilter::INCLUDE_NULL_BEFORE_AND_AFTER}) |
30
|
|
|
* @ApiResource(attributes={"order"={"badge.type", "badge.value"}}) |
31
|
|
|
* @ApiFilter( |
32
|
|
|
* GroupFilter::class, |
33
|
|
|
* arguments={ |
34
|
|
|
* "parameterName": "groups", |
35
|
|
|
* "overrideDefaultGroups": true, |
36
|
|
|
* "whitelist": {"playerBadge.read","playerBadge.badge","playerBadge.player","player.read.mini", "badge.read", "badge.game"} |
37
|
|
|
* } |
38
|
|
|
* ) |
39
|
|
|
* @ApiFilter( |
40
|
|
|
* OrderFilter::class, |
41
|
|
|
* properties={ |
42
|
|
|
* "id":"ASC", |
43
|
|
|
* "createdAt":"ASC", |
44
|
|
|
* "mbOrder":"ASC", |
45
|
|
|
* }, |
46
|
|
|
* arguments={"orderParameterName"="order"} |
47
|
|
|
* ) |
48
|
|
|
*/ |
49
|
|
|
class PlayerBadge implements BadgeInterface |
50
|
|
|
{ |
51
|
|
|
use TimestampableEntity; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ORM\Column(name="id", type="integer") |
55
|
|
|
* @ORM\Id |
56
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
57
|
|
|
*/ |
58
|
|
|
private ?int $id = null; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @ORM\Column(name="ended_at", type="datetime", nullable=true) |
62
|
|
|
*/ |
63
|
|
|
private ?DateTime $ended_at = null; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @ORM\Column(name="mbOrder", type="integer", nullable=true, options={"default":0}) |
67
|
|
|
*/ |
68
|
|
|
private ?int $mbOrder = null; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Player") |
72
|
|
|
* @ORM\JoinColumns({ |
73
|
|
|
* @ORM\JoinColumn(name="idPlayer", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
74
|
|
|
* }) |
75
|
|
|
*/ |
76
|
|
|
private Player $player; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Badge", fetch="EAGER") |
80
|
|
|
* @ORM\JoinColumns({ |
81
|
|
|
* @ORM\JoinColumn(name="idBadge", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
82
|
|
|
* }) |
83
|
|
|
*/ |
84
|
|
|
private Badge $badge; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Set id |
88
|
|
|
* |
89
|
|
|
* @param integer $id |
90
|
|
|
* @return $this |
91
|
|
|
*/ |
92
|
|
|
public function setId(int $id): Self |
93
|
|
|
{ |
94
|
|
|
$this->id = $id; |
95
|
|
|
|
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get id |
101
|
|
|
* |
102
|
|
|
* @return integer |
103
|
|
|
*/ |
104
|
|
|
public function getId(): ?int |
105
|
|
|
{ |
106
|
|
|
return $this->id; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Set ended_at |
111
|
|
|
* |
112
|
|
|
* @param DateTime $ended_at |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
|
|
public function setEndedAt(DateTime $ended_at): Self |
116
|
|
|
{ |
117
|
|
|
$this->ended_at = $ended_at; |
118
|
|
|
|
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get ended_at |
124
|
|
|
* |
125
|
|
|
* @return DateTime |
126
|
|
|
*/ |
127
|
|
|
public function getEndedAt(): ?DateTime |
128
|
|
|
{ |
129
|
|
|
return $this->ended_at; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Set mbOrder |
134
|
|
|
* |
135
|
|
|
* @param integer $mbOrder |
136
|
|
|
* @return $this |
137
|
|
|
*/ |
138
|
|
|
public function setMbOrder(int $mbOrder): Self |
139
|
|
|
{ |
140
|
|
|
$this->mbOrder = $mbOrder; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Get mbOrder |
147
|
|
|
* |
148
|
|
|
* @return integer |
149
|
|
|
*/ |
150
|
|
|
public function getMbOrder(): ?int |
151
|
|
|
{ |
152
|
|
|
return $this->mbOrder; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Set badge |
157
|
|
|
* |
158
|
|
|
* @param Badge $badge |
159
|
|
|
* @return $this |
160
|
|
|
*/ |
161
|
|
|
public function setBadge(Badge $badge): Self |
162
|
|
|
{ |
163
|
|
|
$this->badge = $badge; |
164
|
|
|
|
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Get badge |
170
|
|
|
* |
171
|
|
|
* @return Badge |
172
|
|
|
*/ |
173
|
|
|
public function getBadge(): Badge |
174
|
|
|
{ |
175
|
|
|
return $this->badge; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Set player |
181
|
|
|
* @param Player $player |
182
|
|
|
* @return $this |
183
|
|
|
*/ |
184
|
|
|
public function setPlayer(Player $player): Self |
185
|
|
|
{ |
186
|
|
|
$this->player = $player; |
187
|
|
|
|
188
|
|
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Get player |
193
|
|
|
* |
194
|
|
|
* @return Player |
195
|
|
|
*/ |
196
|
|
|
public function getPlayer(): Player |
197
|
|
|
{ |
198
|
|
|
return $this->player; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return string |
203
|
|
|
*/ |
204
|
|
|
public function getTitle(): string |
205
|
|
|
{ |
206
|
|
|
$badge = $this->getBadge(); |
207
|
|
|
return match (self::TITLES[$badge->getType()]) { |
208
|
|
|
self::TITLE_PLATFORM => $badge->getPlatform() |
209
|
|
|
->getLibPlatform(), |
210
|
|
|
self::TITLE_GAME => $badge->getGame() |
211
|
|
|
->getName(), |
212
|
|
|
self::TITLE_COUNTRY => $badge->getCountry() |
213
|
|
|
->getName(), |
214
|
|
|
self::TITLE_TYPE_VALUE => $badge->getType() . ' ' . $badge->getValue(), |
215
|
|
|
self::TITLE_VALUE_TYPE => $badge->getValue() . ' trad' . $badge->getType(), |
216
|
|
|
default => $badge->getType(), |
217
|
|
|
}; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function __toString(): string |
221
|
|
|
{ |
222
|
|
|
return sprintf('%s # %s ', $this->getPlayer()->getPseudo(), $this->getBadge()->__toString()); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|