Commit 2ee059394f58a2d8b76793ac37d539ef1970e900
1 parent
347da7e2
Exists in
master
Alterado APIs aluno / matricula, para exibir resultados cujo estejam transferidos closes #1
Showing
2 changed files
with
29 additions
and
15 deletions
Show diff stats
ieducar/modules/Api/Views/AlunoController.php
| ... | ... | @@ -478,21 +478,26 @@ class AlunoController extends ApiCoreController |
| 478 | 478 | // search options |
| 479 | 479 | |
| 480 | 480 | protected function searchOptions() { |
| 481 | - return array('sqlParams' => array($this->getRequest()->escola_id), | |
| 481 | + $escolaId = $this->getRequest()->escola_id ? $this->getRequest()->escola_id : 0; | |
| 482 | + | |
| 483 | + return array('sqlParams' => array($escolaId), | |
| 482 | 484 | 'selectFields' => array('matricula_id')); |
| 483 | 485 | } |
| 484 | 486 | |
| 485 | 487 | protected function sqlsForNumericSearch() { |
| 486 | 488 | $sqls = array(); |
| 487 | 489 | |
| 488 | - // caso nao receba id da escola, pesquisa por codigo aluno em todas as escolas | |
| 490 | + // caso nao receba id da escola, pesquisa por codigo aluno em todas as escolas, | |
| 491 | + // alunos com e sem matricula são selecionados. | |
| 489 | 492 | if (! $this->getRequest()->escola_id) { |
| 490 | 493 | $sqls[] = "select distinct aluno.cod_aluno as id, pessoa.nome as name from |
| 491 | 494 | pmieducar.aluno, cadastro.pessoa where pessoa.idpes = aluno.ref_idpes |
| 492 | - and aluno.ativo = 1 and aluno.cod_aluno like $1||'%' and $2 = $2 order by cod_aluno limit 15"; | |
| 495 | + and aluno.ativo = 1 and aluno.cod_aluno like $1||'%' and $2 = $2 | |
| 496 | + order by cod_aluno limit 15"; | |
| 493 | 497 | } |
| 494 | 498 | |
| 495 | - // seleciona por (codigo matricula ou codigo aluno) e/ou codigo escola | |
| 499 | + // seleciona por (codigo matricula ou codigo aluno) e opcionalmente por codigo escola, | |
| 500 | + // apenas alunos com matricula são selecionados. | |
| 496 | 501 | $sqls[] = "select * from (select distinct ON (aluno.cod_aluno) aluno.cod_aluno as id, |
| 497 | 502 | matricula.cod_matricula as matricula_id, pessoa.nome as name from pmieducar.matricula, |
| 498 | 503 | pmieducar.aluno, cadastro.pessoa where aluno.cod_aluno = matricula.ref_cod_aluno and |
| ... | ... | @@ -500,7 +505,7 @@ class AlunoController extends ApiCoreController |
| 500 | 505 | matricula.ativo = 1 and |
| 501 | 506 | (select case when $2 != 0 then matricula.ref_ref_cod_escola = $2 else 1=1 end) and |
| 502 | 507 | (matricula.cod_matricula like $1||'%' or matricula.ref_cod_aluno like $1||'%') and |
| 503 | - matricula.aprovado in (1, 2, 3, 7, 8, 9) limit 15) as alunos order by id"; | |
| 508 | + matricula.aprovado in (1, 2, 3, 4, 7, 8, 9) limit 15) as alunos order by id"; | |
| 504 | 509 | |
| 505 | 510 | return $sqls; |
| 506 | 511 | } |
| ... | ... | @@ -509,7 +514,8 @@ class AlunoController extends ApiCoreController |
| 509 | 514 | protected function sqlsForStringSearch() { |
| 510 | 515 | $sqls = array(); |
| 511 | 516 | |
| 512 | - // caso nao receba id da escola, pesquisa por codigo aluno em todas as escolas | |
| 517 | + // caso nao receba id da escola, pesquisa por nome aluno em todas as escolas, | |
| 518 | + // alunos com e sem matricula são selecionados. | |
| 513 | 519 | if (! $this->getRequest()->escola_id) { |
| 514 | 520 | $sqls[] = "select distinct aluno.cod_aluno as id, |
| 515 | 521 | pessoa.nome as name from pmieducar.aluno, cadastro.pessoa where |
| ... | ... | @@ -518,7 +524,8 @@ class AlunoController extends ApiCoreController |
| 518 | 524 | order by nome limit 15"; |
| 519 | 525 | } |
| 520 | 526 | |
| 521 | - // seleciona por nome aluno e/ou codigo escola | |
| 527 | + // seleciona por nome aluno e e opcionalmente por codigo escola, | |
| 528 | + // apenas alunos com matricula são selecionados. | |
| 522 | 529 | $sqls[] = "select * from(select distinct ON (aluno.cod_aluno) aluno.cod_aluno as id, |
| 523 | 530 | matricula.cod_matricula as matricula_id, pessoa.nome as name from pmieducar.matricula, |
| 524 | 531 | pmieducar.aluno, cadastro.pessoa where aluno.cod_aluno = matricula.ref_cod_aluno and |
| ... | ... | @@ -526,7 +533,7 @@ class AlunoController extends ApiCoreController |
| 526 | 533 | matricula.ativo = 1 and (select case when $2 != 0 then matricula.ref_ref_cod_escola = $2 |
| 527 | 534 | else 1=1 end) and |
| 528 | 535 | lower(to_ascii(pessoa.nome)) like lower(to_ascii($1))||'%' and matricula.aprovado in |
| 529 | - (1, 2, 3, 7, 8, 9) limit 15) as alunos order by name"; | |
| 536 | + (1, 2, 3, 4, 7, 8, 9) limit 15) as alunos order by name"; | |
| 530 | 537 | |
| 531 | 538 | return $sqls; |
| 532 | 539 | } | ... | ... |
ieducar/modules/Api/Views/MatriculaController.php
| ... | ... | @@ -47,30 +47,37 @@ class MatriculaController extends ApiCoreController |
| 47 | 47 | // search options |
| 48 | 48 | |
| 49 | 49 | protected function searchOptions() { |
| 50 | - return array('sqlParams' => array($this->getRequest()->escola_id, $this->getRequest()->ano), | |
| 50 | + $escolaId = $this->getRequest()->escola_id ? $this->getRequest()->escola_id : 0; | |
| 51 | + $ano = $this->getRequest()->ano ? $this->getRequest()->ano : 0; | |
| 52 | + | |
| 53 | + return array('sqlParams' => array($escolaId, $ano), | |
| 51 | 54 | 'selectFields' => array('aluno_id')); |
| 52 | 55 | } |
| 53 | 56 | |
| 54 | 57 | protected function sqlsForNumericSearch() { |
| 55 | - | |
| 58 | + // seleciona por (codigo matricula ou codigo aluno), opcionalmente por codigo escola e | |
| 59 | + // opcionalmente por ano. | |
| 56 | 60 | return "select distinct ON (aluno.cod_aluno) aluno.cod_aluno as aluno_id, |
| 57 | 61 | matricula.cod_matricula as id, pessoa.nome as name from pmieducar.matricula, |
| 58 | 62 | pmieducar.aluno, cadastro.pessoa where aluno.cod_aluno = matricula.ref_cod_aluno and |
| 59 | 63 | pessoa.idpes = aluno.ref_idpes and aluno.ativo = matricula.ativo and |
| 60 | - matricula.ativo = 1 and matricula.ref_ref_cod_escola = $2 and | |
| 64 | + matricula.ativo = 1 and matricula.aprovado in (1, 2, 3, 4, 7, 8, 9) and | |
| 61 | 65 | (matricula.cod_matricula like $1 or matricula.ref_cod_aluno like $1) and |
| 62 | - matricula.aprovado in (1, 2, 3, 7, 8, 9) and ano = $3 limit 15"; | |
| 66 | + (select case when $2 != 0 then matricula.ref_ref_cod_escola = $2 else 1=1 end) and | |
| 67 | + (select case when $3 != 0 then matricula.ano = $3 else 1=1 end) limit 15"; | |
| 63 | 68 | } |
| 64 | 69 | |
| 65 | 70 | |
| 66 | 71 | protected function sqlsForStringSearch() { |
| 72 | + // seleciona por nome aluno, opcionalmente por codigo escola e opcionalmente por ano. | |
| 67 | 73 | return "select distinct ON (aluno.cod_aluno) aluno.cod_aluno as aluno_id, |
| 68 | 74 | matricula.cod_matricula as id, pessoa.nome as name from pmieducar.matricula, |
| 69 | 75 | pmieducar.aluno, cadastro.pessoa where aluno.cod_aluno = matricula.ref_cod_aluno and |
| 70 | 76 | pessoa.idpes = aluno.ref_idpes and aluno.ativo = matricula.ativo and |
| 71 | - matricula.ativo = 1 and matricula.ref_ref_cod_escola = $2 and | |
| 72 | - lower(to_ascii(pessoa.nome)) like lower(to_ascii($1))||'%' and matricula.aprovado in (1, 2, 3, 7, 8, 9) | |
| 73 | - and ano = $3 limit 15"; | |
| 77 | + matricula.ativo = 1 and matricula.aprovado in (1, 2, 3, 4, 7, 8, 9) and | |
| 78 | + lower(to_ascii(pessoa.nome)) like lower(to_ascii($1))||'%' and | |
| 79 | + (select case when $2 != 0 then matricula.ref_ref_cod_escola = $2 else 1=1 end) and | |
| 80 | + (select case when $3 != 0 then matricula.ano = $3 else 1=1 end) limit 15"; | |
| 74 | 81 | } |
| 75 | 82 | |
| 76 | 83 | ... | ... |