From 976db410233414dd4a1d2eca31dfdf8935e72884 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Tue, 14 Sep 2010 15:22:55 -0300 Subject: [PATCH] Atualizado CRUD de aluno para conter opções de cadastro de transporte escolar --- ieducar/intranet/educar_aluno_cad.php | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- ieducar/intranet/educar_aluno_det.php | 15 +++++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/ieducar/intranet/educar_aluno_cad.php b/ieducar/intranet/educar_aluno_cad.php index 0af819d..4d497e6 100644 --- a/ieducar/intranet/educar_aluno_cad.php +++ b/ieducar/intranet/educar_aluno_cad.php @@ -33,7 +33,10 @@ require_once 'include/clsCadastro.inc.php'; require_once 'include/clsBanco.inc.php'; require_once 'include/pmieducar/geral.inc.php'; +require_once 'App/Model/SimNao.php'; require_once 'App/Model/ZonaLocalizacao.php'; +require_once 'Transporte/Model/AlunoDataMapper.php'; +require_once 'Transporte/Model/Responsavel.php'; /** * clsIndexBase class. @@ -702,6 +705,26 @@ class indice extends clsCadastro $this->campoQuebra2('#224488'); + // Transporte escolar + $transporteMapper = new Transporte_Model_AlunoDataMapper(); + $transporte = NULL; + + try { + $transporte = $transporteMapper->find(array($this->cod_aluno)); + } + catch (Exception $e) { + } + + $bit = App_Model_SimNao::getInstance(); + $this->campoLista('transporte_aluno', 'Transporte', $bit->getEnums(), + !is_null($transporte) ? 1 : 0, 'transporteResponsavel();'); + + $responsavel = Transporte_Model_Responsavel::getInstance(); + $this->campoLista('transporte_responsavel', 'Responsável', $responsavel->getEnums(), + !is_null($transporte) ? $transporte->get('responsavel') : 0); + + $this->campoQuebra2('#224488'); + $obj_beneficio = new clsPmieducarAlunoBeneficio(); $obj_beneficio_lista = $obj_beneficio->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1); @@ -1611,10 +1634,11 @@ class indice extends clsCadastro if ($this->ref_idpes) { if ($obj->existePessoa()) { - $obj->edita(); + $aluno = $obj->edita(); + $this->cod_aluno = $aluno['cod_aluno']; } else { - $obj->cadastra(); + $this->cod_aluno = $obj->cadastra(); } } } @@ -1634,6 +1658,10 @@ class indice extends clsCadastro } } + // Atualiza a informação de uso de transporte escolar. + $this->_cadastraTransporte($this->cod_aluno, $this->transporte_aluno, + $this->transporte_responsavel, $this->pessoa_logada); + header('Location: educar_aluno_det.php?cod_aluno=' . $this->cod_aluno); die(); } @@ -1765,6 +1793,53 @@ class indice extends clsCadastro return $nome_do_arquivo; } + + /** + * Cadastra ou atualiza a informação de uso de transporte escolar. + * + * @access protected + * @param int $codAluno Código do aluno + * @param bool $transporte [Opcional] TRUE para cadastrar/atualizar e FALSE + * para remover a informação de uso de transporte escolar + * @param int $responsavel [Opcional] Código do responsável pelo transporte + * escolar, valor mapeado para o enum Transporte_Model_Responsavel. Apenas + * obrigatório caso $transporte = TRUE + * @param int $user Código do usuário a alterar o registroo + * @return bool TRUE caso tenha criado/editado/apagado o registro com sucesso + * @since Método disponível desde a versão 1.2.0 + */ + function _cadastraTransporte($codAluno, $transporte = TRUE, $responsavel = NULL, + $user) + { + $data = array( + 'aluno' => $codAluno, + 'responsavel' => $responsavel, + 'user' => $user, + 'created_at' => 'NOW()' + ); + + $transporteMapper = new Transporte_Model_AlunoDataMapper(); + + if ($transporte) { + if (is_null($responsavel)) { + return FALSE; + } + + try { + $transporteMapper->find(array('aluno' => $codAluno)); + } + catch (Exception $e) { + $transporteMapper->save( + $transporteMapper->createNewEntityInstance($data) + ); + } + } + else { + $transporteMapper->delete(array('aluno' => $codAluno)); + } + + return TRUE; + } } // Instancia objeto de página @@ -2083,4 +2158,18 @@ if (!$_GET['cod_aluno']) { } /** Javascript condicional */ ?> +Event.observe(window, 'load', transporteResponsavel, false); + +function transporteResponsavel() +{ + obj1 = document.getElementById('transporte_aluno'); + obj2 = document.getElementById('transporte_responsavel'); + + if (obj1.value == 1) { + obj2.disabled = false; + } + else { + obj2.disabled = true; + } +} \ No newline at end of file diff --git a/ieducar/intranet/educar_aluno_det.php b/ieducar/intranet/educar_aluno_det.php index 2c89294..b0fe987 100644 --- a/ieducar/intranet/educar_aluno_det.php +++ b/ieducar/intranet/educar_aluno_det.php @@ -34,6 +34,7 @@ require_once 'include/clsBanco.inc.php'; require_once 'include/pmieducar/geral.inc.php'; require_once 'App/Model/ZonaLocalizacao.php'; +require_once 'Transporte/Model/AlunoDataMapper.php'; /** * clsIndexBase class. @@ -610,6 +611,20 @@ class indice extends clsDetalhe )); } + // Transporte escolar. + $transporteMapper = new Transporte_Model_AlunoDataMapper(); + $transporteAluno = NULL; + try { + $transporteAluno = $transporteMapper->find(array('aluno' => $this->cod_aluno)); + } + catch (Exception $e) { + } + + $this->addDetalhe(array('Transporte escolar', isset($transporteAluno) ? 'Sim' : 'Não')); + if ($transporteAluno) { + $this->addDetalhe(array('Responsável transporte', $transporteAluno->responsavel)); + } + $this->addDetalhe(array('Matrícula', $this->montaTabelaMatricula())); // Verificação de permissão para cadastro. -- libgit2 0.21.2