|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\DwhBundle\Creator; |
|
4
|
|
|
|
|
5
|
|
|
use Datetime; |
|
6
|
|
|
use DateInterval; |
|
7
|
|
|
use Exception; |
|
8
|
|
|
use VideoGamesRecords\DwhBundle\Contracts\DwhInterface; |
|
9
|
|
|
use VideoGamesRecords\DwhBundle\DataProvider\TopProvider; |
|
10
|
|
|
use VideoGamesRecords\DwhBundle\Traits\Top\GetHtmlTopTrait; |
|
11
|
|
|
|
|
12
|
|
|
class TopCreator implements DwhInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use GetHtmlTopTrait; |
|
15
|
|
|
|
|
16
|
|
|
protected TopProvider $topProvider; |
|
17
|
|
|
protected string $interval; |
|
18
|
|
|
protected int $nbElement; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct( |
|
21
|
|
|
TopProvider $topProvider, |
|
22
|
|
|
string $interval, |
|
23
|
|
|
int $nbElement |
|
24
|
|
|
) { |
|
25
|
|
|
$this->topProvider = $topProvider; |
|
26
|
|
|
$this->interval = $interval; |
|
27
|
|
|
$this->nbElement = $nbElement; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param $day |
|
32
|
|
|
* @return string[] |
|
33
|
|
|
* @throws Exception |
|
34
|
|
|
*/ |
|
35
|
|
|
public function handle($day): array |
|
36
|
|
|
{ |
|
37
|
|
|
$date1Begin = new DateTime($day); |
|
38
|
|
|
$date1End = new DateTime($day); |
|
39
|
|
|
|
|
40
|
|
|
$date1End->sub(new DateInterval('P1D')); |
|
41
|
|
|
$date1Begin->sub(new DateInterval($this->interval)); |
|
42
|
|
|
|
|
43
|
|
|
$date2Begin = clone($date1Begin); |
|
44
|
|
|
$date2End = clone($date1End); |
|
45
|
|
|
|
|
46
|
|
|
$date2Begin->sub(new DateInterval($this->interval)); |
|
47
|
|
|
$date2End->sub(new DateInterval($this->interval)); |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$gamesData = $this->topProvider->getStrategy(self::TYPE_GAME) |
|
51
|
|
|
->getTop($date1Begin, $date1End, $date2Begin, $date2End, $this->nbElement); |
|
52
|
|
|
$gamesHtmlEn = $this->getHtmlTopGame($gamesData); |
|
53
|
|
|
$gamesHtmlFr = $this->getHtmlTopGame($gamesData, 'fr'); |
|
54
|
|
|
|
|
55
|
|
|
$playersData = $this->topProvider->getStrategy(self::TYPE_PLAYER) |
|
56
|
|
|
->getTop($date1Begin, $date1End, $date2Begin, $date2End, $this->nbElement); |
|
57
|
|
|
$playersHtmlEn = $this->getHtmlTopPlayer($playersData); |
|
58
|
|
|
$playersHtmlFr = $this->getHtmlTopPlayer($playersData, 'fr'); |
|
59
|
|
|
|
|
60
|
|
|
$textEn = $gamesHtmlEn . '<br /><br />' . $playersHtmlEn; |
|
61
|
|
|
$textFr = $gamesHtmlFr . '<br /><br />' . $playersHtmlFr; |
|
62
|
|
|
|
|
63
|
|
|
return [ |
|
64
|
|
|
'fr' => $textFr, |
|
65
|
|
|
'en' => $textEn |
|
66
|
|
|
]; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|