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 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 12
TCheck
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 12
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 show
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 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 */
41class TCheck extends TOption
42{
43    /**
44    * Classe para criação de campos do tipo Checkbox, onde uma ou várias opções poderão ser selecinadas;
45    *
46    *<code>
47    * <?php
48    * $check = new TCheck('tip_bioma',array(1=>'Cerrado',2=>'Pantanal'),null,true,2);
49    * $check->show();
50    * ?>
51    *</code>
52    *
53    * @param string $strName
54    * @param array $arrOptions
55    * @param array $arrValues
56    * @param boolean $boolRequired
57    * @param integer $intQtdColumns
58    * @param integer $intWidth
59    * @param integer $intHeight
60    * @param integer $intPaddingItems
61    * @return TCheck
62    */
63    public function __construct($strName
64        , $arrOptions
65        , $arrValues=null
66        , $boolRequired=null
67        , $intQtdColumns=null
68        , $intWidth=null
69        , $intHeight=null
70        , $intPaddingItems=null)
71    {
72        // no nome do campo check não precisa passar []
73        $strName = $this->removeIllegalChars($strName);
74        parent::__construct($strName,$arrOptions,$arrValues,$boolRequired,$intQtdColumns,$intWidth,$intHeight,$intPaddingItems,true,'check');
75
76    }
77    /**
78     * Exibe html ou retorna o html se $print for false
79     * se $boolShowOnlyInput for true, será retornada somente a tag input do campo
80     *
81     * @param boolean $print
82     * @param boolean $boolShowOnlyInput
83     * @return string
84     */
85    public function show($print=true)
86    {
87        // se o campo check estiver sem nenhuma opção, inicializar com a opção S
88        if( !$this->getOptions())
89        {
90            $this->setOptions(array('S'=>''));
91            $this->setcss('border','none');
92        }
93        // se o controle etiver desativado, gerar um campo oculto com mesmo nome e id para não perder o post e
94        // renomear o input para "id"_disabled
95        if( ! $this->getEnabled() )
96        {
97            foreach ($this->getValue() as $k=>$v)
98            {
99                $h = new THidden($this->getId().'[]');
100                $h->setValue($v);
101                $this->add($h);
102            }
103        }
104        return parent::show($print);
105    }
106}
107/*
108$res['SEQ_PERFIL'][0] = 1;
109$res['DES_PERFIL'][0] = 'Administrador';
110$res['SEQ_PERFIL'][1] = 2;
111$res['DES_PERFIL'][1] = 'Desenvolvedor';
112$res['SEQ_PERFIL'][3] = 3;
113$res['DES_PERFIL'][3] = 'Analista';
114$res['SEQ_PERFIL'][4] = 4;
115$res['DES_PERFIL'][4] = 'Programador';
116*/
117/*
118$radio = new TCheck('sit_publico',$res,null,null,2);
119$radio->show();
120RETURN;
121*/
122
123/*
124$frm = new TForm('Campo Check');
125$frm->addCheckField('seq_perfil','Perfil:',false,$res,true,false,null,2);
126$frm->show();
127*/
128/*
129//$_POST['tip_bioma'][]=2;
130for($i=0;$i<10;$i++)
131{
132    $arr[$i]= 'Opcao '.$i;
133}
134$radio = new TCheck('tip_bioma',$arr,null,true,2);
135print '<form name="formdin" action="" method="POST">';
136//$radio->setEnabled(false);
137$radio->show();
138print '<hr>';
139print '<input type="submit" value="Gravar">';
140print '</form>';
141print_r($_POST);
142*/
143
144/*
145print '<form name="formdin" action="" method="POST">';
146$radio = new TCheck('tip_bioma',array(1=>'Cerrado',2=>'Pantanal'),null,true,2);
147$radio->show();
148print '<hr>';
149print '<input type="submit" value="Gravar">';
150print '</form>';
151print_r($_POST);
152 */
153?>