Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 27
TCnpj
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 10
156
0.00% covered (danger)
0.00%
0 / 27
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 9
 show
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 getFormated
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 4
 getValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setInvalidMessage
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getInvalidMessage
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setAlwaysValidate
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getAlwaysValidate
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 setCallback
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getCallback
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
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* Classe para entrada de dados tipo CNPJ
43*/
44class TCnpj extends TMask
45{
46    private $invalidMessage;
47    private $alwaysValidate;
48    private $callback;
49
50    /**
51    * Metódo construtor
52    *
53    * @param string $strName
54    * @param string $strValue
55    * @param boolean $boolRequired
56    * @return TCnpj
57    */
58    public function __construct($strName,$strValue=null,$boolRequired=null,$strInvalidMessage=null, $boolAwaysValidate = null,$strJsCallback=null)
59    {
60        parent::__construct($strName,$strValue=null,'',$boolRequired);
61        $this->setFieldType('cnpj');
62        $this->setEvent('onblur','fwValidarCnpj(this,event)');
63        $this->setEvent('onkeyup','fwFormatarCnpj(this,event)');
64        $this->setSize(19);
65        $this->setInvalidMessage($strInvalidMessage);
66        $this->setAlwaysValidate($boolAwaysValidate);
67        $this->setCallback($strJsCallback);
68    }
69
70    public function show($print=true)
71    {
72        $this->setAttribute('meta-invalid-message',$this->getInvalidMessage());
73        $this->setAttribute('meta-always-validate',$this->getAlwaysValidate());
74        $this->setAttribute('meta-callback',$this->getCallback());
75        return parent::show($print);
76    }
77
78    /**
79    * Retorna o CNPJ formatado
80    *
81    */
82    public function getFormated()
83    {
84        if ( $this->getValue() )
85        {
86            $cnpj = @preg_replace("/[^0-9]/","",$this->getValue());
87            return substr($cnpj,0,2).".".substr($cnpj,2,3).".".substr($cnpj,5,3)."/".substr($cnpj,8,4)."-".substr($cnpj,12,2);
88        }
89        return $this->getValue();
90    }
91
92    /**
93    * Retorna o CNPJ sem formatação
94    *
95    */
96    public function getValue()
97    {
98        return @preg_replace("/[^0-9]/","",$this->value);
99    }
100    public function setInvalidMessage($strNewValue=null)
101    {
102        $this->invalidMessage = $strNewValue;
103    }
104
105    public function getInvalidMessage()
106    {
107        return $this->invalidMessage;
108    }
109
110    public function setAlwaysValidate($boolNewValue=null)
111    {
112        $this->alwaysValidate = $boolNewValue;
113    }
114
115    public function getAlwaysValidate()
116    {
117        return ($this->alwaysValidate===true) ? 'true' :'false' ;
118    }
119
120    public function setCallback($strJsFunction=null)
121    {
122        $this->callback = $strJsFunction;
123    }
124
125    public function getCallback()
126    {
127        return $this->callback;
128    }
129
130
131
132}
133?>