FormattingSalariu   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 15
lcom 2
cbo 1
dl 0
loc 71
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A buildArrayOfFieldsStyled() 0 9 2
A buildStyleForCellFormat() 0 8 2
A establishLocalizationToDisplay() 0 7 2
A setFormInputSelectPC() 0 8 1
A setFormInputSelectPI() 0 8 3
A setFormInputSelectYM() 0 4 1
A setFormatRow() 0 15 4
1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2016 Daniel Popiniuc
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in all
17
 * copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
 * SOFTWARE.
26
 *
27
 */
28
29
namespace danielgp\salariu;
30
31
trait FormattingSalariu
32
{
33
34
    use \danielgp\salariu\BasicSalariu;
35
36
    private function buildArrayOfFieldsStyled()
37
    {
38
        $sReturn = [];
39
        foreach ($this->appFlags['TCAS'] as $key => $value) {
40
            $sReturn[$this->tApp->gettext($key)]       = $value;
41
            $sReturn[$this->tApp->gettext($key) . ':'] = $value;
42
        }
43
        return $sReturn;
44
    }
45
46
    private function buildStyleForCellFormat($styleId)
47
    {
48
        $sReturn = [];
49
        foreach ($this->appFlags['TCSD'][$styleId] as $key => $value) {
50
            $sReturn[] = $key . ':' . $value;
51
        }
52
        return implode(';', $sReturn) . ';';
53
    }
54
55
    private function establishLocalizationToDisplay()
56
    {
57
        setlocale(LC_TIME, $this->tCmnSession->get('lang') . '.UTF8');
58
        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
59
            setlocale(LC_TIME, explode('_', $this->tCmnSession->get('lang'))[0]);
60
        }
61
    }
62
63
    private function setFormInputSelectPC()
64
    {
65
        $choices = [
66
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceNo'),
67
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceYes'),
68
        ];
69
        return $this->setArrayToSelect($choices, $this->tCmnSuperGlobals->get('pc'), 'pc', ['size' => 1]);
70
    }
71
72
    private function setFormInputSelectPI()
73
    {
74
        $temp2 = [];
75
        for ($counter = 0; $counter <= 4; $counter++) {
76
            $temp2[$counter] = $counter . ($counter == 4 ? '+' : '');
77
        }
78
        return $this->setArrayToSelect($temp2, $this->tCmnSuperGlobals->get('pi'), 'pi', ['size' => 1]);
79
    }
80
81
    private function setFormInputSelectYM($ymValues)
82
    {
83
        return $this->setArrayToSelect($ymValues, $this->tCmnSuperGlobals->get('ym'), 'ym', ['size' => 1]);
84
    }
85
86
    private function setFormatRow($text, $value)
87
    {
88
        $defaultCellStyle = [
89
            'class' => 'labelS',
90
            'style' => 'color:#000;',
91
        ];
92
        $fieldsStyled     = $this->buildArrayOfFieldsStyled();
93
        if (array_key_exists($text, $fieldsStyled)) {
94
            $defaultCellStyle['style'] = $this->buildStyleForCellFormat($fieldsStyled[$text]);
95
        }
96
        if ((is_numeric($value)) && ($value == 0)) {
97
            $defaultCellStyle['style'] = 'color:#666;';
98
        }
99
        return $defaultCellStyle;
100
    }
101
}
102