Completed
Push — master ( 68a26d...f82207 )
by Paul
03:20
created

absences_Csv::encodeFloats()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
/************************************************************************
3
 * OVIDENTIA http://www.ovidentia.org                                   *
4
 ************************************************************************
5
 * Copyright (c) 2003 by CANTICO ( http://www.cantico.fr )              *
6
 *                                                                      *
7
 * This file is part of Ovidentia.                                      *
8
 *                                                                      *
9
 * Ovidentia is free software; you can redistribute it and/or modify    *
10
 * it under the terms of the GNU General Public License as published by *
11
 * the Free Software Foundation; either version 2, or (at your option)  *
12
 * any later version.													*
13
 *																		*
14
 * This program is distributed in the hope that it will be useful, but  *
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of			*
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.					*
17
 * See the  GNU General Public License for more details.				*
18
 *																		*
19
 * You should have received a copy of the GNU General Public License	*
20
 * along with this program; if not, write to the Free Software			*
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,*
22
 * USA.																	*
23
************************************************************************/
24
25
26
class absences_Csv
27
{
28
    
29
30
31
    protected function csvEncode($str)
32
    {
33
        $str = str_replace("\n"," ",$str);
34
        return '"'.str_replace('"','""',$str).'"';
35
    }
36
    
37
    
38
    /**
39
     *
40
     * @return boolean
41
     */
42
    protected function isRowEmpty(Array $currentRow)
43
    {
44
        foreach($currentRow as &$val)
45
        {
46
            if (is_float($val))
47
            {
48
                if ($val > 0) {
49
                    return false;
50
                }
51
            }
52
        }
53
    
54
        return true;
55
    }
56
    
57
    
58
    protected function encodeFloats(Array $currentRow)
59
    {
60
        // encode float
61
        foreach($currentRow as &$val) {
62
            if (is_float($val)) {
63
                $val = $this->csvEncode(number_format($val, 1 , bab_pp('sepdec', ',') , '' ));
64
            }
65
        }
66
    
67
        return $currentRow;
68
    }
69
    
70
    
71
    /**
72
     * @return string
73
     */
74 View Code Duplication
    protected function getAgentDirValue(absences_Agent $agent, $fieldname)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $direntry = $agent->getDirEntry();
77
    
78
        if (isset($direntry[$fieldname]))
79
        {
80
            return $direntry[$fieldname]['value'];
81
        }
82
    
83
        return '';
84
    }
85
    
86
    
87
88
    /**
89
     *
90
     * @param string $quantity_unit
91
     * @return string
92
     */
93 View Code Duplication
    protected function getUnit($quantity_unit)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        switch($quantity_unit)
96
        {
97
            case 'D': return absences_translate('days');
98
            case 'H': return absences_translate('hours');
99
        }
100
         
101
        return '';
102
    }
103
    
104
    
105
    protected function setHeaders($filename)
106
    {
107
        header("Content-Disposition: attachment; filename=\"".$filename.".csv\""."\n");
108
        header("Content-Type: text/csv"."\n");
109
        header("Content-transfert-encoding: binary"."\n");
110
    }
111
    
112
    
113
    
114
    protected function date($strDate) {
115
        return bab_shortDate(bab_mktime($strDate), false);
116
    }
117
}