Commit | Line | Data |
---|---|---|
dc34d722 TO |
1 | <?php |
2 | namespace Civi\CiUtil; | |
3 | ||
4 | class CsvPrinter { | |
5 | var $file; | |
6 | var $headers; | |
7 | var $hasHeader = FALSE; | |
8 | ||
00be9182 | 9 | public function __construct($file, $headers) { |
dc34d722 TO |
10 | $this->file = fopen($file, "w"); |
11 | $this->headers = $headers; | |
12 | } | |
13 | ||
00be9182 | 14 | public function printHeader() { |
dc34d722 TO |
15 | if ($this->hasHeader) { |
16 | return; | |
17 | } | |
18 | ||
19 | $headers = array_values($this->headers); | |
20 | array_unshift($headers, 'TEST NAME'); | |
21 | fputcsv($this->file, $headers); | |
22 | ||
23 | $this->hasHeader = TRUE; | |
24 | } | |
25 | ||
00be9182 | 26 | public function printRow($test, $values) { |
dc34d722 TO |
27 | $this->printHeader(); |
28 | $row = $values; | |
29 | array_unshift($row, $test); | |
30 | fputcsv($this->file, $row); | |
31 | } | |
96025800 | 32 | |
ef10e0b5 | 33 | } |