From a750338588790d041b501fa6ce73504464ae822f Mon Sep 17 00:00:00 2001 From: Lucas Schmoeller da Silva Date: Tue, 24 Mar 2015 08:46:07 -0300 Subject: [PATCH] Criado regra para armazenar notas necessárias no exame --- ieducar/intranet/include/modules/clsModulesNotaExame.inc.php | 337 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ieducar/misc/database/deltas/portabilis/71_cria_tabela_nota_exame.sql | 27 +++++++++++++++++++++++++++ ieducar/modules/Avaliacao/Views/DiarioApiController.php | 26 ++++++++++++++++++++++++-- 3 files changed, 388 insertions(+), 2 deletions(-) create mode 100644 ieducar/intranet/include/modules/clsModulesNotaExame.inc.php create mode 100644 ieducar/misc/database/deltas/portabilis/71_cria_tabela_nota_exame.sql diff --git a/ieducar/intranet/include/modules/clsModulesNotaExame.inc.php b/ieducar/intranet/include/modules/clsModulesNotaExame.inc.php new file mode 100644 index 0000000..9eb94c9 --- /dev/null +++ b/ieducar/intranet/include/modules/clsModulesNotaExame.inc.php @@ -0,0 +1,337 @@ + + * + * 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 Lucas Schmoeller da Silva + * @category i-Educar + * @license @@license@@ + * @package Module + * @since ? + * @version $Id$ + */ + +require_once( "include/pmieducar/geral.inc.php" ); + +/** + * clsModulesNotaExame class. + * + * @author Lucas Schmoeller da Silva + * @category i-Educar + * @license @@license@@ + * @package Module + * @since ? + * @version @@package_version@@ + */ + +class clsModulesNotaExame +{ + var $ref_cod_matricula; + var $ref_cod_componente_curricular; + var $nota_exame; + + // 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 clsModulesNotaExame($ref_cod_matricula = NULL , $ref_cod_componente_curricular = NULL, $nota_exame = NULL) + { + $db = new clsBanco(); + $this->_schema = "modules."; + $this->_tabela = "{$this->_schema}nota_exame"; + + $this->_campos_lista = $this->_todos_campos = "ref_cod_matricula, ref_cod_componente_curricular, nota_exame"; + + if( is_numeric( $ref_cod_matricula ) ) + { + $this->ref_cod_matricula = $ref_cod_matricula; + } + if( is_numeric( $ref_cod_componente_curricular ) ) + { + $this->ref_cod_componente_curricular = $ref_cod_componente_curricular; + } + if( is_numeric( $nota_exame ) ) + { + $this->nota_exame = $nota_exame; + } + } + + /** + * Cria um novo registro + * + * @return bool + */ + function cadastra() + { + if( is_numeric( $this->ref_cod_matricula ) && is_numeric( $this->ref_cod_componente_curricular ) && is_numeric( $this->nota_exame ) ) + { + $db = new clsBanco(); + + $campos = ""; + $valores = ""; + $gruda = ""; + + if( is_numeric( $this->ref_cod_matricula ) ) + { + $campos .= "{$gruda}ref_cod_matricula"; + $valores .= "{$gruda}'{$this->ref_cod_matricula}'"; + $gruda = ", "; + } + if( is_numeric( $this->ref_cod_componente_curricular ) ) + { + $campos .= "{$gruda}ref_cod_componente_curricular"; + $valores .= "{$gruda}'{$this->ref_cod_componente_curricular}'"; + $gruda = ", "; + } + if( is_numeric( $this->nota_exame ) ) + { + $campos .= "{$gruda}nota_exame"; + $valores .= "{$gruda}'{$this->nota_exame}'"; + $gruda = ", "; + } + + $db->Consulta( "INSERT INTO {$this->_tabela} ( $campos ) VALUES( $valores )" ); + return $this->ref_cod_matricula; + } + return false; + } + + /** + * Edita os dados de um registro + * + * @return bool + */ + function edita() + { + if( is_numeric( $this->ref_cod_matricula ) && is_numeric( $this->ref_cod_componente_curricular ) && is_numeric( $this->nota_exame ) ) + { + + $db = new clsBanco(); + $set = ""; + + if( is_numeric( $this->nota_exame ) ) + { + $set .= "{$gruda}nota_exame = '{$this->nota_exame}'"; + $gruda = ", "; + } + + if( $set ) + { + $db->Consulta( "UPDATE {$this->_tabela} SET $set WHERE ref_cod_matricula = '{$this->ref_cod_matricula}' AND ref_cod_componente_curricular = '{$this->ref_cod_componente_curricular}'" ); + return true; + } + } + return false; + } + + /** + * Retorna um array com os dados de um registro + * + * @return array + */ + function detalhe() + { + if( is_numeric( $this->ref_cod_matricula ) && is_numeric( $this->ref_cod_componente_curricular ) ) + { + + $db = new clsBanco(); + $db->Consulta( "SELECT {$this->_todos_campos} FROM {$this->_tabela} WHERE ref_cod_matricula = '{$this->ref_cod_matricula}' AND ref_cod_componente_curricular = '{$this->ref_cod_componente_curricular}'" ); + $db->ProximoRegistro(); + return $db->Tupla(); + } + return false; + } + + /** + * Retorna um array com os dados de um registro + * + * @return array + */ + function existe() + { + if( is_numeric( $this->ref_cod_matricula ) && is_numeric( $this->ref_cod_componente_curricular ) ) + { + + $db = new clsBanco(); + $db->Consulta( "SELECT 1 FROM {$this->_tabela} WHERE ref_cod_matricula = '{$this->ref_cod_matricula}' AND ref_cod_componente_curricular = '{$this->ref_cod_componente_curricular}'" ); + $db->ProximoRegistro(); + return $db->Tupla(); + } + return false; + } + + /** + * Exclui um registro + * + * @return bool + */ + function excluir() + { + if( is_numeric( $this->ref_cod_matricula ) && is_numeric( $this->ref_cod_componente_curricular ) ) + { + + $db = new clsBanco(); + $db->Consulta( "DELETE FROM {$this->_tabela} WHERE ref_cod_matricula = '{$this->ref_cod_matricula}' AND ref_cod_componente_curricular = '{$this->ref_cod_componente_curricular}'" ); + return true; + } + 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 diff --git a/ieducar/misc/database/deltas/portabilis/71_cria_tabela_nota_exame.sql b/ieducar/misc/database/deltas/portabilis/71_cria_tabela_nota_exame.sql new file mode 100644 index 0000000..8b4aeaf --- /dev/null +++ b/ieducar/misc/database/deltas/portabilis/71_cria_tabela_nota_exame.sql @@ -0,0 +1,27 @@ + -- // + + -- + -- Cria tabela temporaria que guarda nota do exame dos alunos + -- + -- @author Lucas Schmoeller da Silva + -- @license @@license@@ + -- @version $Id$ + + CREATE TABLE modules.nota_exame + ( + ref_cod_matricula integer NOT NULL, + ref_cod_componente_curricular integer NOT NULL, + nota_exame numeric(5,3), + CONSTRAINT moradia_aluno_fkey FOREIGN KEY (ref_cod_matricula) + REFERENCES pmieducar.matricula(cod_matricula) MATCH SIMPLE + ON UPDATE RESTRICT ON DELETE RESTRICT + ) + WITH ( + OIDS=TRUE + ); + + -- //@UNDO + + DROP TABLE modules.nota_exame; + + -- // \ No newline at end of file diff --git a/ieducar/modules/Avaliacao/Views/DiarioApiController.php b/ieducar/modules/Avaliacao/Views/DiarioApiController.php index b949ad2..a001568 100644 --- a/ieducar/modules/Avaliacao/Views/DiarioApiController.php +++ b/ieducar/modules/Avaliacao/Views/DiarioApiController.php @@ -47,6 +47,7 @@ require_once 'RegraAvaliacao/Model/TipoPresenca.php'; require_once 'RegraAvaliacao/Model/TipoParecerDescritivo.php'; require_once 'include/pmieducar/clsPmieducarMatricula.inc.php'; +require_once 'include/modules/clsModulesNotaExame.inc.php'; require_once 'Portabilis/Controller/ApiCoreController.php'; require_once 'Portabilis/Array/Utils.php'; @@ -404,7 +405,12 @@ class DiarioApiController extends ApiCoreController $this->appendResponse('componente_curricular_id', $this->getRequest()->componente_curricular_id); $this->appendResponse('matricula_id', $this->getRequest()->matricula_id); $this->appendResponse('situacao', $this->getSituacaoMatricula()); - $this->appendResponse('nota_necessaria_exame', $this->getNotaNecessariaExame($this->getRequest()->componente_curricular_id)); + $this->appendResponse('nota_necessaria_exame', $notaNecessariaExame = $this->getNotaNecessariaExame($this->getRequest()->componente_curricular_id)); + + if (!empty($notaNecessariaExame) && $this->getSituacaoMatricula()=='Em Exame') + $this->createOrUpdateNotaExame($this->getRequest()->matricula_id, $this->getRequest()->componente_curricular_id, $notaNecessariaExame); + else + $this->deleteNotaExame($this->getRequest()->matricula_id, $this->getRequest()->componente_curricular_id); } @@ -753,10 +759,15 @@ class DiarioApiController extends ApiCoreController $componente['nome'] = $this->safeString(strtoupper($_componente->get('nome')), false); $componente['nota_atual'] = $this->getNotaAtual($etapa = null, $componente['id']); $componente['nota_exame'] = $this->getNotaExame($componente['id']); - $componente['nota_necessaria_exame'] = ($componente['situacao'] != 'Em andamento' ? $this->getNotaNecessariaExame($componente['id']) : null ); $componente['falta_atual'] = $this->getFaltaAtual($etapa = null, $componente['id']); $componente['parecer_atual'] = $this->getParecerAtual($componente['id']); $componente['situacao'] = $this->getSituacaoMatricula($componente['id']); + $componente['nota_necessaria_exame'] = ($componente['situacao'] == 'Em Exame' ? $this->getNotaNecessariaExame($componente['id']) : null ); + + if (!empty($componente['nota_necessaria_exame'])) + $this->createOrUpdateNotaExame($matriculaId, $componente['id'], $componente['nota_necessaria_exame']); + else + $this->deleteNotaExame($matriculaId, $componente['id']); //buscando pela área do conhecimento $area = $this->getAreaConhecimento($componente['id']); @@ -805,6 +816,17 @@ class DiarioApiController extends ApiCoreController return $areaConhecimento; } + protected function createOrUpdateNotaExame($matriculaId, $componenteCurricularId, $notaExame) { + + $obj = new clsModulesNotaExame($matriculaId, $componenteCurricularId, $notaExame); + + return ($obj->existe() ? $obj->edita() : $obj->cadastra()); + } + + protected function deleteNotaExame($matriculaId, $componenteCurricularId){ + $obj = new clsModulesNotaExame($matriculaId, $componenteCurricularId); + return ($obj->excluir()); + } protected function getNotaAtual($etapa = null, $componenteCurricularId = null) { // defaults -- libgit2 0.21.2