Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
LggrCsv
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 generiereDateiname
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 generiere
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
72
1<?php
2namespace Lggr;
3
4/**
5 * @brief Export as CSV class.
6 */
7class LggrCsv {
8
9    private $lggr = null;
10
11    const PROPERTIES = [
12        'id',
13        'date',
14        'facility',
15        'level',
16        'host',
17        'program',
18        'pid',
19        'message'
20    ];
21
22    function __construct(Lggr &$oLggr) {
23        $this->lggr = & $oLggr;
24    }
25
26    // constructor
27    private function generiereDateiname() {
28        return 'lggrarchive_' . date('Ymd') . '.csv';
29    }
30
31    function generiere() {
32        header('Content-Type: text/csv; charset=utf-8');
33        header(
34            'Content-Disposition: attachment; filename="' .
35                 $this->generiereDateiname() . '"');
36        
37        $iCnt = 0;
38        $aEntries = $this->lggr->getArchived(0, 9999);
39        
40        foreach ($aEntries as $entry) {
41            if (0 == $iCnt) {
42                // Spaltentitel
43                foreach (self::PROPERTIES as $sProp) {
44                    echo $sProp . ";";
45                } // foreach
46                echo "\n";
47            } // if 0
48              
49            // Wertespalten
50            foreach (self::PROPERTIES as $sProp) {
51                $sValue = $entry->$sProp;
52                
53                switch ($sProp) {
54                    case 'id':
55                        echo "$sValue;";
56                        break;
57                    
58                    case 'message':
59                        echo '"' . strtr(utf8_decode($sValue), '"', "'") . "\";";
60                        break;
61                    
62                    default:
63                        echo '"' . utf8_decode($sValue) . "\";";
64                        break;
65                } // switch
66            } // foreach
67            echo "\n";
68            
69            $iCnt ++;
70        } // foreach
71    } // function
72} // class