LJ
popular um radio através de composição
Estou precisando fazer um formulario que tem um radio que é feito dinamicamente através do relacionamento composição entre as classes Questionario_Tipo_Documento e Questionario_Opcoes.
Ao Executar o metodo onEdit consigo pegar as opçoes (L195) mas não sei como enviar para o formulario ?
OBS: removi do codigo abaixo o onSave e onDelete para facilitar.
Ao Executar o metodo onEdit consigo pegar as opçoes (L195) mas não sei como enviar para o formulario ?
OBS: removi do codigo abaixo o onSave e onDelete para facilitar.
- <?php
- /**
- * CompleteFormDataGridView
- *
- * @version 1.0
- * @package samples
- * @subpackage tutor
- * @author Pablo Dall'Oglio
- * @copyright Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- class Quest_Saude extends TPage
- {
- private $form; // registration form
- private $datagrid; // listing
- private $loaded;
- private $itens;
- /**
- * Class constructor
- * Creates the page, the form and the listing
- */
- public function __construct()
- {
- parent::__construct();
- // create the form
- $this->form = new TQuickForm('form_saude');
- $this->form->class = 'tform'; // CSS class
- $this->form->style = 'width: 640px';
- $this->form->setFormTitle(utf8_encode('Questionário de Sáude'));
- // create the form fields
- $questionario_tipo_documento_id = new TEntry('questionario_tipo_documento_id');
- $ds_questionario = new TText('ds_questionario');
- $radio = new TRadioGroup('radio');
- $itens = array();
- $itens['1'] ='SIM';
- $itens['2'] =utf8_encode('NÃO');
- //$itens = array();
- $radio->addItems($itens);
- // validacao
- //$name->addValidation('Name', new TRequiredValidator);
- // add the fields in the form
- $this->form->addQuickField('ID', $questionario_tipo_documento_id, 40);
- $this->form->addQuickField(utf8_encode('Questão'), $ds_questionario,200);
- $this->form->addQuickField(utf8_encode('Opções'), $radio,200);
- $ds_questionario->setSize(500,80);
- $radio->setLayout('vertical');
- // create the form actions
- $this->form->addQuickAction('Salvar', new TAction(array($this, 'onSave')), 'ico_save.png');
- $this->form->addQuickAction('Novo', new TAction(array($this, 'onEdit')), 'ico_new.png');
- // id not editable
- $questionario_tipo_documento_id->setEditable(FALSE);
- // create the datagrid
- $this->datagrid = new TQuickGrid;
- $this->datagrid->setHeight(320);
- // add the datagrid columns
- $this->datagrid->addQuickColumn('ID', 'questionario_tipo_documento_id', 'center', 50);
- $this->datagrid->addQuickColumn(utf8_encode('Questão'), 'ds_questionario','left', 390);
- // add the datagrid actions
- $this->datagrid->addQuickAction('Editar', new TDataGridAction(array($this, 'onEdit')), 'questionario_tipo_documento_id', 'ico_edit.png');
- $this->datagrid->addQuickAction('Deletar', new TDataGridAction(array($this, 'onDelete')), 'questionario_tipo_documento_id', 'ico_delete.png');
- // create the datagrid model
- $this->datagrid->createModel();
- // wrap objects
- $table = new TTable;
- $table->addRow()->addCell(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $table->addRow()->addCell($this->form);
- $table->addRow()->addCell($this->datagrid);
- // add the table in the page
- parent::add($table);
- }
- /**
- * method onReload()
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'samples'
- TTransaction::open('audesp');
- // creates a repository for Category
- $repository = new TRepository('Questionario_Tipo_Documento');
- // creates a criteria, ordered by id
- $criteria = new TCriteria;
- $order = isset($param['order']) ? $param['order'] : 'ordem_questionario';
- $criteria->setProperty('order', $order);
- // tp -= 1128 - Saude
- $criteria->add(new TFilter('tp_documento_id','=','1128'));
- $criteria->add(new TFilter('fl_valida','=','t'));
- // load the objects according to criteria
- $questoes = $repository->load($criteria);
- $this->datagrid->clear();
- if ($questoes)
- {
- // iterate the collection of active records
- foreach ($questoes as $questao)
- {
- // add the object inside the datagrid
- $questao->ds_questionario = utf8_encode($questao->ds_questionario);
- $this->datagrid->addItem($questao);
- }
- }
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * method onEdit()
- * Executed whenever the user clicks at the edit button
- */
- function onEdit($param)
- {
- try
- {
- if (isset($param['key']))
- {
- // get the parameter e exibe mensagem
- $key=$param['key'];
- // open a transaction with database 'samples'
- TTransaction::open('audesp');
- // instantiates object Category
- $questao = new Questionario_Tipo_Documento($key);
- $opcoes = $questao->getOpcoes();
- foreach ($opcoes as $opcao) {
- $opcao->ds_opcao = utf8_encode($opcao->ds_opcao);
- $itens[$opcao->questionario_opcoes_id] = $opcao->ds_opcao;
- echo $opcao->ds_opcao." \n"; // correto esta aparecendo as opcoes do BD ex sim parcialmente não
- }
- $questao->ds_questionario = utf8_encode($questao->ds_questionario);
- // lança os data do category no form
- $this->form->setData($questao);
- // close the transaction
- TTransaction::close();
- $this->onReload();
- }
- else
- {
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * method show()
- * Shows the page e seu conteúdo
- */
- function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded)
- {
- $this->onReload( func_get_arg(0) );
- }
- parent::show();
- }
- }
- ?>