1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\DwhBundle\Repository; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
7
|
|
|
use Doctrine\ORM\NonUniqueResultException; |
8
|
|
|
use Doctrine\ORM\NoResultException; |
9
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
10
|
|
|
use VideoGamesRecords\DwhBundle\Entity\Game; |
11
|
|
|
|
12
|
|
|
class GameRepository extends ServiceEntityRepository |
13
|
|
|
{ |
14
|
|
|
public function __construct(ManagerRegistry $registry) |
15
|
|
|
{ |
16
|
|
|
parent::__construct($registry, Game::class); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param DateTime $begin |
21
|
|
|
* @param DateTime $end |
22
|
|
|
* @param integer $limit |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
|
|
public function getTop(DateTime $begin, DateTime $end, int $limit = 20): array |
26
|
|
|
{ |
27
|
|
|
$query = $this->_em->createQuery(" |
28
|
|
|
SELECT g.id, |
29
|
|
|
SUM(g.nbPostDay) as nb |
30
|
|
|
FROM VideoGamesRecords\DwhBundle\Entity\Game g |
31
|
|
|
WHERE g.date BETWEEN :begin AND :end |
32
|
|
|
GROUP BY g.id |
33
|
|
|
HAVING nb > 0 |
34
|
|
|
ORDER BY nb DESC"); |
35
|
|
|
|
36
|
|
|
$query->setParameter('begin', $begin); |
37
|
|
|
$query->setParameter('end', $end); |
38
|
|
|
$query->setMaxResults($limit); |
39
|
|
|
|
40
|
|
|
return $query->getArrayResult(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param DateTime $begin |
45
|
|
|
* @param DateTime $end |
46
|
|
|
* @return mixed |
47
|
|
|
* @throws NoResultException |
48
|
|
|
* @throws NonUniqueResultException |
49
|
|
|
*/ |
50
|
|
|
public function getTotalNbGame(DateTime $begin, DateTime $end): mixed |
51
|
|
|
{ |
52
|
|
|
$query = $this->_em->createQuery(" |
53
|
|
|
SELECT COUNT(DISTINCT(g.id)) as nb |
54
|
|
|
FROM VideoGamesRecords\DwhBundle\Entity\Game g |
55
|
|
|
WHERE g.date BETWEEN :begin AND :end |
56
|
|
|
AND g.nbPostDay > 0"); |
57
|
|
|
|
58
|
|
|
$query->setParameter('begin', $begin); |
59
|
|
|
$query->setParameter('end', $end); |
60
|
|
|
|
61
|
|
|
return $query->getSingleScalarResult(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param DateTime $begin |
66
|
|
|
* @param DateTime $end |
67
|
|
|
* @return mixed |
68
|
|
|
* @throws NoResultException |
69
|
|
|
* @throws NonUniqueResultException |
70
|
|
|
*/ |
71
|
|
|
public function getTotalNbPostDay(DateTime $begin, DateTime $end): mixed |
72
|
|
|
{ |
73
|
|
|
$query = $this->_em->createQuery(" |
74
|
|
|
SELECT SUM(g.nbPostDay) as nb |
75
|
|
|
FROM VideoGamesRecords\DwhBundle\Entity\Game g |
76
|
|
|
WHERE g.date BETWEEN :begin AND :end"); |
77
|
|
|
|
78
|
|
|
$query->setParameter('begin', $begin); |
79
|
|
|
$query->setParameter('end', $end); |
80
|
|
|
|
81
|
|
|
return $query->getSingleScalarResult(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|