function indexAction() { /* @var $model CidadesModel */ $model = newModel('CidadesModel'); /* @var $v CidadeVO */ $start = microtime(true); $estado = url_parans(0) ? url_parans(0) : inputPost('estado'); $cidade = url_parans(1) ? url_parans(1) : inputPost('cidade'); if ($estado > 0 or preg_match('/^[A-Z]{2}$/i', $estado)) { $cache = new Cache('cidades.' . $estado, 60); if (!($options = $cache->getContent())) { $cidades = $model->getCidades($estado); if (count($cidades)) { $options = formOption('-- Selecione a cidade --', ''); } else { $options = formOption('-- Selecione o estado --', ''); } foreach ($cidades as $v) { $options .= formOption($v->getTitle(), $v->getId(), false); } # Salvando cache $cache->setContent($options); } echo preg_replace(['/(value="' . preg_quote($cidade) . '")/', '/>(' . preg_quote($cidade) . ')</'], ['$1 selected=""', 'selected="" >$1<'], $options); } $end = microtime(true); echo "\n\n<!-- " . number_format(($end - $start) * 1000, 5, ',', '.') . "ms --> Buscou por {$cidade}"; exit; }
/** * Retorna a lista de options para select * @param string $Ref * @param string $Ordem * @param int $setValue * @return string HTML */ function optionsByRef($Ref = null, $OrderBY = null, $setValue = 0) { $html = ''; foreach ($this->listByRef($Ref, 1, $OrderBY) as $v) { $html .= formOption($v->getTitle(), $v->getId(), $v->getId() == $setValue); } return $html; }
/** * Retorna a lista de tipos de conta * @param int $UserType * @return string|select.options */ function options($UserType = null) { ob_start(); foreach ($this->Lista('WHERE a.status != 99 AND (:type IS NULL OR :type = 1 OR a.permissoes LIKE CONCAT("%[",:type,"]%")) ORDER BY a.title ASC', ['type' => $UserType]) as $v) { echo formOption($v->getTitle(), $v->getId()); } return ob_get_clean(); }
/** * select.options * @param string $Label uf | title * @return string */ public function options($Label = 'title', $Current = null, $optSelecione = true) { $html = $optSelecione ? formOption($Label == 'title' ? '-- Selecione --' : '- UF -', '') : ''; $method = strtolower($Label) == 'title' ? 'getTitle' : 'getUF'; foreach ($this->getEstados() as $v) { $html .= formOption($v->{$method}(), $v->getId(), in_array($Current, [$v->getId(), $v->getUf()]) ? true : false); } return $html; }
/** * * @param int $start * @param int $end * @param string $prefixo * @param string $sufixo * @return string */ function formOptionRange($start, $end, $prefixo = null, $sufixo = null) { $html = ''; foreach (range($start, $end) as $value) { $html .= formOption("{$prefixo}{$value}{$sufixo}", $value); } return $html; }