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 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 49
TTime
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 11
992
0.00% covered (danger)
0.00%
0 / 49
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 6
 show
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 setMask
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 7
 getMaskType
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setButtonVisible
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getButtonVisible
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 validate
0.00% covered (danger)
0.00%
0 / 1
342
0.00% covered (danger)
0.00%
0 / 22
 setMaxValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getMaxValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setMinValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getMinValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
1
2<?php
3/*
4 * Formdin Framework
5 * Copyright (C) 2012 Ministério do Planejamento
6 * Criado por Luís Eugênio Barbosa
7 * Essa versão é um Fork https://github.com/bjverde/formDin
8 *
9 * ----------------------------------------------------------------------------
10 * This file is part of Formdin Framework.
11 *
12 * Formdin Framework is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License version 3
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License version 3
22 * along with this program; if not,  see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
24 * Fifth Floor, Boston, MA  02110-1301, USA.
25 * ----------------------------------------------------------------------------
26 * Este arquivo é parte do Framework Formdin.
27 *
28 * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou
29 * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
30 * do Software Livre (FSF).
31 *
32 * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
33 * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
34 * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
35 * para maiores detalhes.
36 *
37 * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
38 * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
39 * ou escreva para a Fundação do Software Livre (FSF) Inc.,
40 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
41 */
42
43  /**
44 * Campo para edição de horas.
45 * maskType como hms,hm
46 *
47 */
48class TTime extends TMask
49{
50    private $maskType;
51    private $minValue;
52    private $maxValue;
53    /**
54     * @param string $name
55     * @param string $value
56     * @param boolean $required
57     * @param string $minValue
58     * @param string $maxValue
59     * @param string $maskType
60     */
61    public function __construct($strName,$boolRequired=null,$strValue=null,$strMinValue=null,$strMaxValue=null,$strMaskType=null)
62    {
63        parent::__construct($strName,$strValue,null,$boolRequired);
64        $this->setFieldType('time');
65        $this->setMask($strMaskType);
66        $this->setMinValue($strMinValue);
67        $this->setMaxValue($strMaxValue);
68    }
69    //-------------------------------------------------------------------------------
70    public function show($print=true)
71    {
72        // não colocar a imagem no campo data se ele estiver desabilitado
73        if( $this->getEnabled())
74        {
75            $this->addEvent('onBlur' ,'fwValidarHora(this,this.value,"'.$this->getMaskType().'","'.$this->getMinValue().'","'.$this->getMaxValue().'","Hora inválida")');
76        }
77        return parent::show($print);
78    }
79    //--------------------------------------------------------------------------
80    public function setMask($strNewMaskType=null)
81    {
82        $strNewMaskType = StringHelper::strtolower($strNewMaskType);
83        $arrMasksTypes = array(
84         'hms'    => '99:99:99'
85        ,'hm'    => '99:99');
86        if (!array_key_exists($strNewMaskType,$arrMasksTypes) )
87        {
88            $strNewMaskType = 'hm';
89        }
90        $this->maskType = $strNewMaskType;
91        parent::setMask($arrMasksTypes[$strNewMaskType]);
92    }
93    //--------------------------------------------------------------------------
94    public function getMaskType()
95    {
96        return $this->maskType;
97    }
98    //--------------------------------------------------------------------------
99    public function setButtonVisible($boolValue=null)
100    {
101        $boolValue = $boolValue===null ? true : (bool)$boolValue;
102        $this->buttonVisible = $boolValue;
103    }
104    public function getButtonVisible()
105    {
106        return $this->buttonVisible;
107    }
108    /**
109    * validar campo dmy, dm, my
110    *
111    */
112    public function validate()
113    {
114        if( parent::validate() )
115        {
116            $hora= $this->getValue();
117            $tam = StringHelper::strlen($hora);
118            if( $tam == 0 )
119            {
120                return true; // campo está vazio
121            }
122            if ( $tam == 5 or $tam==8 )
123            {
124                $h = (integer) substr($hora,0,2);
125                $m = (integer) substr($hora,3,2);
126                $s = (integer) substr($hora,5,4)+0;
127                //print $h.','.$m.'.'.$s;
128                if ( ($h<0) || ($h>23)  || ($m<0) || ($m>59)|| ($s<0) || ($s>59) )
129                {
130
131                    $this->setError('Hora inválida');
132                }
133            }
134            else
135            {
136                $this->setError('Hora inválida');
137            }
138            if(!$this->getError())
139            {
140                // validar intervalo
141                if($this->getMinValue() && $this->getValue()<$this->getMinValue())
142                {
143                    if($this->getMaxValue())
144                    {
145                        $this->setError('Hora deve estar entre '.$this->getMinValue().' e '. $this->getMaxValue());
146                    }
147                    else
148                    {
149                        $this->setError('Hora deve estar MAIOR ou IGUAL a'.$this->getMinValue());
150                    }
151                }
152                if($this->getMaxValue() && $this->getValue()>$this->getMaxValue())
153                {
154                    if($this->getMinValue())
155                    {
156                        $this->setError('Hora deve estar entre '.$this->getMinValue().' e '. $this->getMaxValue());
157                    }
158                    else
159                    {
160                        $this->setError('Hora deve estar MENOR ou IGUAL a'.$this->getMaxValue());
161                    }
162                }
163            }
164        }
165        return ( (string)$this->getError()==="" );
166    }
167
168
169//---------------------------------------------------------------------------
170    public function setMaxValue($strNewValue=null)
171    {
172        $this->maxValue = $strNewValue;
173    }
174    //---------------------------------------------------------------------------
175    public function getMaxValue()
176    {
177        return $this->maxValue;
178    }
179    //---------------------------------------------------------------------------
180    public function setMinValue($strNewValue=null)
181    {
182        $this->minValue = $strNewValue;
183    }
184    //---------------------------------------------------------------------------
185    public function getMinValue()
186    {
187        return $this->minValue;
188    }
189}
190?>