Commit 07cf03879c9552871ccfd46445c33953cf5c9aff
1 parent
e6873799
Exists in
master
Refactoring para Coding Standards
Showing
1 changed file
with
337 additions
and
377 deletions
Show diff stats
ieducar/intranet/include/pessoa/clsCadastroEscolaridade.inc.php
| 1 | 1 | <?php |
| 2 | -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 3 | -* * | |
| 4 | -* @author Prefeitura Municipal de Itajaí * | |
| 5 | -* @updated 29/03/2007 * | |
| 6 | -* Pacote: i-PLB Software Público Livre e Brasileiro * | |
| 7 | -* * | |
| 8 | -* Copyright (C) 2006 PMI - Prefeitura Municipal de Itajaí * | |
| 9 | -* ctima@itajai.sc.gov.br * | |
| 10 | -* * | |
| 11 | -* Este programa é software livre, você pode redistribuí-lo e/ou * | |
| 12 | -* modificá-lo sob os termos da Licença Pública Geral GNU, conforme * | |
| 13 | -* publicada pela Free Software Foundation, tanto a versão 2 da * | |
| 14 | -* Licença como (a seu critério) qualquer versão mais nova. * | |
| 15 | -* * | |
| 16 | -* Este programa é distribuído na expectativa de ser útil, mas SEM * | |
| 17 | -* QUALQUER GARANTIA. Sem mesmo a garantia implícita de COMERCIALI- * | |
| 18 | -* ZAÇÃO ou de ADEQUAÇÃO A QUALQUER PROPÓSITO EM PARTICULAR. Con- * | |
| 19 | -* sulte a Licença Pública Geral GNU para obter mais detalhes. * | |
| 20 | -* * | |
| 21 | -* Você deve ter recebido uma cópia da Licença Pública Geral GNU * | |
| 22 | -* junto com este programa. Se não, escreva para a Free Software * | |
| 23 | -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * | |
| 24 | -* 02111-1307, USA. * | |
| 25 | -* * | |
| 26 | -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
| 2 | + | |
| 27 | 3 | /** |
| 28 | -* @author Prefeitura Municipal de Itajaí | |
| 29 | -* | |
| 30 | -* Criado em 09/05/2006 | |
| 31 | -*/ | |
| 4 | + * i-Educar - Sistema de gestão escolar | |
| 5 | + * | |
| 6 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
| 7 | + * <ctima@itajai.sc.gov.br> | |
| 8 | + * | |
| 9 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
| 10 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
| 11 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
| 12 | + * qualquer versão posterior. | |
| 13 | + * | |
| 14 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
| 15 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
| 16 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
| 17 | + * do GNU para mais detalhes. | |
| 18 | + * | |
| 19 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
| 20 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
| 21 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
| 22 | + * | |
| 23 | + * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br> | |
| 24 | + * @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL | |
| 25 | + * @package Core | |
| 26 | + * @subpackage pessoa | |
| 27 | + * @since Arquivo disponível desde a versão 1.0.0 | |
| 28 | + * @version $Id$ | |
| 29 | + */ | |
| 32 | 30 | |
| 31 | +/** | |
| 32 | + * clsCadastroEscolaridade class. | |
| 33 | + * | |
| 34 | + * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br> | |
| 35 | + * @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL | |
| 36 | + * @package Core | |
| 37 | + * @subpackage pessoa | |
| 38 | + * @since Classe disponível desde a versão 1.0.0 | |
| 39 | + * @version $Id$ | |
| 40 | + */ | |
| 33 | 41 | class clsCadastroEscolaridade |
| 34 | 42 | { |
| 35 | - var $idesco; | |
| 36 | - var $descricao; | |
| 37 | - | |
| 38 | - | |
| 39 | - // propriedades padrao | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * Armazena o total de resultados obtidos na ultima chamada ao metodo lista | |
| 43 | - * | |
| 44 | - * @var int | |
| 45 | - */ | |
| 46 | - var $_total; | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * Nome do schema | |
| 50 | - * | |
| 51 | - * @var string | |
| 52 | - */ | |
| 53 | - var $_schema; | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * Nome da tabela | |
| 57 | - * | |
| 58 | - * @var string | |
| 59 | - */ | |
| 60 | - var $_tabela; | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * Lista separada por virgula, com os campos que devem ser selecionados na proxima chamado ao metodo lista | |
| 64 | - * | |
| 65 | - * @var string | |
| 66 | - */ | |
| 67 | - var $_campos_lista; | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * Lista com todos os campos da tabela separados por virgula, padrao para selecao no metodo lista | |
| 71 | - * | |
| 72 | - * @var string | |
| 73 | - */ | |
| 74 | - var $_todos_campos; | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * Valor que define a quantidade de registros a ser retornada pelo metodo lista | |
| 78 | - * | |
| 79 | - * @var int | |
| 80 | - */ | |
| 81 | - var $_limite_quantidade; | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * Define o valor de offset no retorno dos registros no metodo lista | |
| 85 | - * | |
| 86 | - * @var int | |
| 87 | - */ | |
| 88 | - var $_limite_offset; | |
| 89 | - | |
| 90 | - /** | |
| 91 | - * Define o campo padrao para ser usado como padrao de ordenacao no metodo lista | |
| 92 | - * | |
| 93 | - * @var string | |
| 94 | - */ | |
| 95 | - var $_campo_order_by; | |
| 96 | - | |
| 97 | - | |
| 98 | - /** | |
| 99 | - * Construtor (PHP 5) | |
| 100 | - * | |
| 101 | - * @return object | |
| 102 | - */ | |
| 103 | - function __construct( $idesco = null, $descricao = null ) | |
| 104 | - { | |
| 105 | - $db = new clsBanco(); | |
| 106 | - $this->_schema = "cadastro."; | |
| 107 | - $this->_tabela = "{$this->_schema}escolaridade"; | |
| 108 | - | |
| 109 | - $this->_campos_lista = $this->_todos_campos = "idesco, descricao"; | |
| 110 | - | |
| 111 | - if( is_numeric( $idesco ) ) | |
| 112 | - { | |
| 113 | - $this->idesco = $idesco; | |
| 114 | - } | |
| 115 | - if( is_string( $descricao ) ) | |
| 116 | - { | |
| 117 | - $this->descricao = $descricao; | |
| 118 | - } | |
| 119 | - | |
| 120 | - } | |
| 121 | - /** | |
| 122 | - * Construtor (PHP 4) | |
| 123 | - * | |
| 124 | - * @return object | |
| 125 | - */ | |
| 126 | - function clsCadastroEscolaridade( $idesco = null, $descricao = null ) | |
| 127 | - { | |
| 128 | - $db = new clsBanco(); | |
| 129 | - $this->_schema = "cadastro."; | |
| 130 | - $this->_tabela = "{$this->_schema}escolaridade"; | |
| 131 | - | |
| 132 | - $this->_campos_lista = $this->_todos_campos = "idesco, descricao"; | |
| 133 | - | |
| 134 | - if( is_numeric( $idesco ) ) | |
| 135 | - { | |
| 136 | - $this->idesco = $idesco; | |
| 137 | - } | |
| 138 | - if( is_string( $descricao ) ) | |
| 139 | - { | |
| 140 | - $this->descricao = $descricao; | |
| 141 | - } | |
| 142 | - | |
| 143 | - } | |
| 144 | - | |
| 145 | - /** | |
| 146 | - * Cria um novo registro | |
| 147 | - * | |
| 148 | - * @return bool | |
| 149 | - */ | |
| 150 | - function cadastra() | |
| 151 | - { | |
| 152 | - if( is_string( $this->descricao ) ) | |
| 153 | - { | |
| 154 | - $db = new clsBanco(); | |
| 155 | - | |
| 156 | - $campos = ""; | |
| 157 | - $valores = ""; | |
| 158 | - $gruda = ""; | |
| 159 | - | |
| 160 | - $this->idesco = $db->CampoUnico( "SELECT MAX( idesco ) + 1 | |
| 161 | - FROM cadastro.escolaridade" ); | |
| 162 | - if( is_numeric( $this->idesco ) ) | |
| 163 | - { | |
| 164 | - $campos .= "{$gruda}idesco"; | |
| 165 | - $valores .= "{$gruda}'{$this->idesco}'"; | |
| 166 | - $gruda = ", "; | |
| 167 | - } | |
| 168 | - if( is_string( $this->descricao ) ) | |
| 169 | - { | |
| 170 | - $campos .= "{$gruda}descricao"; | |
| 171 | - $valores .= "{$gruda}'{$this->descricao}'"; | |
| 172 | - $gruda = ", "; | |
| 173 | - } | |
| 174 | - $db->Consulta( "INSERT INTO {$this->_tabela} ( $campos ) VALUES( $valores )" ); | |
| 175 | - return $this->idesco; | |
| 176 | - } | |
| 177 | - return false; | |
| 178 | - } | |
| 179 | - | |
| 180 | - /** | |
| 181 | - * Edita os dados de um registro | |
| 182 | - * | |
| 183 | - * @return bool | |
| 184 | - */ | |
| 185 | - function edita() | |
| 186 | - { | |
| 187 | - if( is_numeric( $this->idesco ) ) | |
| 188 | - { | |
| 189 | - $db = new clsBanco(); | |
| 190 | - $set = ""; | |
| 191 | - | |
| 192 | - if( is_string( $this->descricao ) ) | |
| 193 | - { | |
| 194 | - $set .= "{$gruda}descricao = '{$this->descricao}'"; | |
| 195 | - $gruda = ", "; | |
| 196 | - } | |
| 197 | - | |
| 198 | - | |
| 199 | - if( $set ) | |
| 200 | - { | |
| 201 | - $db->Consulta( "UPDATE {$this->_tabela} SET $set WHERE idesco = '{$this->idesco}'" ); | |
| 202 | - return true; | |
| 203 | - } | |
| 204 | - } | |
| 205 | - return false; | |
| 206 | - } | |
| 207 | - | |
| 208 | - /** | |
| 209 | - * Retorna uma lista filtrados de acordo com os parametros | |
| 210 | - * | |
| 211 | - * @return array | |
| 212 | - */ | |
| 213 | - function lista( $int_idesco = null, $str_descricao = null ) | |
| 214 | - { | |
| 215 | - $sql = "SELECT {$this->_campos_lista} FROM {$this->_tabela}"; | |
| 216 | - $filtros = ""; | |
| 217 | - | |
| 218 | - $whereAnd = " WHERE "; | |
| 219 | - | |
| 220 | - if( is_numeric( $int_idesco ) ) | |
| 221 | - { | |
| 222 | - $filtros .= "{$whereAnd} idesco = '{$int_idesco}'"; | |
| 223 | - $whereAnd = " AND "; | |
| 224 | - } | |
| 225 | - if( is_string( $str_descricao ) ) | |
| 226 | - { | |
| 227 | - $filtros .= "{$whereAnd} descricao ILIKE '%{$str_descricao}%'"; | |
| 228 | - $whereAnd = " AND "; | |
| 229 | - } | |
| 230 | - | |
| 231 | - | |
| 232 | - $db = new clsBanco(); | |
| 233 | - $countCampos = count( explode( ",", $this->_campos_lista ) ); | |
| 234 | - $resultado = array(); | |
| 235 | - | |
| 236 | - $sql .= $filtros . $this->getOrderby() . $this->getLimite(); | |
| 237 | - | |
| 238 | - $this->_total = $db->CampoUnico( "SELECT COUNT(0) FROM {$this->_tabela} {$filtros}" ); | |
| 239 | - | |
| 240 | - $db->Consulta( $sql ); | |
| 241 | - | |
| 242 | - if( $countCampos > 1 ) | |
| 243 | - { | |
| 244 | - while ( $db->ProximoRegistro() ) | |
| 245 | - { | |
| 246 | - $tupla = $db->Tupla(); | |
| 247 | - | |
| 248 | - $tupla["_total"] = $this->_total; | |
| 249 | - $resultado[] = $tupla; | |
| 250 | - } | |
| 251 | - } | |
| 252 | - else | |
| 253 | - { | |
| 254 | - while ( $db->ProximoRegistro() ) | |
| 255 | - { | |
| 256 | - $tupla = $db->Tupla(); | |
| 257 | - $resultado[] = $tupla[$this->_campos_lista]; | |
| 258 | - } | |
| 259 | - } | |
| 260 | - if( count( $resultado ) ) | |
| 261 | - { | |
| 262 | - return $resultado; | |
| 263 | - } | |
| 264 | - return false; | |
| 265 | - } | |
| 266 | - | |
| 267 | - /** | |
| 268 | - * Retorna um array com os dados de um registro | |
| 269 | - * | |
| 270 | - * @return array | |
| 271 | - */ | |
| 272 | - function detalhe() | |
| 273 | - { | |
| 274 | - if( is_numeric( $this->idesco ) ) | |
| 275 | - { | |
| 276 | - $db = new clsBanco(); | |
| 277 | - $db->Consulta( "SELECT {$this->_todos_campos} FROM {$this->_tabela} WHERE idesco = '{$this->idesco}'" ); | |
| 278 | - $db->ProximoRegistro(); | |
| 279 | - return $db->Tupla(); | |
| 280 | - } | |
| 281 | - return false; | |
| 282 | - } | |
| 283 | - | |
| 284 | - /** | |
| 285 | - * Exclui um registro | |
| 286 | - * | |
| 287 | - * @return bool | |
| 288 | - */ | |
| 289 | - function excluir() | |
| 290 | - { | |
| 291 | - if( is_numeric( $this->idesco ) ) | |
| 292 | - { | |
| 293 | - // delete | |
| 294 | - $db = new clsBanco(); | |
| 295 | - $db->Consulta( "DELETE FROM {$this->_tabela} WHERE idesco = '{$this->idesco}'" ); | |
| 296 | - return true; | |
| 297 | - } | |
| 298 | - return false; | |
| 299 | - } | |
| 300 | - | |
| 301 | - /** | |
| 302 | - * Define quais campos da tabela serao selecionados na invocacao do metodo lista | |
| 303 | - * | |
| 304 | - * @return null | |
| 305 | - */ | |
| 306 | - function setCamposLista( $str_campos ) | |
| 307 | - { | |
| 308 | - $this->_campos_lista = $str_campos; | |
| 309 | - } | |
| 310 | - | |
| 311 | - /** | |
| 312 | - * Define que o metodo Lista devera retornoar todos os campos da tabela | |
| 313 | - * | |
| 314 | - * @return null | |
| 315 | - */ | |
| 316 | - function resetCamposLista() | |
| 317 | - { | |
| 318 | - $this->_campos_lista = $this->_todos_campos; | |
| 319 | - } | |
| 320 | - | |
| 321 | - /** | |
| 322 | - * Define limites de retorno para o metodo lista | |
| 323 | - * | |
| 324 | - * @return null | |
| 325 | - */ | |
| 326 | - function setLimite( $intLimiteQtd, $intLimiteOffset = null ) | |
| 327 | - { | |
| 328 | - $this->_limite_quantidade = $intLimiteQtd; | |
| 329 | - $this->_limite_offset = $intLimiteOffset; | |
| 330 | - } | |
| 331 | - | |
| 332 | - /** | |
| 333 | - * Retorna a string com o trecho da query resposavel pelo Limite de registros | |
| 334 | - * | |
| 335 | - * @return string | |
| 336 | - */ | |
| 337 | - function getLimite() | |
| 338 | - { | |
| 339 | - if( is_numeric( $this->_limite_quantidade ) ) | |
| 340 | - { | |
| 341 | - $retorno = " LIMIT {$this->_limite_quantidade}"; | |
| 342 | - if( is_numeric( $this->_limite_offset ) ) | |
| 343 | - { | |
| 344 | - $retorno .= " OFFSET {$this->_limite_offset} "; | |
| 345 | - } | |
| 346 | - return $retorno; | |
| 347 | - } | |
| 348 | - return ""; | |
| 349 | - } | |
| 350 | - | |
| 351 | - /** | |
| 352 | - * Define campo para ser utilizado como ordenacao no metolo lista | |
| 353 | - * | |
| 354 | - * @return null | |
| 355 | - */ | |
| 356 | - function setOrderby( $strNomeCampo ) | |
| 357 | - { | |
| 358 | - // limpa a string de possiveis erros (delete, insert, etc) | |
| 359 | - //$strNomeCampo = eregi_replace(); | |
| 360 | - | |
| 361 | - if( is_string( $strNomeCampo ) && $strNomeCampo ) | |
| 362 | - { | |
| 363 | - $this->_campo_order_by = $strNomeCampo; | |
| 364 | - } | |
| 365 | - } | |
| 366 | - | |
| 367 | - /** | |
| 368 | - * Retorna a string com o trecho da query resposavel pela Ordenacao dos registros | |
| 369 | - * | |
| 370 | - * @return string | |
| 371 | - */ | |
| 372 | - function getOrderby() | |
| 373 | - { | |
| 374 | - if( is_string( $this->_campo_order_by ) ) | |
| 375 | - { | |
| 376 | - return " ORDER BY {$this->_campo_order_by} "; | |
| 377 | - } | |
| 378 | - return ""; | |
| 379 | - } | |
| 380 | - | |
| 381 | -} | |
| 382 | -?> | |
| 383 | 43 | \ No newline at end of file |
| 44 | + var $idesco; | |
| 45 | + var $descricao; | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Armazena o total de resultados obtidos na última chamada ao método lista. | |
| 49 | + * @var int | |
| 50 | + */ | |
| 51 | + var $_total; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Nome do schema. | |
| 55 | + * @var string | |
| 56 | + */ | |
| 57 | + var $_schema; | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Nome da tabela. | |
| 61 | + * @var string | |
| 62 | + */ | |
| 63 | + var $_tabela; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Lista separada por virgula, com os campos que devem ser selecionados na próxima chamado ao método lista. | |
| 67 | + * @var string | |
| 68 | + */ | |
| 69 | + var $_campos_lista; | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * Lista com todos os campos da tabela separados por vírgula, padrão para seleção no método lista. | |
| 73 | + * @var string | |
| 74 | + */ | |
| 75 | + var $_todos_campos; | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Valor que define a quantidade de registros a ser retornada pelo método lista. | |
| 79 | + * @var int | |
| 80 | + */ | |
| 81 | + var $_limite_quantidade; | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Define o valor de offset no retorno dos registros no método lista. | |
| 85 | + * @var int | |
| 86 | + */ | |
| 87 | + var $_limite_offset; | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Define o campo padrão para ser usado como padrão de ordenação no método lista. | |
| 91 | + * @var string | |
| 92 | + */ | |
| 93 | + var $_campo_order_by; | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Construtor (PHP 5). | |
| 97 | + */ | |
| 98 | + function __construct($idesco = NULL, $descricao = NULL) | |
| 99 | + { | |
| 100 | + $db = new clsBanco(); | |
| 101 | + $this->_schema = "cadastro."; | |
| 102 | + $this->_tabela = "{$this->_schema}escolaridade"; | |
| 103 | + | |
| 104 | + $this->_campos_lista = $this->_todos_campos = "idesco, descricao"; | |
| 105 | + | |
| 106 | + if (is_numeric($idesco)) { | |
| 107 | + $this->idesco = $idesco; | |
| 108 | + } | |
| 109 | + if (is_string($descricao)) { | |
| 110 | + $this->descricao = $descricao; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Construtor (PHP 4). | |
| 116 | + */ | |
| 117 | + function clsCadastroEscolaridade( $idesco = null, $descricao = null ) | |
| 118 | + { | |
| 119 | + $db = new clsBanco(); | |
| 120 | + $this->_schema = "cadastro."; | |
| 121 | + $this->_tabela = "{$this->_schema}escolaridade"; | |
| 122 | + | |
| 123 | + $this->_campos_lista = $this->_todos_campos = "idesco, descricao"; | |
| 124 | + | |
| 125 | + if (is_numeric($idesco)) { | |
| 126 | + $this->idesco = $idesco; | |
| 127 | + } | |
| 128 | + if (is_string($descricao)) { | |
| 129 | + $this->descricao = $descricao; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * Cria um novo registro. | |
| 135 | + * @return bool | |
| 136 | + */ | |
| 137 | + function cadastra() | |
| 138 | + { | |
| 139 | + if (is_string($this->descricao)) | |
| 140 | + { | |
| 141 | + $db = new clsBanco(); | |
| 142 | + | |
| 143 | + $campos = ''; | |
| 144 | + $valores = ''; | |
| 145 | + $gruda = ''; | |
| 146 | + | |
| 147 | + $this->idesco = $db->CampoUnico('SELECT MAX(idesco) + 1 | |
| 148 | + FROM cadastro.escolaridade'); | |
| 149 | + | |
| 150 | + if (is_numeric($this->idesco)) { | |
| 151 | + $campos .= "{$gruda}idesco"; | |
| 152 | + $valores .= "{$gruda}'{$this->idesco}'"; | |
| 153 | + $gruda = ", "; | |
| 154 | + } | |
| 155 | + if (is_string($this->descricao)) { | |
| 156 | + $campos .= "{$gruda}descricao"; | |
| 157 | + $valores .= "{$gruda}'{$this->descricao}'"; | |
| 158 | + $gruda = ", "; | |
| 159 | + } | |
| 160 | + | |
| 161 | + $db->Consulta("INSERT INTO {$this->_tabela} ($campos) VALUES($valores)"); | |
| 162 | + return $this->idesco; | |
| 163 | + } | |
| 164 | + | |
| 165 | + return FALSE; | |
| 166 | + } | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * Edita os dados de um registro. | |
| 170 | + * @return bool | |
| 171 | + */ | |
| 172 | + function edita() | |
| 173 | + { | |
| 174 | + if (is_numeric($this->idesco)) { | |
| 175 | + $db = new clsBanco(); | |
| 176 | + $set = ""; | |
| 177 | + | |
| 178 | + if (is_string($this->descricao)) { | |
| 179 | + $set .= "{$gruda}descricao = '{$this->descricao}'"; | |
| 180 | + $gruda = ", "; | |
| 181 | + } | |
| 182 | + | |
| 183 | + if ($set) { | |
| 184 | + $db->Consulta("UPDATE {$this->_tabela} SET $set WHERE idesco = '{$this->idesco}'"); | |
| 185 | + return TRUE; | |
| 186 | + } | |
| 187 | + } | |
| 188 | + | |
| 189 | + return FALSE; | |
| 190 | + } | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * Retorna uma lista de registros filtrados de acordo com os parâmetros. | |
| 194 | + * @return array | |
| 195 | + */ | |
| 196 | + function lista($int_idesco = NULL, $str_descricao = NULL) { | |
| 197 | + $sql = "SELECT {$this->_campos_lista} FROM {$this->_tabela}"; | |
| 198 | + $filtros = ""; | |
| 199 | + | |
| 200 | + $whereAnd = " WHERE "; | |
| 201 | + | |
| 202 | + if (is_numeric($int_idesco)) { | |
| 203 | + $filtros .= "{$whereAnd} idesco = '{$int_idesco}'"; | |
| 204 | + $whereAnd = " AND "; | |
| 205 | + } | |
| 206 | + if (is_string($str_descricao)) { | |
| 207 | + $filtros .= "{$whereAnd} descricao ILIKE '%{$str_descricao}%'"; | |
| 208 | + $whereAnd = " AND "; | |
| 209 | + } | |
| 210 | + | |
| 211 | + $db = new clsBanco(); | |
| 212 | + $countCampos = count(explode(",", $this->_campos_lista)); | |
| 213 | + $resultado = array(); | |
| 214 | + | |
| 215 | + $sql .= $filtros . $this->getOrderby() . $this->getLimite(); | |
| 216 | + | |
| 217 | + $this->_total = $db->CampoUnico("SELECT COUNT(0) FROM {$this->_tabela} {$filtros}"); | |
| 218 | + | |
| 219 | + $db->Consulta($sql); | |
| 220 | + | |
| 221 | + if ($countCampos > 1) { | |
| 222 | + while ($db->ProximoRegistro()) { | |
| 223 | + $tupla = $db->Tupla(); | |
| 224 | + | |
| 225 | + $tupla["_total"] = $this->_total; | |
| 226 | + $resultado[] = $tupla; | |
| 227 | + } | |
| 228 | + } | |
| 229 | + else { | |
| 230 | + while ($db->ProximoRegistro()) { | |
| 231 | + $tupla = $db->Tupla(); | |
| 232 | + $resultado[] = $tupla[$this->_campos_lista]; | |
| 233 | + } | |
| 234 | + } | |
| 235 | + if (count($resultado)) { | |
| 236 | + return $resultado; | |
| 237 | + } | |
| 238 | + | |
| 239 | + return FALSE; | |
| 240 | + } | |
| 241 | + | |
| 242 | + /** | |
| 243 | + * Retorna um array com os dados de um registro. | |
| 244 | + * @return array | |
| 245 | + */ | |
| 246 | + function detalhe() | |
| 247 | + { | |
| 248 | + if (is_numeric($this->idesco)) { | |
| 249 | + $db = new clsBanco(); | |
| 250 | + $db->Consulta("SELECT {$this->_todos_campos} FROM {$this->_tabela} WHERE idesco = '{$this->idesco}'"); | |
| 251 | + $db->ProximoRegistro(); | |
| 252 | + | |
| 253 | + return $db->Tupla(); | |
| 254 | + } | |
| 255 | + | |
| 256 | + return FALSE; | |
| 257 | + } | |
| 258 | + | |
| 259 | + /** | |
| 260 | + * Exclui um registro. | |
| 261 | + * @return bool | |
| 262 | + */ | |
| 263 | + function excluir() | |
| 264 | + { | |
| 265 | + if (is_numeric($this->idesco)) { | |
| 266 | + $db = new clsBanco(); | |
| 267 | + $db->Consulta("DELETE FROM {$this->_tabela} WHERE idesco = '{$this->idesco}'"); | |
| 268 | + | |
| 269 | + return TRUE; | |
| 270 | + } | |
| 271 | + | |
| 272 | + return FALSE; | |
| 273 | + } | |
| 274 | + | |
| 275 | + /** | |
| 276 | + * Define quais campos da tabela serão selecionados na invocação do método lista. | |
| 277 | + * @return null | |
| 278 | + */ | |
| 279 | + function setCamposLista($str_campos) { | |
| 280 | + $this->_campos_lista = $str_campos; | |
| 281 | + } | |
| 282 | + | |
| 283 | + /** | |
| 284 | + * Define que o método Lista deverá retornoar todos os campos da tabela. | |
| 285 | + * @return null | |
| 286 | + */ | |
| 287 | + function resetCamposLista() { | |
| 288 | + $this->_campos_lista = $this->_todos_campos; | |
| 289 | + } | |
| 290 | + | |
| 291 | + /** | |
| 292 | + * Define limites de retorno para o método lista. | |
| 293 | + * @return null | |
| 294 | + */ | |
| 295 | + function setLimite($intLimiteQtd, $intLimiteOffset = NULL) | |
| 296 | + { | |
| 297 | + $this->_limite_quantidade = $intLimiteQtd; | |
| 298 | + $this->_limite_offset = $intLimiteOffset; | |
| 299 | + } | |
| 300 | + | |
| 301 | + /** | |
| 302 | + * Retorna a string com o trecho da query resposável pelo limite de registros. | |
| 303 | + * @return string | |
| 304 | + */ | |
| 305 | + function getLimite() | |
| 306 | + { | |
| 307 | + if (is_numeric($this->_limite_quantidade)) { | |
| 308 | + $retorno = " LIMIT {$this->_limite_quantidade}"; | |
| 309 | + | |
| 310 | + if (is_numeric($this->_limite_offset)) { | |
| 311 | + $retorno .= " OFFSET {$this->_limite_offset} "; | |
| 312 | + } | |
| 313 | + | |
| 314 | + return $retorno; | |
| 315 | + } | |
| 316 | + | |
| 317 | + return ''; | |
| 318 | + } | |
| 319 | + | |
| 320 | + /** | |
| 321 | + * Define campo para ser utilizado como ordenação no método lista. | |
| 322 | + * @return null | |
| 323 | + */ | |
| 324 | + function setOrderby($strNomeCampo) | |
| 325 | + { | |
| 326 | + if (is_string($strNomeCampo) && $strNomeCampo) { | |
| 327 | + $this->_campo_order_by = $strNomeCampo; | |
| 328 | + } | |
| 329 | + } | |
| 330 | + | |
| 331 | + /** | |
| 332 | + * Retorna a string com o trecho da query resposável pela ordenação dos registros. | |
| 333 | + * @return string | |
| 334 | + */ | |
| 335 | + function getOrderby() | |
| 336 | + { | |
| 337 | + if (is_string($this->_campo_order_by)) { | |
| 338 | + return " ORDER BY {$this->_campo_order_by} "; | |
| 339 | + } | |
| 340 | + | |
| 341 | + return ''; | |
| 342 | + } | |
| 343 | +} | |
| 384 | 344 | \ No newline at end of file | ... | ... |