Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
CRAP | |
95.83% |
23 / 24 |
| TNumeroTJDFT | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
7 | |
95.83% |
23 / 24 |
| __construct | |
100.00% |
1 / 1 |
3 | |
100.00% |
15 / 15 |
|||
| getFormated | |
0.00% |
0 / 1 |
4.02 | |
88.89% |
8 / 9 |
|||
| 1 | <?php |
| 2 | /* |
| 3 | * Formdin Framework |
| 4 | * Copyright (C) 2012 Ministério do Planejamento |
| 5 | * Criado por Luís Eugênio Barbosa |
| 6 | * Essa versão é um Fork https://github.com/bjverde/formDin |
| 7 | * |
| 8 | * ---------------------------------------------------------------------------- |
| 9 | * This file is part of Formdin Framework. |
| 10 | * |
| 11 | * Formdin Framework is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Lesser General Public License version 3 |
| 13 | * as published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public License version 3 |
| 21 | * along with this program; if not, see <http://www.gnu.org/licenses/> |
| 22 | * or write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 23 | * Fifth Floor, Boston, MA 02110-1301, USA. |
| 24 | * ---------------------------------------------------------------------------- |
| 25 | * Este arquivo é parte do Framework Formdin. |
| 26 | * |
| 27 | * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou |
| 28 | * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação |
| 29 | * do Software Livre (FSF). |
| 30 | * |
| 31 | * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA |
| 32 | * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou |
| 33 | * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português |
| 34 | * para maiores detalhes. |
| 35 | * |
| 36 | * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título |
| 37 | * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> |
| 38 | * ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 39 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 40 | */ |
| 41 | |
| 42 | /* |
| 43 | Classe para entrada de número de processo |
| 44 | */ |
| 45 | class TNumeroTJDFT extends TEdit |
| 46 | { |
| 47 | /** |
| 48 | * Classe para entrada de número de processo |
| 49 | * |
| 50 | * @param string $strName - 1: ID do campo |
| 51 | * @param string $strValue - 2: Valor inicial do campo |
| 52 | * @param boolean $boolRequired - 3: Campo Obrigatório, DEFALUT is FALSE não Obrigatório. |
| 53 | * @param boolean $boolAcceptNumeroDistribuicao |
| 54 | * @param boolean $boolAcceptNumeroUnico |
| 55 | */ |
| 56 | public function __construct($strName,$strValue=null,$boolRequired=null, $boolAcceptNumeroDistribuicao=true, $boolAcceptNumeroUnico = true) |
| 57 | { |
| 58 | |
| 59 | $numeroDistribuicao = 'false'; |
| 60 | $numeroUnico = 'false'; |
| 61 | |
| 62 | if ($boolAcceptNumeroDistribuicao == true){ |
| 63 | $intMaxLength = 20; |
| 64 | $intSize = 14; |
| 65 | $numeroDistribuicao = 'true'; |
| 66 | } |
| 67 | |
| 68 | if ($boolAcceptNumeroUnico == true){ |
| 69 | $intMaxLength = 26; |
| 70 | $intSize = 20; |
| 71 | $numeroUnico = 'true'; |
| 72 | } |
| 73 | |
| 74 | parent::__construct($strName,$strValue,$intMaxLength,$boolRequired,$intSize); |
| 75 | $this->setFieldType('numeroTJDFT'); |
| 76 | $this->addEvent('onkeyup',"fwFormatarNumeroTJDFT(this,'".$numeroDistribuicao."','".$numeroUnico."')"); |
| 77 | $this->addEvent('onblur','fwValidarNumeroTJDFT(this)'); |
| 78 | } |
| 79 | |
| 80 | public function getFormated() |
| 81 | { |
| 82 | if( $this->getValue() ){ |
| 83 | $value = preg_replace("/\D/", '', $this->getValue()); |
| 84 | if( strlen($value) == 20 ){ |
| 85 | //#######-##.####.#.##.#### - 20 dígitos |
| 86 | //0123456-78.9012.3.45.6789 |
| 87 | //7-2.4.1.2.4 |
| 88 | $value = substr($value,0,7).'-'.substr($value,7,2).'.'.substr($value,9,4).'.'.substr($value,13,1).'.'.substr($value,14,2).'.'.substr($value,16,4); |
| 89 | } else if( strlen($value) == 14 ) { |
| 90 | //formatação para o número de 14 digitos |
| 91 | //1999.01.1.001573-8 |
| 92 | //4.2.1.6-1 |
| 93 | $value = substr($value,0,4).'.'.substr($value,4,2).'.'.substr($value,6,1).'.'.substr($value,7,6).'-'.substr($value,13,1); |
| 94 | } else { |
| 95 | $value = null; |
| 96 | } |
| 97 | return $value; |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | ?> |