clsPmieducarReservaVaga.inc.php
18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
<?php
/**
* i-Educar - Sistema de gestão escolar
*
* Copyright (C) 2006 Prefeitura Municipal de Itajaí
* <ctima@itajai.sc.gov.br>
*
* Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
* sob os termos da Licença Pública Geral GNU conforme publicada pela Free
* Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
* qualquer versão posterior.
*
* Este programa é distribuído na expectativa de que seja útil, porém, SEM
* NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU
* ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
* do GNU para mais detalhes.
*
* Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
* com este programa; se não, escreva para a Free Software Foundation, Inc., no
* endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
*
* @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br>
* @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL
* @package Core
* @subpackage pmieducar
* @subpackage ReservaVaga
* @since Arquivo disponível desde a versão 1.0.0
* @version $Id$
*/
require_once 'include/pmieducar/geral.inc.php';
/**
* clsPmieducarReservaVaga class.
*
* @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br>
* @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL
* @package Core
* @subpackage pmieducar
* @subpackage ReservaVaga
* @since Classe disponível desde a versão 1.0.0
* @version $Id$
*/
class clsPmieducarReservaVaga
{
var $cod_reserva_vaga;
var $ref_ref_cod_escola;
var $ref_ref_cod_serie;
var $ref_usuario_exc;
var $ref_usuario_cad;
var $ref_cod_aluno;
var $data_cadastro;
var $data_exclusao;
var $ativo;
var $nm_aluno;
var $cpf_responsavel;
/**
* Armazena o total de resultados obtidos na ultima chamada ao metodo lista.
* @var int
*/
var $_total;
/**
* Nome do schema.
* @var string
*/
var $_schema;
/**
* Nome da tabela.
* @var string
*/
var $_tabela;
/**
* Lista separada por vírgula, com os campos que devem ser selecionados na
* próxima chamado ao metodo lista.
* @var string
*/
var $_campos_lista;
/**
* Lista com todos os campos da tabela separados por vírgula, padrão para
* seleçã no método lista.
* @var string
*/
var $_todos_campos;
/**
* Valor que define a quantidade de registros a ser retornada pelo método lista.
* @var int
*/
var $_limite_quantidade;
/**
* Define o valor de offset no retorno dos registros no método lista.
* @var int
*/
var $_limite_offset;
/**
* Define o campo padrao para ser usado como padrão de ordenação no método lista.
* @var string
*/
var $_campo_order_by;
/**
* Construtor.
*
* @param int $cod_reserva_vaga
* @param int $ref_ref_cod_escola
* @param int $ref_ref_cod_serie
* @param int $ref_usuario_exc
* @param int $ref_usuario_cad
* @param int $ref_cod_aluno
* @param string $data_cadastro
* @param string $data_exclusao
* @param int $ativo
* @param string $nm_aluno
* @param int $cpf_responsavel
*/
function clsPmieducarReservaVaga($cod_reserva_vaga = NULL,
$ref_ref_cod_escola = NULL, $ref_ref_cod_serie = NULL, $ref_usuario_exc = NULL,
$ref_usuario_cad = NULL, $ref_cod_aluno = NULL, $data_cadastro = NULL,
$data_exclusao = NULL, $ativo = NULL, $nm_aluno = NULL, $cpf_responsavel = NULL)
{
$db = new clsBanco();
$this->_schema = 'pmieducar.';
$this->_tabela = $this->_schema . 'reserva_vaga';
$this->_campos_lista = $this->_todos_campos = "rv.cod_reserva_vaga, rv.ref_ref_cod_escola, rv.ref_ref_cod_serie, rv.ref_usuario_exc, rv.ref_usuario_cad, rv.ref_cod_aluno, rv.data_cadastro, rv.data_exclusao, rv.ativo, rv.nm_aluno, rv.cpf_responsavel";
if (is_numeric($ref_ref_cod_serie) && is_numeric($ref_ref_cod_escola)) {
if (class_exists("clsPmieducarEscolaSerie")) {
$tmp_obj = new clsPmieducarEscolaSerie($ref_ref_cod_escola, $ref_ref_cod_serie);
if (method_exists($tmp_obj, 'existe')) {
if ($tmp_obj->existe()) {
$this->ref_ref_cod_serie = $ref_ref_cod_serie;
$this->ref_ref_cod_escola = $ref_ref_cod_escola;
}
}
elseif (method_exists($tmp_obj, 'detalhe')) {
if ($tmp_obj->detalhe()) {
$this->ref_ref_cod_serie = $ref_ref_cod_serie;
$this->ref_ref_cod_escola = $ref_ref_cod_escola;
}
}
}
else {
if($db->CampoUnico("SELECT 1 FROM pmieducar.escola_serie WHERE ref_cod_serie = '{$ref_ref_cod_serie}' AND ref_cod_escola = '{$ref_ref_cod_escola}'")) {
$this->ref_ref_cod_serie = $ref_ref_cod_serie;
$this->ref_ref_cod_escola = $ref_ref_cod_escola;
}
}
}
if (is_numeric($ref_usuario_exc)) {
if (class_exists('clsPmieducarUsuario')) {
$tmp_obj = new clsPmieducarUsuario($ref_usuario_exc);
if (method_exists($tmp_obj, 'existe')) {
if ($tmp_obj->existe()) {
$this->ref_usuario_exc = $ref_usuario_exc;
}
}
elseif (method_exists($tmp_obj, 'detalhe')) {
if ($tmp_obj->detalhe()) {
$this->ref_usuario_exc = $ref_usuario_exc;
}
}
}
else {
if ($db->CampoUnico("SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_exc}'")) {
$this->ref_usuario_exc = $ref_usuario_exc;
}
}
}
if (is_numeric($ref_usuario_cad)) {
if (class_exists('clsPmieducarUsuario')) {
$tmp_obj = new clsPmieducarUsuario( $ref_usuario_cad );
if (method_exists($tmp_obj, 'existe')) {
if ($tmp_obj->existe()) {
$this->ref_usuario_cad = $ref_usuario_cad;
}
}
elseif (method_exists($tmp_obj, 'detalhe')) {
if ($tmp_obj->detalhe()) {
$this->ref_usuario_cad = $ref_usuario_cad;
}
}
}
else {
if ($db->CampoUnico( "SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_cad}'")) {
$this->ref_usuario_cad = $ref_usuario_cad;
}
}
}
if (is_numeric($ref_cod_aluno)) {
if (class_exists('clsPmieducarAluno')) {
$tmp_obj = new clsPmieducarAluno( $ref_cod_aluno );
if (method_exists($tmp_obj, 'existe')) {
if ($tmp_obj->existe()) {
$this->ref_cod_aluno = $ref_cod_aluno;
}
}
elseif (method_exists($tmp_obj, 'detalhe')) {
if ($tmp_obj->detalhe()) {
$this->ref_cod_aluno = $ref_cod_aluno;
}
}
}
else {
if ($db->CampoUnico("SELECT 1 FROM pmieducar.aluno WHERE cod_aluno = '{$ref_cod_aluno}'")) {
$this->ref_cod_aluno = $ref_cod_aluno;
}
}
}
if (is_numeric($cod_reserva_vaga)) {
$this->cod_reserva_vaga = $cod_reserva_vaga;
}
if (is_string($data_cadastro)) {
$this->data_cadastro = $data_cadastro;
}
if (is_string($data_exclusao)) {
$this->data_exclusao = $data_exclusao;
}
if (is_numeric($ativo)) {
$this->ativo = $ativo;
}
if (is_string($nm_aluno)) {
$this->nm_aluno = $nm_aluno;
}
if (is_numeric($cpf_responsavel)) {
$this->cpf_responsavel = $cpf_responsavel;
}
}
/**
* Cria um novo registro.
* @return int|bool Retorna o valor da sequence ou FALSE em caso de erro.
*/
function cadastra()
{
if (is_numeric($this->ref_ref_cod_escola) &&
is_numeric($this->ref_ref_cod_serie) && is_numeric($this->ref_usuario_cad) &&
(is_numeric($this->ref_cod_aluno) || (is_numeric($this->cpf_responsavel) && is_string($this->nm_aluno))))
{
$db = new clsBanco();
$campos = "";
$valores = "";
$gruda = "";
if (is_numeric($this->ref_ref_cod_escola)) {
$campos .= "{$gruda}ref_ref_cod_escola";
$valores .= "{$gruda}'{$this->ref_ref_cod_escola}'";
$gruda = ", ";
}
if (is_numeric($this->ref_ref_cod_serie)) {
$campos .= "{$gruda}ref_ref_cod_serie";
$valores .= "{$gruda}'{$this->ref_ref_cod_serie}'";
$gruda = ", ";
}
if (is_numeric($this->ref_usuario_cad)) {
$campos .= "{$gruda}ref_usuario_cad";
$valores .= "{$gruda}'{$this->ref_usuario_cad}'";
$gruda = ", ";
}
if (is_numeric($this->ref_cod_aluno)) {
$campos .= "{$gruda}ref_cod_aluno";
$valores .= "{$gruda}'{$this->ref_cod_aluno}'";
$gruda = ", ";
}
if (is_string($this->nm_aluno)) {
$campos .= "{$gruda}nm_aluno";
$valores .= "{$gruda}'{$this->nm_aluno}'";
$gruda = ", ";
}
if (is_numeric($this->cpf_responsavel)) {
$campos .= "{$gruda}cpf_responsavel";
$valores .= "{$gruda}'{$this->cpf_responsavel}'";
$gruda = ", ";
}
$campos .= "{$gruda}data_cadastro";
$valores .= "{$gruda}NOW()";
$gruda = ", ";
$campos .= "{$gruda}ativo";
$valores .= "{$gruda}'1'";
$gruda = ", ";
$db->Consulta("INSERT INTO {$this->_tabela} ( $campos ) VALUES( $valores )");
return $db->InsertId("{$this->_tabela}_cod_reserva_vaga_seq");
}
return FALSE;
}
/**
* Atualiza os dados de um registro.
* @return bool
*/
function edita()
{
if (is_numeric($this->cod_reserva_vaga)) {
$db = new clsBanco();
$set = "";
if (is_numeric($this->ref_ref_cod_escola)) {
$set .= "{$gruda}ref_ref_cod_escola = '{$this->ref_ref_cod_escola}'";
$gruda = ", ";
}
if (is_numeric($this->ref_ref_cod_serie)) {
$set .= "{$gruda}ref_ref_cod_serie = '{$this->ref_ref_cod_serie}'";
$gruda = ", ";
}
if (is_numeric($this->ref_usuario_exc)) {
$set .= "{$gruda}ref_usuario_exc = '{$this->ref_usuario_exc}'";
$gruda = ", ";
}
if (is_numeric($this->ref_usuario_cad)) {
$set .= "{$gruda}ref_usuario_cad = '{$this->ref_usuario_cad}'";
$gruda = ", ";
}
if (is_numeric($this->ref_cod_aluno)) {
$set .= "{$gruda}ref_cod_aluno = '{$this->ref_cod_aluno}'";
$gruda = ", ";
}
if (is_string($this->data_cadastro)) {
$set .= "{$gruda}data_cadastro = '{$this->data_cadastro}'";
$gruda = ", ";
}
$set .= "{$gruda}data_exclusao = NOW()";
$gruda = ", ";
if (is_numeric($this->ativo)) {
$set .= "{$gruda}ativo = '{$this->ativo}'";
$gruda = ", ";
}
if (is_string($this->nm_aluno)) {
$set .= "{$gruda}nm_aluno = '{$this->nm_aluno}'";
$gruda = ", ";
}
if (is_numeric($this->cpf_responsavel)) {
$set .= "{$gruda}cpf_responsavel = '{$this->cpf_responsavel}'";
$gruda = ", ";
}
if ($set) {
$db->Consulta("UPDATE {$this->_tabela} SET $set WHERE cod_reserva_vaga = '{$this->cod_reserva_vaga}'");
return TRUE;
}
}
return FALSE;
}
/**
* Retorna uma lista de registros filtrados de acordo com os parâmetros.
*
* @var int $int_cod_reserva_vaga
* @var int $int_ref_ref_cod_escola
* @var int $int_ref_ref_cod_serie
* @var int $int_ref_usuario_exc
* @var int $int_ref_usuario_cad
* @var int $int_ref_cod_aluno
* @var string $date_data_cadastro_ini
* @var string $date_data_cadastro_fim
* @var string $date_data_exclusao_ini
* @var string $date_data_exclusao_fim
* @var int $int_ativo
* @var int $int_ref_cod_instituicao
* @var int $int_ref_cod_curso
* @var string $str_nm_aluno
* @var int $int_cpf_responsavel
* @return array|bool Retorna um array com registro(s) ou FALSE em caso de erro.
*/
function lista($int_cod_reserva_vaga = NULL, $int_ref_ref_cod_escola = NULL,
$int_ref_ref_cod_serie = NULL, $int_ref_usuario_exc = NULL,
$int_ref_usuario_cad = NULL, $int_ref_cod_aluno = NULL,
$date_data_cadastro_ini = NULL, $date_data_cadastro_fim = NULL,
$date_data_exclusao_ini = NULL, $date_data_exclusao_fim = NULL,
$int_ativo = NULL, $int_ref_cod_instituicao = NULL, $int_ref_cod_curso = NULL,
$str_nm_aluno = NULL, $int_cpf_responsavel = NULL)
{
$sql = "SELECT {$this->_campos_lista}, c.ref_cod_instituicao, s.ref_cod_curso FROM {$this->_tabela} rv, {$this->_schema}serie s, {$this->_schema}curso c";
$whereAnd = " AND ";
$filtros = " WHERE rv.ref_ref_cod_serie = s.cod_serie AND s.ref_cod_curso = c.cod_curso ";
if (is_numeric($int_cod_reserva_vaga)) {
$filtros .= "{$whereAnd} rv.cod_reserva_vaga = '{$int_cod_reserva_vaga}'";
$whereAnd = " AND ";
}
if (is_numeric($int_ref_ref_cod_escola)) {
$filtros .= "{$whereAnd} rv.ref_ref_cod_escola = '{$int_ref_ref_cod_escola}'";
$whereAnd = " AND ";
}
if (is_numeric($int_ref_ref_cod_serie)) {
$filtros .= "{$whereAnd} rv.ref_ref_cod_serie = '{$int_ref_ref_cod_serie}'";
$whereAnd = " AND ";
}
if (is_numeric($int_ref_usuario_exc)) {
$filtros .= "{$whereAnd} rv.ref_usuario_exc = '{$int_ref_usuario_exc}'";
$whereAnd = " AND ";
}
if (is_numeric($int_ref_usuario_cad)) {
$filtros .= "{$whereAnd} rv.ref_usuario_cad = '{$int_ref_usuario_cad}'";
$whereAnd = " AND ";
}
if (is_numeric($int_ref_cod_aluno)) {
$filtros .= "{$whereAnd} rv.ref_cod_aluno = '{$int_ref_cod_aluno}'";
$whereAnd = " AND ";
}
if (is_string($date_data_cadastro_ini)) {
$filtros .= "{$whereAnd} rv.data_cadastro >= '{$date_data_cadastro_ini}'";
$whereAnd = " AND ";
}
if (is_string($date_data_cadastro_fim)) {
$filtros .= "{$whereAnd} rv.data_cadastro <= '{$date_data_cadastro_fim}'";
$whereAnd = " AND ";
}
if (is_string($date_data_exclusao_ini)) {
$filtros .= "{$whereAnd} rv.data_exclusao >= '{$date_data_exclusao_ini}'";
$whereAnd = " AND ";
}
if (is_string($date_data_exclusao_fim)) {
$filtros .= "{$whereAnd} rv.data_exclusao <= '{$date_data_exclusao_fim}'";
$whereAnd = " AND ";
}
if (is_null($int_ativo) || $int_ativo) {
$filtros .= "{$whereAnd} rv.ativo = '1'";
$whereAnd = " AND ";
}
else {
$filtros .= "{$whereAnd} rv.ativo = '0'";
$whereAnd = " AND ";
}
if (is_numeric($int_ref_cod_instituicao)) {
$filtros .= "{$whereAnd} c.ref_cod_instituicao = '{$int_ref_cod_instituicao}'";
$whereAnd = " AND ";
}
if (is_numeric($int_ref_cod_curso)) {
$filtros .= "{$whereAnd} s.ref_cod_curso = '{$int_ref_cod_curso}'";
$whereAnd = " AND ";
}
if (is_string($str_nm_aluno)) {
$filtros .= "{$whereAnd} rv.nm_aluno ilike '%{$str_nm_aluno}%'";
$whereAnd = " AND ";
}
if (is_numeric($int_cpf_responsavel)) {
$filtros .= "{$whereAnd} rv.cpf_responsavel like '%{$int_cpf_responsavel}%'";
$whereAnd = " AND ";
}
$db = new clsBanco();
$countCampos = count(explode(',', $this->_campos_lista));
$resultado = array();
$sql .= $filtros . $this->getOrderby() . $this->getLimite();
$this->_total = $db->CampoUnico("SELECT COUNT(0) FROM {$this->_tabela} rv, {$this->_schema}serie s, {$this->_schema}curso c {$filtros}");
$db->Consulta($sql);
if ($countCampos > 1) {
while ($db->ProximoRegistro()) {
$tupla = $db->Tupla();
$tupla["_total"] = $this->_total;
$resultado[] = $tupla;
}
}
else {
while ($db->ProximoRegistro()) {
$tupla = $db->Tupla();
$resultado[] = $tupla[$this->_campos_lista];
}
}
if (count($resultado)) {
return $resultado;
}
return FALSE;
}
/**
* Retorna um array com os dados de um registro
* @return array|bool
*/
function detalhe()
{
if (is_numeric($this->cod_reserva_vaga)) {
$db = new clsBanco();
$db->Consulta("SELECT {$this->_todos_campos} FROM {$this->_tabela} rv WHERE rv.cod_reserva_vaga = '{$this->cod_reserva_vaga}'");
$db->ProximoRegistro();
return $db->Tupla();
}
return FALSE;
}
/**
* Retorna um array com os dados de um registro
* @return array|bool
*/
function existe()
{
if (is_numeric($this->cod_reserva_vaga)) {
$db = new clsBanco();
$db->Consulta("SELECT 1 FROM {$this->_tabela} WHERE cod_reserva_vaga = '{$this->cod_reserva_vaga}'");
$db->ProximoRegistro();
return $db->Tupla();
}
return FALSE;
}
/**
* Exclui um registro
*
* @return bool
*/
function excluir()
{
if (is_numeric($this->cod_reserva_vaga)) {
$this->ativo = 0;
return $this->edita();
}
return FALSE;
}
/**
* Define quais campos da tabela serão selecionados na invocação do método lista.
* @param string $str_campos
*/
function setCamposLista($str_campos) {
$this->_campos_lista = $str_campos;
}
/**
* Define que o método lista deverá retornar todos os campos da tabela.
*/
function resetCamposLista() {
$this->_campos_lista = $this->_todos_campos;
}
/**
* Define limites de retorno para o método lista.
* @param int $intLimiteQtd
* @param int $intLimiteOffset
*/
function setLimite($intLimiteQtd, $intLimiteOffset = NULL)
{
$this->_limite_quantidade = $intLimiteQtd;
$this->_limite_offset = $intLimiteOffset;
}
/**
* Retorna a string com o trecho da query resposável pelo limite de registros.
* @return string
*/
function getLimite()
{
if (is_numeric($this->_limite_quantidade)) {
$retorno = ' LIMIT ' . $this->_limite_quantidade;
if (is_numeric($this->_limite_offset)) {
$retorno .= ' OFFSET ' . $this->_limite_offset;
}
return $retorno;
}
return '';
}
/**
* Define campo para ser utilizado como ordenação no método lista.
* @param string $strNomeCampo
*/
function setOrderby($strNomeCampo)
{
if (is_string($strNomeCampo) && $strNomeCampo) {
$this->_campo_order_by = $strNomeCampo;
}
}
/**
* Retorna a string com o trecho da query resposável pela ordenação dos registros.
* @return string
*/
function getOrderby()
{
if( is_string( $this->_campo_order_by ) )
{
return ' ORDER BY ' . $this->_campo_order_by;
}
return '';
}
}