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 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 58
TGridCheckColumn
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 9
552
0.00% covered (danger)
0.00%
0 / 58
 __construct
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 10
 getEdit
0.00% covered (danger)
0.00%
0 / 1
110
0.00% covered (danger)
0.00%
0 / 38
 setDescField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getDescField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setDescValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getDescValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setValues
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getValues
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getAllowCheckAll
0.00% covered (danger)
0.00%
0 / 1
6
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
42class TGridCheckColumn extends TGridEditColumn
43{
44    private $descField;
45    private $descValue;
46    private $values;
47    private $allowCheckAll;
48    public function __construct(string $strEditName
49                               ,string $strTitle=null
50                               ,string $strKeyField,$strDescField=null,$boolReadOnly=null,$boolAllowCheckAll=null)
51    {
52        parent::__construct($strEditName,$strTitle,$strKeyField,'checkbox',null,null,null,null,$boolReadOnly);
53        $boolAllowCheckAll = is_null($boolAllowCheckAll) ? true : $boolAllowCheckAll;
54        $this->allowCheckAll = $boolAllowCheckAll;
55        $this->setSortable(true);
56        if( is_null( $strDescField ) )
57        {
58            $this->setCss('text-align','center');
59        }
60        $this->setDescField($strDescField);
61        if( $_POST && isset($_POST[$strEditName]))
62        {
63            $this->setvalues($_POST[$strEditName]);
64        }
65    }
66    //---------------------------------------------------------------------------------------------------
67    public function getEdit()
68    {
69        if(!$this->getTitle())
70        {
71            $this->setTitle('[X]');
72        }
73        $check = new TElement('input');
74        $check->setProperty('type','checkbox');
75        $check->setClass('fwCheckbox');
76        //$check->setCss('vertical-align','middle');
77        //$check->setCss('cursor','pointer');
78        $check->setId($this->getEditName().'_'.$this->getRowNum());
79        //$check->setName($this->getEditName().'['.$this->getRowNum().']');
80        $check->setName($this->getEditName().'[]');
81        $check->setValue($this->getValue());
82        $check->addEvent('onclick',"fwFieldCheckBoxClick(this,'".$this->getEditName().'_desc_'.$this->getRowNum()."')");
83        if( $this->getEvents() )
84        {
85            foreach($this->getEvents() as $name=>$event)
86            {
87                $check->addEvent($name,$event);
88            }
89        }
90        if($this->getReadOnly())
91        {
92            $check->setProperty('disabled','true');
93        }
94        $hidden=null;
95        if( is_array($this->getValues()))
96        {
97            //print $this->getValue().':';
98             if( array_search($this->getValue(),$this->getValues()) !== false)
99            {
100                $check->setProperty('checked','true');
101                $check->setCss('color','#0000ff');
102                if($check->getProperty('disabled'))
103                {
104                    $hidden = new THidden($check->getName(),$this->getValue());
105                    $hidden->setName($check->getName());
106                    $hidden->setId($check->getId());
107                    $check->setId($check->getId().'_disabled');
108                    $check->setName($check->getName().'_disabled');
109                    $check->add($hidden);
110                }
111            }
112        }
113        if($this->getDescField())
114        {
115            $span = new TElement('span');
116            $span->setId($this->getEditName().'_desc_'.$this->getRowNum());
117            $span->setCss('cursor','pointer');
118            $span->setCss('margin-right','2px');
119            $span->add($this->getDescValue());
120            $span->setEvent('onclick',"fwGetObj('".$this->getEditName()."_".$this->getRowNum()."').click();");
121            if($check->getProperty('checked'))
122            {
123                $span->setCss('color','#0000ff');
124             }
125            $check->add($span);
126        }
127
128        // adicionar o nome do campo como attibuto do input
129        $check->setAttribute('fieldname',$this->getFieldName() );
130
131        /*
132        assim náo funciona - exceção do camp check
133         $edit = new TCheck($this->getEditName(),array($this->getvalue()=>''),null,false,null);
134         $edit->setShowMinimal(true);
135         $edit->setId('seq_bioma');
136        $edit->setEvents($this->getEvents());
137        */
138        return $check;
139    }
140    public function setDescField($strNewValue=null)
141    {
142        $this->descField = $strNewValue;
143    }
144    public function getDescField()
145    {
146        return $this->descField;
147    }
148    public function setDescValue($strNewValue=null)
149    {
150        $this->descValue = $strNewValue;
151    }
152    public function getDescValue()
153    {
154        return $this->descValue;
155    }
156    public function setValues($arrValues=null)
157    {
158        $this->values = $arrValues;
159    }
160    public function getValues($arrValues=null)
161    {
162        return $this->values;
163    }
164    public function getAllowCheckAll()
165    {
166        return is_null($this->allowCheckAll) ? true : (bool)$this->allowCheckAll;
167    }
168}
169?>