Passed
Branch develop (4ef38d)
by BENARD
03:50
created

CoreGameStrategy::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace VideoGamesRecords\DwhBundle\DataProvider\Strategy\Core;
4
5
use VideoGamesRecords\DwhBundle\Contracts\Strategy\CoreStrategyInterface;
6
7
class CoreGameStrategy extends AbstractCoreProvider implements CoreStrategyInterface
8
{
9
    public function supports(string $name): bool
10
    {
11
        return $name === self::TYPE_GAME;
12
    }
13
14
    /**
15
     * @return array
16
     */
17
    public function getData(): array
18
    {
19
        return $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Game')
20
            ->findAll();
21
    }
22
23
    /**
24
     * @param $date1
25
     * @param $date2
26
     * @return array
27
     */
28
    public function getNbPostDay($date1, $date2): array
29
    {
30
        //----- data nbPostDay
31
        $query = $this->em->createQuery(
32
            "
33
            SELECT
34
                 ga.id,
35
                 COUNT(pc.id) as nb
36
            FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc
37
            JOIN pc.chart c
38
            JOIN c.group gr
39
            JOIN gr.game ga
40
            WHERE pc.lastUpdate BETWEEN :date1 AND :date2
41
            GROUP BY ga.id"
42
        );
43
44
        $query->setParameter('date1', $date1);
45
        $query->setParameter('date2', $date2);
46
        $result = $query->getResult();
47
48
        $data = array();
49
        foreach ($result as $row) {
50
            $data[$row['id']] = $row['nb'];
51
        }
52
53
        return $data;
54
    }
55
56
}
57
58