GameRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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