Passed
Branch develop (a13b53)
by BENARD
12:48
created

Chart::getStatusChoices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Entity;
4
5
use ApiPlatform\Core\Annotation\ApiFilter;
6
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping as ORM;
10
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
11
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
12
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
13
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
14
use Symfony\Component\Intl\Locale;
15
use Symfony\Component\Validator\Constraints as Assert;
16
use VideoGamesRecords\CoreBundle\ValueObject\ChartStatus;
17
18
/**
19
 * Chart
20
 *
21
 * @ORM\Table(name="vgr_chart")
22
 * @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\ChartRepository")
23
 * @ORM\EntityListeners({"VideoGamesRecords\CoreBundle\EventListener\Entity\ChartListener"})
24
 * @ApiFilter(
25
 *     OrderFilter::class,
26
 *     properties={
27
 *          "id":"ASC",
28
 *          "libChartEn" : "ASC",
29
 *          "libChartFr" : "ASC",
30
 *     },
31
 *     arguments={"orderParameterName"="order"}
32
 * )
33
 */
34
class Chart implements SluggableInterface, TimestampableInterface
35
{
36
    use TimestampableTrait;
37
    use SluggableTrait;
38
39
    /**
40
     * @ORM\Column(name="id", type="integer")
41
     * @ORM\Id
42
     * @ORM\GeneratedValue(strategy="IDENTITY")
43
     */
44
    private ?int $id = null;
45
46
    /**
47
     * @Assert\Length(max="255")
48
     * @ORM\Column(name="libChartEn", type="string", length=255, nullable=false)
49
     */
50
    private ?string $libChartEn;
51
52
    /**
53
     * @Assert\Length(max="255")
54
     * @ORM\Column(name="libChartFr", type="string", length=255, nullable=false)
55
     */
56
    private ?string $libChartFr = null;
57
58
    /**
59
     * @ORM\Column(name="statusPlayer", type="string", nullable=false)
60
     */
61
    private string $statusPlayer = 'NORMAL';
62
63
    /**
64
     * @ORM\Column(name="statusTeam", type="string", nullable=false)
65
     */
66
    private string $statusTeam = 'NORMAL';
67
68
    /**
69
     * @ORM\Column(name="nbPost", type="integer", nullable=false)
70
     */
71
    private int $nbPost = 0;
72
73
    /**
74
     * @Assert\NotNull
75
     * @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Group", inversedBy="charts")
76
     * @ORM\JoinColumns({
77
     *   @ORM\JoinColumn(name="idGroup", referencedColumnName="id", nullable=false)
78
     * })
79
     */
80
    private Group $group;
81
82
    /**
83
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\ChartLib", mappedBy="chart", cascade={"persist", "remove"}, orphanRemoval=true)
84
     */
85
    private Collection $libs;
86
87
    /**
88
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerChart", mappedBy="chart")
89
     */
90
    private Collection $playerCharts;
91
92
    /**
93
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\LostPosition", mappedBy="chart")
94
     */
95
    private Collection $lostPositions;
96
97
    /**
98
     * Shortcut to playerChart.rank = 1
99
     */
100
    private ?PlayerChart $playerChart1 = null;
101
102
    /**
103
     * Shortcut to playerChart.player = player
104
     */
105
    private ?PlayerChart $playerChartP = null;
106
107
    /**
108
     * Constructor
109
     */
110
    public function __construct()
111
    {
112
        $this->libs = new ArrayCollection();
113
        $this->playerCharts = new ArrayCollection();
114
        $this->lostPositions = new ArrayCollection();
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function __toString()
121
    {
122
        return sprintf('%s [%s]', $this->getDefaultName(), $this->id);
123
    }
124
125
    /**
126
     * @return string
127
     */
128
    public function getDefaultName(): ?string
129
    {
130
        return $this->libChartEn;
131
    }
132
133
     /**
134
     * @return string
135
     */
136
    public function getName(): string
137
    {
138
        $locale = Locale::getDefault();
139
        if ($locale == 'fr') {
140
            return $this->libChartFr;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->libChartFr could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
141
        } else {
142
            return $this->libChartEn;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->libChartEn could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
143
        }
144
    }
145
146
    /**
147
     * @param string $locale
148
     * @return string
149
     */
150
    public function getCompleteName(string $locale = 'en'): string
151
    {
152
        if ($locale == 'fr') {
153
            return $this->getGroup()->getGame()->getLibGameFr() . ' - ' .
154
            $this->getGroup()->getLibGroupFr()  . ' - ' .
155
            $this->getLibChartFr();
156
        } else {
157
            return $this->getGroup()->getGame()->getLibGameEn() . ' - ' .
158
            $this->getGroup()->getLibGroupEn()  . ' - ' .
159
            $this->getLibChartEn();
160
        }
161
    }
162
163
    /**
164
     * Set idChart
165
     *
166
     * @param integer $id
167
     * @return Chart
168
     */
169
    public function setId(int $id): self
170
    {
171
        $this->id = $id;
172
173
        return $this;
174
    }
175
176
    /**
177
     * Get idChart
178
     *
179
     * @return integer
180
     */
181
    public function getId(): ?int
182
    {
183
        return $this->id;
184
    }
185
186
    /**
187
     * @param string $libChartEn
188
     * @return $this
189
     */
190
    public function setLibChartEn(string $libChartEn): self
191
    {
192
        $this->libChartEn = $libChartEn;
193
        return $this;
194
    }
195
196
    /**
197
     * @return string
198
     */
199
    public function getLibChartEn(): ?string
200
    {
201
        return $this->libChartEn;
202
    }
203
204
    /**
205
     * @param string|null $libChartFr
206
     * @return $this
207
     */
208
    public function setLibChartFr(?string $libChartFr): self
209
    {
210
        $this->libChartFr = $libChartFr;
211
        return $this;
212
    }
213
214
    /**
215
     * @return string
216
     */
217
    public function getLibChartFr(): ?string
218
    {
219
        return $this->libChartFr;
220
    }
221
222
    /**
223
     * Set statusPlayer
224
     *
225
     * @param string $statusPlayer
226
     * @return Chart
227
     */
228
    public function setStatusPlayer(string $statusPlayer): self
229
    {
230
        $this->statusPlayer = $statusPlayer;
231
        return $this;
232
    }
233
234
    /**
235
     * Get statusPlayer
236
     *
237
     * @return ChartStatus
238
     */
239
    public function getStatusPlayer(): ChartStatus
240
    {
241
        return new ChartStatus($this->statusPlayer);
242
    }
243
244
245
    /**
246
     * Set statusTeam
247
     *
248
     * @param string $statusTeam
249
     * @return Chart
250
     */
251
    public function setStatusTeam(string $statusTeam): self
252
    {
253
        $this->statusTeam = $statusTeam;
254
        return $this;
255
    }
256
257
    /**
258
     * Get statusTeam
259
     *
260
     * @return ChartStatus
261
     */
262
    public function getStatusTeam(): ChartStatus
263
    {
264
        return new ChartStatus($this->statusTeam);
265
    }
266
267
    /**
268
     * @return Collection
269
     */
270
    public function getPlayerCharts(): Collection
271
    {
272
        return $this->playerCharts;
273
    }
274
275
    /**
276
     * @return Collection
277
     */
278
    public function getLostPositions(): Collection
279
    {
280
        return $this->lostPositions;
281
    }
282
283
    /**
284
     * @param ArrayCollection|PlayerChart[] $playerCharts
285
     * @return Chart
286
     */
287
    public function setPlayerCharts($playerCharts): self
288
    {
289
        $this->playerCharts = $playerCharts;
290
291
        return $this;
292
    }
293
294
    /**
295
     * @param PlayerChart $playerChart
296
     * @return $this
297
     */
298
    public function addPlayerChart(PlayerChart $playerChart): self
299
    {
300
        $this->playerCharts->add($playerChart);
301
302
        return $this;
303
    }
304
305
    /**
306
     * Set nbPost
307
     *
308
     * @param integer $nbPost
309
     * @return Chart
310
     */
311
    public function setNbPost(int $nbPost)
312
    {
313
        $this->nbPost = $nbPost;
314
        return $this;
315
    }
316
317
    /**
318
     * Get nbPost
319
     *
320
     * @return integer
321
     */
322
    public function getNbPost()
323
    {
324
        return $this->nbPost;
325
    }
326
327
    /**
328
     * Set group
329
     * @param Group|null $group
330
     * @return Chart
331
     */
332
    public function setGroup(Group $group = null)
333
    {
334
        $this->group = $group;
335
336
        return $this;
337
    }
338
339
    /**
340
     * Get group
341
     *
342
     * @return Group
343
     */
344
    public function getGroup()
345
    {
346
        return $this->group;
347
    }
348
349
    /**
350
     * @param ChartLib $lib
351
     * @return $this
352
     */
353
    public function addLib(ChartLib $lib)
354
    {
355
        $lib->setChart($this);
356
        $this->libs[] = $lib;
357
        return $this;
358
    }
359
360
    /**
361
     * @param ChartLib $lib
362
     */
363
    public function removeLib(ChartLib $lib)
364
    {
365
        $this->libs->removeElement($lib);
366
    }
367
368
    /**
369
     * @return Collection
370
     */
371
    public function getLibs(): Collection
372
    {
373
        return $this->libs;
374
    }
375
376
377
    /**
378
     * @param PlayerChart|null $playerChart1
379
     */
380
    public function setPlayerChart1(?PlayerChart $playerChart1)
381
    {
382
        $this->playerChart1 = $playerChart1;
383
    }
384
385
    /**
386
     * @return PlayerChart|null
387
     */
388
    public function getPlayerChart1(): ?PlayerChart
389
    {
390
        return $this->playerChart1;
391
    }
392
393
    /**
394
     * @param PlayerChart|null $playerChartP
395
     */
396
    public function setPlayerChartP(?PlayerChart $playerChartP)
397
    {
398
        $this->playerChartP = $playerChartP;
399
    }
400
401
    /**
402
     * @return PlayerChart|null
403
     */
404
    public function getPlayerChartP(): ?PlayerChart
405
    {
406
        return $this->playerChartP;
407
    }
408
409
    /**
410
     * @return string
411
     */
412
    public function getUrl(): string
413
    {
414
        return sprintf(
415
            '%s-game-g%d/%s-group-g%d/%s-chart-c%d/index',
416
            $this->getGroup()->getGame()->getSlug(),
417
            $this->getGroup()->getGame()->getId(),
418
            $this->getGroup()->getSlug(),
419
            $this->getGroup()->getId(),
420
            $this->getSlug(),
421
            $this->getId()
422
        );
423
    }
424
425
426
    /**
427
     * Returns an array of the fields used to generate the slug.
428
     *
429
     * @return string[]
430
     */
431
    public function getSluggableFields(): array
432
    {
433
        return ['defaultName'];
434
    }
435
}
436