CoreGameStrategy::getData()   A
last analyzed

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