|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NFLScores\Utilities; |
|
4
|
|
|
|
|
5
|
|
|
use LaravelZero\Framework\Commands\Command; |
|
6
|
|
|
use NFLScores\Models\Game; |
|
7
|
|
|
use PHPCollections\Collections\GenericList; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Utility class for printing |
|
11
|
|
|
* elements into the console. |
|
12
|
|
|
*/ |
|
13
|
|
|
class Printer |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The command which will be execute. |
|
17
|
|
|
* |
|
18
|
|
|
* @var \LaravelZero\Framework\Commands\Command |
|
19
|
|
|
*/ |
|
20
|
|
|
private $command; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Initialize values. |
|
24
|
|
|
* |
|
25
|
|
|
* @param \LaravelZero\Framework\Commands\Command |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(Command $command) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->command = $command; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Return an array with the name and |
|
34
|
|
|
* score of a specific team. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $abbr |
|
37
|
|
|
* @param array $score |
|
38
|
|
|
* |
|
39
|
|
|
* @return array |
|
40
|
|
|
*/ |
|
41
|
|
|
private function buildScoreBoardRow(string $abbr, array $score): array |
|
42
|
|
|
{ |
|
43
|
|
|
return [ |
|
44
|
|
|
$abbr, |
|
45
|
|
|
$score['pointQ1'], |
|
46
|
|
|
$score['pointQ2'], |
|
47
|
|
|
$score['pointQ3'], |
|
48
|
|
|
$score['pointQ4'], |
|
49
|
|
|
$score['pointOT'], |
|
50
|
|
|
$score['pointTotal'], |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Build and print a game' scoreboard |
|
56
|
|
|
* into the terminal. |
|
57
|
|
|
* |
|
58
|
|
|
* @param \NFLScores\Models\Game $game |
|
59
|
|
|
* |
|
60
|
|
|
* @return void |
|
61
|
|
|
*/ |
|
62
|
|
|
private function printScoreBoard(Game $game): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->printScoreBoardHeader($game); |
|
65
|
|
|
|
|
66
|
|
|
$this->command->table( |
|
67
|
|
|
['', '1', '2', '3', '4', 'OT', 'T'], |
|
68
|
|
|
[ |
|
69
|
|
|
$this->buildScoreBoardRow($game->gameSchedule['homeTeamAbbr'], $game->score['homeTeamScore']), |
|
|
|
|
|
|
70
|
|
|
$this->buildScoreBoardRow($game->gameSchedule['visitorTeamAbbr'], $game->score['visitorTeamScore']), |
|
71
|
|
|
] |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$this->command->line("\n"); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Build and print the scoreboard header. |
|
79
|
|
|
* |
|
80
|
|
|
* @param \NFLScores\Models\Game $game |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public function printScoreBoardHeader(Game $game) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->command->line( |
|
87
|
|
|
sprintf( |
|
88
|
|
|
'%s VS %s @ %s', |
|
89
|
|
|
$game->gameSchedule['homeTeamAbbr'], |
|
|
|
|
|
|
90
|
|
|
$game->gameSchedule['visitorTeamAbbr'], |
|
91
|
|
|
$game->gameSchedule['site']['siteFullname'] |
|
92
|
|
|
) |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
if (!$game->isFinished()) { |
|
96
|
|
|
$this->command->line(sprintf( |
|
97
|
|
|
'%s | %s | %s %s', |
|
98
|
|
|
$game->getCurrentQuarter(), |
|
99
|
|
|
$game->score['time'], |
|
|
|
|
|
|
100
|
|
|
$game->getPossesionTeam(), |
|
101
|
|
|
$game->getCurrentDown() |
|
102
|
|
|
)); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Print a table with a list of games. |
|
108
|
|
|
* |
|
109
|
|
|
* @param \PHPCollections\Collections\GenericList $gameCollection |
|
110
|
|
|
* |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
public function renderGamesList(?GenericList $gameCollection): void |
|
114
|
|
|
{ |
|
115
|
|
|
$data = []; |
|
116
|
|
|
|
|
117
|
|
|
$gameCollection->forEach(function ($game, $key) use (&$data) { |
|
|
|
|
|
|
118
|
|
|
array_push($data, [ |
|
119
|
|
|
$game->gameSchedule['homeTeamAbbr'], |
|
120
|
|
|
$game->gameSchedule['visitorTeamAbbr'], |
|
121
|
|
|
$game->gameSchedule['site']['siteFullname'], |
|
122
|
|
|
$game->gameSchedule['gameDate'], |
|
123
|
|
|
sprintf('%s ET', $game->gameSchedule['gameTimeEastern']), |
|
124
|
|
|
]); |
|
125
|
|
|
}); |
|
126
|
|
|
|
|
127
|
|
|
$this->command->table(['Home', 'Visitor', 'Stadium', 'Date', 'Hour'], $data); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Print a collection of game' |
|
132
|
|
|
* scoreboards into the terminal. |
|
133
|
|
|
* |
|
134
|
|
|
* @param PHPCollections\Collections\GenericList |
|
135
|
|
|
* |
|
136
|
|
|
* @return void |
|
137
|
|
|
*/ |
|
138
|
|
|
public function renderScoreBoard(?GenericList $games): void |
|
139
|
|
|
{ |
|
140
|
|
|
if (is_null($games)) { |
|
141
|
|
|
exit($this->command->line('Sorry, there is no games right now.')); |
|
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
$games->forEach(function ($game, $key) { |
|
|
|
|
|
|
145
|
|
|
$this->printScoreBoard($game); |
|
146
|
|
|
}); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|