Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TFilelList só carrega a primeira linha. Boa tarde Pessoal estou tentando carregar o TFieldList no método onEdit, porém só carrega a primeira linha segue o código abaixo. Agradeço desde já: ...
JH
TFilelList só carrega a primeira linha.  
Boa tarde Pessoal estou tentando carregar o TFieldList no método onEdit, porém só carrega a primeira linha segue o código abaixo. Agradeço desde já:

  1. <?php
  2. class OrdemPagamentoCadastroForm extends TPage
  3. {
  4.     private $form;
  5.     
  6.     /**
  7.      * Class constructor
  8.      * Creates the page
  9.      */
  10.     public function __construct()
  11.     {
  12.         parent::__construct();
  13.         
  14.         $this->form = new BootstrapFormBuilder('form_cadastro_etapa');
  15.         $this->form->setFormTitle('Cadastro Etapa');
  16.         $this->form->setFieldSizes('100%');
  17.         //$this->form->generateAria(); // automatic aria-label        
  18.         
  19.         $id = new THidden('id');
  20.         $nome = new TEntry('nome');
  21.         
  22.         $combo_fk_id_formulario = new TCombo('fk_id_formulario');
  23.         $combo_fk_id_formulario->enableSearch();
  24.         $combo_fk_id_formulario->addItems(['1'=>'Ordem de Pagamento São Paulo','2'=>'Ordem de Pagamento Salvador']);
  25.         $combo_fk_id_formulario->setSize('100%');
  26.         $this->form->addFields( [$id]);
  27.         $this->form->addFields([new TLabel('Nome:')], [$nome]);
  28.         $this->form->addFields([new TLabel('Formulario:')], [$combo_fk_id_formulario]);
  29.         $fk_id_usuario = new TDBCombo('fk_id_usuario[]'TSession::getValue('arquivo_banco'), 'SystemUser''id''name''name asc');
  30.         $fk_id_usuario->enableSearch();        
  31.         $fk_id_usuario->setSize('100%');       
  32.         
  33.         
  34.         $this->fieldlist = new TFieldList;
  35.         $this->fieldlist->width '100%';
  36.         $this->fieldlist->class .= ' dashed'// important
  37.         $this->fieldlist->name  'field_list_usuarios';
  38.         $this->fieldlist->addField'<b>Usuario - Ordem </b>',  $fk_id_usuario,  ['width' => '25%'] );
  39.         
  40.         $this->fieldlist->enableSorting();
  41.         
  42.         $this->form->addField($fk_id_usuario);        
  43.         
  44.         $this->fieldlist->addHeader();
  45.         $this->fieldlist->addDetail( new stdClass );
  46.         $this->fieldlist->addCloneAction();
  47.         
  48.         // add field list to the form
  49.         $this->form->addContent([], [$this->fieldlist]);
  50.         
  51.         
  52.         $this->form->addAction('Salvar', new TAction(array($this'onSave')), 'far:check-circle green');
  53.         
  54.         // wrap the page content using vertical box
  55.         $vbox = new TVBox;
  56.         $vbox->style 'width: 100%';
  57.         //$vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  58.         $vbox->add($this->form);
  59.         parent::add($vbox);
  60.     }
  61.     
  62.     /**
  63.      * Post data
  64.      */
  65.     public function onSave($param)
  66.     {
  67.         try 
  68.         {
  69.             $data $this->form->getData();
  70.             TTransaction::open(TSession::getValue('arquivo_banco'));
  71.             TForm::sendData('form_cadastro_etapa'$param);
  72.             
  73.             $cadastroPagamento = new CadastroEtapa;
  74.             $cadastroPagamento->id $data->id;
  75.             $cadastroPagamento->nome $data->nome;
  76.             $cadastroPagamento->fk_id_formulario $data->fk_id_formulario;
  77.             if(isset($data->fk_id_formulario) || sizeof($data->fk_id_formulario) > 0)
  78.             {
  79.                 $cadastroPagamento->store();
  80.                 $cont 0;
  81.                 
  82.                 foreach ($data->fk_id_usuario as $user) {
  83.                     
  84.                     $etapa_class = new Etapa;
  85.                     $etapa_class->fk_id_user $user;
  86.                     $etapa_class->fk_id_formulario $data->fk_id_formulario;
  87.                     $etapa_class->fk_id_cadastro $cadastroPagamento->id;
  88.                     $etapa_class->etapa $cont;
  89.                     $etapa_class->store();
  90.                     $cont $cont 1;
  91.                 }
  92.             }
  93.             TTransaction::close();
  94.         } 
  95.         catch (Exception $e
  96.         {
  97.             new TMessage('error'$e->getMessage());
  98.             TTransaction::rollback();
  99.             
  100.         }
  101.     }
  102.     public function onEdit($param)
  103.     {
  104.         $key $param['key'];
  105.         try 
  106.         {
  107.             TTransaction::open(TSession::getValue('arquivo_banco'));
  108.             $cadastroEtapa = new CadastroEtapa($key);
  109.             $criteria = new TCriteria;
  110.             $criteria->add(new TFilter('fk_id_cadastro''='$cadastroEtapa->id));
  111.             $etapas Etapa::getObjects($criteria);
  112.             $stdClass = new stdClass;
  113.             
  114.             $fk_id_users = [];
  115.             foreach ($etapas  as $etapa)
  116.             {
  117.                 $fk_id_users[] = $etapa->fk_id_user;
  118.             }
  119.             $qtd_linha sizeof($fk_id_users) -;
  120.             
  121.             print_r($fk_id_users);
  122.             $stdClass->id $cadastroEtapa->id;
  123.             $stdClass->nome $cadastroEtapa->nome;
  124.             $stdClass->fk_id_formulario $cadastroEtapa->fk_id_formulario;
  125.             $stdClass->fk_id_usuario $fk_id_users;
  126.             print_r($stdClass);
  127.             TFieldList::clear('field_list_usuarios');
  128.             TFieldList::addRows('field_list_usuarios'$qtd_linha);
  129.             TForm::sendData('form_cadastro_etapa'$stdClassfalsetrue200); // 200 ms of timeout after recreate rows!
  130.             //$this->form->setData($stdClass);
  131.             TTransaction::close();
  132.         } 
  133.         catch (Exception $e
  134.         {
  135.             new TMessage('error'$e->getMessage());
  136.             TTransaction::rollback();
  137.             
  138.         }
  139.     }
  140. }
  141. ?>

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 (1)


NR

Tente usar a função addDetail ao invés da TForm::sendData:
  1. <?php
  2. foreach ($etapas  as $etapa)
  3. {
  4.      $fk_id_users[] = $etapa->fk_id_user;
  5.                 
  6.      $this->fieldlist->addDetail((object)['fk_id_usuario'=>$etapa->fk_id_user]);
  7. }
  8. ?>