Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 52 |
CRAP | |
0.00% |
0 / 277 |
| TCoordGMS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 52 |
16770 | |
0.00% |
0 / 277 |
| __construct | |
0.00% |
0 / 1 |
240 | |
0.00% |
0 / 58 |
|||
| show | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 18 |
|||
| getValue | |
0.00% |
0 / 1 |
156 | |
0.00% |
0 / 23 |
|||
| gd2gms | |
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 17 |
|||
| trunc | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 5 |
|||
| roundUp | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| setLat | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 14 |
|||
| setLon | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 13 |
|||
| setFieldNameLat | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setFieldNameLon | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getFieldNameLat | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| getFieldNameLon | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| setValue | |
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 11 |
|||
| validate | |
0.00% |
0 / 1 |
506 | |
0.00% |
0 / 38 |
|||
| clear | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 7 |
|||
| setSymbols | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getSymbols | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setLabels | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getLabels | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setLatGrau | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setLatMin | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setLatSeg | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setLatHem | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setLonGrau | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setLonMin | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setLonSeg | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setLonHem | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getLatGrau | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getLatMin | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getLatSeg | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getLatHem | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getLonGrau | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getLonMin | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getLonSeg | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getLonHem | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setMapWidth | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMapWidth | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setMapHeight | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMapHeight | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getButtonGMap | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setMapHeaderText | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMapHeaderText | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setMapHeaderFontSize | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMapHeaderFontSize | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setMapHeaderFontColor | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMapHeaderFontColor | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setMapCallback | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMapCallback | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
|||
| setMapZoom | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMapZoom | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 2 |
|||
| setMapType | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMapType | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| 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 TCoordGMS extends TGroup |
| 43 | { |
| 44 | |
| 45 | private $latGrau; |
| 46 | private $latMin; |
| 47 | private $latSeg; |
| 48 | private $latHem; |
| 49 | private $lonGrau; |
| 50 | private $lonMin; |
| 51 | private $lonSeg; |
| 52 | private $lonHem; |
| 53 | private $fieldNameLat; |
| 54 | private $fieldNameLon; |
| 55 | private $fieldZoom; |
| 56 | private $symbols; |
| 57 | private $labels; |
| 58 | private $mapWidth; |
| 59 | private $mapHeight; |
| 60 | private $buttonGMap; |
| 61 | private $mapHeaderText; |
| 62 | private $mapHeaderFontSize; |
| 63 | private $mapHeaderFontColor; |
| 64 | private $mapCallback; |
| 65 | private $mapZoom; |
| 66 | private $mapType; |
| 67 | |
| 68 | /** |
| 69 | * campo para inclusão de coordenadas geográficas no formato Grau, Minuto e Segundos |
| 70 | * |
| 71 | * @param string $strName |
| 72 | * @param boolean $boolRequired |
| 73 | * @param float $floatLatY |
| 74 | * @param float $floatLonX |
| 75 | * @param string $strFieldNameLat |
| 76 | * @param string $strFieldNameLon |
| 77 | * @param string $strSymbols |
| 78 | * @param int $intSymbolsFontSize |
| 79 | * @param int $intMapHeight |
| 80 | * @param int $intMapWidth |
| 81 | * @param string $mapHeaderText |
| 82 | * @param string $mapHeaderFontColor |
| 83 | * @param string $mapHeaderFontSize |
| 84 | * @return TCoordGMS |
| 85 | */ |
| 86 | public function __construct($strName, $boolRequired=null, $floatLatY=null, $floatLonX=null, $strFieldNameLat=null, $strFieldNameLon=null, $strLabels=null, $strSymbols=null, $intSymbolsFontSize=null, $intMapHeight=null, $intMapWidth=null, $strMapHeaderText=null, $strMapHeaderFontColor=null, $strMapHeaderFontSize=null,$strJsMapCallback=null,$intMapZoom=null,$strMapType=null) |
| 87 | { |
| 88 | parent::__construct($strName, 'Coordenadas Geográficas', 55, 425); |
| 89 | $this->setFieldType('coordgms'); |
| 90 | $this->setRequired($boolRequired); |
| 91 | $this->setFieldNameLat($strFieldNameLat); |
| 92 | $this->setFieldNameLon($strFieldNameLon); |
| 93 | $this->setMapHeight($intMapHeight); |
| 94 | $this->setMapWidth($intMapWidth); |
| 95 | $this->setMapHeaderText(is_null($strMapHeaderText) ? 'Clique com o botão direito do mouse sobre o mapa para selecionar o ponto.' : $strMapHeaderText ); |
| 96 | $this->setMapHeaderFontSize(is_null($strMapHeaderFontSize) ? '12px' : $strMapHeaderFontSize ); |
| 97 | $this->setMapHeaderFontColor(is_null($strMapHeaderFontColor) ? 'black' : $strMapHeaderFontColor ); |
| 98 | $this->setMapCallback($strJsMapCallback); |
| 99 | $this->setMapZoom( $intMapZoom ); |
| 100 | $this->setMapType($strMapType); |
| 101 | $strSymbols = is_null($strSymbols) ? "°,',\"" : $strSymbols; |
| 102 | $strLabels = is_null($strSymbols) ? ",," : $strLabels; |
| 103 | $intSymbolsFontSize = is_null($intSymbolsFontSize) ? "18" : $intSymbolsFontSize; |
| 104 | $labels = explode(',', $strLabels); |
| 105 | $labels[0] = isset($labels[0]) ? $labels[0] : ''; |
| 106 | $labels[1] = isset($labels[1]) ? $labels[1] : ''; |
| 107 | $labels[2] = isset($labels[2]) ? $labels[2] : ''; |
| 108 | |
| 109 | $symbols = explode(',', $strSymbols); |
| 110 | $symbols[0] = isset($symbols[0]) ? $symbols[0] : ''; |
| 111 | $symbols[1] = isset($symbols[1]) ? $symbols[1] : ''; |
| 112 | $symbols[2] = isset($symbols[2]) ? $symbols[2] : ''; |
| 113 | |
| 114 | if ($labels[0] != '') |
| 115 | { |
| 116 | parent::setWidth(465); |
| 117 | } |
| 118 | if (preg_match('/Segundos/i',$labels[2])) |
| 119 | { |
| 120 | parent::setWidth(535); |
| 121 | } |
| 122 | $this->setColumns(array(60)); |
| 123 | |
| 124 | // construir os campos de latitude e longitude |
| 125 | $this->latGrau = $this->addNumberField($this->getId() . '_lat_grau', "Latitude " . $labels[0], 2, $boolRequired, 0, true, null, 0, 33, false, null, true, true); |
| 126 | $this->latGrau->setExampleText('<span style="font-size:' . $intSymbolsFontSize . 'px;">' . $symbols[0] . '</span>'); |
| 127 | $this->latGrau->setProperty('title', 'Intervalo válido - Grau: 0º a 33º'); |
| 128 | $this->latMin = $this->addNumberField($this->getId() . '_lat_min', $labels[1], 2, $boolRequired, 0, false, null, 0, 59, false, null, true); |
| 129 | $this->latMin->setExampleText('<span style="font-size:' . $intSymbolsFontSize . 'px;">' . $symbols[1] . '</span>'); |
| 130 | $this->latMin->setProperty('title', "Intervalo válido - Minuto: 0 a 59"); |
| 131 | //$this->latSeg = $this->addNumberField($this->getId() . '_lat_seg', $labels[2], 5, $boolRequired, 2, false, null, 0, "59.99", false, null, true, true); |
| 132 | //$this->latSeg = $this->addMaskField($this->getId() . '_lat_seg', $labels[2],$boolRequired,'99,99',false)->setAttribute('dir', 'rtl'); |
| 133 | $this->latSeg = $this->addTextField($this->getId() . '_lat_seg', $labels[2],5,$boolRequired,5,null,false)->setCss('text-align', 'right'); |
| 134 | $this->latSeg->addEvent('onblur',"fwChkMinMax(0, 59.99, '".$this->getId() . '_lat_seg'."',2,true,0)"); |
| 135 | $this->latSeg->addEvent('onkeydown',"fwFormatSecondsGms(this,event)"); |
| 136 | $this->latSeg->setExampleText('<span style="font-size:' . $intSymbolsFontSize . 'px;">' . $symbols[2] . '</span>'); |
| 137 | $this->latSeg->setProperty('title', 'Intervalo válido - Segundo: 0 a 59,99'); |
| 138 | $this->latHem = $this->addSelectField($this->getId() . '_lat_hem', 'Hem:', $boolRequired, "S=Sul,N=Norte", false, null, null, null, null, null, ""); |
| 139 | |
| 140 | |
| 141 | // longitude |
| 142 | $this->lonGrau = $this->addNumberField($this->getId() . '_lon_grau', "Longitude " . $labels[0], 2, $boolRequired, 0, true, null, 32, 73, false, null, false, true); |
| 143 | $this->lonGrau->setProperty('title', 'Intervalo válido - Grau: 32º a 73º'); |
| 144 | $this->lonGrau->setExampleText('<span style="font-size:' . $intSymbolsFontSize . 'px;">' . $symbols[0] . '</span>'); |
| 145 | $this->lonMin = $this->addNumberField($this->getId() . '_lon_min', $labels[1], 2, $boolRequired, 0, false, null, 0, 59, false, null, true); |
| 146 | $this->lonMin->setProperty('title', 'Intervalo válido - Minuto: 0 a 59'); |
| 147 | $this->lonMin->setExampleText('<span style="font-size:' . $intSymbolsFontSize . 'px;">' . $symbols[1] . '</span>'); |
| 148 | //$this->lonSeg = $this->addNumberField($this->getId() . '_lon_seg', $labels[2], 5, $boolRequired, 2, false, null, 0, "59.99", false, null, true, true); |
| 149 | //$this->lonSeg = $this->addMaskField($this->getId() . '_lon_seg', $labels[2],$boolRequired,'99,99',false)->setAttribute('dir', 'rtl'); |
| 150 | $this->lonSeg = $this->addTextField($this->getId() . '_lon_seg', $labels[2],5,$boolRequired,5,null,false)->setCss('text-align', 'right'); |
| 151 | $this->lonSeg->addEvent('onblur',"fwChkMinMax(0, 59.99, '".$this->getId() . '_lon_seg'."',2,true,false)"); |
| 152 | $this->lonSeg->addEvent('onkeydown',"fwFormatSecondsGms(this,event)"); |
| 153 | $this->lonSeg->setProperty('title', 'Intervalo válido - Segundo: 0 a 59,99'); |
| 154 | $this->lonSeg->setExampleText('<span style="font-size:' . $intSymbolsFontSize . 'px;">' . $symbols[2] . '</span>'); |
| 155 | //$this->lonHem = $this->addTextField($this->getId() . '_lon_hem', 'Hem:', 1, $boolRequired, 1, 'W', false); |
| 156 | $this->lonHem = $this->addSelectField($this->getId() . '_lon_hem', 'Hem:', $boolRequired, "W=Oeste,E=Leste", false, null, null, null, null, null, ""); |
| 157 | |
| 158 | //$this->lonHem->setEnabled(false); |
| 159 | // botão para abrir o mapa |
| 160 | $this->buttonGMap = $this->addButton('G', null, 'btnGoogle_' . $this->getId(), null, null, false, false, 'fwgoogle-maps-icon_19x19px.gif', 'fwgoogle-maps-icon_19x19px.gif', 'Mapa - Visualizar / selecionar a coordenada'); |
| 161 | $this->fieldZoom = $this->addHiddenField($this->getId().'_map_zoom'); |
| 162 | $this->fieldLonCenter = $this->addHiddenField($this->getId().'_map_lon_center'); |
| 163 | $this->fieldLatCenter= $this->addHiddenField($this->getId().'_map_lat_center'); |
| 164 | /* |
| 165 | //$this->addButton('G',null,'btnGoogle_'.$this->getId(),'fwFieldCoordShowMap("'.$this->getId().'","'.$this->getMapHeight().'","'.$this->getMapWidth().'")',null,false,false,'gmark_grey.jpg',null,'Google Map - Visualizar/selecionar coordenadas'); |
| 166 | // se não tiver sido postado, inicializar com os valores passados em $floatLat e $floatLon |
| 167 | if(is_null($this->latGrau->getValue())) |
| 168 | { |
| 169 | $this->setLat($floatLatY); |
| 170 | $this->setLon($floatLonX); |
| 171 | } |
| 172 | */ |
| 173 | } |
| 174 | /** |
| 175 | * Imprime ou devolve o código html se $print for false |
| 176 | * |
| 177 | * @param boolean $print |
| 178 | * @return string |
| 179 | */ |
| 180 | function show($print=true,$flat=false) |
| 181 | { |
| 182 | if (!$this->getButtonGMap()->getOnClick()) |
| 183 | { |
| 184 | $params = array('readonly' => !$this->getEnabled() |
| 185 | , 'mapHeaderText' => utf8_encode($this->getMapHeaderText()) |
| 186 | , 'mapHeaderFontColor' => utf8_encode($this->getMapHeaderFontColor()) |
| 187 | , 'mapHeaderFontColor' => utf8_encode($this->getMapHeaderFontColor()) |
| 188 | , 'mapHeaderCallBaFontSize' => utf8_encode((integer) $this->getMapHeaderFontSize()) |
| 189 | , 'mapCallback' => $this->getMapCallback() |
| 190 | , 'zoom' => $this->getMapZoom() |
| 191 | , 'mapType' => $this->getMapType() |
| 192 | ); |
| 193 | $this->getButtonGMap()->setOnClick('fwFieldCoordShowMap("' . $this->getId() . '","' . $this->getMapHeight() . '","' . $this->getMapWidth() . '",' . json_encode($params) . ')'); |
| 194 | // $this->getButtonGMap()->setOnClick('fwFieldCoordShowMap("'.$this->getId().'","'.$this->getMapHeight().'","'.$this->getMapWidth().'","'.$params.'")'); |
| 195 | $this->getButtonGMap()->setAction(null); |
| 196 | $this->getButtonGMap()->setEnabled(true); |
| 197 | if (!$this->getEnabled()) |
| 198 | { |
| 199 | $this->getButtonGMap()->setHint('Mapa - Visualizar Coordenada'); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | $this->fieldZoom->setValue($this->getMapZoom()); |
| 204 | // retirar este if quando o problema do TForm de gerar as larguras das colunas corretamente estiver resolvido |
| 205 | if ($this->getRequired() == true) |
| 206 | { |
| 207 | $this->setColumns(array(60)); |
| 208 | } |
| 209 | return parent::show($print); |
| 210 | } |
| 211 | /** |
| 212 | * Retorna o array contendo o valor da latitude (y) e da longitude (x) |
| 213 | * |
| 214 | */ |
| 215 | function getValue($strField=null) |
| 216 | { |
| 217 | if ( ! is_null( $this->latGrau->getValue() ) ) |
| 218 | { |
| 219 | // latitude |
| 220 | $grau = $this->latGrau->getValue(); |
| 221 | $min = $this->latMin->getValue(); |
| 222 | $seg = $this->latSeg->getValue(); |
| 223 | list($hem) = $this->latHem->getValue(); |
| 224 | $grau = is_null($grau) ? 0 : (float) str_replace(',', '.', $grau); |
| 225 | $min = is_null($min) ? 0 : (float) str_replace(',', '.', $min); |
| 226 | $seg = is_null($seg) ? 0 : (float) str_replace(',', '.', $seg); |
| 227 | if (strtoupper($hem) == 'W' || strtoupper($hem) == 'S') |
| 228 | { |
| 229 | $lat = (-$grau - $min / 60) - ($seg / 3600); |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | $lat = ($grau + $min / 60) + ($seg / 3600); |
| 234 | } |
| 235 | // longitude |
| 236 | $grau = $this->lonGrau->getValue(); |
| 237 | $min = $this->lonMin->getValue(); |
| 238 | $seg = $this->lonSeg->getValue(); |
| 239 | //$hem = $this->lonHem->getValue(); |
| 240 | list($hem) = $this->lonHem->getValue(); |
| 241 | $grau = is_null($grau) ? 0 : (float) str_replace(',', '.', $grau); |
| 242 | $min = is_null($min) ? 0 : (float) str_replace(',', '.', $min); |
| 243 | $seg = is_null($seg) ? 0 : (float) str_replace(',', '.', $seg); |
| 244 | if (strtoupper($hem) == 'W' || strtoupper($hem) == 'S') |
| 245 | { |
| 246 | $lon = (-$grau - $min / 60) - ($seg / 3600); |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | $lon = ($grau + $min / 60) + ($seg / 3600); |
| 251 | } |
| 252 | return array($this->getFieldNameLat() => $lat, $this->getFieldNameLon() => $lon); |
| 253 | } |
| 254 | return null; |
| 255 | // campo select retorna array no getValue() |
| 256 | /* list($latHem)=$this->latHem->getValue(); |
| 257 | return array( |
| 258 | $this->latGrau->getId() =>$this->latGrau->getValue(), |
| 259 | $this->latMin->getId() =>$this->latMin->getValue(), |
| 260 | $this->latSeg->getId() =>$this->latSeg->getValue(), |
| 261 | $this->latHem->getId() =>$latHem[0], |
| 262 | $this->lonGrau->getId() =>$this->lonGrau->getValue(), |
| 263 | $this->lonMin->getId() =>$this->lonMin->getValue(), |
| 264 | $this->lonSeg->getId() =>$this->lonSeg->getValue(), |
| 265 | str_replace('_disabled','',$this->lonHem->getId())=>$this->lonHem->getValue()); |
| 266 | */ |
| 267 | } |
| 268 | //------------------------------------------------------------------------- |
| 269 | /** |
| 270 | * converte grau decimal em Grau, Min e Seg |
| 271 | * |
| 272 | * @param float $gd |
| 273 | * @param float $latlon |
| 274 | * |
| 275 | * @return array |
| 276 | */ |
| 277 | protected function gd2gms($gd, $latlon=null) |
| 278 | { |
| 279 | $result = array(); |
| 280 | if (is_null($latlon) || ( strtoupper($latlon) != 'LAT' && strtoupper($latlon) != 'LON')) |
| 281 | { |
| 282 | return $result; |
| 283 | } |
| 284 | |
| 285 | if (!is_null($gd)) |
| 286 | { |
| 287 | $grau = abs( (int) $gd ); |
| 288 | $min = abs( (int) ( ( abs($gd) - $grau ) * 60 )); |
| 289 | $seg = $this->roundUp((60*((abs($gd)-$grau)*60-$min)),2); |
| 290 | if (strtoupper($latlon) == 'LON') |
| 291 | { |
| 292 | if ($gd > 0) |
| 293 | { |
| 294 | $hem = 'E'; |
| 295 | } |
| 296 | else |
| 297 | { |
| 298 | $hem = 'W'; |
| 299 | } |
| 300 | } |
| 301 | else if (strtoupper($latlon) == 'LAT') |
| 302 | { |
| 303 | if ($gd > 0) |
| 304 | { |
| 305 | $hem = 'N'; |
| 306 | } |
| 307 | else |
| 308 | { |
| 309 | $hem = 'S'; |
| 310 | } |
| 311 | } |
| 312 | $result = array($grau, $min, $seg, $hem); |
| 313 | } |
| 314 | return $result; |
| 315 | } |
| 316 | |
| 317 | //---------------------------------------------------------------------- |
| 318 | /** |
| 319 | * Retorna um valor decimal sem arredondamento até a quantidade de casas informada |
| 320 | * |
| 321 | * @param float $val |
| 322 | * @param int $casas |
| 323 | * @return float |
| 324 | */ |
| 325 | protected function trunc($val, $casas) |
| 326 | { |
| 327 | $casas = is_null($casas) ? 0 : ($casas + 1); |
| 328 | $pos = strpos($val, '.'); |
| 329 | if ($pos) |
| 330 | { |
| 331 | return substr($val, 0, ($pos + $casas)); |
| 332 | } |
| 333 | return $val; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Arredondar para cima |
| 338 | |
| 339 | * |
| 340 | * @param float $value |
| 341 | * @param integer $precision |
| 342 | */ |
| 343 | function roundUp($value, $precision=0) |
| 344 | { |
| 345 | if ($precision == 0) |
| 346 | { |
| 347 | $precisionFactor = 1; |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | $precisionFactor = pow(10, $precision); |
| 352 | } |
| 353 | return ceil($value * $precisionFactor) / $precisionFactor; |
| 354 | } |
| 355 | |
| 356 | //------------------------------------------- |
| 357 | /** |
| 358 | * Define o valor de grau min e seg da latitude (y) em função do valor decimal passado |
| 359 | * |
| 360 | * @param float $y |
| 361 | */ |
| 362 | public function setLat($y=null) |
| 363 | { |
| 364 | $this->latGrau->setValue(null); |
| 365 | $this->latMin->setValue(null); |
| 366 | $this->latSeg->setValue(null); |
| 367 | $this->latHem->setValue(null); |
| 368 | if (!is_null($y)) |
| 369 | { |
| 370 | $y = (float) str_replace(",", ".", $y); |
| 371 | $y = $this->roundUp($y, 14); |
| 372 | $aDados = $this->gd2gms($y, 'lat'); |
| 373 | if (isset($aDados[0])) |
| 374 | { |
| 375 | //$this->lat->setValue($y); |
| 376 | $this->latGrau->setValue(( $aDados[0])); |
| 377 | $this->latMin->setValue($aDados[1]); |
| 378 | $this->latSeg->setValue($aDados[2]); |
| 379 | $this->latHem->setValue($aDados[3]); |
| 380 | } |
| 381 | } |
| 382 | return $this; |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * Define o valor de grau min e seg da longitude (x) em função do valor decimal passado |
| 387 | * |
| 388 | * @param float $x |
| 389 | */ |
| 390 | public function setLon($x=null) |
| 391 | { |
| 392 | $this->lonGrau->setValue(null); |
| 393 | $this->lonMin->setValue(null); |
| 394 | $this->lonSeg->setValue(null); |
| 395 | if (!is_null($x)) |
| 396 | { |
| 397 | $x = (float) str_replace(",", ".", $x); |
| 398 | $x = $this->roundUp($x, 8); |
| 399 | $aDados = $this->gd2gms($x, 'lon'); |
| 400 | if (isset($aDados[0])) |
| 401 | { |
| 402 | //$this->lon->setValue($x); |
| 403 | $this->lonGrau->setValue(( $aDados[0])); |
| 404 | $this->lonMin->setValue($aDados[1]); |
| 405 | $this->lonSeg->setValue($aDados[2]); |
| 406 | $this->lonHem->setValue($aDados[3]); |
| 407 | } |
| 408 | } |
| 409 | return $this; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Define o nome do campo referente ao valor da latitude que será retornado no array da função getValue() |
| 414 | * |
| 415 | * @param string $strNewValue |
| 416 | */ |
| 417 | public function setFieldNameLat($strNewValue=null) |
| 418 | { |
| 419 | $this->fieldNameLat = $strNewValue; |
| 420 | return $this; |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Define o nome do campo referente ao valor da longitude que será retornado no array da função getValue() |
| 425 | * |
| 426 | * @param string $strNewValue |
| 427 | */ |
| 428 | public function setFieldNameLon($strNewValue=null) |
| 429 | { |
| 430 | $this->fieldNameLon = $strNewValue; |
| 431 | return $this; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Retonra o nome do campo referente ao valor da latitude que será retornado no array da função getValue() |
| 436 | * |
| 437 | */ |
| 438 | public function getFieldNameLat() |
| 439 | { |
| 440 | if (is_null($this->fieldNameLat)) |
| 441 | { |
| 442 | return $this->getId() . '_lat'; |
| 443 | } |
| 444 | return $this->fieldNameLat; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Retonra o nome do campo referente ao valor da longitude que será retornado no array da função getValue() |
| 449 | * |
| 450 | */ |
| 451 | public function getFieldNameLon() |
| 452 | { |
| 453 | if (is_null($this->fieldNameLon)) |
| 454 | { |
| 455 | return $this->getId() . '_lon'; |
| 456 | } |
| 457 | return $this->fieldNameLon; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Define o valor da latitude ou da longitude |
| 462 | * |
| 463 | * @param string $strFieldName |
| 464 | * @param mixed $strValue |
| 465 | * @param string $strLatLon |
| 466 | */ |
| 467 | public function setValue($strFieldName=null, $strValue=null, $strLatLon=null) |
| 468 | { |
| 469 | if ($strFieldName == $this->getFieldNameLat()) |
| 470 | { |
| 471 | $this->setLat($strValue); |
| 472 | } |
| 473 | else if ($strFieldName == $this->getFieldNameLon()) |
| 474 | { |
| 475 | $this->setLon($strValue); |
| 476 | } |
| 477 | else if ($strFieldName == $this->getId() && isset($strLatLon)) |
| 478 | { |
| 479 | $strLatLon = strtoupper($strLatLon); |
| 480 | if ($strLatLon == 'LAT') |
| 481 | { |
| 482 | $this->setLat($strValue); |
| 483 | } |
| 484 | else if ($strLatLon == 'LON') |
| 485 | { |
| 486 | $this->setLon($strValue); |
| 487 | } |
| 488 | } |
| 489 | return $this; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Valida se os campos estão preenchidos coretamente. |
| 494 | * |
| 495 | */ |
| 496 | public function validate($strPage=null, $strFields=null, $strIgnoreFields=null) |
| 497 | { |
| 498 | $this->setClass('fwFieldBoarder'); |
| 499 | $this->latGrau->setClass('fwFieldBoarder'); |
| 500 | $this->latMin->setClass('fwFieldBoarder'); |
| 501 | $this->latSeg->setClass('fwFieldBoarder'); |
| 502 | $this->latHem->setClass('fwFieldBoarder'); |
| 503 | $this->lonGrau->setClass('fwFieldBoarder'); |
| 504 | $this->lonMin->setClass('fwFieldBoarder'); |
| 505 | $this->lonSeg->setClass('fwFieldBoarder'); |
| 506 | $this->lonHem->setClass('fwFieldBoarder'); |
| 507 | if ($this->getRequired() == true) |
| 508 | { |
| 509 | if (is_null($this->latGrau->getValue()) || |
| 510 | is_null($this->latMin->getValue()) || |
| 511 | is_null($this->latSeg->getValue()) || |
| 512 | is_null($this->lonGrau->getValue()) || |
| 513 | is_null($this->lonMin->getValue()) || |
| 514 | is_null($this->lonSeg->getValue())) |
| 515 | { |
| 516 | $this->addError("Campo obrigatório"); |
| 517 | $this->setClass('fwFieldRequiredBoarder'); |
| 518 | return ( (string) $this->getError() === "" ); |
| 519 | } |
| 520 | } |
| 521 | if (!is_null($this->latGrau->getValue()) && $this->latGrau->getValue() > 35) |
| 522 | { |
| 523 | $this->addError("Grau Latitude inválido"); |
| 524 | $this->latGrau->setClass('fwFieldRequiredBoarder'); |
| 525 | } |
| 526 | if (!is_null($this->latMin->getValue()) && $this->latMin->getValue() > 59) |
| 527 | { |
| 528 | $this->addError("Minuto Latitude inválido"); |
| 529 | $this->latMin->setClass('fwFieldRequiredBoarder'); |
| 530 | } |
| 531 | if (!is_null($this->latSeg->getValue()) && $this->latSeg->getValue() > 59) |
| 532 | { |
| 533 | $this->addError("Segundo Latitude inválido"); |
| 534 | $this->latSeg->setClass('fwFieldRequiredBoarder'); |
| 535 | } |
| 536 | // longitude |
| 537 | if (!is_null($this->lonGrau->getValue()) && $this->lonGrau->getValue() != '' && $this->lonGrau->getValue() < 30 || $this->lonGrau->getValue() > 70) |
| 538 | { |
| 539 | $this->addError("Grau Longitude inválido"); |
| 540 | $this->lonGrau->setClass('fwFieldRequiredBoarder'); |
| 541 | } |
| 542 | if (!is_null($this->lonMin->getValue()) && $this->lonMin->getValue() > 59) |
| 543 | { |
| 544 | $this->addError("Minuto Longitude inválido"); |
| 545 | $this->lonMin->setClass('fwFieldRequiredBoarder'); |
| 546 | } |
| 547 | if (!is_null($this->lonSeg->getValue()) && $this->lonSeg->getValue() > 59) |
| 548 | { |
| 549 | $this->addError("Segundo Longitude inválido"); |
| 550 | $this->lonSeg->setClass('fwFieldRequiredBoarder'); |
| 551 | } |
| 552 | return ( (string) $this->getError() === "" ); |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Limpa o conteudo dos campos |
| 557 | * |
| 558 | */ |
| 559 | public function clear() |
| 560 | { |
| 561 | $this->latGrau->setValue(null); |
| 562 | $this->latMin->setValue(null); |
| 563 | $this->latSeg->setValue(null); |
| 564 | $this->lonGrau->setValue(null); |
| 565 | $this->lonMin->setValue(null); |
| 566 | $this->lonSeg->setValue(null); |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Define os simbolos para Grau, Minuto e Segundos, que serão exibidos depois dos campos como texto de exemplo |
| 571 | * Devem ser passados separados por virgula; |
| 572 | * <code> |
| 573 | * $f->setSymbolS('G,M,S'); |
| 574 | * </code> |
| 575 | * |
| 576 | * @param mixed $strNewValue |
| 577 | */ |
| 578 | public function setSymbols($strNewValue='grau,min,seg') |
| 579 | { |
| 580 | $this->symbols = $strNewValue; |
| 581 | return $this; |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * Retorna a string com os simbolos para Grau, Minutos e Segundos, separados por vírgula |
| 586 | * |
| 587 | */ |
| 588 | public function getSymbols() |
| 589 | { |
| 590 | return $this->symbols; |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Define os rótulos para os campos Grau, Minuto e Segundos, que serão exibidos na frente dos campos. |
| 595 | * Devem ser passados separados por virgula; |
| 596 | * <code> |
| 597 | * $f->setLabels('Grau:,Min:,Seg:'); |
| 598 | * </code> |
| 599 | * |
| 600 | * @param mixed $strNewValue |
| 601 | */ |
| 602 | public function setLabels($strNewValue='Grau:,Min:,Seg:') |
| 603 | { |
| 604 | $this->labels = $strNewValue; |
| 605 | return $this; |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Retorna a string com os labels dos campos separados por virgula. |
| 610 | * |
| 611 | */ |
| 612 | public function getLabels() |
| 613 | { |
| 614 | return $this->labels; |
| 615 | } |
| 616 | |
| 617 | public function setLatGrau($intNewValue=null) |
| 618 | { |
| 619 | $this->latGrau->setValue($intNewValue); |
| 620 | return $this; |
| 621 | } |
| 622 | |
| 623 | public function setLatMin($intNewValue=null) |
| 624 | { |
| 625 | $this->latMin->setValue($intNewValue); |
| 626 | return $this; |
| 627 | } |
| 628 | |
| 629 | public function setLatSeg($intNewValue=null) |
| 630 | { |
| 631 | $this->latSeg->setValue($intNewValue); |
| 632 | return $this; |
| 633 | } |
| 634 | |
| 635 | public function setLatHem($strNewValue=null) |
| 636 | { |
| 637 | $this->latHem->setValue($strNewValue); |
| 638 | return $this; |
| 639 | } |
| 640 | |
| 641 | public function setLonGrau($intNewValue=null) |
| 642 | { |
| 643 | $this->lonGrau->setValue($intNewValue); |
| 644 | return $this; |
| 645 | } |
| 646 | |
| 647 | public function setLonMin($intNewValue=null) |
| 648 | { |
| 649 | $this->lonMin->setValue($intNewValue); |
| 650 | return $this; |
| 651 | } |
| 652 | |
| 653 | public function setLonSeg($intNewValue=null) |
| 654 | { |
| 655 | $this->lonSeg->setValue($intNewValue); |
| 656 | return $this; |
| 657 | } |
| 658 | |
| 659 | public function setLonHem($strNewValue=null) |
| 660 | { |
| 661 | $this->lonHem->setValue($strNewValue); |
| 662 | return $this; |
| 663 | } |
| 664 | |
| 665 | public function getLatGrau() |
| 666 | { |
| 667 | return $this->latGrau->getValue(); |
| 668 | } |
| 669 | |
| 670 | public function getLatMin() |
| 671 | { |
| 672 | return $this->latMin->getValue(); |
| 673 | } |
| 674 | |
| 675 | public function getLatSeg() |
| 676 | { |
| 677 | return $this->latSeg->getValue(); |
| 678 | } |
| 679 | |
| 680 | public function getLatHem() |
| 681 | { |
| 682 | return $this->latHem->getValue(); |
| 683 | } |
| 684 | |
| 685 | public function getLonGrau() |
| 686 | { |
| 687 | return $this->lonGrau->getValue(); |
| 688 | } |
| 689 | |
| 690 | public function getLonMin() |
| 691 | { |
| 692 | return $this->lonMin->getValue(); |
| 693 | } |
| 694 | |
| 695 | public function getLonSeg() |
| 696 | { |
| 697 | return $this->lonSeg->getValue(); |
| 698 | } |
| 699 | |
| 700 | public function getLonHem() |
| 701 | { |
| 702 | return $this->lonHem->getValue(); |
| 703 | } |
| 704 | |
| 705 | public function setMapWidth($intNewValue=null) |
| 706 | { |
| 707 | $this->mapWidth = $intNewValue; |
| 708 | return $this; |
| 709 | } |
| 710 | |
| 711 | public function getMapWidth($intNewValue=null) |
| 712 | { |
| 713 | return $this->mapWidth; |
| 714 | } |
| 715 | |
| 716 | public function setMapHeight($intNewValue=null) |
| 717 | { |
| 718 | $this->mapHeight = $intNewValue; |
| 719 | return $this; |
| 720 | } |
| 721 | |
| 722 | public function getMapHeight() |
| 723 | { |
| 724 | return $this->mapHeight; |
| 725 | } |
| 726 | |
| 727 | public function getButtonGMap() |
| 728 | { |
| 729 | return $this->buttonGMap; |
| 730 | } |
| 731 | |
| 732 | public function setMapHeaderText($strNewValue=null) |
| 733 | { |
| 734 | $this->mapHeaderText = $strNewValue; |
| 735 | return $this; |
| 736 | } |
| 737 | |
| 738 | public function getMapHeaderText() |
| 739 | { |
| 740 | return $this->mapHeaderText; |
| 741 | } |
| 742 | |
| 743 | public function setMapHeaderFontSize($strNewValue=null) |
| 744 | { |
| 745 | $this->mapHeaderFontSize = $strNewValue; |
| 746 | return $this; |
| 747 | } |
| 748 | |
| 749 | public function getMapHeaderFontSize() |
| 750 | { |
| 751 | return $this->mapHeaderFontSize; |
| 752 | } |
| 753 | |
| 754 | public function setMapHeaderFontColor($strNewValue=null) |
| 755 | { |
| 756 | $this->mapHeaderFontColor = $strNewValue; |
| 757 | return $this; |
| 758 | } |
| 759 | |
| 760 | public function getMapHeaderFontColor() |
| 761 | { |
| 762 | return $this->mapHeaderFontColor; |
| 763 | } |
| 764 | |
| 765 | public function setMapCallback($strNewValue=null) |
| 766 | { |
| 767 | $this->mapCallback= $strNewValue; |
| 768 | return $this; |
| 769 | } |
| 770 | public function getMapCallback() |
| 771 | { |
| 772 | return is_null($this->mapCallback) ? '' : $this->mapCallback; |
| 773 | } |
| 774 | public function setMapZoom($intNewValue=null) |
| 775 | { |
| 776 | $this->mapZoom = $intNewValue; |
| 777 | return $this; |
| 778 | } |
| 779 | public function getMapZoom() |
| 780 | { |
| 781 | $zoom = ( ( $this->getLatGrau() && $this->getLonGrau() ) ? 12 : 4 ); |
| 782 | return is_null($this->mapZoom) ? $zoom : $this->mapZoom; |
| 783 | } |
| 784 | public function setMapType($strNewValue=null) |
| 785 | { |
| 786 | $this->mapType = $strNewValue; |
| 787 | return $this; |
| 788 | } |
| 789 | public function getMapType() |
| 790 | { |
| 791 | $aTypes = array('ROADMAP','SATELLITE','TERRAIN','HYBRID'); |
| 792 | if( in_array( strtoupper($this->mapType), $aTypes ) ) |
| 793 | { |
| 794 | return strtolower( $this->mapType ); |
| 795 | } |
| 796 | return 'roadmap'; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | print '<form name="formdin" action="" method="POST">'; |
| 802 | $c = new TCoordGMS('coord'); |
| 803 | $c->setRequired(true); |
| 804 | $c->setLat(-15.52); |
| 805 | $c->setLon(-28.74); |
| 806 | $c->show(); |
| 807 | print '<hr>'; |
| 808 | print '<input type="submit" value="Gravar">'; |
| 809 | print '</form><pre>'; |
| 810 | print_r($c->getValue()); |
| 811 | print '</pre>' |
| 812 | */ |
| 813 | ?> |