ET
Problema com TDBCheckGroup
Bom dia a todos.
Tenho um formulário de cadastro que não está carregando os dados do TDBCheckGroup na tela de edição de cadastro (Todos os outros dados são cadastrados menos o do TDBCheckGroup), não consigo encontrar o erro alguem pode me ajudar?
Desde já agradeço.
Tenho um formulário de cadastro que não está carregando os dados do TDBCheckGroup na tela de edição de cadastro (Todos os outros dados são cadastrados menos o do TDBCheckGroup), não consigo encontrar o erro alguem pode me ajudar?
Desde já agradeço.
CÓDIGO DO FORM
- <?php
- /**
- * AlunoForm Form
- * @author <your name here>
- */
- class AlunoForm extends TPage
- {
- protected $form; // form
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Aluno');
- $this->form->setFormTitle('Cadastro de Aluno');
- // create the form fields
- $id = new TEntry('id');
- $nome = new TEntry('nome');
- $serie_id = new TDBCombo('serie_id', 'farolerp', 'Serie', 'id', 'descricao');
- $dt_nascimento = new TDate('dt_nascimento');
- $municipio_id = new TDBUniqueSearch('municipio_id', 'farolerp', 'Municipio', 'id', 'nome');
- $estado_id = new TDBCombo('estado_id', 'farolerp', 'Estado', 'id', 'nome');
- $n_documento = new TEntry('n_documento');
- $tipo_documento = new TEntry('tipo_documento');
- $nome_pai = new TEntry('nome_pai');
- $profissao_pai = new TEntry('profissao_pai');
- $nome_mae = new TEntry('nome_mae');
- $profissao_mae = new TEntry('profissao_mae');
- $endereco = new TEntry('endereco');
- $cidade = new TDBUniqueSearch('cidade', 'farolerp', 'Municipio', 'id', 'nome');
- $telefone = new TEntry('telefone');
- $celular = new TEntry('celular');
- $local_origem_aluno_id = new TDBRadioGroup('local_origem_aluno_id', 'farolerp', 'LocalOrigemAluno', 'id', 'nome');
- $rede_origem_aluno_id = new TDBRadioGroup('rede_origem_aluno_id', 'farolerp', 'RedeOrigemAluno', 'id', 'nome');
- $frequencia_ano_anterior_id = new TDBRadioGroup('frequencia_ano_anterior_id', 'farolerp', 'FrequenciaAnoAnterior', 'id', 'descricao');
- $nivel_ensino_origem_aluno_id = new TDBRadioGroup('nivel_ensino_origem_aluno_id', 'farolerp', 'NivelEnsinoOrigemAluno', 'id', 'descricao');
- $situacao_ingresso_id = new TDBRadioGroup('situacao_ingresso_id', 'farolerp', 'SituacaoIngresso', 'id', 'descricao');
- $educacao_especial_id = new TDBCheckGroup('educacao_especial_id', 'farolerp', 'EducacaoEspecial', 'id', 'descricao');
- $tipo_sanguineo = new TEntry('tipo_sanguineo');
- $necessidades_especiais_id = new TDBCheckGroup('necessidades_especiais_id', 'farolerp', 'NecessidadesEspeciais', 'id', 'descricao');
- $problemas_alergicos = new TCombo('problemas_alergicos');
- $descricao_alergia = new TText('descricao_alergia');
- $outros = new TText('outros');
- // add the combo filds problemas_alergicos
- $problemas_alergicos->addItems(array('SIM'=>'SIM',
- 'NÃO'=>'NÃO'
- ));
- //Rádio Goups
- //local_origem_aluno_id
- $local_origem_aluno_id->setLayout('horizontal');
- if ($local_origem_aluno_id->getLabels())
- {
- foreach ($local_origem_aluno_id->getLabels() as $label)
- {
- $label->setSize(200);
- }
- }
- //rede_origem_aluno_id
- $rede_origem_aluno_id->setLayout('horizontal');
- if ($rede_origem_aluno_id->getLabels())
- {
- foreach ($rede_origem_aluno_id->getLabels() as $label)
- {
- $label->setSize(200);
- }
- }
- //frequencia_ano_anterior_id
- $frequencia_ano_anterior_id->setLayout('horizontal');
- if ($frequencia_ano_anterior_id->getLabels())
- {
- foreach ($frequencia_ano_anterior_id->getLabels() as $label)
- {
- $label->setSize(200);
- }
- }
- //nivel_ensino_origem_aluno_id
- $nivel_ensino_origem_aluno_id->setLayout('horizontal');
- if ($nivel_ensino_origem_aluno_id->getLabels())
- {
- foreach ($nivel_ensino_origem_aluno_id->getLabels() as $label)
- {
- $label->setSize(400);
- }
- }
- //educacao_especial_id
- $educacao_especial_id->setLayout('horizontal');
- if ($educacao_especial_id->getLabels())
- {
- foreach ($educacao_especial_id->getLabels() as $label)
- {
- $label->setSize(200);
- }
- }
- //necessidades_especiais_id
- $necessidades_especiais_id->setLayout('horizontal');
- if ($necessidades_especiais_id->getLabels())
- {
- foreach ($necessidades_especiais_id->getLabels() as $label)
- {
- $label->setSize(400);
- }
- }
- // Formatação de datas
- $dt_nascimento->setDatabaseMask('yyyy/mm/dd');
- $dt_nascimento->setMask('dd/mm/yyyy');
- $nome->setMaxLength(100);
- $n_documento->setMaxLength(40);
- $tipo_documento->setMaxLength(100);
- $nome_pai->setMaxLength(100);
- $profissao_pai->setMaxLength(100);
- $nome_mae->setMaxLength(100);
- $profissao_mae->setMaxLength(100);
- $endereco->setMaxLength(100);
- $telefone->setMask('(99)9999-9999');
- $celular->setMask('(99)9.9999-9999');
- $tipo_sanguineo->setMaxLength(2);
- // add the fields
- $this->form->addContent( [new TFormSeparator('<b>Identificação do aluno</b>')]);
- $this->form->addFields( [ new TLabel('Código') ], [ $id ] );
- $this->form->addFields( [ new TLabel('Nome', '#ff0000') ], [ $nome ] );
- $this->form->addFields( [ new TLabel('Série') ], [ $serie_id ], [ new TLabel('Data Nascimento') ], [ $dt_nascimento ] );
- $this->form->addFields( [ new TLabel('Municipio') ], [ $municipio_id ], [ new TLabel('Estado') ], [ $estado_id ] );
- $this->form->addFields( [ new TLabel('Nº do Documento') ], [ $n_documento ], [ new TLabel('Tipo de Documento') ], [ $tipo_documento ] );
- $this->form->addFields( [ new TLabel('Nome do Pai') ], [ $nome_pai ], [ new TLabel('Profissão do Pai') ], [ $profissao_pai ] );
- $this->form->addFields( [ new TLabel('Nome Mãe') ], [ $nome_mae ], [ new TLabel('Profissão da Mãe') ], [ $profissao_mae ] );
- $this->form->addFields( [ new TLabel('Endereço') ], [ $endereco ], [ new TLabel('Cidade') ], [ $cidade ] );
- $this->form->addFields( [ new TLabel('Telefone') ], [ $telefone ], [ new TLabel('Celular') ], [ $celular ] );
- $this->form->addContent( [new TFormSeparator('<b>Local de origem do aluno</b>')]);
- $this->form->addFields( [ new TLabel('') ],[ $local_origem_aluno_id ] );
- $this->form->addContent( [new TFormSeparator('<b>Rede de origem do aluno</b>')]);
- $this->form->addFields( [ new TLabel('') ], [ $rede_origem_aluno_id ] );
- $this->form->addContent( [new TFormSeparator('<b>Frequência á escola em relação ao ano anterior</b>')]);
- $this->form->addFields( [ new TLabel('') ], [ $frequencia_ano_anterior_id ] );
- $this->form->addContent( [new TFormSeparator('<b>Nivel de ensino de origem do aluno</b>')]);
- $this->form->addFields( [ new TLabel('') ], [ $nivel_ensino_origem_aluno_id ] );
- $this->form->addContent( [new TFormSeparator('<b>Situacao do aluno na série que está ingressando</b>')]);
- $this->form->addFields( [ new TLabel('') ], [ $situacao_ingresso_id ] );
- $this->form->addContent( [new TFormSeparator('<b>Educação Especial</b>')]);
- $this->form->addFields( [ new TLabel('') ], [ $educacao_especial_id ] );
- $this->form->addFields( [ new TLabel('Tipo Sanguíneo') ], [ $tipo_sanguineo ] );
- $this->form->addContent( [new TFormSeparator('<b>Aluno de necessidades especiais</b>')]);
- $this->form->addFields( [ new TLabel('') ], [ $necessidades_especiais_id ] );
- $this->form->addFields( [ new TLabel('Problemas Alérgicos') ], [ $problemas_alergicos ] );
- $this->form->addFields( [ new TLabel('Descrição da Alergia') ], [ $descricao_alergia ] );
- $this->form->addFields( [ new TLabel('Outros') ], [ $outros ] );
- $nome->addValidation('Nome', new TRequiredValidator);
- // set sizes
- $id->setSize('100');
- $nome->setSize('100%');
- $serie_id->setSize('100%');
- $dt_nascimento->setSize('100%');
- $municipio_id->setSize('100%');
- $estado_id->setSize('100%');
- $n_documento->setSize('100%');
- $tipo_documento->setSize('100%');
- $nome_pai->setSize('100%');
- $profissao_pai->setSize('100%');
- $nome_mae->setSize('100%');
- $profissao_mae->setSize('100%');
- $endereco->setSize('100%');
- $cidade->setSize('100%');
- $telefone->setSize('100%');
- $celular->setSize('100%');
- $local_origem_aluno_id->setSize('100%');
- $rede_origem_aluno_id->setSize('100%');
- $frequencia_ano_anterior_id->setSize('100%');
- $nivel_ensino_origem_aluno_id->setSize('100%');
- $situacao_ingresso_id->setSize('100%');
- $educacao_especial_id->setSize('100%');
- $tipo_sanguineo->setSize('38%');
- $necessidades_especiais_id->setSize('100%');
- $problemas_alergicos->setSize('38%');
- $descricao_alergia->setSize('100%');
- $outros->setSize('100%');
- if (!empty($id))
- {
- $id->setEditable(FALSE);
- }
- /** samples
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( '100%' ); // set size
- **/
- // create the form actions
- $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:save');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addActionLink(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 100%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- /**
- * Save form data
- * @param $param Request
- */
- public function onSave( $param )
- {
- try
- {
- TTransaction::open('farolerp'); // open a transaction
- /**
- // Enable Debug logger for SQL operations inside the transaction
- TTransaction::setLogger(new TLoggerSTD); // standard output
- TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
- **/
- $this->form->validate(); // validate form data
- $data = $this->form->getData(); // get form data as array
- $object = new Aluno; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- // get the generated id
- $data->id = $object->id;
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
- new TMessage('info', AdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear(TRUE);
- }
- /**
- * Load object to form data
- * @param $param Request
- */
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('farolerp'); // open a transaction
- $object = new Aluno($key); // instantiates the Active Record
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear(TRUE);
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
- ?>
MODEL
- <?php
- /**
- * Aluno Active Record
- * @author <your-name-here>
- */
- class Aluno extends TRecord
- {
- const TABLENAME = 'aluno';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'serial'; // {max, serial}
- private $serie;
- private $municipio;
- private $rede_origem_aluno;
- private $estado;
- private $situacao_ingresso;
- private $local_origem_aluno;
- private $frequencia_ano_anterior;
- private $nivel_ensino_origem_aluno;
- private $educacao_especial;
- private $necessidades_especiais;
- /**
- * Constructor method
- */
- public function __construct($id = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct($id, $callObjectLoad);
- parent::addAttribute('nome');
- parent::addAttribute('serie_id');
- parent::addAttribute('dt_nascimento');
- parent::addAttribute('municipio_id');
- parent::addAttribute('estado_id');
- parent::addAttribute('n_documento');
- parent::addAttribute('tipo_documento');
- parent::addAttribute('nome_pai');
- parent::addAttribute('profissao_pai');
- parent::addAttribute('nome_mae');
- parent::addAttribute('profissao_mae');
- parent::addAttribute('endereco');
- parent::addAttribute('cidade');
- parent::addAttribute('telefone');
- parent::addAttribute('celular');
- parent::addAttribute('local_origem_aluno_id');
- parent::addAttribute('rede_origem_aluno_id');
- parent::addAttribute('frequencia_ano_anterior_id');
- parent::addAttribute('nivel_ensino_origem_aluno_id');
- parent::addAttribute('situacao_ingresso_id');
- parent::addAttribute('educacao_especial_id');
- parent::addAttribute('tipo_sanguineo');
- parent::addAttribute('necessidades_especiais_id');
- parent::addAttribute('problemas_alergicos');
- parent::addAttribute('descricao_alergia');
- parent::addAttribute('outros');
- }
- /**
- * Method set_serie
- * Sample of usage: $aluno->serie = $object;
- * @param $object Instance of Serie
- */
- public function set_serie(Serie $object)
- {
- $this->serie = $object;
- $this->serie_id = $object->id;
- }
- /**
- * Method get_serie
- * Sample of usage: $aluno->serie->attribute;
- * @returns Serie instance
- */
- public function get_serie()
- {
- // loads the associated object
- if (empty($this->serie))
- $this->serie = new Serie($this->serie_id);
- // returns the associated object
- return $this->serie;
- }
- /**
- * Method set_municipio
- * Sample of usage: $aluno->municipio = $object;
- * @param $object Instance of Municipio
- */
- public function set_municipio(Municipio $object)
- {
- $this->municipio = $object;
- $this->municipio_id = $object->id;
- }
- /**
- * Method get_municipio
- * Sample of usage: $aluno->municipio->attribute;
- * @returns Municipio instance
- */
- public function get_municipio()
- {
- // loads the associated object
- if (empty($this->municipio))
- $this->municipio = new Municipio($this->municipio_id);
- // returns the associated object
- return $this->municipio;
- }
- /**
- * Method set_rede_origem_aluno
- * Sample of usage: $aluno->rede_origem_aluno = $object;
- * @param $object Instance of RedeOrigemAluno
- */
- public function set_rede_origem_aluno(RedeOrigemAluno $object)
- {
- $this->rede_origem_aluno = $object;
- $this->rede_origem_aluno_id = $object->id;
- }
- /**
- * Method get_rede_origem_aluno
- * Sample of usage: $aluno->rede_origem_aluno->attribute;
- * @returns RedeOrigemAluno instance
- */
- public function get_rede_origem_aluno()
- {
- // loads the associated object
- if (empty($this->rede_origem_aluno))
- $this->rede_origem_aluno = new RedeOrigemAluno($this->rede_origem_aluno_id);
- // returns the associated object
- return $this->rede_origem_aluno;
- }
- /**
- * Method set_estado
- * Sample of usage: $aluno->estado = $object;
- * @param $object Instance of Estado
- */
- public function set_estado(Estado $object)
- {
- $this->estado = $object;
- $this->estado_id = $object->id;
- }
- /**
- * Method get_estado
- * Sample of usage: $aluno->estado->attribute;
- * @returns Estado instance
- */
- public function get_estado()
- {
- // loads the associated object
- if (empty($this->estado))
- $this->estado = new Estado($this->estado_id);
- // returns the associated object
- return $this->estado;
- }
- /**
- * Method set_situacao_ingresso
- * Sample of usage: $aluno->situacao_ingresso = $object;
- * @param $object Instance of SituacaoIngresso
- */
- public function set_situacao_ingresso(SituacaoIngresso $object)
- {
- $this->situacao_ingresso = $object;
- $this->situacao_ingresso_id = $object->id;
- }
- /**
- * Method get_situacao_ingresso
- * Sample of usage: $aluno->situacao_ingresso->attribute;
- * @returns SituacaoIngresso instance
- */
- public function get_situacao_ingresso()
- {
- // loads the associated object
- if (empty($this->situacao_ingresso))
- $this->situacao_ingresso = new SituacaoIngresso($this->situacao_ingresso_id);
- // returns the associated object
- return $this->situacao_ingresso;
- }
- /**
- * Method set_local_origem_aluno
- * Sample of usage: $aluno->local_origem_aluno = $object;
- * @param $object Instance of LocalOrigemAluno
- */
- public function set_local_origem_aluno(LocalOrigemAluno $object)
- {
- $this->local_origem_aluno = $object;
- $this->local_origem_aluno_id = $object->id;
- }
- /**
- * Method get_local_origem_aluno
- * Sample of usage: $aluno->local_origem_aluno->attribute;
- * @returns LocalOrigemAluno instance
- */
- public function get_local_origem_aluno()
- {
- // loads the associated object
- if (empty($this->local_origem_aluno))
- $this->local_origem_aluno = new LocalOrigemAluno($this->local_origem_aluno_id);
- // returns the associated object
- return $this->local_origem_aluno;
- }
- /**
- * Method set_frequencia_ano_anterior
- * Sample of usage: $aluno->frequencia_ano_anterior = $object;
- * @param $object Instance of FrequenciaAnoAnterior
- */
- public function set_frequencia_ano_anterior(FrequenciaAnoAnterior $object)
- {
- $this->frequencia_ano_anterior = $object;
- $this->frequencia_ano_anterior_id = $object->id;
- }
- /**
- * Method get_frequencia_ano_anterior
- * Sample of usage: $aluno->frequencia_ano_anterior->attribute;
- * @returns FrequenciaAnoAnterior instance
- */
- public function get_frequencia_ano_anterior()
- {
- // loads the associated object
- if (empty($this->frequencia_ano_anterior))
- $this->frequencia_ano_anterior = new FrequenciaAnoAnterior($this->frequencia_ano_anterior_id);
- // returns the associated object
- return $this->frequencia_ano_anterior;
- }
- /**
- * Method set_nivel_ensino_origem_aluno
- * Sample of usage: $aluno->nivel_ensino_origem_aluno = $object;
- * @param $object Instance of NivelEnsinoOrigemAluno
- */
- public function set_nivel_ensino_origem_aluno(NivelEnsinoOrigemAluno $object)
- {
- $this->nivel_ensino_origem_aluno = $object;
- $this->nivel_ensino_origem_aluno_id = $object->id;
- }
- /**
- * Method get_nivel_ensino_origem_aluno
- * Sample of usage: $aluno->nivel_ensino_origem_aluno->attribute;
- * @returns NivelEnsinoOrigemAluno instance
- */
- public function get_nivel_ensino_origem_aluno()
- {
- // loads the associated object
- if (empty($this->nivel_ensino_origem_aluno))
- $this->nivel_ensino_origem_aluno = new NivelEnsinoOrigemAluno($this->nivel_ensino_origem_aluno_id);
- // returns the associated object
- return $this->nivel_ensino_origem_aluno;
- }
- /**
- * Method set_educacao_especial
- * Sample of usage: $aluno->educacao_especial = $object;
- * @param $object Instance of EducacaoEspecial
- */
- public function set_educacao_especial(EducacaoEspecial $object)
- {
- $this->educacao_especial = $object;
- $this->educacao_especial_id = $object->id;
- }
- /**
- * Method get_educacao_especial
- * Sample of usage: $aluno->educacao_especial->attribute;
- * @returns EducacaoEspecial instance
- */
- public function get_educacao_especial()
- {
- // loads the associated object
- if (empty($this->educacao_especial))
- $this->educacao_especial = new EducacaoEspecial($this->educacao_especial_id);
- // returns the associated object
- return $this->educacao_especial;
- }
- /**
- * Method set_necessidades_especiais
- * Sample of usage: $aluno->necessidades_especiais = $object;
- * @param $object Instance of NecessidadesEspeciais
- */
- public function set_necessidades_especiais(NecessidadesEspeciais $object)
- {
- $this->necessidades_especiais = $object;
- $this->necessidades_especiais_id = $object->id;
- }
- /**
- * Method get_necessidades_especiais
- * Sample of usage: $aluno->necessidades_especiais->attribute;
- * @returns NecessidadesEspeciais instance
- */
- public function get_necessidades_especiais()
- {
- // loads the associated object
- if (empty($this->necessidades_especiais))
- $this->necessidades_especiais = new NecessidadesEspeciais($this->necessidades_especiais_id);
- // returns the associated object
- return $this->necessidades_especiais;
- }
- }
- ?>