Commit | Line | Data |
---|---|---|
dc34d722 TO |
1 | <?php |
2 | namespace Civi\CiUtil; | |
3 | ||
7fe37828 EM |
4 | /** |
5 | * Class CsvPrinter | |
6 | * | |
7 | * @package Civi\CiUtil | |
8 | */ | |
dc34d722 | 9 | class CsvPrinter { |
34f3bbd9 SL |
10 | public $file; |
11 | public $headers; | |
12 | public $hasHeader = FALSE; | |
dc34d722 | 13 | |
7fe37828 EM |
14 | /** |
15 | * @param $file | |
16 | * @param $headers | |
17 | */ | |
00be9182 | 18 | public function __construct($file, $headers) { |
dc34d722 TO |
19 | $this->file = fopen($file, "w"); |
20 | $this->headers = $headers; | |
21 | } | |
22 | ||
00be9182 | 23 | public function printHeader() { |
dc34d722 TO |
24 | if ($this->hasHeader) { |
25 | return; | |
26 | } | |
27 | ||
28 | $headers = array_values($this->headers); | |
29 | array_unshift($headers, 'TEST NAME'); | |
30 | fputcsv($this->file, $headers); | |
31 | ||
32 | $this->hasHeader = TRUE; | |
33 | } | |
34 | ||
7fe37828 EM |
35 | /** |
36 | * @param $test | |
37 | * @param $values | |
38 | */ | |
00be9182 | 39 | public function printRow($test, $values) { |
dc34d722 TO |
40 | $this->printHeader(); |
41 | $row = $values; | |
42 | array_unshift($row, $test); | |
43 | fputcsv($this->file, $row); | |
44 | } | |
96025800 | 45 | |
ef10e0b5 | 46 | } |