Completed
Push — master ( 017158...db914b )
by Daniel
04:20
created

establishLocalizationToDisplay()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
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
        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
58
            setlocale(LC_TIME, explode('_', $this->tCmnSession->get('lang'))[0]);
59
        } else {
60
            setlocale(LC_TIME, $this->tCmnSession->get('lang') . '.UTF8');
61
        }
62
    }
63
64
    private function setFormInputSelectPC()
65
    {
66
        $choices = [
67
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceNo'),
68
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceYes'),
69
        ];
70
        return $this->setArrayToSelect($choices, $this->tCmnSuperGlobals->get('pc'), 'pc', ['size' => 1]);
71
    }
72
73
    private function setFormInputSelectPI()
74
    {
75
        $temp2 = [];
76
        for ($counter = 0; $counter <= 4; $counter++) {
77
            $temp2[$counter] = $counter . ($counter == 4 ? '+' : '');
78
        }
79
        return $this->setArrayToSelect($temp2, $this->tCmnSuperGlobals->get('pi'), 'pi', ['size' => 1]);
80
    }
81
82
    private function setFormInputSelectYM($ymValues)
83
    {
84
        return $this->setArrayToSelect($ymValues, $this->tCmnSuperGlobals->get('ym'), 'ym', ['size' => 1]);
85
    }
86
87
    private function setFormatRow($text, $value)
88
    {
89
        $defaultCellStyle = [
90
            'class' => 'labelS',
91
            'style' => 'color:#000;',
92
        ];
93
        $fieldsStyled     = $this->buildArrayOfFieldsStyled();
94
        if (array_key_exists($text, $fieldsStyled)) {
95
            $defaultCellStyle['style'] = $this->buildStyleForCellFormat($fieldsStyled[$text]);
96
        }
97
        if ((is_numeric($value)) && ($value == 0)) {
98
            $defaultCellStyle['style'] = 'color:#666;';
99
        }
100
        return $defaultCellStyle;
101
    }
102
}
103