CS
Carregar dados de Composição na Datagrid
Possuo uma classe Prova e uma outra chamada Alternativa. Elas estão relacionadas por Composição. Gostaria que uma célula da datagrid que mostra as provas cadastradas trouxesse TODAS as alternativas cadastradas para a respectiva prova. Não entendi como fazer a array de dados aparecer numa única célula da datagrid. O que estou fazendo errado?
- <?php
- <?php
- class Prova extends TRecord
- {
- const TABLENAME = 'prova';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'serial'; // {max, serial}
- private $alternativas;
- private $curso;
- /**
- * Constructor method
- */
- public function __construct($id = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct($id, $callObjectLoad);
- parent::addAttribute('texto_questao');
- parent::addAttribute('caminho_imagem');
- parent::addAttribute('curso_id');
- }
- /**
- * Method addAlternativa
- * Add a Alternativa to the Prova
- * @param $object Instance of Alternativa
- */
- public function addAlternativa(Alternativa $object)
- {
- $this->alternativas[] = $object;
- }
- /**
- * Method getAlternativas
- * Return the Prova' Alternativa's
- * @return Collection of Alternativa
- */
- public function getAlternativas()
- {
- // loads the associated object
- if (empty($this->alternativa))
- // $this->alternativa = Alternativa::where('prova_id', '=', $id)->load();
- // foreach ($this->alternativa as $alt)
- // {
- // $return $alt;
- // }
- // returns the associated object
- return $this->alternativa;
- }
- /**
- * Method getCurso
- * Return the Prova' Curso's
- * @return Collection of Curso
- */
- public function get_curso()
- {
- // loads the associated object
- if (empty($this->curso))
- $this->curso = new Curso($this->curso_id);
- // returns the associated object
- return $this->curso;
- }
- /**
- * Reset aggregates
- */
- public function clearParts()
- {
- $this->alternativas = array();
- }
- /**
- * Load the object and its aggregates
- * @param $id object ID
- */
- public function load($id)
- {
- // load the related Alternativa objects
- $repository = new TRepository('Alternativa');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('prova_id', '=', $id));
- $this->alternativas = $repository->load($criteria);
- // load the object itself
- return parent::load($id);
- }
- /**
- * Store the object and its aggregates
- */
- public function store()
- {
- // store the object itself
- parent::store();
- // delete the related Alternativa objects
- $criteria = new TCriteria;
- $criteria->add(new TFilter('prova_id', '=', $this->id));
- $repository = new TRepository('Alternativa');
- $repository->delete($criteria);
- // store the related Alternativa objects
- if ($this->alternativas)
- {
- foreach ($this->alternativas as $alternativa)
- {
- unset($alternativa->id);
- $alternativa->prova_id = $this->id;
- $alternativa->store();
- }
- }
- }
- /**
- * Delete the object and its aggregates
- * @param $id object ID
- */
- public function delete($id = NULL)
- {
- $id = isset($id) ? $id : $this->id;
- // delete the related Alternativa objects
- $repository = new TRepository('Alternativa');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('prova_id', '=', $id));
- $repository->delete($criteria);
- // delete the object itself
- parent::delete($id);
- }
- }
- ?>
Cleber
Se entendi, vc precisa de uma datagrid onde mostre "grupos" de "alternativas" por "prova" imagino que seja isso.
Tenta usar o setGroup
$this->datagrid->setGroupColumn(....
Exemplo
adianti.com.br/framework_files/tutor/index.php?class=DatagridColumnG
Felipe,
muito obrigado. A sua dica resolveu o meu problema!