From 1d95e57dd7a73c7206fad7ee7aad6ad91cbd33bf Mon Sep 17 00:00:00 2001 From: Eriksen Costa Paixão Date: Thu, 30 Jul 2009 18:19:41 +0000 Subject: [PATCH] Refactoring para coding standards --- ieducar/intranet/educar_reserva_vaga_cad.php | 387 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ieducar/intranet/educar_reserva_vaga_lst.php | 440 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ieducar/intranet/include/pmieducar/clsPmieducarReservaVaga.inc.php | 1304 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 3 files changed, 1052 insertions(+), 1079 deletions(-) diff --git a/ieducar/intranet/educar_reserva_vaga_cad.php b/ieducar/intranet/educar_reserva_vaga_cad.php index 6b3ad1a..4250525 100644 --- a/ieducar/intranet/educar_reserva_vaga_cad.php +++ b/ieducar/intranet/educar_reserva_vaga_cad.php @@ -1,214 +1,219 @@ + * + * 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í + * @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL + * @package Core + * @subpackage ReservaVaga + * @since Arquivo disponível desde a versão 1.0.0 + * @version $Id$ + */ + +require_once 'include/clsBase.inc.php'; +require_once 'include/clsCadastro.inc.php'; +require_once 'include/clsBanco.inc.php'; +require_once 'include/pmieducar/geral.inc.php'; class clsIndexBase extends clsBase { - function Formular() - { - $this->SetTitulo( "{$this->_instituicao} i-Educar - Reserva Vaga" ); - $this->processoAp = "639"; - } + function Formular() { + $this->SetTitulo($this->_instituicao . ' i-Educar - Reserva Vaga'); + $this->processoAp = '639'; + } } class indice extends clsCadastro { - /** - * Referencia pega da session para o idpes do usuario atual - * - * @var int - */ - var $pessoa_logada; - - var $ref_cod_escola; - var $ref_cod_serie; - var $ref_cod_aluno; - var $nm_aluno; - var $nm_aluno_; - - var $ref_cod_instituicao; - var $ref_cod_curso; - - var $passo; - - var $nm_aluno_ext; - var $cpf_responsavel; - var $tipo_aluno; - - function Inicializar() - { - $retorno = "Novo"; - @session_start(); - $this->pessoa_logada = $_SESSION['id_pessoa']; - @session_write_close(); - - $this->ref_cod_serie=$_GET["ref_cod_serie"]; - $this->ref_cod_escola=$_GET["ref_cod_escola"]; - - $obj_permissoes = new clsPermissoes(); - $obj_permissoes->permissao_cadastra( 639, $this->pessoa_logada, 7, "educar_reserva_vaga_lst.php" ); - -// $this->url_cancelar = "educar_reserva_vaga_lst.php"; -// $this->nome_url_cancelar = "Cancelar"; - return $retorno; - } - - function Gerar() - { - if ($this->ref_cod_aluno) - { - $obj_reserva_vaga = new clsPmieducarReservaVaga(); - $lst_reserva_vaga = $obj_reserva_vaga->lista( null,null,null,null,null,$this->ref_cod_aluno,null,null,null,null,1 ); - // verifica se o aluno já possui reserva alguma reserva ativa no sistema - if ( is_array($lst_reserva_vaga) ) - { - echo ""; - die(); - } - echo ""; - } - $this->campoOculto("ref_cod_serie", $this->ref_cod_serie); - $this->campoOculto("ref_cod_escola", $this->ref_cod_escola); - -// $this->nm_aluno = $_POST["nm_aluno"]; - $this->nm_aluno = $this->nm_aluno_; - - $this->campoTexto("nm_aluno", "Aluno", $this->nm_aluno, 30, 255, false, false, false, "", "","","",true); - - $this->campoOculto("nm_aluno_", $this->nm_aluno_); - $this->campoOculto("ref_cod_aluno", $this->ref_cod_aluno); - - $this->campoOculto("tipo_aluno", "i"); - - $this->campoTexto("nm_aluno_ext","Nome aluno", $this->nm_aluno_ext,50,255,false); - $this->campoCpf("cpf_responsavel","CPF responsável", $this->cpf_responsavel,false,""); - - $this->campoOculto("passo",1); - - $this->acao_enviar = 'acao2()'; - - $this->url_cancelar = "educar_reserva_vaga_lst.php"; - $this->nome_url_cancelar = "Cancelar"; - } - - function Novo() - { - @session_start(); - $this->pessoa_logada = $_SESSION['id_pessoa']; - @session_write_close(); - - if ($this->passo == 2) - return true; - - - $obj_reserva_vaga = new clsPmieducarReservaVaga( null,$this->ref_cod_escola,$this->ref_cod_serie,null,$this->pessoa_logada,$this->ref_cod_aluno,null,null,1, $this->nm_aluno_ext, idFederal2int($this->cpf_responsavel) ); - $cadastrou = $obj_reserva_vaga->cadastra(); - if( $cadastrou ) - { - $this->mensagem .= "Reserva de Vaga efetuada com sucesso.
"; - header( "Location: educar_reservada_vaga_det.php?cod_reserva_vaga={$cadastrou}" ); - die(); - return true; - } - - $this->mensagem = "Reserva de Vaga não realizada.
"; - return false; - } + /** + * Referência a usuário da sessão + * @var int + */ + var $pessoa_logada = NULL; + + var $ref_cod_escola; + var $ref_cod_serie; + var $ref_cod_aluno; + var $nm_aluno; + var $nm_aluno_; + + var $ref_cod_instituicao; + var $ref_cod_curso; + + var $passo; + + var $nm_aluno_ext; + var $cpf_responsavel; + var $tipo_aluno; + + function Inicializar() + { + $retorno = 'Novo'; + session_start(); + $this->pessoa_logada = $_SESSION['id_pessoa']; + session_write_close(); + + $this->ref_cod_serie = $_GET['ref_cod_serie']; + $this->ref_cod_escola = $_GET['ref_cod_escola']; + + $obj_permissoes = new clsPermissoes(); + $obj_permissoes->permissao_cadastra(639, $this->pessoa_logada, 7, + 'educar_reserva_vaga_lst.php'); + + return $retorno; + } + + function Gerar() + { + if ($this->ref_cod_aluno) { + $obj_reserva_vaga = new clsPmieducarReservaVaga(); + $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, NULL, NULL, NULL, NULL, + $this->ref_cod_aluno, NULL, NULL, NULL, NULL, 1); + + // Verifica se o aluno já possui reserva alguma reserva ativa no sistema + if (is_array($lst_reserva_vaga)) { + echo " + "; + die(); + } + + echo " + "; + } + + $this->campoOculto('ref_cod_serie', $this->ref_cod_serie); + $this->campoOculto('ref_cod_escola', $this->ref_cod_escola); + + $this->nm_aluno = $this->nm_aluno_; + + $this->campoTexto('nm_aluno', 'Aluno', $this->nm_aluno, 30, 255, FALSE, + FALSE, FALSE, '', "", + '', '', TRUE); + + $this->campoOculto('nm_aluno_', $this->nm_aluno_); + $this->campoOculto('ref_cod_aluno', $this->ref_cod_aluno); + + $this->campoOculto('tipo_aluno', 'i'); + + $this->campoTexto('nm_aluno_ext', 'Nome aluno', $this->nm_aluno_ext, 50, 255, FALSE); + $this->campoCpf('cpf_responsavel', 'CPF responsável', + $this->cpf_responsavel, FALSE, ""); + + $this->campoOculto('passo', 1); + + $this->acao_enviar = 'acao2()'; + + $this->url_cancelar = 'educar_reserva_vaga_lst.php'; + $this->nome_url_cancelar = 'Cancelar'; + } + + function Novo() + { + session_start(); + $this->pessoa_logada = $_SESSION['id_pessoa']; + session_write_close(); + + if ($this->passo == 2) { + return true; + } + + $obj_reserva_vaga = new clsPmieducarReservaVaga(NULL, $this->ref_cod_escola, + $this->ref_cod_serie, NULL, $this->pessoa_logada, $this->ref_cod_aluno, NULL, + NULL, 1, $this->nm_aluno_ext, idFederal2int($this->cpf_responsavel)); + + $cadastrou = $obj_reserva_vaga->cadastra(); + + if ($cadastrou) { + $this->mensagem .= 'Reserva de Vaga efetuada com sucesso.
'; + header('Location: educar_reservada_vaga_det.php?cod_reserva_vaga=' . $cadastrou); + die(); + } + + $this->mensagem = 'Reserva de Vaga não realizada.
'; + return FALSE; + } } -// cria uma extensao da classe base +// Instancia objeto de página $pagina = new clsIndexBase(); -// cria o conteudo + +// Instancia objeto de conteúdo $miolo = new indice(); -// adiciona o conteudo na clsBase -$pagina->addForm( $miolo ); -// gera o html + +// Atribui o conteúdo à  página +$pagina->addForm($miolo); + +// Gera o código HTML $pagina->MakeAll(); ?> - \ No newline at end of file diff --git a/ieducar/intranet/educar_reserva_vaga_lst.php b/ieducar/intranet/educar_reserva_vaga_lst.php index 981162f..ba2254b 100644 --- a/ieducar/intranet/educar_reserva_vaga_lst.php +++ b/ieducar/intranet/educar_reserva_vaga_lst.php @@ -1,243 +1,233 @@ + * + * 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í + * @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL + * @package Core + * @subpackage ReservaVaga + * @since Arquivo disponível desde a versão 1.0.0 + * @version $Id$ + */ + +require_once 'include/clsBase.inc.php'; +require_once 'include/clsListagem.inc.php'; +require_once 'include/clsBanco.inc.php'; +require_once 'include/pmieducar/geral.inc.php'; class clsIndexBase extends clsBase { - function Formular() - { - $this->SetTitulo( "{$this->_instituicao} i-Educar - Reserva Vaga" ); - $this->processoAp = "639"; - } + public function Formular() { + $this->SetTitulo($this->_instituicao . ' i-Educar - Reserva Vaga'); + $this->processoAp = '639'; + } } class indice extends clsListagem { - /** - * Referencia pega da session para o idpes do usuario atual - * - * @var int - */ - var $pessoa_logada; - - /** - * Titulo no topo da pagina - * - * @var int - */ - var $titulo; - - /** - * Quantidade de registros a ser apresentada em cada pagina - * - * @var int - */ - var $limite; - - /** - * Inicio dos registros a serem exibidos (limit) - * - * @var int - */ - var $offset; - - var $ref_cod_escola; - var $ref_cod_serie; - var $ref_usuario_exc; - var $ref_usuario_cad; - var $data_cadastro; - var $data_exclusao; - var $ativo; - var $ref_ref_cod_serie; - var $ref_cod_curso; - var $ref_cod_instituicao; - - function Gerar() - { - @session_start(); - $this->pessoa_logada = $_SESSION['id_pessoa']; - session_write_close(); - - $this->titulo = "Reserva Vaga - Listagem"; - - foreach( $_GET AS $var => $val ) // passa todos os valores obtidos no GET para atributos do objeto - $this->$var = ( $val === "" ) ? null: $val; - - $this->addBanner( "imagens/nvp_top_intranet.jpg", "imagens/nvp_vert_intranet.jpg", "Intranet" ); - - $lista_busca = array( - "Série", - "Curso" - ); - - $obj_permissao = new clsPermissoes(); - $nivel_usuario = $obj_permissao->nivel_acesso($this->pessoa_logada); - if ($nivel_usuario == 1) - { - $lista_busca[] = "Escola"; - $lista_busca[] = "Instituição"; - } - else if ($nivel_usuario == 2) - { - $lista_busca[] = "Escola"; - } - $this->addCabecalhos($lista_busca); - - $get_escola = true; -// $get_escola_curso = true; - $get_curso = true; - $get_escola_curso_serie = true; - include("include/pmieducar/educar_campo_lista.php"); - - // Paginador - $this->limite = 20; - $this->offset = ( $_GET["pagina_{$this->nome}"] ) ? $_GET["pagina_{$this->nome}"]*$this->limite-$this->limite: 0; - - $obj_escola_serie = new clsPmieducarEscolaSerie(); -// $obj_escola_serie->setOrderby( "hora_inicial ASC" ); - $obj_escola_serie->setLimite( $this->limite, $this->offset ); - - $lista = $obj_escola_serie->lista( - $this->ref_cod_escola, - $this->ref_ref_cod_serie, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - 1, - null, - null, - null, - null, - $this->ref_cod_instituicao, - $this->ref_cod_curso - ); - - $total = $obj_escola_serie->_total; - - // monta a lista - if( is_array( $lista ) && count( $lista ) ) - { - foreach ( $lista AS $registro ) - { - if( class_exists( "clsPmieducarSerie" ) ) - { - $obj_ref_cod_serie = new clsPmieducarSerie( $registro["ref_cod_serie"] ); - $det_ref_cod_serie = $obj_ref_cod_serie->detalhe(); - $nm_serie = $det_ref_cod_serie["nm_serie"]; - } - else - { - $registro["ref_cod_serie"] = "Erro na geração"; - echo ""; - } - if( class_exists( "clsPmieducarCurso" ) ) - { - $obj_curso = new clsPmieducarCurso( $registro["ref_cod_curso"] ); - $det_curso = $obj_curso->detalhe(); - $registro["ref_cod_curso"] = $det_curso["nm_curso"]; - } - else - { - $registro["ref_cod_serie"] = "Erro na geração"; - echo ""; - } - if( class_exists( "clsPmieducarEscola" ) ) - { - $obj_ref_cod_escola = new clsPmieducarEscola( $registro["ref_cod_escola"] ); - $det_ref_cod_escola = $obj_ref_cod_escola->detalhe(); - $nm_escola = $det_ref_cod_escola["nome"]; - } - else - { - $registro["ref_cod_escola"] = "Erro na geração"; - echo ""; - } - if( class_exists( "clsPmieducarInstituicao" ) ) - { - $obj_ref_cod_instituicao = new clsPmieducarInstituicao( $registro["ref_cod_instituicao"] ); - $det_ref_cod_instituicao = $obj_ref_cod_instituicao->detalhe(); - $registro["ref_cod_instituicao"] = $det_ref_cod_instituicao["nm_instituicao"]; - } - else - { - $registro["ref_cod_escola"] = "Erro na geração"; - echo ""; - } - - $lista_busca = array( - "{$nm_serie}", - "{$registro["ref_cod_curso"]}" - ); - - if ($nivel_usuario == 1) - { - $lista_busca[] = "{$nm_escola}"; - $lista_busca[] = "{$registro["ref_cod_instituicao"]}"; - } - else if ($nivel_usuario == 2) - { - $lista_busca[] = "{$nm_escola}"; - } - $this->addLinhas($lista_busca); - } - } - $this->addPaginador2( "educar_reserva_vaga_lst.php", $total, $_GET, $this->nome, $this->limite ); - $this->largura = "100%"; - } + /** + * Referência a usuário da sessão + * @var int + */ + var $pessoa_logada = NULL; + + /** + * Título no topo da página + * @var string + */ + var $titulo = ''; + + /** + * Limite de registros por página + * @var int + */ + var $limite = 0; + + /** + * Início dos registros a serem exibidos (limit) + * @var int + */ + var $offset = 0; + + var $ref_cod_escola; + var $ref_cod_serie; + var $ref_usuario_exc; + var $ref_usuario_cad; + var $data_cadastro; + var $data_exclusao; + var $ativo; + var $ref_ref_cod_serie; + var $ref_cod_curso; + var $ref_cod_instituicao; + + function Gerar() + { + @session_start(); + $this->pessoa_logada = $_SESSION['id_pessoa']; + session_write_close(); + + $this->titulo = "Reserva Vaga - Listagem"; + + foreach ($_GET as $var => $val) // passa todos os valores obtidos no GET para atributos do objeto + $this->$var = ($val === '') ? NULL : $val; + + $this->addBanner('imagens/nvp_top_intranet.jpg', 'imagens/nvp_vert_intranet.jpg', 'Intranet'); + + $lista_busca = array( + "Série", + "Curso" + ); + + $obj_permissao = new clsPermissoes(); + $nivel_usuario = $obj_permissao->nivel_acesso($this->pessoa_logada); + if ($nivel_usuario == 1) { + $lista_busca[] = 'Escola'; + $lista_busca[] = 'Instituição'; + } + elseif ($nivel_usuario == 2) { + $lista_busca[] = "Escola"; + } + $this->addCabecalhos($lista_busca); + + $get_escola = TRUE; + $get_curso = TRUE; + $get_escola_curso_serie = TRUE; + include 'include/pmieducar/educar_campo_lista.php'; + + // Paginador + $this->limite = 20; + $this->offset = $_GET['pagina_' . $this->nome] ? + $_GET['pagina_' . $this->nome] * $this->limite - $this->limite : + 0; + + $obj_escola_serie = new clsPmieducarEscolaSerie(); + $obj_escola_serie->setLimite($this->limite, $this->offset); + + $lista = $obj_escola_serie->lista( + $this->ref_cod_escola, + $this->ref_ref_cod_serie, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + 1, + NULL, + NULL, + NULL, + NULL, + $this->ref_cod_instituicao, + $this->ref_cod_curso + ); + + $total = $obj_escola_serie->_total; + + // monta a lista + if (is_array($lista) && count($lista)) { + foreach ($lista as $registro) { + if (class_exists('clsPmieducarSerie')) { + $obj_ref_cod_serie = new clsPmieducarSerie($registro['ref_cod_serie']); + $det_ref_cod_serie = $obj_ref_cod_serie->detalhe(); + $nm_serie = $det_ref_cod_serie['nm_serie']; + } + else { + $registro['ref_cod_serie'] = "Erro na geração"; + echo ""; + } + + if (class_exists('clsPmieducarCurso')) { + $obj_curso = new clsPmieducarCurso( $registro["ref_cod_curso"] ); + $det_curso = $obj_curso->detalhe(); + $registro["ref_cod_curso"] = $det_curso["nm_curso"]; + } + else { + $registro["ref_cod_serie"] = "Erro na geração"; + echo ""; + } + + if (class_exists('clsPmieducarEscola')) { + $obj_ref_cod_escola = new clsPmieducarEscola( $registro["ref_cod_escola"] ); + $det_ref_cod_escola = $obj_ref_cod_escola->detalhe(); + $nm_escola = $det_ref_cod_escola["nome"]; + } + else { + $registro["ref_cod_escola"] = "Erro na geração"; + echo ""; + } + + if (class_exists('clsPmieducarInstituicao')) { + $obj_ref_cod_instituicao = new clsPmieducarInstituicao( $registro["ref_cod_instituicao"] ); + $det_ref_cod_instituicao = $obj_ref_cod_instituicao->detalhe(); + $registro["ref_cod_instituicao"] = $det_ref_cod_instituicao["nm_instituicao"]; + } + else { + $registro["ref_cod_escola"] = "Erro na geração"; + echo ""; + } + + $lista_busca = array( + "{$nm_serie}", + "{$registro["ref_cod_curso"]}" + ); + + if ($nivel_usuario == 1) { + $lista_busca[] = "{$nm_escola}"; + $lista_busca[] = "{$registro["ref_cod_instituicao"]}"; + } + else if ($nivel_usuario == 2) { + $lista_busca[] = "{$nm_escola}"; + } + $this->addLinhas($lista_busca); + } + } + + $this->addPaginador2('educar_reserva_vaga_lst.php', $total, $_GET, $this->nome, $this->limite); + $this->largura = "100%"; + } } -// cria uma extensao da classe base + +// Instancia objeto de página $pagina = new clsIndexBase(); -// cria o conteudo + +// Instancia objeto de conteúdo $miolo = new indice(); -// adiciona o conteudo na clsBase -$pagina->addForm( $miolo ); -// gera o html + +// Atribui o conteúdo à  página +$pagina->addForm($miolo); + +// Gera o código HTML $pagina->MakeAll(); ?> - \ No newline at end of file diff --git a/ieducar/intranet/include/pmieducar/clsPmieducarReservaVaga.inc.php b/ieducar/intranet/include/pmieducar/clsPmieducarReservaVaga.inc.php index 8227dc8..c68d557 100644 --- a/ieducar/intranet/include/pmieducar/clsPmieducarReservaVaga.inc.php +++ b/ieducar/intranet/include/pmieducar/clsPmieducarReservaVaga.inc.php @@ -1,668 +1,646 @@ + * + * 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í + * @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í + * @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; - - // propriedades padrao - - /** - * 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 virgula, com os campos que devem ser selecionados na proxima chamado ao metodo lista - * - * @var string - */ - var $_campos_lista; - - /** - * Lista com todos os campos da tabela separados por virgula, padrao para selecao no metodo lista - * - * @var string - */ - var $_todos_campos; - - /** - * Valor que define a quantidade de registros a ser retornada pelo metodo lista - * - * @var int - */ - var $_limite_quantidade; - - /** - * Define o valor de offset no retorno dos registros no metodo lista - * - * @var int - */ - var $_limite_offset; - - /** - * Define o campo padrao para ser usado como padrao de ordenacao no metodo lista - * - * @var string - */ - var $_campo_order_by; - - - /** - * Construtor (PHP 4) - * - * @return object - */ - 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; - } - } - else if( 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; - } - } - else if( 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; - } - } - else if( 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; - } - } - else if( 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 bool - */ - 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; - } - - /** - * Edita os dados de um registro - * - * @return bool - */ - function edita() - { - if( is_numeric( $this->cod_reserva_vaga ) /*&& is_numeric( $this->ref_usuario_exc )*/ ) - { - - $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 filtrados de acordo com os parametros - * - * @return array - */ - 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 - */ - 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 - */ - 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 ) /*&& is_numeric( $this->ref_usuario_exc )*/ ) - { - - /* - delete - $db = new clsBanco(); - $db->Consulta( "DELETE FROM {$this->_tabela} WHERE cod_reserva_vaga = '{$this->cod_reserva_vaga}'" ); - return true; - */ - - $this->ativo = 0; - return $this->edita(); - } - return false; - } - - /** - * Define quais campos da tabela serao selecionados na invocacao do metodo lista - * - * @return null - */ - function setCamposLista( $str_campos ) - { - $this->_campos_lista = $str_campos; - } - - /** - * Define que o metodo Lista devera retornoar todos os campos da tabela - * - * @return null - */ - function resetCamposLista() - { - $this->_campos_lista = $this->_todos_campos; - } - - /** - * Define limites de retorno para o metodo lista - * - * @return null - */ - function setLimite( $intLimiteQtd, $intLimiteOffset = null ) - { - $this->_limite_quantidade = $intLimiteQtd; - $this->_limite_offset = $intLimiteOffset; - } - - /** - * Retorna a string com o trecho da query resposavel 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 ordenacao no metolo lista - * - * @return null - */ - function setOrderby( $strNomeCampo ) - { - // limpa a string de possiveis erros (delete, insert, etc) - //$strNomeCampo = eregi_replace(); - - if( is_string( $strNomeCampo ) && $strNomeCampo ) - { - $this->_campo_order_by = $strNomeCampo; - } - } - - /** - * Retorna a string com o trecho da query resposavel pela Ordenacao dos registros - * - * @return string - */ - function getOrderby() - { - if( is_string( $this->_campo_order_by ) ) - { - return " ORDER BY {$this->_campo_order_by} "; - } - return ""; - } - -} -?> \ No newline at end of file + 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 ''; + } + +} \ No newline at end of file -- libgit2 0.21.2