Created
March 1, 2017 17:22
-
-
Save ianrodrigues/63e6c06e0e20c60d8d7f1507bc5fbd58 to your computer and use it in GitHub Desktop.
CÓDIGO DO MEU ÓDIO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function tempoAgora() | |
{ | |
$ufRepo = $this->em->getRepository("Adm\Uf\Model\Uf"); | |
$estacaoRepo = $this->em->getRepository("Pcd\Estacao\Model\Estacao"); | |
$postos = $estacaoRepo->get_estacoes_ne(); | |
$result = []; | |
foreach ($postos as $posto) { | |
if ($posto['est_codigo'] == 572) { | |
continue; | |
} | |
if ($posto['est_modelo'] == 1 && $posto['est_ins_codigo'] == 41 || $posto['est_codigo'] == 12) { | |
$result[] = array( | |
'cod' => $posto['est_codigo'], | |
'nome' => $posto['est_nome'], | |
'geom' => $posto['est_geom'], | |
); | |
} | |
} | |
$tipo = isset($_GET['tipo']) ? $_GET['tipo'] : null; | |
$atual = 'N'; | |
if ($tipo == 1) { | |
$data2 = "["; | |
foreach ($result as $est) { | |
$data2 .= json_encode(array('cod' => $est['cod'], 'nome' => $est['nome'], 'cat' => substr($est['nome'], 0, 1), 'atual' => $atual)) . ","; | |
} | |
$data2 = substr($data2, 0, -1); | |
$data2 .= "]"; | |
$json = $data2; | |
} else { | |
$lista = array(); | |
if (isset($result)) { | |
foreach ($result as $est) { | |
$uf = $ufRepo->findByGeom($est['geom']); | |
$lista[$est['cod']] = array('cod' => (string) $est['cod'], 'nome' => $est['nome'] . "-" . $uf['uf_codigo'], 'cat' => substr($est['nome'], 0, 1), 'atual' => $atual); | |
} | |
} | |
foreach ($lista as $key => $row) { | |
$nome[$key] = $row['nome']; | |
} | |
// Ordena os dados com volume descendente, edition ascendente | |
// adiciona $data como o último parãmetro, para ordenar pela chave comum | |
array_multisort($nome, SORT_ASC, $nome, SORT_ASC, $lista); | |
//echo "<pre>"; | |
//print_r($lista);exit; | |
$lista2 = array(); | |
if (!empty($lista)) { | |
foreach ($lista as $list) { | |
$lista2['cidades'][] = $list; | |
} | |
} | |
$data2 = json_encode($lista2); | |
} | |
$json = substr($data2, 0, -1); | |
$json .= "}"; | |
print_r($json); exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment