1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\DataProvider\Ranking\Player; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Exception\ORMException; |
6
|
|
|
use VideoGamesRecords\CoreBundle\DataProvider\Ranking\AbstractRankingQuery; |
7
|
|
|
|
8
|
|
|
class PlayerRankingQuery extends AbstractRankingQuery |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param array $options |
12
|
|
|
* @return array |
13
|
|
|
* @throws ORMException |
14
|
|
|
*/ |
15
|
|
|
public function getRankingPointChart(array $options = []): array |
16
|
|
|
{ |
17
|
|
|
return $this->getRanking('rankPointChart', $options); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param array $options |
22
|
|
|
* @return array |
23
|
|
|
* @throws ORMException |
24
|
|
|
*/ |
25
|
|
|
public function getRankingPointGame(array $options = []): array |
26
|
|
|
{ |
27
|
|
|
return $this->getRanking('rankPointGame', $options); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param array $options |
32
|
|
|
* @return array |
33
|
|
|
* @throws ORMException |
34
|
|
|
*/ |
35
|
|
|
public function getRankingMedals(array $options = []): array |
36
|
|
|
{ |
37
|
|
|
return $this->getRanking('rankMedal', $options); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param array $options |
42
|
|
|
* @return array |
43
|
|
|
* @throws ORMException |
44
|
|
|
*/ |
45
|
|
|
public function getRankingBadge(array $options = []): array |
46
|
|
|
{ |
47
|
|
|
return $this->getRanking('rankBadge', $options); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param array $options |
52
|
|
|
* @return array |
53
|
|
|
* @throws ORMException |
54
|
|
|
*/ |
55
|
|
|
public function getRankingCup(array $options = []): array |
56
|
|
|
{ |
57
|
|
|
return $this->getRanking('rankCup', $options); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param array $options |
62
|
|
|
* @return array |
63
|
|
|
* @throws ORMException |
64
|
|
|
*/ |
65
|
|
|
public function getRankingProof(array $options = []): array |
66
|
|
|
{ |
67
|
|
|
return $this->getRanking('rankProof', $options); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $column |
72
|
|
|
* @param array $options |
73
|
|
|
* @return array |
74
|
|
|
* @throws ORMException |
75
|
|
|
*/ |
76
|
|
|
private function getRanking(string $column = 'rankPointChart', array $options = []): array |
77
|
|
|
{ |
78
|
|
|
$maxRank = $options['maxRank'] ?? 100; |
79
|
|
|
$limit = $options['limit'] ?? null; |
80
|
|
|
$player = $this->getPlayer(); |
81
|
|
|
$team = !empty($options['idTeam']) ? $this->em->getReference('VideoGamesRecords\CoreBundle\Entity\Team', $options['idTeam']) : null; |
82
|
|
|
|
83
|
|
|
$query = $this->em->createQueryBuilder() |
84
|
|
|
->select('p') |
85
|
|
|
->from('VideoGamesRecords\CoreBundle\Entity\Player', 'p') |
86
|
|
|
->leftJoin('p.team', 't') |
87
|
|
|
->addSelect('t') |
88
|
|
|
->leftJoin('p.country', 'c') |
89
|
|
|
->addSelect('c') |
90
|
|
|
->leftJoin('c.translations', 'trans') |
91
|
|
|
->addSelect('trans') |
92
|
|
|
->where("p.$column != 0") |
93
|
|
|
->orderBy("p.$column"); |
94
|
|
|
|
95
|
|
|
if ($team !== null) { |
96
|
|
|
$query->andWhere('(p.team = :team)') |
97
|
|
|
->setParameter('team', $team); |
98
|
|
|
} elseif (($maxRank !== null) && ($player !== null)) { |
99
|
|
|
$query->andWhere("(p.$column <= :maxRank OR p = :player)") |
100
|
|
|
->setParameter('maxRank', $maxRank) |
101
|
|
|
->setParameter('player', $player); |
102
|
|
|
} else { |
103
|
|
|
$query->andWhere("p.$column <= :maxRank") |
104
|
|
|
->setParameter('maxRank', $maxRank); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if (null !== $limit) { |
108
|
|
|
$query->setMaxResults($limit); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $query->getQuery()->getResult(); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|