|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Ranking\Provider\Team; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Exception\ORMException; |
|
6
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Team; |
|
7
|
|
|
use VideoGamesRecords\CoreBundle\Entity\TeamSerie; |
|
8
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Serie; |
|
9
|
|
|
use VideoGamesRecords\CoreBundle\Ranking\Provider\AbstractRankingProvider; |
|
10
|
|
|
|
|
11
|
|
|
class TeamSerieRankingProvider extends AbstractRankingProvider |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param int|null $id |
|
15
|
|
|
* @param array $options |
|
16
|
|
|
* @return array |
|
17
|
|
|
* @throws ORMException |
|
18
|
|
|
*/ |
|
19
|
|
|
public function getRankingPoints(int $id = null, array $options = []): array |
|
20
|
|
|
{ |
|
21
|
|
|
$serie = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Serie')->find($id); |
|
22
|
|
|
if (null === $serie) { |
|
23
|
|
|
return []; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$maxRank = $options['maxRank'] ?? null; |
|
27
|
|
|
$limit = $options['limit'] ?? null; |
|
28
|
|
|
|
|
29
|
|
|
$query = $this->em->createQueryBuilder() |
|
30
|
|
|
->select('ts') |
|
31
|
|
|
->from('VideoGamesRecords\CoreBundle\Entity\TeamSerie', 'ts') |
|
32
|
|
|
->join('ts.team', 't') |
|
33
|
|
|
->addSelect('t') |
|
34
|
|
|
->orderBy('ts.rankPointChart'); |
|
35
|
|
|
|
|
36
|
|
|
$query->where('ts.serie = :serie') |
|
37
|
|
|
->setParameter('serie', $serie); |
|
38
|
|
|
|
|
39
|
|
|
if (null !== $maxRank) { |
|
40
|
|
|
$query->andWhere('ts.rankPointChart <= :maxRank'); |
|
41
|
|
|
$query->setParameter('maxRank', $maxRank); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (null !== $limit) { |
|
45
|
|
|
$query->setMaxResults($limit); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $query->getQuery()->getResult(); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param int|null $id |
|
53
|
|
|
* @param array $options |
|
54
|
|
|
* @return array |
|
55
|
|
|
* @throws ORMException |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getRankingMedals(int $id = null, array $options = []): array |
|
58
|
|
|
{ |
|
59
|
|
|
$serie = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Serie')->find($id); |
|
60
|
|
|
if (null === $serie) { |
|
61
|
|
|
return []; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$maxRank = $options['maxRank'] ?? null; |
|
65
|
|
|
$player = $this->getPlayer(); |
|
|
|
|
|
|
66
|
|
|
$limit = $options['limit'] ?? null; |
|
67
|
|
|
|
|
68
|
|
|
$query = $this->em->createQueryBuilder() |
|
69
|
|
|
->select('ps') |
|
70
|
|
|
->from('VideoGamesRecords\CoreBundle\Entity\PlayerSerie', 'ps') |
|
71
|
|
|
->join('ps.player', 'p') |
|
72
|
|
|
->addSelect('p') |
|
73
|
|
|
->orderBy('ps.rankMedal'); |
|
74
|
|
|
|
|
75
|
|
|
$query->where('ps.serie = :serie') |
|
76
|
|
|
->setParameter('serie', $serie); |
|
77
|
|
|
|
|
78
|
|
|
$row = (null !== $player) ? $this->getRow($serie, $player) : null; |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
if (null !== $maxRank) { |
|
81
|
|
|
if (null !== $row) { |
|
|
|
|
|
|
82
|
|
|
$query->andWhere('(ps.rankMedal <= :maxRank OR ps.rankMedal BETWEEN :min AND :max)') |
|
83
|
|
|
->setParameter('min', $row->getRankPoint() - 5) |
|
84
|
|
|
->setParameter('max', $row->getRankPoint() + 5); |
|
85
|
|
|
} else { |
|
86
|
|
|
$query->andWhere('ps.rankMedal <= :maxRank'); |
|
87
|
|
|
} |
|
88
|
|
|
$query->setParameter('maxRank', $maxRank); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (null !== $limit) { |
|
92
|
|
|
$query->setMaxResults($limit); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $query->getQuery()->getResult(); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
private function getRow(Serie $serie, Team $team) |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\TeamSerie')->findOneBy( |
|
101
|
|
|
[ |
|
102
|
|
|
'serie' => $serie, |
|
103
|
|
|
'team' => $team, |
|
104
|
|
|
] |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|