Commit 075fe6ce2f4dcb3e03358d163396f5d73f401fc5
1 parent
8541bcd9
Exists in
master
Alterado tabela de arredondamento, para somente arrendondar notas caso tenha sid…
…o definido opções de arredondamento, do contrário a nota somente será limitado a 2 casas decimais sem qualquer arredondamento
Showing
1 changed file
with
23 additions
and
14 deletions
Show diff stats
ieducar/modules/TabelaArredondamento/Model/Tabela.php
... | ... | @@ -31,6 +31,7 @@ |
31 | 31 | |
32 | 32 | require_once 'CoreExt/Entity.php'; |
33 | 33 | require_once 'App/Model/IedFinder.php'; |
34 | +require_once 'lib/Portabilis/Utils/Float.php'; | |
34 | 35 | |
35 | 36 | /** |
36 | 37 | * TabelaArredondamento_Model_Tabela class. |
... | ... | @@ -117,24 +118,32 @@ class TabelaArredondamento_Model_Tabela extends CoreExt_Entity |
117 | 118 | . 'arredondamento deve estar entre 0 e 10.'); |
118 | 119 | } |
119 | 120 | |
120 | - if (0 == count($this->_tabelaValores)) { | |
121 | - $this->_tabelaValores = $this->getDataMapper()->findTabelaValor($this); | |
122 | - } | |
123 | - | |
124 | - // Multiplicador para transformar os números em uma escala inteira. | |
125 | - $scale = pow(10, $this->_precision); | |
121 | + /* Inicializa o retorno com o valor recebido (limitando a para uma casa decimal), | |
122 | + o qual será retornado caso não tenha sido definido opcoes na tabela de arredondamento, | |
123 | + do contrário será arredondado a nota conforme opções da tabela de arredondamento. */ | |
124 | + $return = Portabilis_Utils_Float::limitDecimal($value, array('limit' => 1)); | |
126 | 125 | |
127 | - // Escala o valor para se tornar comparável | |
128 | - $value = $this->getFloat($value) * $scale; | |
126 | + // carrega tabela de arredondamento, caso ainda não tenha sido carregada. | |
127 | + if (0 == count($this->_tabelaValores)) | |
128 | + $this->_tabelaValores = $this->getDataMapper()->findTabelaValor($this); | |
129 | 129 | |
130 | - $return = 0; | |
131 | - foreach ($this->_tabelaValores as $tabelaValor) { | |
132 | - if ($value >= ($tabelaValor->valorMinimo * $scale) && | |
133 | - $value <= ($tabelaValor->valorMaximo * $scale)) { | |
130 | + // somente será arredondado a nota, caso tenha sido definido opções de arredondamento, na respectiva tabela. | |
131 | + if (count($this->_tabelaValores) > 0) { | |
132 | + // Multiplicador para transformar os números em uma escala inteira. | |
133 | + $scale = pow(10, $this->_precision); | |
134 | + | |
135 | + // Escala o valor para se tornar comparável | |
136 | + $value = $this->getFloat($value) * $scale; | |
137 | + | |
138 | + $return = 0; | |
139 | + foreach ($this->_tabelaValores as $tabelaValor) { | |
140 | + if ($value >= ($tabelaValor->valorMinimo * $scale) && | |
141 | + $value <= ($tabelaValor->valorMaximo * $scale)) { | |
142 | + $return = $tabelaValor->nome; | |
143 | + break; | |
144 | + } | |
134 | 145 | $return = $tabelaValor->nome; |
135 | - break; | |
136 | 146 | } |
137 | - $return = $tabelaValor->nome; | |
138 | 147 | } |
139 | 148 | |
140 | 149 | return $return; | ... | ... |