Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
54.55% |
6 / 11 |
CRAP | |
29.73% |
22 / 74 |
| TEdit | |
0.00% |
0 / 1 |
|
54.55% |
6 / 11 |
684.58 | |
29.73% |
22 / 74 |
| __construct | |
0.00% |
0 / 1 |
25.52 | |
54.55% |
12 / 22 |
|||
| show | |
0.00% |
0 / 1 |
132 | |
0.00% |
0 / 22 |
|||
| setMaxLenght | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getMaxLenght | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| setRequired | |
100.00% |
1 / 1 |
2 | |
100.00% |
2 / 2 |
|||
| getRequired | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setSize | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getSize | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| validate | |
0.00% |
0 / 1 |
110 | |
0.00% |
0 / 16 |
|||
| setExampleText | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getExampleText | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| 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 base para criação de inputs |
| 44 | * Adiciona as propriedades: maxlenght, required e size do campo |
| 45 | * |
| 46 | */ |
| 47 | class TEdit extends TControl |
| 48 | { |
| 49 | private $exampleText; |
| 50 | |
| 51 | public function __construct($strName,$strValue=null,$intMaxLength=null,$boolRequired=null,$intSize=null) |
| 52 | { |
| 53 | parent::__construct('input',$strName,$strValue); |
| 54 | $this->setMaxLenght($intMaxLength); |
| 55 | $this->setSize($intSize); |
| 56 | $this->setRequired($boolRequired); |
| 57 | $this->setCss('border','1px solid #c0c0c0'); |
| 58 | //$this->setClass('fwFieldBoarder'); |
| 59 | $this->setCss('cursor','pointer'); |
| 60 | $this->setCss('font-family',"Arial"); |
| 61 | //$this->setCss('font-size',"13px"); |
| 62 | // carregar o valor do campo com o $_POST |
| 63 | if( isset($_POST[$strName]) && (string) $_POST[$strName] != "" ) |
| 64 | { |
| 65 | if( isset( $_POST[$strName] ) && is_string($_POST[$strName] ) ) |
| 66 | { |
| 67 | $this->setValue(str_replace(array('"'),array('“'),stripslashes($_POST[$strName]))); |
| 68 | } |
| 69 | } |
| 70 | else if( isset($_GET[$strName]) && (string) $_GET[$strName] != "" ) |
| 71 | { |
| 72 | if( isset( $_GET[$strName] ) && is_string($_GET[$strName] ) ) |
| 73 | { |
| 74 | $this->setValue(str_replace(array('"'),array('“'),stripslashes($_GET[$strName]))); |
| 75 | } |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | // tratamento quando o campo texto estiver no formato de array nome[1], nome[2]... |
| 80 | $name = preg_replace('/\[\]/','[1]',$this->getName()); // evitar erro dos campos array do TGrid |
| 81 | if( preg_match('/\[/',$name) > 0 ) |
| 82 | { |
| 83 | $arrTemp = explode('[',$name); |
| 84 | if( isset($_POST[$arrTemp[0] ] ) ) |
| 85 | { |
| 86 | $post = '$_POST[\''.str_replace('[',"'][",$name).';'; |
| 87 | @eval('$v=$_POST[\''.str_replace('[',"'][",$name).';'); |
| 88 | if( !is_null( $v ) ) |
| 89 | { |
| 90 | $this->setValue($v); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | //------------------------------------------------------------------------------------- |
| 97 | public function show($print=true) |
| 98 | { |
| 99 | if(!$this->getId()) |
| 100 | { |
| 101 | $this->setId( $this->removeIllegalChars($this->getName())); |
| 102 | } |
| 103 | if($this->getFieldType() !='hidden') |
| 104 | { |
| 105 | if( (int) $this->size==0 && (int)$this->maxlength > 0 ) |
| 106 | { |
| 107 | $this->size = $this->maxlength; |
| 108 | } |
| 109 | if( (int) $this->size==0 ) |
| 110 | { |
| 111 | $this->size = null; |
| 112 | } |
| 113 | if( (int) $this->maxlength==0 ) |
| 114 | { |
| 115 | $this->maxlength = null; |
| 116 | } |
| 117 | if( $this->getFieldType() != 'tag' && $this->getFieldType() != 'link') |
| 118 | { |
| 119 | $this->addEvent('onKeyUp','fwSetBordaCampo(this,false,event)'); |
| 120 | } |
| 121 | if($this->getRequired()==true) |
| 122 | { |
| 123 | // remover a borda de advertencia dos inputs |
| 124 | $this->addEvent('onBlur' ,'fwValidarObrigatorio(this)'); |
| 125 | } |
| 126 | if($this->getExampleText()) |
| 127 | { |
| 128 | $span = new TElement('span'); |
| 129 | $span->setId($this->getId().'_exempleText'); |
| 130 | $span->setClass('fwExampleText'); |
| 131 | $span->add($this->getExampleText()); |
| 132 | $this->add($span); |
| 133 | } |
| 134 | |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | $this->clearCss(); |
| 139 | $this->clearEvents(); |
| 140 | } |
| 141 | return parent::show($print); |
| 142 | } |
| 143 | //------------------------------------------------------------------------------------- |
| 144 | public function setMaxLenght($intLenght=null) |
| 145 | { |
| 146 | $this->maxlength = (int)$intLenght; |
| 147 | } |
| 148 | public function getMaxLenght() |
| 149 | { |
| 150 | return $this->getProperty('maxlength'); |
| 151 | } |
| 152 | public function setRequired($boolValue=null) |
| 153 | { |
| 154 | $this->setAttribute('needed',( (bool)$boolValue ? "true" : null) ); |
| 155 | } |
| 156 | public function getRequired() |
| 157 | { |
| 158 | return $this->getAttribute('needed')=="true"; |
| 159 | } |
| 160 | public function setSize($intSize=null) |
| 161 | { |
| 162 | $this->size=(int)$intSize; |
| 163 | } |
| 164 | public function getSize() |
| 165 | { |
| 166 | return $this->size; |
| 167 | } |
| 168 | /** |
| 169 | * Valida se o campo foi preenchido |
| 170 | * |
| 171 | */ |
| 172 | public function validate() |
| 173 | { |
| 174 | $this->setCss('border','1px solid #c0c0c0'); |
| 175 | //$this->setClass('fwFieldBoarder'); |
| 176 | //$this->setError(null); |
| 177 | if($this->getRequired() && (string)$this->getValue()=="") |
| 178 | { |
| 179 | $this->setCss('border','1px solid #ff0000'); //#176 relacionado com FormDin4.js |
| 180 | //$this->setClass('fwFieldRequiredBoarder'); |
| 181 | $this->setError('Campo obrigatório.'); |
| 182 | } |
| 183 | // validar o tamanho |
| 184 | if($this->getFieldType() != 'hidden' && $this->getFieldType() != 'file' && $this->getFieldType() != 'fileAsync') |
| 185 | { |
| 186 | if($this->getMaxLenght()) |
| 187 | { |
| 188 | $value = $this->getValue(); |
| 189 | if( $this->getFieldType() =='number') |
| 190 | { |
| 191 | $value = preg_replace('/[^0-9]/','',$value); |
| 192 | } |
| 193 | //Conta caracteres ao invés de bytes |
| 194 | $tamanho = 0; |
| 195 | if( !empty($value) ){ |
| 196 | $tamanho = mb_strlen(str_replace(PHP_EOL, '', $value)); |
| 197 | } |
| 198 | if( (int)$this->getMaxLenght() < $tamanho ){ |
| 199 | $this->setCss('border','1px solid #ff0000'); //#176 relacionado com FormDin4.js |
| 200 | //$this->setClass('fwFieldRequiredBoarder'); |
| 201 | $this->setError('máximo '.$this->getMaxLenght().' caracteres.'); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | return ( (string)$this->getError()==="" ); |
| 206 | } |
| 207 | /** |
| 208 | * Define um texto de exemplo de preenchimento do campo |
| 209 | * |
| 210 | * @param string $strNewValue |
| 211 | */ |
| 212 | public function setExampleText($strNewValue=null) |
| 213 | { |
| 214 | $this->exampleText=$strNewValue; |
| 215 | return $this; |
| 216 | } |
| 217 | /** |
| 218 | * Retorna o texto de exemplo de preenchimento do campo |
| 219 | * |
| 220 | */ |
| 221 | public function getExampleText() |
| 222 | { |
| 223 | if( is_null($this->exampleText)) |
| 224 | { |
| 225 | return null; |
| 226 | } |
| 227 | return trim($this->exampleText); |
| 228 | } |
| 229 | } |
| 230 | ?> |