MO
Campo de outra classe em um Grid
Fechado
Galera ainda não consegui desenrolar, já tentaram me ajudar, mas sem sucesso ainda.
Meu problema é o seguinte, quero passar para o grid um informação de outra classe relacionada,
as classes são as seguintes:
Titular (Mestre)
Meu problema é o seguinte, quero passar para o grid um informação de outra classe relacionada,
as classes são as seguintes:
Titular (Mestre)
- <?php
- /**
- * Titular Active Record
- * @author <your-name-here>
- */
- class Titular extends TRecord
- {
- const TABLENAME = 'titular';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'serial'; // {max, serial}
- private $tipo_nec_esp;
- private $ocupacaoprof;
- private $escolaridade;
- private $sithabitacional;
- private $estado_civil;
- private $sitconjugal;
- private $situacao_trab;
- private $beneficio;
- private $tempo_trabalho;
- private $renda_mensal;
- private $renda_comp;
- private $compfams;
- /**
- * Constructor method
- */
- public function __construct(2599 = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct(2599, $callObjectLoad);
- parent::addAttribute('nome');
- parent::addAttribute('apelido');
- parent::addAttribute('cpf');
- parent::addAttribute('nis');
- parent::addAttribute('celular1');
- parent::addAttribute('celular2');
- parent::addAttribute('telefone');
- parent::addAttribute('contato');
- parent::addAttribute('sexo');
- parent::addAttribute('pai');
- parent::addAttribute('mae');
- parent::addAttribute('rg');
- parent::addAttribute('viarg');
- parent::addAttribute('datemisrg');
- parent::addAttribute('ufrg');
- parent::addAttribute('orgexprg');
- parent::addAttribute('datnasc');
- parent::addAttribute('naturalidade');
- parent::addAttribute('endereco');
- parent::addAttribute('numero');
- parent::addAttribute('complemento');
- parent::addAttribute('pontoref');
- parent::addAttribute('cep');
- parent::addAttribute('localtrabalho');
- parent::addAttribute('portnecesp');
- parent::addAttribute('qualnecespecial');
- parent::addAttribute('necadap');
- parent::addAttribute('qtdpesres');
- parent::addAttribute('valorbeneficio');
- parent::addAttribute('desistente');
- parent::addAttribute('declaracao');
- parent::addAttribute('situacaoderua');
- parent::addAttribute('assocmorador');
- parent::addAttribute('participa');
- parent::addAttribute('situacao_trab_id');
- parent::addAttribute('escolaridade_id');
- parent::addAttribute('ocupacaoprof_id');
- parent::addAttribute('tipo_nec_esp_id');
- parent::addAttribute('tempo_trabalho_id');
- parent::addAttribute('renda_mensal_id');
- parent::addAttribute('estado_civil_id');
- parent::addAttribute('beneficio_id');
- parent::addAttribute('sithabitacional_id');
- parent::addAttribute('sitconjugal_id');
- parent::addAttribute('bairro_id');
- parent::addAttribute('logradouro_id');
- parent::addAttribute('rendatotal');
- parent::addAttribute('renda_comp_id');
- parent::addAttribute('observacao');
- }
- /**
- * Method set_tipo_nec_esp
- * Sample of usage: $titular->tipo_nec_esp = $object;
- * @param $object Instance of TipoNecEsp
- */
- public function set_tipo_nec_esp(TipoNecEsp $object)
- {
- $this->tipo_nec_esp = $object;
- $this->tipo_nec_esp_id = $object->id;
- }
- /**
- * Method get_tipo_nec_esp
- * Sample of usage: $titular->tipo_nec_esp->attribute;
- * @returns TipoNecEsp instance
- */
- public function get_tipo_nec_esp()
- {
- // loads the associated object
- if (empty($this->tipo_nec_esp))
- $this->tipo_nec_esp = new TipoNecEsp($this->tipo_nec_esp_id);
- // returns the associated object
- return $this->tipo_nec_esp;
- }
- /**
- * Method set_ocupacaoprof
- * Sample of usage: $titular->ocupacaoprof = $object;
- * @param $object Instance of Ocupacaoprof
- */
- public function set_ocupacaoprof(Ocupacaoprof $object)
- {
- $this->ocupacaoprof = $object;
- $this->ocupacaoprof_id = $object->id;
- }
- /**
- * Method get_ocupacaoprof
- * Sample of usage: $titular->ocupacaoprof->attribute;
- * @returns Ocupacaoprof instance
- */
- public function get_ocupacaoprof()
- {
- // loads the associated object
- if (empty($this->ocupacaoprof))
- $this->ocupacaoprof = new Ocupacaoprof($this->ocupacaoprof_id);
- // returns the associated object
- return $this->ocupacaoprof;
- }
- /**
- * Method set_escolaridade
- * Sample of usage: $titular->escolaridade = $object;
- * @param $object Instance of Escolaridade
- */
- public function set_escolaridade(Escolaridade $object)
- {
- $this->escolaridade = $object;
- $this->escolaridade_id = $object->id;
- }
- /**
- * Method get_escolaridade
- * Sample of usage: $titular->escolaridade->attribute;
- * @returns Escolaridade instance
- */
- public function get_escolaridade()
- {
- // loads the associated object
- if (empty($this->escolaridade))
- $this->escolaridade = new Escolaridade($this->escolaridade_id);
- // returns the associated object
- return $this->escolaridade;
- }
- /**
- * Method set_sithabitacional
- * Sample of usage: $titular->sithabitacional = $object;
- * @param $object Instance of Sithabitacional
- */
- public function set_sithabitacional(Sithabitacional $object)
- {
- $this->sithabitacional = $object;
- $this->sithabitacional_id = $object->id;
- }
- /**
- * Method get_sithabitacional
- * Sample of usage: $titular->sithabitacional->attribute;
- * @returns Sithabitacional instance
- */
- public function get_sithabitacional()
- {
- // loads the associated object
- if (empty($this->sithabitacional))
- $this->sithabitacional = new Sithabitacional($this->sithabitacional_id);
- // returns the associated object
- return $this->sithabitacional;
- }
- /**
- * Method set_estado_civil
- * Sample of usage: $titular->estado_civil = $object;
- * @param $object Instance of EstadoCivil
- */
- public function set_estado_civil(EstadoCivil $object)
- {
- $this->estado_civil = $object;
- $this->estado_civil_id = $object->id;
- }
- /**
- * Method get_estado_civil
- * Sample of usage: $titular->estado_civil->attribute;
- * @returns EstadoCivil instance
- */
- public function get_estado_civil()
- {
- // loads the associated object
- if (empty($this->estado_civil))
- $this->estado_civil = new EstadoCivil($this->estado_civil_id);
- // returns the associated object
- return $this->estado_civil;
- }
- /**
- * Method set_sitconjugal
- * Sample of usage: $titular->sitconjugal = $object;
- * @param $object Instance of Sitconjugal
- */
- public function set_sitconjugal(Sitconjugal $object)
- {
- $this->sitconjugal = $object;
- $this->sitconjugal_id = $object->id;
- }
- /**
- * Method get_sitconjugal
- * Sample of usage: $titular->sitconjugal->attribute;
- * @returns Sitconjugal instance
- */
- public function get_sitconjugal()
- {
- // loads the associated object
- if (empty($this->sitconjugal))
- $this->sitconjugal = new Sitconjugal($this->sitconjugal_id);
- // returns the associated object
- return $this->sitconjugal;
- }
- /**
- * Method set_situacao_trab
- * Sample of usage: $titular->situacao_trab = $object;
- * @param $object Instance of SituacaoTrab
- */
- public function set_situacao_trab(SituacaoTrab $object)
- {
- $this->situacao_trab = $object;
- $this->situacao_trab_id = $object->id;
- }
- /**
- * Method get_situacao_trab
- * Sample of usage: $titular->situacao_trab->attribute;
- * @returns SituacaoTrab instance
- */
- public function get_situacao_trab()
- {
- // loads the associated object
- if (empty($this->situacao_trab))
- $this->situacao_trab = new SituacaoTrab($this->situacao_trab_id);
- // returns the associated object
- return $this->situacao_trab;
- }
- /**
- * Method set_beneficio
- * Sample of usage: $titular->beneficio = $object;
- * @param $object Instance of Beneficio
- */
- public function set_beneficio(Beneficio $object)
- {
- $this->beneficio = $object;
- $this->beneficio_id = $object->id;
- }
- /**
- * Method get_beneficio
- * Sample of usage: $titular->beneficio->attribute;
- * @returns Beneficio instance
- */
- public function get_beneficio()
- {
- // loads the associated object
- if (empty($this->beneficio))
- $this->beneficio = new Beneficio($this->beneficio_id);
- // returns the associated object
- return $this->beneficio;
- }
- /**
- * Method set_tempo_trabalho
- * Sample of usage: $titular->tempo_trabalho = $object;
- * @param $object Instance of TempoTrabalho
- */
- public function set_tempo_trabalho(TempoTrabalho $object)
- {
- $this->tempo_trabalho = $object;
- $this->tempo_trabalho_id = $object->id;
- }
- /**
- * Method get_tempo_trabalho
- * Sample of usage: $titular->tempo_trabalho->attribute;
- * @returns TempoTrabalho instance
- */
- public function get_tempo_trabalho()
- {
- // loads the associated object
- if (empty($this->tempo_trabalho))
- $this->tempo_trabalho = new TempoTrabalho($this->tempo_trabalho_id);
- // returns the associated object
- return $this->tempo_trabalho;
- }
- /**
- * Method set_renda_mensal
- * Sample of usage: $titular->renda_mensal = $object;
- * @param $object Instance of RendaMensal
- */
- public function set_renda_mensal(RendaMensal $object)
- {
- $this->renda_mensal = $object;
- $this->renda_mensal_id = $object->id;
- }
- /**
- * Method get_renda_mensal
- * Sample of usage: $titular->renda_mensal->attribute;
- * @returns RendaMensal instance
- */
- public function get_renda_mensal()
- {
- // loads the associated object
- if (empty($this->renda_mensal))
- $this->renda_mensal = new RendaMensal($this->renda_mensal_id);
- // returns the associated object
- return $this->renda_mensal;
- }
- /**
- * Method set_renda_comp
- * Sample of usage: $titular->renda_mensal = $object;
- * @param $object Instance of RendaMensal
- */
- public function set_renda_comp(RendaCompl $object)
- {
- $this->renda_comp = $object;
- $this->renda_comp_id = $object->id;
- }
- /**
- * Method get_renda_comp
- * Sample of usage: $titular->renda_mensal->attribute;
- * @returns RendaMensal instance
- */
- public function get_renda_comp()
- {
- // loads the associated object
- if (empty($this->renda_comp))
- $this->renda_comp = new RendaCompl($this->renda_comp_id);
- // returns the associated object
- return $this->renda_comp;
- }
- public function addCompfam(CompFam $object)
- {
- $this->compfams[] = $object;
- }
- public function getCompfams()
- {
- return $this->compfams;
- }
- public function load(2599)
- {
- $repository = new TRepository('CompFam');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('compf_titular_id','=',2599));
- $this->compfams = $repository->load($criteria);
- return parent::load(2599);
- }
- public function store()
- {
- parent::store();
- $repository = new TRepository('CompFam');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('compf_titular_id','=',$this->id));
- $criteria->delete($criteria);
- if ($htis->compfams)
- {
- foreach($this->compfams as $compfam)
- {
- unset($compfam->id);
- $compfam->compf_titular_id = $this->id;
- $compfam->store();
- }
- }
- }
- public function delete(2599 = NULL)
- {
- 2599 = isset(2599) ? 2599 : $this->id;
- $repository = new TRepository('CompFam');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('compf_titular_id','=',2599));
- $criteria->delete($criteria);
- parent::delete(2599);
- }
- }
Classe CompFam (Detalhe) "Composição Familiar"
Classe Grauparent (Relacionada com CompFam) - quero pegar o nome do parentesco dessa classe
Resumindo gostaria de fazer da seguinte forma, pegando o valor: $compfam->grauparent->grauparentesco
$titular = new Titular(2);
$compfam = $titular->getCompfams();
foreach ($titular->getCompfams() as $compfam)
{
print $compfam->compf_nome . ' - '. $compfam->compf_titular_id . $compfam->grauparent->grauparentesco.'
';
}
O nome do atributo no model CompFam é compf_grauparent_id:
Mas na função get_grauparent você está usando grauparent_id:
Isso mesmo deu certo, obrigado não estava enxergando, vlw!!