CoreTeamStrategy::supports()   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
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\DwhBundle\DataProvider\Strategy\Core;
6
7
use DateTime;
8
use Doctrine\DBAL\Exception;
9
use VideoGamesRecords\DwhBundle\Contracts\Strategy\CoreStrategyInterface;
10
11
class CoreTeamStrategy extends AbstractCoreProvider implements CoreStrategyInterface
12
{
13
    public function supports(string $name): bool
14
    {
15
        return $name === self::TYPE_TEAM;
16
    }
17
18
19
    /**
20
     * @throws Exception
21
     */
22
    public function getData(): array
23
    {
24
        $conn = $this->em->getConnection();
25
        $sql = "SELECT t.id,
26
                   t.point_chart,
27
                   t.point_badge,
28
                   t.chart_rank0,
29
                   t.chart_rank1,
30
                   t.chart_rank2,
31
                   t.chart_rank3,
32
                   t.rank_point_chart,
33
                   t.rank_medal,
34
                   t.rank_badge,
35
                   t.rank_cup,
36
                   t.game_rank0,
37
                   t.game_rank1,
38
                   t.game_rank2,
39
                   t.game_rank3,
40
                   t.nb_master_badge,
41
                   t.point_game,
42
                   t.rank_point_game                  
43
            FROM vgr_team t";
44
45
        $stmt = $conn->prepare($sql);
46
        $resultSet = $stmt->executeQuery();
47
        return $resultSet->fetchAllAssociative();
48
    }
49
50
    /**
51
     * @param DateTime $date1
52
     * @param DateTime $date2
53
     * @return array
54
     */
55
    public function getNbPostDay(DateTime $date1, DateTime $date2): array
56
    {
57
        $query = $this->em->createQuery(
58
            "
59
            SELECT
60
                 t.id,
61
                 COUNT(pc.id) as nb
62
            FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc
63
            JOIN pc.player p
64
            JOIN p.team t
65
            WHERE pc.lastUpdate BETWEEN :date1 AND :date2
66
            GROUP BY t.id"
67
        );
68
69
        $query->setParameter('date1', $date1);
70
        $query->setParameter('date2', $date2);
71
        $result = $query->getResult();
72
73
        $data = array();
74
        foreach ($result as $row) {
75
            $data[$row['id']] = $row['nb'];
76
        }
77
        return $data;
78
    }
79
}
80