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. ...
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.
 
  1. <?php
  2. /**
  3. * CompleteFormDataGridView
  4. *
  5. * @version 1.0
  6. * @package samples
  7. * @subpackage tutor
  8. * @author Pablo Dall'Oglio
  9. * @copyright Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10. * @license http://www.adianti.com.br/framework-license
  11. */
  12. class Quest_Saude extends TPage
  13. {
  14. private $form; // registration form
  15. private $datagrid; // listing
  16. private $loaded;
  17. private $itens;
  18. /**
  19. * Class constructor
  20. * Creates the page, the form and the listing
  21. */
  22. public function __construct()
  23. {
  24. parent::__construct();
  25. // create the form
  26. $this->form = new TQuickForm('form_saude');
  27. $this->form->class = 'tform'; // CSS class
  28. $this->form->style = 'width: 640px';
  29. $this->form->setFormTitle(utf8_encode('Questionário de Sáude'));
  30. // create the form fields
  31. $questionario_tipo_documento_id = new TEntry('questionario_tipo_documento_id');
  32. $ds_questionario = new TText('ds_questionario');
  33. $radio = new TRadioGroup('radio');
  34. $itens = array();
  35. $itens['1'] ='SIM';
  36. $itens['2'] =utf8_encode('NÃO');
  37. //$itens = array();
  38. $radio->addItems($itens);
  39. // validacao
  40. //$name->addValidation('Name', new TRequiredValidator);
  41. // add the fields in the form
  42. $this->form->addQuickField('ID', $questionario_tipo_documento_id, 40);
  43. $this->form->addQuickField(utf8_encode('Questão'), $ds_questionario,200);
  44. $this->form->addQuickField(utf8_encode('Opções'), $radio,200);
  45. $ds_questionario->setSize(500,80);
  46. $radio->setLayout('vertical');
  47. // create the form actions
  48. $this->form->addQuickAction('Salvar', new TAction(array($this, 'onSave')), 'ico_save.png');
  49. $this->form->addQuickAction('Novo', new TAction(array($this, 'onEdit')), 'ico_new.png');
  50. // id not editable
  51. $questionario_tipo_documento_id->setEditable(FALSE);
  52. // create the datagrid
  53. $this->datagrid = new TQuickGrid;
  54. $this->datagrid->setHeight(320);
  55. // add the datagrid columns
  56. $this->datagrid->addQuickColumn('ID', 'questionario_tipo_documento_id', 'center', 50);
  57. $this->datagrid->addQuickColumn(utf8_encode('Questão'), 'ds_questionario','left', 390);
  58. // add the datagrid actions
  59. $this->datagrid->addQuickAction('Editar', new TDataGridAction(array($this, 'onEdit')), 'questionario_tipo_documento_id', 'ico_edit.png');
  60. $this->datagrid->addQuickAction('Deletar', new TDataGridAction(array($this, 'onDelete')), 'questionario_tipo_documento_id', 'ico_delete.png');
  61. // create the datagrid model
  62. $this->datagrid->createModel();
  63. // wrap objects
  64. $table = new TTable;
  65. $table->addRow()->addCell(new TXMLBreadCrumb('menu.xml', __CLASS__));
  66. $table->addRow()->addCell($this->form);
  67. $table->addRow()->addCell($this->datagrid);
  68. // add the table in the page
  69. parent::add($table);
  70. }
  71. /**
  72. * method onReload()
  73. * Load the datagrid with the database objects
  74. */
  75. function onReload($param = NULL)
  76. {
  77. try
  78. {
  79. // open a transaction with database 'samples'
  80. TTransaction::open('audesp');
  81. // creates a repository for Category
  82. $repository = new TRepository('Questionario_Tipo_Documento');
  83. // creates a criteria, ordered by id
  84. $criteria = new TCriteria;
  85. $order = isset($param['order']) ? $param['order'] : 'ordem_questionario';
  86. $criteria->setProperty('order', $order);
  87. // tp -= 1128 - Saude
  88. $criteria->add(new TFilter('tp_documento_id','=','1128'));
  89. $criteria->add(new TFilter('fl_valida','=','t'));
  90. // load the objects according to criteria
  91. $questoes = $repository->load($criteria);
  92. $this->datagrid->clear();
  93. if ($questoes)
  94. {
  95. // iterate the collection of active records
  96. foreach ($questoes as $questao)
  97. {
  98. // add the object inside the datagrid
  99. $questao->ds_questionario = utf8_encode($questao->ds_questionario);
  100. $this->datagrid->addItem($questao);
  101. }
  102. }
  103. // close the transaction
  104. TTransaction::close();
  105. $this->loaded = true;
  106. }
  107. catch (Exception $e) // in case of exception
  108. {
  109. // shows the exception error message
  110. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  111. // undo all pending operations
  112. TTransaction::rollback();
  113. }
  114. }
  115. /**
  116. * method onEdit()
  117. * Executed whenever the user clicks at the edit button
  118. */
  119. function onEdit($param)
  120. {
  121. try
  122. {
  123. if (isset($param['key']))
  124. {
  125. // get the parameter e exibe mensagem
  126. $key=$param['key'];
  127. // open a transaction with database 'samples'
  128. TTransaction::open('audesp');
  129. // instantiates object Category
  130. $questao = new Questionario_Tipo_Documento($key);
  131. $opcoes = $questao->getOpcoes();
  132. foreach ($opcoes as $opcao) {
  133. $opcao->ds_opcao = utf8_encode($opcao->ds_opcao);
  134. $itens[$opcao->questionario_opcoes_id] = $opcao->ds_opcao;
  135. echo $opcao->ds_opcao." \n"; // correto esta aparecendo as opcoes do BD ex sim parcialmente não
  136. }
  137. $questao->ds_questionario = utf8_encode($questao->ds_questionario);
  138. // lança os data do category no form
  139. $this->form->setData($questao);
  140. // close the transaction
  141. TTransaction::close();
  142. $this->onReload();
  143. }
  144. else
  145. {
  146. $this->form->clear();
  147. }
  148. }
  149. catch (Exception $e) // in case of exception
  150. {
  151. // shows the exception error message
  152. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  153. // undo all pending operations
  154. TTransaction::rollback();
  155. }
  156. }
  157. /**
  158. * method show()
  159. * Shows the page e seu conteúdo
  160. */
  161. function show()
  162. {
  163. // check if the datagrid is already loaded
  164. if (!$this->loaded)
  165. {
  166. $this->onReload( func_get_arg(0) );
  167. }
  168. parent::show();
  169. }
  170. }
  171. ?>

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (0)