Passed
Push — master ( eab5c4...c49531 )
by Andrea
09:04 queued 11s
created

TabellaDecoderTrait::getFieldValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Cdf\BiCoreBundle\Utils\Tabella;
4
5
use Datetime;
6
use Doctrine\Common\Collections\Expr\Comparison;
7
use Exception;
8
9
trait TabellaDecoderTrait
10
{
11
    private $aliasGenerati;
12
    private $decodificaAlias;
13
14 2
    protected function getDescrizioneFiltro(&$descrizionefiltri, $filtrocorrente, $criteria)
15
    {
16 2
        if (false === $filtrocorrente['prefiltro']) {
17 1
            $descrizionefiltri = $descrizionefiltri.', '.$criteria->getDescrizioneFiltro();
18
        }
19 2
    }
20
21 3
    protected function getFieldValue($fieldvalue)
22
    {
23 3
        if (isset($fieldvalue['date'])) {
24
            return new Datetime($fieldvalue['date']);
25
        } else {
26 3
            return $fieldvalue;
27
        }
28
    }
29
30 3
    protected function getOperator($operator)
31
    {
32 3
        switch (strtoupper($operator)) {
33 3
            case 'LIKE':
34 1
                $operator = Comparison::CONTAINS;
35 1
                break;
36 3
            case 'IN':
37 1
                $operator = Comparison::IN;
38 1
                break;
39 3
            case 'NOT IN':
40 1
                $operator = Comparison::NIN;
41 1
                break;
42
            default:
43 3
                break;
44
        }
45
46 3
        return $operator;
47
    }
48
49 12
    protected function generaAlias($nometabella, $nomepadre = false, $ancestors = array())
50
    {
51 12
        $nometabellapulito = preg_replace('/[^a-z0-9\.]/i', '', $nometabella);
52 12
        $primalettera = strtolower(substr($nometabellapulito, 0, 1));
53 12
        if ($nomepadre && !in_array($nomepadre, $ancestors)) {
54
            $ancestors[] = $nomepadre;
55
        }
56 12
        if (!in_array($nometabella, $ancestors)) {
57 12
            $ancestors[] = $nometabella;
58
        }
59
60 12
        if (isset($this->aliasGenerati[$primalettera])) {
61 3
            $risposta = $primalettera.$this->aliasGenerati[$primalettera];
62 3
            $this->aliasGenerati[$primalettera] = $this->aliasGenerati[$primalettera] + 1;
63
        } else {
64 12
            $risposta = $primalettera;
65 12
            $this->aliasGenerati[$primalettera] = 1;
66
        }
67
68 12
        $this->decodificaAlias[ucfirst(implode('.', $ancestors))] = array('alias' => $risposta);
69
70 12
        return $risposta;
71
    }
72
73 3
    protected function findAliasByTablename($tablename)
74
    {
75 3
        if (!array_key_exists($tablename, $this->decodificaAlias)) {
76 1
            $ex = 'BiCore: table or association '.$tablename." not found, did you mean one of these:\n".
77 1
                    implode("\n", array_keys($this->decodificaAlias)).
78 1
                    ' ?';
79 1
            throw new Exception($ex);
80
        }
81
82 3
        return $this->getAliasGenerato($tablename);
83
    }
84
85 3
    protected function findFieldnameByAlias($nomecampo)
86
    {
87 3
        if (!array_key_exists($nomecampo, $this->configurazionecolonnetabella)) {
88 1
            $ex = 'BiCore: field or association '.$nomecampo." not found, did you mean one of these:\n".
89 1
                    implode("\n", array_keys($this->configurazionecolonnetabella)).
90 1
                    ' ?';
91 1
            throw new Exception($ex);
92
        }
93
94 2
        return $this->configurazionecolonnetabella[$nomecampo];
95
    }
96
97 10
    public function getAliasGenerato($tablename)
98
    {
99 10
        return $this->decodificaAlias[$tablename]['alias'];
100
    }
101
}
102