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

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (0)