|
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 PlayerGroupRankingProvider 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
|
|
|
$group = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Group')->find($id); |
|
19
|
|
|
if (null === $group) { |
|
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\PlayerGroup', 'pg') |
|
30
|
|
|
->join('pg.player', 'p') |
|
31
|
|
|
->addSelect('p') |
|
32
|
|
|
->orderBy('pg.rankPointChart'); |
|
33
|
|
|
|
|
34
|
|
|
$query->where('pg.group = :group') |
|
35
|
|
|
->setParameter('group', $group); |
|
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
|
|
|
|
|
51
|
|
|
return $query->getQuery()->getResult(); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param int|null $id |
|
56
|
|
|
* @param array $options |
|
57
|
|
|
* @return array |
|
58
|
|
|
* @throws ORMException |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getRankingMedals(int $id = null, array $options = []): array |
|
61
|
|
|
{ |
|
62
|
|
|
$group = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Group')->find($id); |
|
63
|
|
|
if (null === $group) { |
|
64
|
|
|
return []; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$maxRank = $options['maxRank'] ?? null; |
|
68
|
|
|
$player = $this->getPlayer(); |
|
69
|
|
|
|
|
70
|
|
|
$query = $this->em->createQueryBuilder() |
|
71
|
|
|
->select('pg') |
|
72
|
|
|
->from('VideoGamesRecords\CoreBundle\Entity\PlayerGroup', 'pg') |
|
73
|
|
|
->join('pg.player', 'p') |
|
74
|
|
|
->addSelect('p') |
|
75
|
|
|
->orderBy('pg.rankMedal'); |
|
76
|
|
|
|
|
77
|
|
|
$query->where('pg.group = :group') |
|
78
|
|
|
->setParameter('group', $group); |
|
79
|
|
|
|
|
80
|
|
|
if (($maxRank !== null) && ($player !== null)) { |
|
81
|
|
|
$query->andWhere('(pg.rankMedal <= :maxRank OR pg.player= :player)') |
|
82
|
|
|
->setParameter('maxRank', $maxRank) |
|
83
|
|
|
->setParameter('player', $player); |
|
84
|
|
|
} elseif ($maxRank !== null) { |
|
85
|
|
|
$query->andWhere('pg.rankMedal <= :maxRank') |
|
86
|
|
|
->setParameter('maxRank', $maxRank); |
|
87
|
|
|
} else { |
|
88
|
|
|
$query->setMaxResults(100); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $query->getQuery()->getResult(); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|