Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
42.86% |
3 / 7 |
CRAP | |
34.15% |
14 / 41 |
| TSelect | |
0.00% |
0 / 1 |
|
42.86% |
3 / 7 |
134.24 | |
34.15% |
14 / 41 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
10 / 10 |
|||
| show | |
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 13 |
|||
| setFirstOptionText | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getFirstOptionText | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setFirstOptionValue | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getFirstOptionValue | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getText | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 12 |
|||
| 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 | class TSelect extends TOption |
| 43 | { |
| 44 | private $firstOptionText; |
| 45 | private $firstOptionValue; |
| 46 | |
| 47 | /** |
| 48 | * Adicionar campo tipo combobox ou menu select |
| 49 | * |
| 50 | * $mixOptions = array no formato "key=>value", nome do pacote oracle e da função a ser executada, comando sql ou tabela|condicao |
| 51 | * $strKeyColumn = nome da coluna que será utilizada para preencher os valores das opções |
| 52 | * $strDisplayColumn = nome da coluna que será utilizada para preencher as opções que serão exibidas para o usuário |
| 53 | * $strDataColumns = informações extras do banco de dados que deverão ser adicionadas na tag option do campo select |
| 54 | * |
| 55 | * <code> |
| 56 | * // exemplos |
| 57 | * $frm->addSelectField('tipo','Tipo:',false,'1=Tipo 1,2=Tipo 2'); |
| 58 | * $frm->addSelectField('tipo','Tipo:',false,'tipo'); |
| 59 | * $frm->addSelectField('tipo','Tipo:',false,'select * from tipo order by descricao'); |
| 60 | * $frm->addSelectField('tipo','Tipo:',false,'tipo|descricao like "F%"'); |
| 61 | * |
| 62 | * //Exemplo espcial - Campo obrigatorio e sem senhum elemento pre selecionado. |
| 63 | * $frm->addSelectField('tipo','Tipo',true,$tiposDocumentos,null,null,null,null,null,null,' ',''); |
| 64 | * </code> |
| 65 | * |
| 66 | * @param string $strName - 01: ID do campo |
| 67 | * @param mixed $mixOptions - 02: array dos valores. no formato "id=>value", nome do pacote oracle e da função a ser executada, comando sql ou tabela|condicao |
| 68 | * @param mixed $strValue - 03: Valor DEFAULT, informe o ID do array |
| 69 | * @param mixed $boolRequired - 04: Default FALSE = não obrigatori, TRUE = obrigatorio |
| 70 | * @param mixed $boolMultiSelect- 05: Default FALSE = SingleSelect, TRUE = MultiSelect |
| 71 | * @param mixed $intSize - 06: Default 1. Num itens que irão aparecer no MultiSelect |
| 72 | * @param mixed $intWidth - 07: Largura em Pixels |
| 73 | * @param mixed $strFirstOptionText - 08: First Key in Display. Informe um valor diferente de '' ou null para mostrar um Label. |
| 74 | * @param mixed $strFirstOptionValue- 09: Frist Valeu in Display, use value NULL for required. Para o valor DEFAULT informe o ID do $mixOptions e $strFirstOptionText = '' e não pode ser null |
| 75 | * @param mixed $strKeyColumn - 10: Nome da coluna que será utilizada para preencher os valores das opções |
| 76 | * @param mixed $strDisplayColumn - 11: Nome da coluna que será utilizada para preencher as opções que serão exibidas para o usuário |
| 77 | * @param mixed $strDataColumns - 12: Informações extras do banco de dados que deverão ser adicionadas na tag option do campo select |
| 78 | * @return TSelect |
| 79 | */ |
| 80 | public function __construct($strName |
| 81 | ,$mixOptions=null |
| 82 | ,$strValue=null |
| 83 | ,$boolRequired=null |
| 84 | ,$boolMultiSelect=null |
| 85 | ,$intSize=null |
| 86 | ,$intWidth=null |
| 87 | ,$strFirstOptionText=null |
| 88 | ,$strFirstOptionValue=null |
| 89 | ,$strKeyColumn=null |
| 90 | ,$strDisplayColumn=null |
| 91 | ,$strDataColumns=null) |
| 92 | { |
| 93 | parent::__construct($strName |
| 94 | ,$mixOptions // 2: array no formato "key=>value" ou nome do pacote oracle e da função a ser executada |
| 95 | ,$strValue // 3: array no formato "key=>key" para identificar a(s) opção(ões) selecionada(s) |
| 96 | ,$boolRequired // 4: Default FALSE = não obrigatori, TRUE = obrigatorio |
| 97 | ,null |
| 98 | ,$intWidth |
| 99 | ,null |
| 100 | ,null |
| 101 | ,$boolMultiSelect //09: Default FALSE = SingleSelect, TRUE = MultiSelect |
| 102 | ,TOption::SELECT //10: 10: define o tipo de input a ser gerado. Ex: select, radio ou check |
| 103 | ,$strKeyColumn //11: Nome da coluna que será utilizada para preencher os valores das opções |
| 104 | ,$strDisplayColumn//12: Nome da coluna que será utilizada para preencher as opções que serão exibidas para o usuário |
| 105 | ,null |
| 106 | ,$strDataColumns //14: informações extras do banco de dados que deverão ser adicionadas na tag option do campo select |
| 107 | ); |
| 108 | parent::setSelectSize($intSize); |
| 109 | $this->setFirstOptionText($strFirstOptionText); |
| 110 | $this->setFirstOptionValue($strFirstOptionValue); |
| 111 | } |
| 112 | public function show($print=true) |
| 113 | { |
| 114 | // adicionar o texto "-- selecione --" como primeira opção, se o campo não for obrigatório |
| 115 | if(!$this->getMultiSelect() ) |
| 116 | { |
| 117 | if( is_null($this->getFirstOptionText()) && !$this->getRequired() ) |
| 118 | { |
| 119 | $this->setFirstOptionText('-- selecione --'); |
| 120 | } |
| 121 | if( !$this->getFirstOptionValue() && !$this->getRequired() ) |
| 122 | { |
| 123 | $this->setFirstOptionValue(null); |
| 124 | } |
| 125 | $arrTemp=array(); |
| 126 | if($this->getFirstOptionText()) |
| 127 | { |
| 128 | $arrTemp = array($this->getFirstOptionValue()=>$this->getFirstOptionText()); |
| 129 | } |
| 130 | if(is_array($this->getOptions()) ) |
| 131 | { |
| 132 | forEach($this->getOptions() as $k=>$v) |
| 133 | { |
| 134 | $arrTemp[$k]=$v; |
| 135 | } |
| 136 | } |
| 137 | $this->setOptions($arrTemp); |
| 138 | } |
| 139 | return parent::show($print); |
| 140 | } |
| 141 | |
| 142 | //--------------------------------------------------------------------------------- |
| 143 | public function setFirstOptionText($strNewValue=null) |
| 144 | { |
| 145 | $this->firstOptionText = $strNewValue; |
| 146 | return $this; |
| 147 | } |
| 148 | //--------------------------------------------------------------------------------- |
| 149 | public function getFirstOptionText() |
| 150 | { |
| 151 | return $this->firstOptionText; |
| 152 | } |
| 153 | //--------------------------------------------------------------------------------- |
| 154 | public function setFirstOptionValue($strNewValue=null) |
| 155 | { |
| 156 | $this->firstOptionValue = $strNewValue; |
| 157 | return $this; |
| 158 | } |
| 159 | //--------------------------------------------------------------------------------- |
| 160 | public function getFirstOptionValue() |
| 161 | { |
| 162 | return $this->firstOptionValue; |
| 163 | } |
| 164 | // Retorna o texto da opção selecionada do combobox |
| 165 | public function getText($strKeyValue=null) |
| 166 | { |
| 167 | $strKeyValue = ( is_null( $strKeyValue ) ) ? $this->getValue() : $strKeyValue ; |
| 168 | if(!$this->getMultiSelect() ) |
| 169 | { |
| 170 | //if( !is_null($this->getValue() ) ) |
| 171 | if( !is_null($strKeyValue ) ) |
| 172 | { |
| 173 | $aTemp = $this->getOptions(); |
| 174 | return $aTemp[$strKeyValue]; |
| 175 | //return $aTemp[$this->getValue()]; |
| 176 | } |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | $result=null; |
| 181 | if( is_array($strKeyValue)) |
| 182 | { |
| 183 | $aTemp = $this->getOptions(); |
| 184 | forEach( $strKeyValue as $k ) |
| 185 | { |
| 186 | $result[] = $aTemp[$k]; |
| 187 | } |
| 188 | } |
| 189 | return $result; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | ?> |