1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Ranking\Provider\Player; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Exception\ORMException; |
6
|
|
|
use VideoGamesRecords\CoreBundle\Ranking\Provider\AbstractRankingProvider; |
7
|
|
|
|
8
|
|
|
class PlayerGameRankingProvider extends AbstractRankingProvider |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param int|null $id |
12
|
|
|
* @param array $options |
13
|
|
|
* @return array |
14
|
|
|
* @throws ORMException |
15
|
|
|
*/ |
16
|
|
|
public function getRankingPoints(int $id = null, array $options = []): array |
17
|
|
|
{ |
18
|
|
|
$game = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Game')->find($id); |
19
|
|
|
if (null === $game) { |
20
|
|
|
return []; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
$maxRank = $options['maxRank'] ?? null; |
24
|
|
|
$player = $this->getPlayer(); |
25
|
|
|
$team = !empty($options['idTeam']) ? $this->em->getReference('VideoGamesRecords\CoreBundle\Entity\Team', $options['idTeam']) : null; |
26
|
|
|
|
27
|
|
|
$query = $this->em->createQueryBuilder() |
28
|
|
|
->select('pg') |
29
|
|
|
->from('VideoGamesRecords\CoreBundle\Entity\PlayerGame', 'pg') |
30
|
|
|
->join('pg.player', 'p') |
31
|
|
|
->addSelect('p') |
32
|
|
|
->orderBy('pg.rankPointChart'); |
33
|
|
|
|
34
|
|
|
$query->where('pg.game = :game') |
35
|
|
|
->setParameter('game', $game); |
36
|
|
|
|
37
|
|
|
if ($team != null) { |
38
|
|
|
$query->andWhere('(p.team = :team)') |
39
|
|
|
->setParameter('team', $team); |
40
|
|
|
} elseif (($maxRank !== null) && ($player !== null)) { |
41
|
|
|
$query->andWhere('(pg.rankPointChart <= :maxRank OR pg.player = :player)') |
42
|
|
|
->setParameter('maxRank', $maxRank) |
43
|
|
|
->setParameter('player', $player); |
44
|
|
|
} elseif ($maxRank !== null) { |
45
|
|
|
$query->andWhere('pg.rankPointChart <= :maxRank') |
46
|
|
|
->setParameter('maxRank', $maxRank); |
47
|
|
|
} else { |
48
|
|
|
$query->setMaxResults(100); |
49
|
|
|
} |
50
|
|
|
return $query->getQuery()->getResult(); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param int|null $id |
55
|
|
|
* @param array $options |
56
|
|
|
* @return array |
57
|
|
|
* @throws ORMException |
58
|
|
|
*/ |
59
|
|
|
public function getRankingMedals(int $id = null, array $options = []): array |
60
|
|
|
{ |
61
|
|
|
$game = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Game')->find($id); |
62
|
|
|
if (null === $game) { |
63
|
|
|
return []; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$maxRank = $options['maxRank'] ?? null; |
67
|
|
|
$player = $this->getPlayer(); |
68
|
|
|
|
69
|
|
|
$query = $this->em->createQueryBuilder() |
70
|
|
|
->select('pg') |
71
|
|
|
->from('VideoGamesRecords\CoreBundle\Entity\PlayerGame', 'pg') |
72
|
|
|
->join('pg.player', 'p') |
73
|
|
|
->addSelect('p') |
74
|
|
|
->orderBy('pg.rankMedal'); |
75
|
|
|
|
76
|
|
|
$query->where('pg.game = :game') |
77
|
|
|
->setParameter('game', $game); |
78
|
|
|
|
79
|
|
|
if (($maxRank !== null) && ($player !== null)) { |
80
|
|
|
$query->andWhere('(pg.rankMedal <= :maxRank OR pg.player = :player)') |
81
|
|
|
->setParameter('maxRank', $maxRank) |
82
|
|
|
->setParameter('player', $player); |
83
|
|
|
} elseif ($maxRank !== null) { |
84
|
|
|
$query->andWhere('pg.rankMedal <= :maxRank') |
85
|
|
|
->setParameter('maxRank', $maxRank); |
86
|
|
|
} else { |
87
|
|
|
$query->setMaxResults(100); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $query->getQuery()->getResult(); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|