From 606af4a20939ec3309bc1ba862900a27a28cace6 Mon Sep 17 00:00:00 2001 From: bonot Date: Wed, 13 Mar 2024 21:55:44 -0300 Subject: [PATCH] =?UTF-8?q?Revert=20"Remove=20endpoint=20alunos=5Fby=5Fgua?= =?UTF-8?q?rdian=5Fcpf=20da=20API=20do=20I-Di=C3=A1rio"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ed1591ea315cb91d332a0a103cf9edf3f1e5ba47. --- ieducar/modules/Api/Views/AlunoController.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/ieducar/modules/Api/Views/AlunoController.php b/ieducar/modules/Api/Views/AlunoController.php index 53413ed560..0fbe0cce3f 100644 --- a/ieducar/modules/Api/Views/AlunoController.php +++ b/ieducar/modules/Api/Views/AlunoController.php @@ -179,6 +179,11 @@ protected function canGetTodosAlunos() return $this->validatesPresenceOf('instituicao_id') && $this->validatesPresenceOf('escola'); } + protected function canGetAlunosByGuardianCpf() + { + return $this->validatesPresenceOf('aluno_id') && $this->validatesPresenceOf('cpf'); + } + protected function validateInepCode() { if ($this->getRequest()->aluno_inep_id) { @@ -1325,6 +1330,62 @@ protected function getTodosAlunos() } } + protected function getIdpesFromCpf($cpf) + { + $sql = 'SELECT idpes FROM cadastro.fisica WHERE cpf = $1'; + + return $this->fetchPreparedQuery($sql, $cpf, true, 'first-field'); + } + + protected function checkAlunoIdpesGuardian($idpesGuardian, $alunoId) + { + $sql = ' + SELECT 1 + FROM pmieducar.aluno + INNER JOIN cadastro.fisica ON (aluno.ref_idpes = fisica.idpes) + WHERE cod_aluno = $2 + AND (idpes_pai = $1 + OR idpes_mae = $1 + OR idpes_responsavel = $1) LIMIT 1 + '; + + return $this->fetchPreparedQuery($sql, [$idpesGuardian, $alunoId], true, 'first-field') == 1; + } + + protected function getAlunosByGuardianCpf() + { + if ($this->canGetAlunosByGuardianCpf()) { + $cpf = $this->getRequest()->cpf; + $alunoId = $this->getRequest()->aluno_id; + + $idpesGuardian = $this->getIdpesFromCpf($cpf); + + if (is_numeric($idpesGuardian) && $this->checkAlunoIdpesGuardian($idpesGuardian, $alunoId)) { + $sql = ' + SELECT cod_aluno as aluno_id, pessoa.nome as nome_aluno + FROM pmieducar.aluno + INNER JOIN cadastro.fisica ON (aluno.ref_idpes = fisica.idpes) + INNER JOIN cadastro.pessoa ON (pessoa.idpes = fisica.idpes) + WHERE idpes_pai = $1 + OR idpes_mae = $1 + OR idpes_responsavel = $1 + '; + + $alunos = $this->fetchPreparedQuery($sql, [$idpesGuardian]); + $attrs = ['aluno_id', 'nome_aluno']; + $alunos = Portabilis_Array_Utils::filterSet($alunos, $attrs); + + foreach ($alunos as &$aluno) { + $aluno['nome_aluno'] = Portabilis_String_Utils::toUtf8($aluno['nome_aluno']); + } + + return ['alunos' => $alunos]; + } else { + $this->messenger->append('Não foi encontrado nenhum vínculos entre esse aluno e cpf.'); + } + } + } + protected function getMatriculas() { if ($this->canGetMatriculas()) { @@ -2077,6 +2138,8 @@ public function Gerar() $this->appendResponse($this->getOcorrenciasDisciplinares()); } elseif ($this->isRequestFor('get', 'grade_ultimo_historico')) { $this->appendResponse($this->getGradeUltimoHistorico()); + } elseif ($this->isRequestFor('get', 'alunos_by_guardian_cpf')) { + $this->appendResponse($this->getAlunosByGuardianCpf()); } elseif ($this->isRequestFor('post', 'aluno')) { $this->appendResponse($this->post()); } elseif ($this->isRequestFor('put', 'aluno')) {