1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: wechsler |
5
|
|
|
* Date: 28/10/15 |
6
|
|
|
* Time: 08:11 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Phase\TakeATicket; |
10
|
|
|
|
11
|
|
|
use Doctrine\DBAL\Connection; |
12
|
|
|
use Phase\TakeATicket\DataSource\Factory; |
13
|
|
|
|
14
|
|
|
class PlaylistExporter |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var Connection |
18
|
|
|
*/ |
19
|
|
|
protected $dbConn; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* PlaylistExporter constructor. |
23
|
|
|
* |
24
|
|
|
* @param Connection $dbConn |
25
|
|
|
*/ |
26
|
|
|
public function __construct(Connection $dbConn) |
27
|
|
|
{ |
28
|
|
|
$this->dbConn = $dbConn; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function exportToFile($outFile) |
32
|
|
|
{ |
33
|
|
|
$dataSource = Factory::datasourceFromDbConnection($this->dbConn); |
34
|
|
|
|
35
|
|
|
$tickets = $dataSource->fetchPerformedTickets(); |
36
|
|
|
|
37
|
|
|
$handle = fopen($outFile, 'w'); |
38
|
|
|
|
39
|
|
|
if ($handle === false) { |
40
|
|
|
echo "Failed to open '$outFile'\n"; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$title = [ |
44
|
|
|
'Ticket Id', |
45
|
|
|
'Start Time', |
46
|
|
|
'Song Id', |
47
|
|
|
'Artist', |
48
|
|
|
'Title', |
49
|
|
|
'Duration (seconds)', |
50
|
|
|
'Band Name', |
51
|
|
|
'Vocals', |
52
|
|
|
'Guitar', |
53
|
|
|
'Bass', |
54
|
|
|
'Drums', |
55
|
|
|
'Keytar', |
56
|
|
|
'RB3', |
57
|
|
|
'RB4', |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
fputcsv($handle, $title); |
61
|
|
|
|
62
|
|
|
foreach ($tickets as $ticket) { |
63
|
|
|
$band = $ticket['band']; |
64
|
|
|
|
65
|
|
|
$line = [ |
66
|
|
|
$ticket['id'], |
67
|
|
|
date('H:i:s', $ticket['startTime']), |
68
|
|
|
$ticket['song']['id'], |
69
|
|
|
$ticket['song']['artist'], |
70
|
|
|
$ticket['song']['title'], |
71
|
|
|
$ticket['song']['duration'], |
72
|
|
|
$ticket['title'], |
73
|
|
|
$this->performersByInstrument($band, 'V'), |
74
|
|
|
$this->performersByInstrument($band, 'G'), |
75
|
|
|
$this->performersByInstrument($band, 'B'), |
76
|
|
|
$this->performersByInstrument($band, 'D'), |
77
|
|
|
$this->performersByInstrument($band, 'K'), |
78
|
|
|
$ticket['song']['inRb3'] ? 'x' : '', |
79
|
|
|
$ticket['song']['inRb4'] ? 'x' : '', |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
fputcsv($handle, $line); |
83
|
|
|
} |
84
|
|
|
fputcsv($handle, ['ENDS']); |
85
|
|
|
|
86
|
|
|
// echo "\n Wrote to '$outFile'\n"; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function performersByInstrument($band, $instrument) |
90
|
|
|
{ |
91
|
|
|
$performers = ''; |
92
|
|
|
|
93
|
|
|
if (is_array($band) && !empty($band[$instrument])) { |
94
|
|
|
$performers = array_map( |
95
|
|
|
function ($performer) { |
96
|
|
|
return $performer['performerName']; |
97
|
|
|
}, |
98
|
|
|
$band[$instrument] |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$performers = implode(', ', $performers); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $performers; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|