From 8541bcd9df82c927e0b39ab083b1967d1fb2a577 Mon Sep 17 00:00:00 2001 From: Lucas D'Avila Date: Thu, 31 Jan 2013 22:36:42 -0200 Subject: [PATCH] Aplicado correções a modelos / datamapper modulos educacenso e transporte --- ieducar/modules/Educacenso/Model/Aluno.php | 18 ++++++++++-------- ieducar/modules/Educacenso/Model/AlunoDataMapper.php | 23 ++++++++++++++++++----- ieducar/modules/Transporte/Model/AlunoDataMapper.php | 9 +++++++++ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/ieducar/modules/Educacenso/Model/Aluno.php b/ieducar/modules/Educacenso/Model/Aluno.php index d254500..335eae1 100644 --- a/ieducar/modules/Educacenso/Model/Aluno.php +++ b/ieducar/modules/Educacenso/Model/Aluno.php @@ -45,6 +45,16 @@ require_once 'Educacenso/Model/CodigoReferencia.php'; */ class Educacenso_Model_Aluno extends Educacenso_Model_CodigoReferencia { + protected $_data = array( + 'aluno' => NULL, + 'alunoInep' => NULL, + 'nomeInep' => NULL, + 'fonte' => NULL, + 'created_at' => NULL, + 'updated_at' => NULL + ); + + public function getDefaultValidatorCollection() { $validators = array( @@ -54,12 +64,4 @@ class Educacenso_Model_Aluno extends Educacenso_Model_CodigoReferencia return array_merge($validators, parent::getDefaultValidatorCollection()); } - - public function __construct(array $options = array()) - { - $this->_data['aluno'] = NULL; - $this->_data['alunoInep'] = NULL; - - parent::__construct($options); - } } \ No newline at end of file diff --git a/ieducar/modules/Educacenso/Model/AlunoDataMapper.php b/ieducar/modules/Educacenso/Model/AlunoDataMapper.php index 5f49804..f5bc050 100644 --- a/ieducar/modules/Educacenso/Model/AlunoDataMapper.php +++ b/ieducar/modules/Educacenso/Model/AlunoDataMapper.php @@ -48,14 +48,27 @@ class Educacenso_Model_AlunoDataMapper extends Educacenso_Model_CodigoReferencia protected $_entityClass = 'Educacenso_Model_Aluno'; protected $_tableName = 'educacenso_cod_aluno'; + protected $_attributeMap = array( + 'aluno' => 'cod_aluno', + 'alunoInep' => 'cod_aluno_inep', + 'nomeInep' => 'nome_inep', + 'fonte' => 'fonte', + 'created_at' => 'created_at', + 'updated_at' => 'updated_at' + ); + + // aparentemente o campo alunoInep não deveria fazer parte da chave primaria, pois este pode + // ser alterado no cadastro de aluno, #TODO criar migracao para remover PK de tal campo ? protected $_primaryKey = array( - 'aluno', 'alunoInep' + 'aluno' #, 'alunoInep' ); - public function __construct(clsBanco $db = NULL) + // fixup para find funcionar em tabelas cujo PK não se chama id + protected function _getFindStatment($pkey) { - $this->_attributeMap['aluno'] = 'cod_aluno'; - $this->_attributeMap['alunoInep'] = 'cod_aluno_inep'; - parent::__construct($db); + if (! is_array($pkey)) + $pkey = array('cod_aluno' => $pkey); + + return parent::_getFindStatment($pkey); } } \ No newline at end of file diff --git a/ieducar/modules/Transporte/Model/AlunoDataMapper.php b/ieducar/modules/Transporte/Model/AlunoDataMapper.php index fe146d8..b5a7e5a 100644 --- a/ieducar/modules/Transporte/Model/AlunoDataMapper.php +++ b/ieducar/modules/Transporte/Model/AlunoDataMapper.php @@ -58,4 +58,13 @@ class Transporte_Model_AlunoDataMapper extends CoreExt_DataMapper ); protected $_primaryKey = array('aluno'); + + // fixup para find funcionar em tabelas cujo PK não se chama id + protected function _getFindStatment($pkey) + { + if (! is_array($pkey)) + $pkey = array('aluno_id' => $pkey); + + return parent::_getFindStatment($pkey); + } } \ No newline at end of file -- libgit2 0.21.2