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

CoreTeamStrategy::getNbPostDay()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 23
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace VideoGamesRecords\DwhBundle\DataProvider\Strategy\Core;
4
5
use DateTime;
6
use VideoGamesRecords\DwhBundle\Contracts\Strategy\CoreStrategyInterface;
7
8
class CoreTeamStrategy extends AbstractCoreProvider implements CoreStrategyInterface
9
{
10
    public function supports(string $name): bool
11
    {
12
        return $name === self::TYPE_TEAM;
13
    }
14
15
    /**
16
     * @return array
17
     */
18
    public function getData(): array
19
    {
20
        $conn = $this->em->getConnection();
21
        $sql = "SELECT t.id,
22
                   t.pointChart,
23
                   t.pointBadge,
24
                   t.chartRank0,
25
                   t.chartRank1,
26
                   t.chartRank2,
27
                   t.chartRank3,
28
                   t.rankPointChart,
29
                   t.rankMedal,
30
                   t.rankBadge,
31
                   t.rankCup,
32
                   t.gameRank0,
33
                   t.gameRank1,
34
                   t.gameRank2,
35
                   t.gameRank3,
36
                   t.nbMasterBadge,
37
                   t.pointGame,
38
                   t.rankPointGame                  
39
            FROM vgr_team t";
40
41
        $stmt = $conn->prepare($sql);
42
        $resultSet = $stmt->executeQuery();
43
        return $resultSet->fetchAllAssociative();
44
    }
45
46
    /**
47
     * @param DateTime $date1
48
     * @param DateTime $date2
49
     * @return array
50
     */
51
    public function getNbPostDay(DateTime $date1, DateTime $date2): array
52
    {
53
        $query = $this->em->createQuery(
54
            "
55
            SELECT
56
                 t.id,
57
                 COUNT(pc.id) as nb
58
            FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc
59
            JOIN pc.player p
60
            JOIN p.team t
61
            WHERE pc.lastUpdate BETWEEN :date1 AND :date2
62
            GROUP BY t.id"
63
        );
64
65
        $query->setParameter('date1', $date1);
66
        $query->setParameter('date2', $date2);
67
        $result = $query->getResult();
68
69
        $data = array();
70
        foreach ($result as $row) {
71
            $data[$row['id']] = $row['nb'];
72
        }
73
        return $data;
74
    }
75
}
76
77