Commit 23fef5795165a2bbe4ce59e024c5bc3ba73ae0c0
1 parent
c0d931e2
Exists in
master
Refactoring para coding standards
Showing
1 changed file
with
735 additions
and
747 deletions
Show diff stats
ieducar/intranet/include/public/clsPublicBairro.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 | -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
27 | -/** | |
28 | -* @author Prefeitura Municipal de Itajaí | |
29 | -* | |
30 | -* Criado em 12/02/2007 15:36 pelo gerador automatico de classes | |
31 | -*/ | |
32 | 2 | |
33 | -require_once( "include/public/geral.inc.php" ); | |
3 | +/** | |
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 | + * @category i-Educar | |
25 | + * @license @@license@@ | |
26 | + * @package iEd_Public | |
27 | + * @since Arquivo disponível desde a versão 1.0.0 | |
28 | + * @version $Id$ | |
29 | + */ | |
30 | + | |
31 | +require_once 'include/public/geral.inc.php'; | |
34 | 32 | |
33 | +/** | |
34 | + * clsPublicBairro class. | |
35 | + * | |
36 | + * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br> | |
37 | + * @category i-Educar | |
38 | + * @license @@license@@ | |
39 | + * @package iEd_Public | |
40 | + * @since Classe disponível desde a versão 1.0.0 | |
41 | + * @version @@package_version@@ | |
42 | + */ | |
35 | 43 | class clsPublicBairro |
36 | 44 | { |
37 | - var $idmun; | |
38 | - var $geom; | |
39 | - var $idbai; | |
40 | - var $nome; | |
41 | - var $idpes_rev; | |
42 | - var $data_rev; | |
43 | - var $origem_gravacao; | |
44 | - var $idpes_cad; | |
45 | - var $data_cad; | |
46 | - var $operacao; | |
47 | - var $idsis_rev; | |
48 | - var $idsis_cad; | |
49 | - | |
50 | - // propriedades padrao | |
51 | - | |
52 | - /** | |
53 | - * Armazena o total de resultados obtidos na ultima chamada ao metodo lista | |
54 | - * | |
55 | - * @var int | |
56 | - */ | |
57 | - var $_total; | |
58 | - | |
59 | - /** | |
60 | - * Nome do schema | |
61 | - * | |
62 | - * @var string | |
63 | - */ | |
64 | - var $_schema; | |
65 | - | |
66 | - /** | |
67 | - * Nome da tabela | |
68 | - * | |
69 | - * @var string | |
70 | - */ | |
71 | - var $_tabela; | |
72 | - | |
73 | - /** | |
74 | - * Lista separada por virgula, com os campos que devem ser selecionados na proxima chamado ao metodo lista | |
75 | - * | |
76 | - * @var string | |
77 | - */ | |
78 | - var $_campos_lista; | |
79 | - | |
80 | - /** | |
81 | - * Lista com todos os campos da tabela separados por virgula, padrao para selecao no metodo lista | |
82 | - * | |
83 | - * @var string | |
84 | - */ | |
85 | - var $_todos_campos; | |
86 | - | |
87 | - /** | |
88 | - * Valor que define a quantidade de registros a ser retornada pelo metodo lista | |
89 | - * | |
90 | - * @var int | |
91 | - */ | |
92 | - var $_limite_quantidade; | |
93 | - | |
94 | - /** | |
95 | - * Define o valor de offset no retorno dos registros no metodo lista | |
96 | - * | |
97 | - * @var int | |
98 | - */ | |
99 | - var $_limite_offset; | |
100 | - | |
101 | - /** | |
102 | - * Define o campo padrao para ser usado como padrao de ordenacao no metodo lista | |
103 | - * | |
104 | - * @var string | |
105 | - */ | |
106 | - var $_campo_order_by; | |
107 | - | |
108 | - | |
109 | - /** | |
110 | - * Construtor (PHP 4) | |
111 | - * | |
112 | - * @param integer idmun | |
113 | - * @param string geom | |
114 | - * @param integer idbai | |
115 | - * @param string nome | |
116 | - * @param integer idpes_rev | |
117 | - * @param string data_rev | |
118 | - * @param string origem_gravacao | |
119 | - * @param integer idpes_cad | |
120 | - * @param string data_cad | |
121 | - * @param string operacao | |
122 | - * @param integer idsis_rev | |
123 | - * @param integer idsis_cad | |
124 | - * | |
125 | - * @return object | |
126 | - */ | |
127 | - function clsPublicBairro( $idmun = null, $geom = null, $idbai = null, $nome = null, $idpes_rev = null, $data_rev = null, $origem_gravacao = null, $idpes_cad = null, $data_cad = null, $operacao = null, $idsis_rev = null, $idsis_cad = null ) | |
128 | - { | |
129 | - $db = new clsBanco(); | |
130 | - $this->_schema = "public."; | |
131 | - $this->_tabela = "{$this->_schema}bairro"; | |
132 | - | |
133 | - $this->_campos_lista = $this->_todos_campos = "b.idmun, b.geom, b.idbai, b.nome, b.idpes_rev, b.data_rev, b.origem_gravacao, b.idpes_cad, b.data_cad, b.operacao, b.idsis_rev, b.idsis_cad"; | |
134 | - | |
135 | - if( is_numeric( $idsis_rev ) ) | |
136 | - { | |
137 | - if( class_exists( "clsAcessoSistema" ) ) | |
138 | - { | |
139 | - $tmp_obj = new clsAcessoSistema( $idsis_rev ); | |
140 | - if( method_exists( $tmp_obj, "existe") ) | |
141 | - { | |
142 | - if( $tmp_obj->existe() ) | |
143 | - { | |
144 | - $this->idsis_rev = $idsis_rev; | |
145 | - } | |
146 | - } | |
147 | - else if( method_exists( $tmp_obj, "detalhe") ) | |
148 | - { | |
149 | - if( $tmp_obj->detalhe() ) | |
150 | - { | |
151 | - $this->idsis_rev = $idsis_rev; | |
152 | - } | |
153 | - } | |
154 | - } | |
155 | - else | |
156 | - { | |
157 | - if( $db->CampoUnico( "SELECT 1 FROM acesso.sistema WHERE idsis = '{$idsis_rev}'" ) ) | |
158 | - { | |
159 | - $this->idsis_rev = $idsis_rev; | |
160 | - } | |
161 | - } | |
162 | - } | |
163 | - if( is_numeric( $idsis_cad ) ) | |
164 | - { | |
165 | - if( class_exists( "clsAcessoSistema" ) ) | |
166 | - { | |
167 | - $tmp_obj = new clsAcessoSistema( $idsis_cad ); | |
168 | - if( method_exists( $tmp_obj, "existe") ) | |
169 | - { | |
170 | - if( $tmp_obj->existe() ) | |
171 | - { | |
172 | - $this->idsis_cad = $idsis_cad; | |
173 | - } | |
174 | - } | |
175 | - else if( method_exists( $tmp_obj, "detalhe") ) | |
176 | - { | |
177 | - if( $tmp_obj->detalhe() ) | |
178 | - { | |
179 | - $this->idsis_cad = $idsis_cad; | |
180 | - } | |
181 | - } | |
182 | - } | |
183 | - else | |
184 | - { | |
185 | - if( $db->CampoUnico( "SELECT 1 FROM acesso.sistema WHERE idsis = '{$idsis_cad}'" ) ) | |
186 | - { | |
187 | - $this->idsis_cad = $idsis_cad; | |
188 | - } | |
189 | - } | |
190 | - } | |
191 | - if( is_numeric( $idpes_rev ) ) | |
192 | - { | |
193 | - if( class_exists( "clsCadastroPessoa" ) ) | |
194 | - { | |
195 | - $tmp_obj = new clsCadastroPessoa( $idpes_rev ); | |
196 | - if( method_exists( $tmp_obj, "existe") ) | |
197 | - { | |
198 | - if( $tmp_obj->existe() ) | |
199 | - { | |
200 | - $this->idpes_rev = $idpes_rev; | |
201 | - } | |
202 | - } | |
203 | - else if( method_exists( $tmp_obj, "detalhe") ) | |
204 | - { | |
205 | - if( $tmp_obj->detalhe() ) | |
206 | - { | |
207 | - $this->idpes_rev = $idpes_rev; | |
208 | - } | |
209 | - } | |
210 | - } | |
211 | - else | |
212 | - { | |
213 | - if( $db->CampoUnico( "SELECT 1 FROM cadastro.pessoa WHERE idpes = '{$idpes_rev}'" ) ) | |
214 | - { | |
215 | - $this->idpes_rev = $idpes_rev; | |
216 | - } | |
217 | - } | |
218 | - } | |
219 | - if( is_numeric( $idpes_cad ) ) | |
220 | - { | |
221 | - if( class_exists( "clsCadastroPessoa" ) ) | |
222 | - { | |
223 | - $tmp_obj = new clsCadastroPessoa( $idpes_cad ); | |
224 | - if( method_exists( $tmp_obj, "existe") ) | |
225 | - { | |
226 | - if( $tmp_obj->existe() ) | |
227 | - { | |
228 | - $this->idpes_cad = $idpes_cad; | |
229 | - } | |
230 | - } | |
231 | - else if( method_exists( $tmp_obj, "detalhe") ) | |
232 | - { | |
233 | - if( $tmp_obj->detalhe() ) | |
234 | - { | |
235 | - $this->idpes_cad = $idpes_cad; | |
236 | - } | |
237 | - } | |
238 | - } | |
239 | - else | |
240 | - { | |
241 | - if( $db->CampoUnico( "SELECT 1 FROM cadastro.pessoa WHERE idpes = '{$idpes_cad}'" ) ) | |
242 | - { | |
243 | - $this->idpes_cad = $idpes_cad; | |
244 | - } | |
245 | - } | |
246 | - } | |
247 | - if( is_numeric( $idmun ) ) | |
248 | - { | |
249 | - if( class_exists( "clsMunicipio" ) ) | |
250 | - { | |
251 | - $tmp_obj = new clsMunicipio( $idmun ); | |
252 | - if( method_exists( $tmp_obj, "existe") ) | |
253 | - { | |
254 | - if( $tmp_obj->existe() ) | |
255 | - { | |
256 | - $this->idmun = $idmun; | |
257 | - } | |
258 | - } | |
259 | - else if( method_exists( $tmp_obj, "detalhe") ) | |
260 | - { | |
261 | - if( $tmp_obj->detalhe() ) | |
262 | - { | |
263 | - $this->idmun = $idmun; | |
264 | - } | |
265 | - } | |
266 | - } | |
267 | - else | |
268 | - { | |
269 | - if( $db->CampoUnico( "SELECT 1 FROM municipio WHERE idmun = '{$idmun}'" ) ) | |
270 | - { | |
271 | - $this->idmun = $idmun; | |
272 | - } | |
273 | - } | |
274 | - } | |
275 | - | |
276 | - | |
277 | - if( is_string( $geom ) ) | |
278 | - { | |
279 | - $this->geom = $geom; | |
280 | - } | |
281 | - if( is_numeric( $idbai ) ) | |
282 | - { | |
283 | - $this->idbai = $idbai; | |
284 | - } | |
285 | - if( is_string( $nome ) ) | |
286 | - { | |
287 | - $this->nome = $nome; | |
288 | - } | |
289 | - if( is_string( $data_rev ) ) | |
290 | - { | |
291 | - $this->data_rev = $data_rev; | |
292 | - } | |
293 | - if( is_string( $origem_gravacao ) ) | |
294 | - { | |
295 | - $this->origem_gravacao = $origem_gravacao; | |
296 | - } | |
297 | - if( is_string( $data_cad ) ) | |
298 | - { | |
299 | - $this->data_cad = $data_cad; | |
300 | - } | |
301 | - if( is_string( $operacao ) ) | |
302 | - { | |
303 | - $this->operacao = $operacao; | |
304 | - } | |
305 | - | |
306 | - } | |
307 | - | |
308 | - /** | |
309 | - * Cria um novo registro | |
310 | - * | |
311 | - * @return bool | |
312 | - */ | |
313 | - function cadastra() | |
314 | - { | |
315 | - if( is_numeric( $this->idmun ) && is_string( $this->nome ) && is_string( $this->origem_gravacao ) && is_string( $this->operacao ) && is_numeric( $this->idsis_cad ) ) | |
316 | - { | |
317 | - $db = new clsBanco(); | |
318 | - | |
319 | - $campos = ""; | |
320 | - $valores = ""; | |
321 | - $gruda = ""; | |
322 | - | |
323 | - if( is_numeric( $this->idmun ) ) | |
324 | - { | |
325 | - $campos .= "{$gruda}idmun"; | |
326 | - $valores .= "{$gruda}'{$this->idmun}'"; | |
327 | - $gruda = ", "; | |
328 | - } | |
329 | - if( is_string( $this->geom ) ) | |
330 | - { | |
331 | - $campos .= "{$gruda}geom"; | |
332 | - $valores .= "{$gruda}'{$this->geom}'"; | |
333 | - $gruda = ", "; | |
334 | - } | |
335 | - if( is_string( $this->nome ) ) | |
336 | - { | |
337 | - $campos .= "{$gruda}nome"; | |
338 | - $valores .= "{$gruda}'{$this->nome}'"; | |
339 | - $gruda = ", "; | |
340 | - } | |
341 | - if( is_numeric( $this->idpes_rev ) ) | |
342 | - { | |
343 | - $campos .= "{$gruda}idpes_rev"; | |
344 | - $valores .= "{$gruda}'{$this->idpes_rev}'"; | |
345 | - $gruda = ", "; | |
346 | - } | |
347 | - if( is_string( $this->data_rev ) ) | |
348 | - { | |
349 | - $campos .= "{$gruda}data_rev"; | |
350 | - $valores .= "{$gruda}'{$this->data_rev}'"; | |
351 | - $gruda = ", "; | |
352 | - } | |
353 | - if( is_string( $this->origem_gravacao ) ) | |
354 | - { | |
355 | - $campos .= "{$gruda}origem_gravacao"; | |
356 | - $valores .= "{$gruda}'{$this->origem_gravacao}'"; | |
357 | - $gruda = ", "; | |
358 | - } | |
359 | - if( is_numeric( $this->idpes_cad ) ) | |
360 | - { | |
361 | - $campos .= "{$gruda}idpes_cad"; | |
362 | - $valores .= "{$gruda}'{$this->idpes_cad}'"; | |
363 | - $gruda = ", "; | |
364 | - } | |
365 | - $campos .= "{$gruda}data_cad"; | |
366 | - $valores .= "{$gruda}NOW()"; | |
367 | - $gruda = ", "; | |
368 | - if( is_string( $this->operacao ) ) | |
369 | - { | |
370 | - $campos .= "{$gruda}operacao"; | |
371 | - $valores .= "{$gruda}'{$this->operacao}'"; | |
372 | - $gruda = ", "; | |
373 | - } | |
374 | - if( is_numeric( $this->idsis_rev ) ) | |
375 | - { | |
376 | - $campos .= "{$gruda}idsis_rev"; | |
377 | - $valores .= "{$gruda}'{$this->idsis_rev}'"; | |
378 | - $gruda = ", "; | |
379 | - } | |
380 | - if( is_numeric( $this->idsis_cad ) ) | |
381 | - { | |
382 | - $campos .= "{$gruda}idsis_cad"; | |
383 | - $valores .= "{$gruda}'{$this->idsis_cad}'"; | |
384 | - $gruda = ", "; | |
385 | - } | |
386 | - | |
387 | - | |
388 | - $db->Consulta( "INSERT INTO {$this->_tabela} ( $campos ) VALUES( $valores )" ); | |
389 | - return $db->InsertId( "seq_bairro" ); | |
390 | - } | |
391 | - return false; | |
392 | - } | |
393 | - | |
394 | - /** | |
395 | - * Edita os dados de um registro | |
396 | - * | |
397 | - * @return bool | |
398 | - */ | |
399 | - function edita() | |
400 | - { | |
401 | - if( is_numeric( $this->idbai ) ) | |
402 | - { | |
403 | - | |
404 | - $db = new clsBanco(); | |
405 | - $set = ""; | |
406 | - | |
407 | - if( is_numeric( $this->idmun ) ) | |
408 | - { | |
409 | - $set .= "{$gruda}idmun = '{$this->idmun}'"; | |
410 | - $gruda = ", "; | |
411 | - } | |
412 | - if( is_string( $this->geom ) ) | |
413 | - { | |
414 | - $set .= "{$gruda}geom = '{$this->geom}'"; | |
415 | - $gruda = ", "; | |
416 | - } | |
417 | - if( is_string( $this->nome ) ) | |
418 | - { | |
419 | - $set .= "{$gruda}nome = '{$this->nome}'"; | |
420 | - $gruda = ", "; | |
421 | - } | |
422 | - if( is_numeric( $this->idpes_rev ) ) | |
423 | - { | |
424 | - $set .= "{$gruda}idpes_rev = '{$this->idpes_rev}'"; | |
425 | - $gruda = ", "; | |
426 | - } | |
427 | - if( is_string( $this->data_rev ) ) | |
428 | - { | |
429 | - $set .= "{$gruda}data_rev = '{$this->data_rev}'"; | |
430 | - $gruda = ", "; | |
431 | - } | |
432 | - if( is_string( $this->origem_gravacao ) ) | |
433 | - { | |
434 | - $set .= "{$gruda}origem_gravacao = '{$this->origem_gravacao}'"; | |
435 | - $gruda = ", "; | |
436 | - } | |
437 | - if( is_numeric( $this->idpes_cad ) ) | |
438 | - { | |
439 | - $set .= "{$gruda}idpes_cad = '{$this->idpes_cad}'"; | |
440 | - $gruda = ", "; | |
441 | - } | |
442 | - if( is_string( $this->data_cad ) ) | |
443 | - { | |
444 | - $set .= "{$gruda}data_cad = '{$this->data_cad}'"; | |
445 | - $gruda = ", "; | |
446 | - } | |
447 | - if( is_string( $this->operacao ) ) | |
448 | - { | |
449 | - $set .= "{$gruda}operacao = '{$this->operacao}'"; | |
450 | - $gruda = ", "; | |
451 | - } | |
452 | - if( is_numeric( $this->idsis_rev ) ) | |
453 | - { | |
454 | - $set .= "{$gruda}idsis_rev = '{$this->idsis_rev}'"; | |
455 | - $gruda = ", "; | |
456 | - } | |
457 | - if( is_numeric( $this->idsis_cad ) ) | |
458 | - { | |
459 | - $set .= "{$gruda}idsis_cad = '{$this->idsis_cad}'"; | |
460 | - $gruda = ", "; | |
461 | - } | |
462 | - | |
463 | - | |
464 | - if( $set ) | |
465 | - { | |
466 | - $db->Consulta( "UPDATE {$this->_tabela} SET $set WHERE idbai = '{$this->idbai}'" ); | |
467 | - return true; | |
468 | - } | |
469 | - } | |
470 | - return false; | |
471 | - } | |
472 | - | |
473 | - /** | |
474 | - * Retorna uma lista filtrados de acordo com os parametros | |
475 | - * | |
476 | - * @param integer int_idmun | |
477 | - * @param string str_geom | |
478 | - * @param string str_nome | |
479 | - * @param integer int_idpes_rev | |
480 | - * @param string date_data_rev_ini | |
481 | - * @param string date_data_rev_fim | |
482 | - * @param string str_origem_gravacao | |
483 | - * @param integer int_idpes_cad | |
484 | - * @param string date_data_cad_ini | |
485 | - * @param string date_data_cad_fim | |
486 | - * @param string str_operacao | |
487 | - * @param integer int_idsis_rev | |
488 | - * @param integer int_idsis_cad | |
489 | - * | |
490 | - * @return array | |
491 | - */ | |
492 | - function lista( $int_idmun = null, $str_geom = null, $str_nome = null, $int_idpes_rev = null, $date_data_rev_ini = null, $date_data_rev_fim = null, $str_origem_gravacao = null, $int_idpes_cad = null, $date_data_cad_ini = null, $date_data_cad_fim = null, $str_operacao = null, $int_idsis_rev = null, $int_idsis_cad = null, $int_idpais = null, $str_sigla_uf = null, $int_idbai = null ) | |
493 | - { | |
494 | - $select = ", m.nome as nm_municipio, m.sigla_uf, u.nome as nm_estado, u.idpais, p.nome as nm_pais "; | |
495 | - $from = "b, public.municipio m, public.uf u, public.pais p "; | |
496 | - $sql = "SELECT {$this->_campos_lista}{$select} FROM {$this->_tabela} {$from}"; | |
497 | - $whereAnd = " AND "; | |
498 | - | |
499 | - $filtros = " WHERE b.idmun = m.idmun AND m.sigla_uf = u.sigla_uf AND u.idpais = p.idpais "; | |
500 | - | |
501 | - if( is_numeric( $int_idmun ) ) | |
502 | - { | |
503 | - $filtros .= "{$whereAnd} b.idmun = '{$int_idmun}'"; | |
504 | - $whereAnd = " AND "; | |
505 | - } | |
506 | - if( is_string( $str_geom ) ) | |
507 | - { | |
508 | - $filtros .= "{$whereAnd} b.geom LIKE '%{$str_geom}%'"; | |
509 | - $whereAnd = " AND "; | |
510 | - } | |
511 | - if( is_numeric( $int_idbai ) ) | |
512 | - { | |
513 | - $filtros .= "{$whereAnd} b.idbai = '{$int_idbai}'"; | |
514 | - $whereAnd = " AND "; | |
515 | - } | |
516 | - if( is_string( $str_nome ) ) | |
517 | - { | |
518 | - $filtros .= "{$whereAnd} b.nome LIKE '%{$str_nome}%'"; | |
519 | - $whereAnd = " AND "; | |
520 | - } | |
521 | - if( is_numeric( $int_idpes_rev ) ) | |
522 | - { | |
523 | - $filtros .= "{$whereAnd} b.idpes_rev = '{$int_idpes_rev}'"; | |
524 | - $whereAnd = " AND "; | |
525 | - } | |
526 | - if( is_string( $date_data_rev_ini ) ) | |
527 | - { | |
528 | - $filtros .= "{$whereAnd} b.data_rev >= '{$date_data_rev_ini}'"; | |
529 | - $whereAnd = " AND "; | |
530 | - } | |
531 | - if( is_string( $date_data_rev_fim ) ) | |
532 | - { | |
533 | - $filtros .= "{$whereAnd} b.data_rev <= '{$date_data_rev_fim}'"; | |
534 | - $whereAnd = " AND "; | |
535 | - } | |
536 | - if( is_string( $str_origem_gravacao ) ) | |
537 | - { | |
538 | - $filtros .= "{$whereAnd} b.origem_gravacao LIKE '%{$str_origem_gravacao}%'"; | |
539 | - $whereAnd = " AND "; | |
540 | - } | |
541 | - if( is_numeric( $int_idpes_cad ) ) | |
542 | - { | |
543 | - $filtros .= "{$whereAnd} b.idpes_cad = '{$int_idpes_cad}'"; | |
544 | - $whereAnd = " AND "; | |
545 | - } | |
546 | - if( is_string( $date_data_cad_ini ) ) | |
547 | - { | |
548 | - $filtros .= "{$whereAnd} b.data_cad >= '{$date_data_cad_ini}'"; | |
549 | - $whereAnd = " AND "; | |
550 | - } | |
551 | - if( is_string( $date_data_cad_fim ) ) | |
552 | - { | |
553 | - $filtros .= "{$whereAnd} b.data_cad <= '{$date_data_cad_fim}'"; | |
554 | - $whereAnd = " AND "; | |
555 | - } | |
556 | - if( is_string( $str_operacao ) ) | |
557 | - { | |
558 | - $filtros .= "{$whereAnd} b.operacao LIKE '%{$str_operacao}%'"; | |
559 | - $whereAnd = " AND "; | |
560 | - } | |
561 | - if( is_numeric( $int_idsis_rev ) ) | |
562 | - { | |
563 | - $filtros .= "{$whereAnd} b.idsis_rev = '{$int_idsis_rev}'"; | |
564 | - $whereAnd = " AND "; | |
565 | - } | |
566 | - if( is_numeric( $int_idsis_cad ) ) | |
567 | - { | |
568 | - $filtros .= "{$whereAnd} b.idsis_cad = '{$int_idsis_cad}'"; | |
569 | - $whereAnd = " AND "; | |
570 | - } | |
571 | - if( is_numeric( $int_idpais ) ) | |
572 | - { | |
573 | - $filtros .= "{$whereAnd} p.idpais = '{$int_idpais}'"; | |
574 | - $whereAnd = " AND "; | |
575 | - } | |
576 | - if( is_string( $str_sigla_uf ) ) | |
577 | - { | |
578 | - $filtros .= "{$whereAnd} u.sigla_uf = '{$str_sigla_uf}'"; | |
579 | - $whereAnd = " AND "; | |
580 | - } | |
581 | - | |
582 | - | |
583 | - $db = new clsBanco(); | |
584 | - $countCampos = count( explode( ",", $this->_campos_lista ) ); | |
585 | - $resultado = array(); | |
586 | - | |
587 | - $sql .= $filtros . $this->getOrderby() . $this->getLimite(); | |
588 | - | |
589 | - $this->_total = $db->CampoUnico( "SELECT COUNT(0) FROM {$this->_tabela} {$from}{$filtros}" ); | |
590 | - | |
591 | - $db->Consulta( $sql ); | |
592 | - | |
593 | - if( $countCampos > 1 ) | |
594 | - { | |
595 | - while ( $db->ProximoRegistro() ) | |
596 | - { | |
597 | - $tupla = $db->Tupla(); | |
598 | - | |
599 | - $tupla["_total"] = $this->_total; | |
600 | - $resultado[] = $tupla; | |
601 | - } | |
602 | - } | |
603 | - else | |
604 | - { | |
605 | - while ( $db->ProximoRegistro() ) | |
606 | - { | |
607 | - $tupla = $db->Tupla(); | |
608 | - $resultado[] = $tupla[$this->_campos_lista]; | |
609 | - } | |
610 | - } | |
611 | - if( count( $resultado ) ) | |
612 | - { | |
613 | - return $resultado; | |
614 | - } | |
615 | - return false; | |
616 | - } | |
617 | - | |
618 | - /** | |
619 | - * Retorna um array com os dados de um registro | |
620 | - * | |
621 | - * @return array | |
622 | - */ | |
623 | - function detalhe() | |
624 | - { | |
625 | - if( is_numeric( $this->idbai ) ) | |
626 | - { | |
627 | - $db = new clsBanco(); | |
628 | - $db->Consulta( "SELECT {$this->_todos_campos} FROM {$this->_tabela} b WHERE b.idbai = '{$this->idbai}'" ); | |
629 | - $db->ProximoRegistro(); | |
630 | - return $db->Tupla(); | |
631 | - } | |
632 | - return false; | |
633 | - } | |
634 | - | |
635 | - /** | |
636 | - * Retorna true se o registro existir. Caso contrário retorna false. | |
637 | - * | |
638 | - * @return bool | |
639 | - */ | |
640 | - function existe() | |
641 | - { | |
642 | - if( is_numeric( $this->idbai ) ) | |
643 | - { | |
644 | - $db = new clsBanco(); | |
645 | - $db->Consulta( "SELECT 1 FROM {$this->_tabela} WHERE idbai = '{$this->idbai}'" ); | |
646 | - if( $db->ProximoRegistro() ) | |
647 | - { | |
648 | - return true; | |
649 | - } | |
650 | - } | |
651 | - return false; | |
652 | - } | |
653 | - | |
654 | - /** | |
655 | - * Exclui um registro | |
656 | - * | |
657 | - * @return bool | |
658 | - */ | |
659 | - function excluir() | |
660 | - { | |
661 | - if( is_numeric( $this->idbai ) ) | |
662 | - { | |
663 | -// delete | |
664 | - $db = new clsBanco(); | |
665 | - $db->Consulta( "DELETE FROM {$this->_tabela} WHERE idbai = '{$this->idbai}'" ); | |
666 | - return true; | |
667 | - } | |
668 | - return false; | |
669 | - } | |
670 | - | |
671 | - /** | |
672 | - * Define quais campos da tabela serao selecionados na invocacao do metodo lista | |
673 | - * | |
674 | - * @return null | |
675 | - */ | |
676 | - function setCamposLista( $str_campos ) | |
677 | - { | |
678 | - $this->_campos_lista = $str_campos; | |
679 | - } | |
680 | - | |
681 | - /** | |
682 | - * Define que o metodo Lista devera retornoar todos os campos da tabela | |
683 | - * | |
684 | - * @return null | |
685 | - */ | |
686 | - function resetCamposLista() | |
687 | - { | |
688 | - $this->_campos_lista = $this->_todos_campos; | |
689 | - } | |
690 | - | |
691 | - /** | |
692 | - * Define limites de retorno para o metodo lista | |
693 | - * | |
694 | - * @return null | |
695 | - */ | |
696 | - function setLimite( $intLimiteQtd, $intLimiteOffset = null ) | |
697 | - { | |
698 | - $this->_limite_quantidade = $intLimiteQtd; | |
699 | - $this->_limite_offset = $intLimiteOffset; | |
700 | - } | |
701 | - | |
702 | - /** | |
703 | - * Retorna a string com o trecho da query resposavel pelo Limite de registros | |
704 | - * | |
705 | - * @return string | |
706 | - */ | |
707 | - function getLimite() | |
708 | - { | |
709 | - if( is_numeric( $this->_limite_quantidade ) ) | |
710 | - { | |
711 | - $retorno = " LIMIT {$this->_limite_quantidade}"; | |
712 | - if( is_numeric( $this->_limite_offset ) ) | |
713 | - { | |
714 | - $retorno .= " OFFSET {$this->_limite_offset} "; | |
715 | - } | |
716 | - return $retorno; | |
717 | - } | |
718 | - return ""; | |
719 | - } | |
720 | - | |
721 | - /** | |
722 | - * Define campo para ser utilizado como ordenacao no metolo lista | |
723 | - * | |
724 | - * @return null | |
725 | - */ | |
726 | - function setOrderby( $strNomeCampo ) | |
727 | - { | |
728 | - // limpa a string de possiveis erros (delete, insert, etc) | |
729 | - //$strNomeCampo = eregi_replace(); | |
730 | - | |
731 | - if( is_string( $strNomeCampo ) && $strNomeCampo ) | |
732 | - { | |
733 | - $this->_campo_order_by = $strNomeCampo; | |
734 | - } | |
735 | - } | |
736 | - | |
737 | - /** | |
738 | - * Retorna a string com o trecho da query resposavel pela Ordenacao dos registros | |
739 | - * | |
740 | - * @return string | |
741 | - */ | |
742 | - function getOrderby() | |
743 | - { | |
744 | - if( is_string( $this->_campo_order_by ) ) | |
745 | - { | |
746 | - return " ORDER BY {$this->_campo_order_by} "; | |
747 | - } | |
748 | - return ""; | |
749 | - } | |
750 | - | |
751 | -} | |
752 | -?> | |
753 | 45 | \ No newline at end of file |
46 | + var $idmun; | |
47 | + var $geom; | |
48 | + var $idbai; | |
49 | + var $nome; | |
50 | + var $idpes_rev; | |
51 | + var $data_rev; | |
52 | + var $origem_gravacao; | |
53 | + var $idpes_cad; | |
54 | + var $data_cad; | |
55 | + var $operacao; | |
56 | + var $idsis_rev; | |
57 | + var $idsis_cad; | |
58 | + | |
59 | + /** | |
60 | + * Armazena o total de resultados obtidos na última chamada ao método lista(). | |
61 | + * @var int | |
62 | + */ | |
63 | + var $_total; | |
64 | + | |
65 | + /** | |
66 | + * Nome do schema. | |
67 | + * @var string | |
68 | + */ | |
69 | + var $_schema; | |
70 | + | |
71 | + /** | |
72 | + * Nome da tabela. | |
73 | + * @var string | |
74 | + */ | |
75 | + var $_tabela; | |
76 | + | |
77 | + /** | |
78 | + * Lista separada por vírgula, com os campos que devem ser selecionados na | |
79 | + * próxima chamado ao método lista(). | |
80 | + * @var string | |
81 | + */ | |
82 | + var $_campos_lista; | |
83 | + | |
84 | + /** | |
85 | + * Lista com todos os campos da tabela separados por vírgula, padrão para | |
86 | + * seleção no método lista. | |
87 | + * @var string | |
88 | + */ | |
89 | + var $_todos_campos; | |
90 | + | |
91 | + /** | |
92 | + * Valor que define a quantidade de registros a ser retornada pelo método lista(). | |
93 | + * @var int | |
94 | + */ | |
95 | + var $_limite_quantidade; | |
96 | + | |
97 | + /** | |
98 | + * Define o valor de offset no retorno dos registros no método lista(). | |
99 | + * @var int | |
100 | + */ | |
101 | + var $_limite_offset; | |
102 | + | |
103 | + /** | |
104 | + * Define o campo para ser usado como padrão de ordenação no método lista(). | |
105 | + * @var string | |
106 | + */ | |
107 | + var $_campo_order_by; | |
108 | + | |
109 | + /** | |
110 | + * Construtor. | |
111 | + * | |
112 | + * @param integer $idmun | |
113 | + * @param string $geom | |
114 | + * @param integer $idbai | |
115 | + * @param string $nome | |
116 | + * @param integer $idpes_rev | |
117 | + * @param string $data_rev | |
118 | + * @param string $origem_gravacao | |
119 | + * @param integer $idpes_cad | |
120 | + * @param string $data_cad | |
121 | + * @param string $operacao | |
122 | + * @param integer $idsis_rev | |
123 | + * @param integer $idsis_cad | |
124 | + * | |
125 | + * @return object | |
126 | + */ | |
127 | + function clsPublicBairro($idmun = NULL, $geom = NULL, $idbai = NULL, | |
128 | + $nome = NULL, $idpes_rev = NULL, $data_rev = NULL, $origem_gravacao = NULL, | |
129 | + $idpes_cad = NULL, $data_cad = NULL, $operacao = NULL, $idsis_rev = NULL, | |
130 | + $idsis_cad = NULL) | |
131 | + { | |
132 | + $db = new clsBanco(); | |
133 | + $this->_schema = 'public.'; | |
134 | + $this->_tabela = $this->_schema . 'bairro'; | |
135 | + | |
136 | + $this->_campos_lista = $this->_todos_campos = 'b.idmun, b.geom, b.idbai, ' . | |
137 | + 'b.nome, b.idpes_rev, b.data_rev, b.origem_gravacao, b.idpes_cad, ' . | |
138 | + 'b.data_cad, b.operacao, b.idsis_rev, b.idsis_cad'; | |
139 | + | |
140 | + if (is_numeric($idsis_rev)) { | |
141 | + if (class_exists('clsAcessoSistema')) { | |
142 | + $tmp_obj = new clsAcessoSistema($idsis_rev); | |
143 | + | |
144 | + if (method_exists($tmp_obj, 'existe')) { | |
145 | + if ($tmp_obj->existe()) { | |
146 | + $this->idsis_rev = $idsis_rev; | |
147 | + } | |
148 | + } | |
149 | + elseif (method_exists($tmp_obj, 'detalhe')) { | |
150 | + if ($tmp_obj->detalhe()) { | |
151 | + $this->idsis_rev = $idsis_rev; | |
152 | + } | |
153 | + } | |
154 | + } | |
155 | + else { | |
156 | + if ($db->CampoUnico(sprintf( | |
157 | + 'SELECT 1 FROM acesso.sistema WHERE idsis = \'%d\'', $idsis_rev | |
158 | + ))) { | |
159 | + $this->idsis_rev = $idsis_rev; | |
160 | + } | |
161 | + } | |
162 | + } | |
163 | + | |
164 | + if (is_numeric($idsis_cad)) { | |
165 | + if (class_exists('clsAcessoSistema')) { | |
166 | + $tmp_obj = new clsAcessoSistema($idsis_cad); | |
167 | + | |
168 | + if (method_exists($tmp_obj, 'existe')) { | |
169 | + if ($tmp_obj->existe()) { | |
170 | + $this->idsis_cad = $idsis_cad; | |
171 | + } | |
172 | + } | |
173 | + elseif (method_exists($tmp_obj, 'detalhe')) { | |
174 | + if ($tmp_obj->detalhe()) { | |
175 | + $this->idsis_cad = $idsis_cad; | |
176 | + } | |
177 | + } | |
178 | + } | |
179 | + else { | |
180 | + if ($db->CampoUnico(sprintf( | |
181 | + 'SELECT 1 FROM acesso.sistema WHERE idsis = \'%d\'', $idsis_cad | |
182 | + ))) { | |
183 | + $this->idsis_cad = $idsis_cad; | |
184 | + } | |
185 | + } | |
186 | + } | |
187 | + | |
188 | + if (is_numeric($idpes_rev)) { | |
189 | + if (class_exists('clsCadastroPessoa')) { | |
190 | + $tmp_obj = new clsCadastroPessoa($idpes_rev); | |
191 | + | |
192 | + if (method_exists($tmp_obj, 'existe')) { | |
193 | + if($tmp_obj->existe()) { | |
194 | + $this->idpes_rev = $idpes_rev; | |
195 | + } | |
196 | + } | |
197 | + elseif (method_exists($tmp_obj, 'detalhe')) { | |
198 | + if ($tmp_obj->detalhe()) { | |
199 | + $this->idpes_rev = $idpes_rev; | |
200 | + } | |
201 | + } | |
202 | + } | |
203 | + else { | |
204 | + if ($db->CampoUnico(sprintf( | |
205 | + 'SELECT 1 FROM cadastro.pessoa WHERE idpes = \'%d\'', $idpes_rev | |
206 | + ))) { | |
207 | + $this->idpes_rev = $idpes_rev; | |
208 | + } | |
209 | + } | |
210 | + } | |
211 | + | |
212 | + if (is_numeric($idpes_cad)) { | |
213 | + if (class_exists('clsCadastroPessoa')) { | |
214 | + $tmp_obj = new clsCadastroPessoa($idpes_cad); | |
215 | + | |
216 | + if (method_exists($tmp_obj, 'existe')) { | |
217 | + if ($tmp_obj->existe()) { | |
218 | + $this->idpes_cad = $idpes_cad; | |
219 | + } | |
220 | + } | |
221 | + elseif (method_exists($tmp_obj, 'detalhe')) { | |
222 | + if ($tmp_obj->detalhe()) { | |
223 | + $this->idpes_cad = $idpes_cad; | |
224 | + } | |
225 | + } | |
226 | + } | |
227 | + else { | |
228 | + if ($db->CampoUnico(sprintf( | |
229 | + 'SELECT 1 FROM cadastro.pessoa WHERE idpes = \'%d\'', $idpes_cad | |
230 | + ))) { | |
231 | + $this->idpes_cad = $idpes_cad; | |
232 | + } | |
233 | + } | |
234 | + } | |
235 | + | |
236 | + if (is_numeric($idmun)) { | |
237 | + if (class_exists('clsMunicipio')) { | |
238 | + $tmp_obj = new clsMunicipio($idmun); | |
239 | + | |
240 | + if (method_exists($tmp_obj, 'existe')) { | |
241 | + if ($tmp_obj->existe()) { | |
242 | + $this->idmun = $idmun; | |
243 | + } | |
244 | + } | |
245 | + elseif (method_exists($tmp_obj, 'detalhe')) { | |
246 | + if ($tmp_obj->detalhe()) { | |
247 | + $this->idmun = $idmun; | |
248 | + } | |
249 | + } | |
250 | + } | |
251 | + else { | |
252 | + if ($db->CampoUnico(sprintf( | |
253 | + 'SELECT 1 FROM municipio WHERE idmun = \'%d\'', $idmun | |
254 | + ))) { | |
255 | + $this->idmun = $idmun; | |
256 | + } | |
257 | + } | |
258 | + } | |
259 | + | |
260 | + if (is_string($geom)) { | |
261 | + $this->geom = $geom; | |
262 | + } | |
263 | + | |
264 | + if (is_numeric($idbai)) { | |
265 | + $this->idbai = $idbai; | |
266 | + } | |
267 | + | |
268 | + if (is_string($nome)) { | |
269 | + $this->nome = $nome; | |
270 | + } | |
271 | + | |
272 | + if (is_string($data_rev)) { | |
273 | + $this->data_rev = $data_rev; | |
274 | + } | |
275 | + | |
276 | + if (is_string($origem_gravacao)) { | |
277 | + $this->origem_gravacao = $origem_gravacao; | |
278 | + } | |
279 | + | |
280 | + if (is_string($data_cad)) { | |
281 | + $this->data_cad = $data_cad; | |
282 | + } | |
283 | + | |
284 | + if (is_string($operacao)) { | |
285 | + $this->operacao = $operacao; | |
286 | + } | |
287 | + } | |
288 | + | |
289 | + /** | |
290 | + * Cria um novo registro. | |
291 | + * @return bool | |
292 | + */ | |
293 | + function cadastra() | |
294 | + { | |
295 | + if (is_numeric($this->idmun) && is_string($this->nome) && | |
296 | + is_string($this->origem_gravacao) && is_string($this->operacao) && | |
297 | + is_numeric($this->idsis_cad) | |
298 | + ) { | |
299 | + $db = new clsBanco(); | |
300 | + | |
301 | + $campos = ''; | |
302 | + $valores = ''; | |
303 | + $gruda = ''; | |
304 | + | |
305 | + if (is_numeric($this->idmun)) { | |
306 | + $campos .= "{$gruda}idmun"; | |
307 | + $valores .= "{$gruda}'{$this->idmun}'"; | |
308 | + $gruda = ', '; | |
309 | + } | |
310 | + | |
311 | + if (is_string($this->geom)) { | |
312 | + $campos .= "{$gruda}geom"; | |
313 | + $valores .= "{$gruda}'{$this->geom}'"; | |
314 | + $gruda = ', '; | |
315 | + } | |
316 | + | |
317 | + if (is_string($this->nome)) { | |
318 | + $campos .= "{$gruda}nome"; | |
319 | + $valores .= "{$gruda}'{$this->nome}'"; | |
320 | + $gruda = ', '; | |
321 | + } | |
322 | + | |
323 | + if (is_numeric($this->idpes_rev)) { | |
324 | + $campos .= "{$gruda}idpes_rev"; | |
325 | + $valores .= "{$gruda}'{$this->idpes_rev}'"; | |
326 | + $gruda = ', '; | |
327 | + } | |
328 | + | |
329 | + if (is_string( $this->data_rev)) { | |
330 | + $campos .= "{$gruda}data_rev"; | |
331 | + $valores .= "{$gruda}'{$this->data_rev}'"; | |
332 | + $gruda = ', '; | |
333 | + } | |
334 | + | |
335 | + if (is_string($this->origem_gravacao)) { | |
336 | + $campos .= "{$gruda}origem_gravacao"; | |
337 | + $valores .= "{$gruda}'{$this->origem_gravacao}'"; | |
338 | + $gruda = ', '; | |
339 | + } | |
340 | + | |
341 | + if (is_numeric($this->idpes_cad)) { | |
342 | + $campos .= "{$gruda}idpes_cad"; | |
343 | + $valores .= "{$gruda}'{$this->idpes_cad}'"; | |
344 | + $gruda = ', '; | |
345 | + } | |
346 | + | |
347 | + $campos .= "{$gruda}data_cad"; | |
348 | + $valores .= "{$gruda}NOW()"; | |
349 | + $gruda = ', '; | |
350 | + | |
351 | + if (is_string($this->operacao)) { | |
352 | + $campos .= "{$gruda}operacao"; | |
353 | + $valores .= "{$gruda}'{$this->operacao}'"; | |
354 | + $gruda = ', '; | |
355 | + } | |
356 | + | |
357 | + if (is_numeric($this->idsis_rev)) { | |
358 | + $campos .= "{$gruda}idsis_rev"; | |
359 | + $valores .= "{$gruda}'{$this->idsis_rev}'"; | |
360 | + $gruda = ', '; | |
361 | + } | |
362 | + | |
363 | + if (is_numeric($this->idsis_cad)) { | |
364 | + $campos .= "{$gruda}idsis_cad"; | |
365 | + $valores .= "{$gruda}'{$this->idsis_cad}'"; | |
366 | + $gruda = ', '; | |
367 | + } | |
368 | + | |
369 | + $db->Consulta(sprintf( | |
370 | + "INSERT INTO %s (%s) VALUES (%s)", | |
371 | + $this->_tabela, $campos, $valores | |
372 | + )); | |
373 | + | |
374 | + return $db->InsertId('seq_bairro'); | |
375 | + } | |
376 | + | |
377 | + return FALSE; | |
378 | + } | |
379 | + | |
380 | + /** | |
381 | + * Edita os dados de um registro. | |
382 | + * @return bool | |
383 | + */ | |
384 | + function edita() | |
385 | + { | |
386 | + if (is_numeric($this->idbai)) { | |
387 | + $db = new clsBanco(); | |
388 | + $set = ''; | |
389 | + | |
390 | + if (is_numeric($this->idmun)) { | |
391 | + $set .= "{$gruda}idmun = '{$this->idmun}'"; | |
392 | + $gruda = ', '; | |
393 | + } | |
394 | + | |
395 | + if (is_string($this->geom)) { | |
396 | + $set .= "{$gruda}geom = '{$this->geom}'"; | |
397 | + $gruda = ', '; | |
398 | + } | |
399 | + | |
400 | + if (is_string($this->nome)) { | |
401 | + $set .= "{$gruda}nome = '{$this->nome}'"; | |
402 | + $gruda = ', '; | |
403 | + } | |
404 | + | |
405 | + if (is_numeric($this->idpes_rev)) { | |
406 | + $set .= "{$gruda}idpes_rev = '{$this->idpes_rev}'"; | |
407 | + $gruda = ', '; | |
408 | + } | |
409 | + | |
410 | + if (is_string($this->data_rev)) { | |
411 | + $set .= "{$gruda}data_rev = '{$this->data_rev}'"; | |
412 | + $gruda = ', '; | |
413 | + } | |
414 | + | |
415 | + if (is_string($this->origem_gravacao)) { | |
416 | + $set .= "{$gruda}origem_gravacao = '{$this->origem_gravacao}'"; | |
417 | + $gruda = ', '; | |
418 | + } | |
419 | + | |
420 | + if (is_numeric($this->idpes_cad)) { | |
421 | + $set .= "{$gruda}idpes_cad = '{$this->idpes_cad}'"; | |
422 | + $gruda = ', '; | |
423 | + } | |
424 | + | |
425 | + if (is_string($this->data_cad)) { | |
426 | + $set .= "{$gruda}data_cad = '{$this->data_cad}'"; | |
427 | + $gruda = ', '; | |
428 | + } | |
429 | + | |
430 | + if (is_string($this->operacao)) { | |
431 | + $set .= "{$gruda}operacao = '{$this->operacao}'"; | |
432 | + $gruda = ', '; | |
433 | + } | |
434 | + | |
435 | + if (is_numeric($this->idsis_rev)) { | |
436 | + $set .= "{$gruda}idsis_rev = '{$this->idsis_rev}'"; | |
437 | + $gruda = ', '; | |
438 | + } | |
439 | + | |
440 | + if (is_numeric($this->idsis_cad)) { | |
441 | + $set .= "{$gruda}idsis_cad = '{$this->idsis_cad}'"; | |
442 | + $gruda = ', '; | |
443 | + } | |
444 | + | |
445 | + if ($set) { | |
446 | + $db->Consulta(sprintf( | |
447 | + 'UPDATE %s SET %s WHERE idbai = \'%d\'', | |
448 | + $this->_tabela, $set, $this->idbai | |
449 | + )); | |
450 | + | |
451 | + return TRUE; | |
452 | + } | |
453 | + } | |
454 | + | |
455 | + return FALSE; | |
456 | + } | |
457 | + | |
458 | + /** | |
459 | + * Retorna uma lista de registros filtrados de acordo com os parâmetros. | |
460 | + * | |
461 | + * @param integer $int_idmun | |
462 | + * @param string $str_geom | |
463 | + * @param string $str_nome | |
464 | + * @param integer $int_idpes_rev | |
465 | + * @param string $date_data_rev_ini | |
466 | + * @param string $date_data_rev_fim | |
467 | + * @param string $str_origem_gravacao | |
468 | + * @param integer $int_idpes_cad | |
469 | + * @param string $date_data_cad_ini | |
470 | + * @param string $date_data_cad_fim | |
471 | + * @param string $str_operacao | |
472 | + * @param integer $int_idsis_rev | |
473 | + * @param integer $int_idsis_cad | |
474 | + * @return array | |
475 | + */ | |
476 | + function lista($int_idmun = NULL, $str_geom = NULL, $str_nome = NULL, | |
477 | + $int_idpes_rev = NULL, $date_data_rev_ini = NULL, $date_data_rev_fim = NULL, | |
478 | + $str_origem_gravacao = NULL, $int_idpes_cad = NULL, $date_data_cad_ini = NULL, | |
479 | + $date_data_cad_fim = NULL, $str_operacao = NULL, $int_idsis_rev = NULL, | |
480 | + $int_idsis_cad = NULL, $int_idpais = NULL, $str_sigla_uf = NULL, $int_idbai = NULL) | |
481 | + { | |
482 | + $select = ', m.nome AS nm_municipio, m.sigla_uf, u.nome AS nm_estado, u.idpais, p.nome AS nm_pais '; | |
483 | + $from = 'b, public.municipio m, public.uf u, public.pais p '; | |
484 | + | |
485 | + $sql = sprintf( | |
486 | + 'SELECT %s %s FROM %s %s', $this->_campos_lista, $select, $this->_tabela, $from | |
487 | + ); | |
488 | + | |
489 | + $whereAnd = ' AND '; | |
490 | + | |
491 | + $filtros = ' WHERE b.idmun = m.idmun AND m.sigla_uf = u.sigla_uf AND u.idpais = p.idpais '; | |
492 | + | |
493 | + if (is_numeric($int_idmun)) { | |
494 | + $filtros .= "{$whereAnd} b.idmun = '{$int_idmun}'"; | |
495 | + $whereAnd = ' AND '; | |
496 | + } | |
497 | + | |
498 | + if (is_string($str_geom)) { | |
499 | + $filtros .= "{$whereAnd} b.geom LIKE '%{$str_geom}%'"; | |
500 | + $whereAnd = ' AND '; | |
501 | + } | |
502 | + | |
503 | + if (is_numeric($int_idbai)) { | |
504 | + $filtros .= "{$whereAnd} b.idbai = '{$int_idbai}'"; | |
505 | + $whereAnd = ' AND '; | |
506 | + } | |
507 | + | |
508 | + if (is_string($str_nome)) { | |
509 | + $filtros .= "{$whereAnd} b.nome LIKE '%{$str_nome}%'"; | |
510 | + $whereAnd = ' AND '; | |
511 | + } | |
512 | + | |
513 | + if (is_numeric($int_idpes_rev)) { | |
514 | + $filtros .= "{$whereAnd} b.idpes_rev = '{$int_idpes_rev}'"; | |
515 | + $whereAnd = ' AND '; | |
516 | + } | |
517 | + | |
518 | + if (is_string($date_data_rev_ini)) { | |
519 | + $filtros .= "{$whereAnd} b.data_rev >= '{$date_data_rev_ini}'"; | |
520 | + $whereAnd = ' AND '; | |
521 | + } | |
522 | + | |
523 | + if (is_string($date_data_rev_fim)) { | |
524 | + $filtros .= "{$whereAnd} b.data_rev <= '{$date_data_rev_fim}'"; | |
525 | + $whereAnd = ' AND '; | |
526 | + } | |
527 | + | |
528 | + if (is_string($str_origem_gravacao)) { | |
529 | + $filtros .= "{$whereAnd} b.origem_gravacao LIKE '%{$str_origem_gravacao}%'"; | |
530 | + $whereAnd = ' AND '; | |
531 | + } | |
532 | + | |
533 | + if (is_numeric($int_idpes_cad)) { | |
534 | + $filtros .= "{$whereAnd} b.idpes_cad = '{$int_idpes_cad}'"; | |
535 | + $whereAnd = ' AND '; | |
536 | + } | |
537 | + | |
538 | + if (is_string($date_data_cad_ini)) { | |
539 | + $filtros .= "{$whereAnd} b.data_cad >= '{$date_data_cad_ini}'"; | |
540 | + $whereAnd = ' AND '; | |
541 | + } | |
542 | + | |
543 | + if (is_string($date_data_cad_fim)) { | |
544 | + $filtros .= "{$whereAnd} b.data_cad <= '{$date_data_cad_fim}'"; | |
545 | + $whereAnd = ' AND '; | |
546 | + } | |
547 | + | |
548 | + if (is_string($str_operacao)) { | |
549 | + $filtros .= "{$whereAnd} b.operacao LIKE '%{$str_operacao}%'"; | |
550 | + $whereAnd = ' AND '; | |
551 | + } | |
552 | + | |
553 | + if (is_numeric($int_idsis_rev)) { | |
554 | + $filtros .= "{$whereAnd} b.idsis_rev = '{$int_idsis_rev}'"; | |
555 | + $whereAnd = ' AND '; | |
556 | + } | |
557 | + | |
558 | + if (is_numeric($int_idsis_cad)) { | |
559 | + $filtros .= "{$whereAnd} b.idsis_cad = '{$int_idsis_cad}'"; | |
560 | + $whereAnd = ' AND '; | |
561 | + } | |
562 | + | |
563 | + if (is_numeric($int_idpais)) { | |
564 | + $filtros .= "{$whereAnd} p.idpais = '{$int_idpais}'"; | |
565 | + $whereAnd = ' AND '; | |
566 | + } | |
567 | + | |
568 | + if (is_string($str_sigla_uf)) { | |
569 | + $filtros .= "{$whereAnd} u.sigla_uf = '{$str_sigla_uf}'"; | |
570 | + $whereAnd = ' AND '; | |
571 | + } | |
572 | + | |
573 | + $db = new clsBanco(); | |
574 | + | |
575 | + $countCampos = count(explode(', ', $this->_campos_lista)); | |
576 | + $resultado = array(); | |
577 | + | |
578 | + $sql .= $filtros . $this->getOrderby() . $this->getLimite(); | |
579 | + | |
580 | + $this->_total = $db->CampoUnico(sprintf( | |
581 | + 'SELECT COUNT(0) FROM %s %s %s', $this->_tabela, $from, $filtros | |
582 | + )); | |
583 | + | |
584 | + $db->Consulta($sql); | |
585 | + | |
586 | + if ($countCampos > 1) { | |
587 | + while ($db->ProximoRegistro()) { | |
588 | + $tupla = $db->Tupla(); | |
589 | + $tupla['_total'] = $this->_total; | |
590 | + $resultado[] = $tupla; | |
591 | + } | |
592 | + } | |
593 | + else { | |
594 | + while ($db->ProximoRegistro()) { | |
595 | + $tupla = $db->Tupla(); | |
596 | + $resultado[] = $tupla[$this->_campos_lista]; | |
597 | + } | |
598 | + } | |
599 | + | |
600 | + if (count($resultado)) { | |
601 | + return $resultado; | |
602 | + } | |
603 | + | |
604 | + return FALSE; | |
605 | + } | |
606 | + | |
607 | + /** | |
608 | + * Retorna um array com os dados de um registro | |
609 | + * @return array | |
610 | + */ | |
611 | + function detalhe() | |
612 | + { | |
613 | + if (is_numeric($this->idbai)) { | |
614 | + $db = new clsBanco(); | |
615 | + | |
616 | + $sql = sprintf( | |
617 | + 'SELECT %s FROM %s b WHERE b.idbai = \'%d\'', | |
618 | + $this->_todos_campos, $this->_tabela, $this->idbai | |
619 | + ); | |
620 | + | |
621 | + $db->Consulta($sql); | |
622 | + $db->ProximoRegistro(); | |
623 | + return $db->Tupla(); | |
624 | + } | |
625 | + | |
626 | + return FALSE; | |
627 | + } | |
628 | + | |
629 | + /** | |
630 | + * Retorna um array com os dados de um registro. | |
631 | + * @return array | |
632 | + */ | |
633 | + function existe() | |
634 | + { | |
635 | + if (is_numeric($this->idbai)) { | |
636 | + $db = new clsBanco(); | |
637 | + | |
638 | + $sql = sprintf( | |
639 | + 'SELECT 1 FROM %s WHERE idbai = \'%d\'', | |
640 | + $this->_tabela, $this->idbai | |
641 | + ); | |
642 | + | |
643 | + $db->Consulta($sql); | |
644 | + | |
645 | + if ($db->ProximoRegistro()) { | |
646 | + return TRUE; | |
647 | + } | |
648 | + } | |
649 | + | |
650 | + return FALSE; | |
651 | + } | |
652 | + | |
653 | + /** | |
654 | + * Exclui um registro | |
655 | + * | |
656 | + * @return bool | |
657 | + */ | |
658 | + function excluir() | |
659 | + { | |
660 | + if (is_numeric($this->idbai)) { | |
661 | + $db = new clsBanco(); | |
662 | + | |
663 | + $sql = sprintf( | |
664 | + 'DELETE FROM %s WHERE idbai = \'%d\'', | |
665 | + $this->_tabela, $this->idbai | |
666 | + ); | |
667 | + | |
668 | + $db->Consulta($sql); | |
669 | + return TRUE; | |
670 | + } | |
671 | + | |
672 | + return FALSE; | |
673 | + } | |
674 | + | |
675 | + /** | |
676 | + * Define quais campos da tabela serão selecionados no método Lista(). | |
677 | + */ | |
678 | + function setCamposLista($str_campos) | |
679 | + { | |
680 | + $this->_campos_lista = $str_campos; | |
681 | + } | |
682 | + | |
683 | + /** | |
684 | + * Define que o método Lista() deverpa retornar todos os campos da tabela. | |
685 | + */ | |
686 | + function resetCamposLista() | |
687 | + { | |
688 | + $this->_campos_lista = $this->_todos_campos; | |
689 | + } | |
690 | + | |
691 | + /** | |
692 | + * Define limites de retorno para o método Lista(). | |
693 | + */ | |
694 | + function setLimite($intLimiteQtd, $intLimiteOffset = NULL) | |
695 | + { | |
696 | + $this->_limite_quantidade = $intLimiteQtd; | |
697 | + $this->_limite_offset = $intLimiteOffset; | |
698 | + } | |
699 | + | |
700 | + /** | |
701 | + * Retorna a string com o trecho da query responsável pelo limite de | |
702 | + * registros retornados/afetados. | |
703 | + * | |
704 | + * @return string | |
705 | + */ | |
706 | + function getLimite() | |
707 | + { | |
708 | + if (is_numeric($this->_limite_quantidade)) { | |
709 | + $retorno = " LIMIT {$this->_limite_quantidade}"; | |
710 | + if (is_numeric($this->_limite_offset)) { | |
711 | + $retorno .= " OFFSET {$this->_limite_offset} "; | |
712 | + } | |
713 | + return $retorno; | |
714 | + } | |
715 | + return ''; | |
716 | + } | |
717 | + | |
718 | + /** | |
719 | + * Define o campo para ser utilizado como ordenação no método Lista(). | |
720 | + */ | |
721 | + function setOrderby($strNomeCampo) | |
722 | + { | |
723 | + if (is_string($strNomeCampo) && $strNomeCampo ) { | |
724 | + $this->_campo_order_by = $strNomeCampo; | |
725 | + } | |
726 | + } | |
727 | + | |
728 | + /** | |
729 | + * Retorna a string com o trecho da query responsável pela Ordenação dos | |
730 | + * registros. | |
731 | + * | |
732 | + * @return string | |
733 | + */ | |
734 | + function getOrderby() | |
735 | + { | |
736 | + if (is_string($this->_campo_order_by)) { | |
737 | + return " ORDER BY {$this->_campo_order_by} "; | |
738 | + } | |
739 | + return ''; | |
740 | + } | |
741 | +} | |
754 | 742 | \ No newline at end of file | ... | ... |