Lançado Adianti Framework 8.1!
Clique aqui para saber mais
TDataGrid com TCheckButton não funciona (Ajuda) Duas TDataGrid com TCheckButton na segunda não retorna nada no getData mesmo fazendo addField, alguém pode me ajudar? código abaixo: ...
IS
TDataGrid com TCheckButton não funciona (Ajuda)  
Duas TDataGrid com TCheckButton na segunda não retorna nada no getData mesmo fazendo addField, alguém pode me ajudar? código abaixo:


  1. <?php
  2. class ExameList extends TPage
  3. {
  4.     private $form;      // search form
  5.     private $datagrid;  // listing
  6.     private $total;
  7.     private $cartgrid;
  8.     private $pageNavigation;
  9.     private $loaded;
  10.     
  11.     public function __construct()
  12.     {
  13.         parent::__construct();
  14.         //new TSession;
  15.         
  16.         // creates the form
  17.         $this->form = new TForm('form_exame');
  18.         
  19.         // create the form fields
  20.         $description   = new TEntry('paciente');
  21.         $check = new THidden('check_');
  22.         $description->setSize(170);
  23.         $description->setValue(TSession::getValue('product_description'));
  24.         
  25.         $table = new TTable;
  26.         
  27.         $row $table->addRow();
  28.         $cell=$row->addCell('');
  29.         $cell->width100;
  30.         $row->addCell($description);
  31.         
  32.         // creates the action button
  33.         $button1=new TButton('find');
  34.         $button1->setAction(new TAction(array($this'onSearch')), 'Busca');
  35.         $button1->setImage('fa:search');
  36.         $row->addCell($button1);
  37.         $this->form->add($table);
  38.         $this->form->setFields(array($description$button1));
  39.         
  40.         // creates a DataGrid
  41.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  42.         $this->cartgrid = new BootstrapDatagridWrapper(new TDataGrid);
  43.         $this->datagrid->style 'width:100%';
  44.         $this->cartgrid->style 'width:100%';
  45.         $this->datagrid->disableDefaultClick();
  46.         $this->cartgrid->disableDefaultClick();
  47.         
  48.         //$panel = new TPanelGroup(_t('Datagrids with Checkbutton'));
  49.         //$panel->add($this->cartgrid)->style = 'overflow-x:auto';
  50.         //$this->form->add($panel);
  51.         // creates the datagrid columns
  52.         $cartao = new TDataGridColumn('CARTAO',  'Cartão SUS',  'left');
  53.         $paciente = new TDataGridColumn('NOME_PAC',  'Nome',  'left');
  54.         $sexo = new TDataGridColumn('sexo->nome',  'Sexo',  'left');
  55.         
  56.         $this->datagrid->addColumn($cartao); 
  57.         $this->datagrid->addColumn($paciente); 
  58.         $this->datagrid->addColumn($sexo);
  59.         
  60.         $DATA_NASC =  new TDataGridColumn('DATA_NASC',  'Idade',  'center');
  61.         $this->datagrid->addColumn($DATA_NASC);
  62.         $DATA_NASC->setTransformer(function($value$object$row)
  63.         {        
  64.             $rotulo calcIdade::calcularIdade($value);               
  65.             if ($rotulo <= 18)
  66.             {
  67.                 $bar = new TProgressBar;
  68.                 $bar->setMask('<b>'.$rotulo.'</b>');
  69.                 $bar->setValue(100);
  70.                 $bar->setClass('warning');
  71.                 return $bar;
  72.             }
  73.             else if (($rotulo >= 19) && ($rotulo <= 59))
  74.             {
  75.                 $bar = new TProgressBar;
  76.                 $bar->setMask('<b>'.$rotulo.'</b>');
  77.                 $bar->setValue(100);
  78.                 $bar->setClass('success');
  79.                 return $bar;
  80.             }
  81.             else
  82.             {
  83.                 $bar = new TProgressBar;
  84.                 $bar->setMask('<b>'.$rotulo.'</b>');
  85.                 $bar->setValue(100);
  86.                 $bar->setClass('danger');
  87.                 return $bar
  88.             }                  
  89.         });
  90.         
  91.         $status = new TDataGridColumn('status',  'Status',  'center');
  92.         $status->setTransformer(function($value$object$row)
  93.         {       
  94.             if ($value == 1)
  95.             { 
  96.                 $bar = new TProgressBar;
  97.                 $bar->setMask('<b>Coletado</b>');
  98.                 $bar->setValue(100);
  99.                 $bar->setClass('warning');
  100.                 return $bar;
  101.             }
  102.             else if ($value == 0)
  103.             { 
  104.                 $bar = new TProgressBar;
  105.                 $bar->setMask('<b>Solicitado</b>');
  106.                 $bar->setValue(100);
  107.                 $bar->setClass('success');
  108.                 return $bar;
  109.             }
  110.         });
  111.         $this->datagrid->addColumn($status);
  112.         
  113.         /////////////////////////////////
  114.       
  115.         $check = new TDataGridColumn('check_',  'ID',  'center''30');
  116.         $referencia = new TDataGridColumn('{referencia->procedimento}',  'Procedimento',  'left');
  117.         $material = new TDataGridColumn('{material->nome}',  'Material',  'left');
  118.         $this->cartgrid->addColumn($check); 
  119.         $this->cartgrid->addColumn($referencia); 
  120.         $this->cartgrid->addColumn($material);
  121.       
  122.         // creates datagrid actions        
  123.         $action1 = new TDataGridAction([$this'onSelect'], ['id' => '{id}','CARTAO' => '{CARTAO}']  );
  124.         $action2 = new TDataGridAction([$this'onSave'], ['id' => '{id}'] );
  125.         $this->datagrid->addAction($action1'Select''far:check-circle green');
  126.         $this->datagrid->addAction($action2'Save''far:trash-alt red');
  127.         //$this->cartgrid->addQuickAction('Delete', new TDataGridAction(array($this, 'onDelete')), 'id', 'fa:trash red');
  128.         // create the datagrid model
  129.         $this->datagrid->createModel();
  130.         $this->cartgrid->createModel();
  131.         // creates the page navigation
  132.         $this->pageNavigation = new TPageNavigation;
  133.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  134.         
  135.         // creates the page structure using a table
  136.         $table1 = new TTable;
  137.         $table1->style 'width: 100%';
  138.         $table1->addRow()->addCell($this->form)->height='50';
  139.         $table1->addRow()->addCell($this->datagrid);
  140.         $table1->addRow()->addCell($this->pageNavigation);
  141.         
  142.         $this->total = new TLabel('');
  143.         $this->total->setFontStyle('b');
  144.         
  145.         $table2 = new TTable;
  146.         $table2->style 'width: 100%';
  147.         $table2->addRow()->addCell($this->total)->height '50';
  148.         $table2->addRow()->addCell($this->cartgrid);
  149.         
  150.         $hbox = new THBox;
  151.         $hbox->add($table1)->style.='vertical-align:top; width: 60%';
  152.         $hbox->add($table2)->style.='vertical-align:top; width: 30%';
  153.         
  154.         // wrap the page content using vertical box
  155.         $vbox = new TVBox;
  156.         $vbox->style 'width: 100%';
  157.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  158.         $vbox->add($hbox);
  159.         //$vbox->add($this->pageNavigation);
  160.         parent::add($vbox);
  161.     }
  162.     
  163.     
  164.     /**
  165.      * Put a product inside the cart
  166.      */
  167.     public function onSelect($param)
  168.     {
  169.         // reload datagrids
  170.        // $this->onReload( func_get_arg(0) );
  171.     }
  172.    public function onSave($param)
  173.     {  
  174.    
  175.         $data $this->form->getData(); 
  176.         
  177.         $this->form->setData($data);  
  178.         try
  179.         {
  180.         TTransaction::open('marca');
  181.           
  182.            foreach ($this->form->getFields() as $name => $field)
  183.            {
  184.             if ($field instanceof TCheckButton)
  185.               {
  186.                 if ($field->getValue() == 'on')
  187.                  {
  188.                    $obj = new Exame();
  189.                    $obj->check_ 'on';
  190.                    $obj->store(); 
  191.                  }
  192.               }
  193.            }           
  194.             TTransaction::close();       
  195.         }
  196.          catch (Exception $e)
  197.         {
  198.             // show the message
  199.             new TMessage('error'$e->getMessage());
  200.         }
  201.     }
  202.     /**
  203.      * Remove a product from the cart
  204.      */
  205.     public function onDelete($param)
  206.     {
  207.         // get the cart objects from session
  208.         $cart_objects TSession::getValue('cart_objects');
  209.         unset($cart_objects[$param['key']]); 
  210.         TSession::setValue('cart_objects'$cart_objects);
  211.         
  212.         // reload datagrids
  213.         $this->onReloadfunc_get_arg(0) );
  214.     }
  215.     
  216.     /**
  217.      * method onSearch()
  218.      * Register the filter in the session when the user performs a search
  219.      */
  220.     function onSearch()
  221.     {
  222.         // get the search form data
  223.         $data $this->form->getData();
  224.                     var_dump($data);
  225.         // check if the user has filled the form
  226.         if ($data->paciente)
  227.         {
  228.             // creates a filter using what the user has typed
  229.             $filter = new TFilter('paciente''like'"%{$data->paciente}%");
  230.             
  231.             // stores the filter in the session
  232.             TSession::setValue('product_filter1'$filter);
  233.             TSession::setValue('product_description',   $data->paciente);
  234.             
  235.         }
  236.         else
  237.         {
  238.             TSession::setValue('product_filter1'NULL);
  239.             TSession::setValue('product_description',   '');
  240.         }
  241.         
  242.         // fill the form with data again
  243.         $this->form->setData($data);
  244.         
  245.         $param=array();
  246.         $param['offset']    =0;
  247.         $param['first_page']=1;
  248.         $this->onReload($param);
  249.     }
  250.     
  251.     /**
  252.      * method onReload()
  253.      * Load the datagrid with the database objects
  254.      */
  255.     function onReload($param NULL)
  256.     {
  257.         try
  258.         {
  259.             // open a transaction with database 'samples'
  260.             TTransaction::open('marca');
  261.             
  262.             // creates a repository for Product
  263.             $repository = new TRepository('Exame');
  264.             $limit 10;
  265.             
  266.             // creates a criteria
  267.             $criteria = new TCriteria;
  268.             $criteria->setProperties($param); // order, offset
  269.             $criteria->setProperty('limit'$limit);
  270.             $criteria->setProperty('order''paciente');
  271.             
  272.             if (TSession::getValue('product_filter1'))
  273.             {
  274.                 // add the filter stored in the session to the criteria
  275.                 $criteria->add(TSession::getValue('product_filter1'));
  276.             }
  277.             
  278.             $conn TTransaction::get();
  279.             $sth $conn->prepare("SELECT * FROM exame GROUP BY paciente");                                                    
  280.             $sth->execute(); 
  281.             $resultado =  $sth->fetchAll(PDO::FETCH_CLASS);
  282.             $this->datagrid->clear();
  283.             if ($resultado)
  284.             {
  285.                 foreach ($resultado as $product)
  286.                 { 
  287.                     $criteria = new TCriteria
  288.                     $criteria->add(new TFilter('CARTAO''='$product->paciente));
  289.                    
  290.                     // load using repository
  291.                     $repository = new TRepository('Paciente'); 
  292.                     $customers $repository->load($criteria); 
  293.                    
  294.                     foreach ($customers as $obj)
  295.                     { 
  296.                       $obj->status $product->status;
  297.                       $this->datagrid->addItem($obj);                                                
  298.                     }
  299.                 }
  300.             }
  301.           
  302.             if(isset($param['CARTAO']))
  303.             {  
  304.                 $criteria = new TCriteria
  305.                 $criteria->add(new TFilter('paciente''='$param['CARTAO']));
  306.                 $repository = new TRepository('Exame'); 
  307.                 $customers $repository->load($criteria); 
  308.                 $this->cartgrid->clear();
  309.         
  310.                 if ($customers)
  311.                 {
  312.                     foreach ($customers as $item)
  313.                     {
  314.                         $item->check_ = new TCheckButton('check'.$item->id);
  315.                         $item->check_->setIndexValue('on');
  316.                         $this->cartgrid->addItem($item);
  317.                         $this->form->addField($item->check_);             
  318.                     }
  319.                 }
  320.             }   
  321.             // reset the criteria for record count
  322.             $criteria->resetProperties();
  323.             $count$repository->count($criteria);
  324.             
  325.             $this->pageNavigation->setCount($count); // count of records
  326.             $this->pageNavigation->setProperties($param); // order, page
  327.             $this->pageNavigation->setLimit($limit); // limit
  328.             
  329.             // close the transaction
  330.             TTransaction::close();
  331.             $this->loaded true;
  332.         }
  333.         catch (Exception $e// in case of exception
  334.         {
  335.             // shows the exception error message
  336.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  337.             // undo all pending operations
  338.             TTransaction::rollback();
  339.         }
  340.     }
  341.     
  342.     /**
  343.      * method show()
  344.      * Shows the page
  345.      */
  346.     function show()
  347.     {
  348.         // check if the datagrid is already loaded
  349.         if (!$this->loaded)
  350.         {
  351.             $this->onReloadfunc_get_arg(0) );
  352.         }
  353.         parent::show();
  354.     }
  355. }
  356. ?>


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


NR

Se está chamando a função onSave por uma ação da grid, não vai funcionar. As ações da grid fazem um get, não enviando as informações do formulário. Você precisa criar um botão, do mesmo modo que o "Busca".

Além disso, a organização dos containers também precisa ser ajustada. A grid precisa ser filha do formulário e atualmente a estrutura está assim:

1 - table
tr -> td -> form
tr -> td -> grid
tr -> td -> navigation

Somente os campos que estiverem dentro da tag form serão enviados no post.
IS

Nataniel Rabaioli ainda não consegui nada, se você tiver como gerar algum modelo ou exemplo, estou criando software para laboratorio, na primeira grid apresenta nomes e informações do paciente, na segunda grid tem que mostrar os exame por paciente e confirmar coleta através do TCheckButton. Fico grato pela atenção.
IS

Nataniel Rabaioli ainda não consegui nada, se você tiver como gerar algum modelo ou exemplo, estou criando software para laboratorio, na primeira grid apresenta nomes e informações do paciente, na segunda grid tem que mostrar os exame por paciente e confirmar coleta através do TCheckButton. Fico grato pela atenção.
NR

Veja o exemplo abaixo:
https://adianti.com.br/framework_files/tutor/index.php?class=DatagridCheckView

A datagrid é adicionada a um panel que por sua vez é adicionado ao form. É mais ou menos isso que você precisa, pois a grid precisa ser filha de form para que os checks sejam enviados.

Se tiver dúvidas inspecione o código fonte, os checks devem estar dentro da tag form.

E na onSave use $param para recuperar os dados ao invés de $this->form->getData().
IS

Nataniel Rabaioli seguindo o modelo do tutor "https://adianti.com.br/framework_files/tutor/index.php?class=MultiCheckView" mas ainda não consegui. Se puder ajudar desta vez eu não consigo fazer a carga das grids.
https://drive.google.com/file/d/1LH9pCLgL6B4eHqm5qhSWXy0uQ17I0I32/view?usp=sharing
Resumo: seleção da primeira grid por paciente gera uma segunda grid alimentada por TCheckButton coleta e resultado de lista de exames por pessoa.
Se alguém quiser ajudar e cobrar eu gostaria de entrar em contato.


  1. <?php
  2. class ExameList extends TStandardList
  3. {
  4.     protected $form;     // registration form
  5.     protected $datagrid;
  6.     protected $cartgrid// listing
  7.     protected $pageNavigation;
  8.     protected $formDatagrid;
  9.     protected $postAction;
  10.     
  11.     public function __construct($param)
  12.     {
  13.         parent::__construct();
  14.         
  15.         parent::setDatabase('marca');                // defines the database
  16.         parent::setActiveRecord('Exame');            // defines the active record
  17.         parent::setDefaultOrder('id''asc');          // defines the default order
  18.         parent::addFilterField('description''like'); // add a filter field
  19.         parent::setTransformer( array($this'onBeforeLoad') );
  20.         
  21.         // creates the form, with a table inside
  22.         $this->form = new BootstrapFormBuilder('form_search_Product');
  23.         //$this->form->setFormTitle(_t('Multi check form'));
  24.         
  25.         // create the form fields
  26.         $description = new TEntry('NOME_PAC');
  27.         
  28.         // add a row for the filter field
  29.         $this->form->addFields( [new TLabel('Description')], [$description] );
  30.         
  31.         $this->form->setDataTSession::getValue('Product_filter_data') );
  32.         $this->form->addAction_t('Find'), new TAction(array($this'onSearch')), 'fa:search');
  33.         
  34.         // create the datagrid form wrapper
  35.         $this->formDatagrid = new TForm('datagrid_form');
  36.         
  37.         // creates a DataGrid
  38.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  39.         $this->datagrid->style='width:65%;float:left;margin:2px';
  40.         $this->formDatagrid->add($this->datagrid);
  41.         $this->datagrid->disableDefaultClick();
  42.         $this->cartgrid = new BootstrapDatagridWrapper(new TDataGrid);
  43.         $this->cartgrid->style 'width:30%;float:left;margin:2px';'30%';
  44.         $this->formDatagrid->add($this->cartgrid);
  45.         $this->cartgrid->disableDefaultClick();
  46.         // creates the datagrid columns
  47.         $cartao  $this->datagrid->addColumn( new TDataGridColumn('CARTAO',  'Cartão SUS',  'left') );
  48.         $paciente  $this->datagrid->addColumn( new TDataGridColumn('NOME_PAC',  'Nome',  'left') );
  49.         $sexo $this->datagrid->addColumn( new TDataGridColumn('sexo->nome',  'Sexo',  'left') );
  50.         $DATA_NASC $this->datagrid->addColumn( new TDataGridColumn('DATA_NASC',  'Idade',  'center') );
  51.         $status $this->datagrid->addColumn( new TDataGridColumn('status',  'Status',  'center') );
  52.         
  53.         $DATA_NASC->setTransformer(function($value$object$row)
  54.         {        
  55.             $rotulo calcIdade::calcularIdade($value);               
  56.             if ($rotulo <= 18)
  57.             {
  58.                 $bar = new TProgressBar;
  59.                 $bar->setMask('<b>'.$rotulo.'</b>');
  60.                 $bar->setValue(100);
  61.                 $bar->setClass('warning');
  62.                 return $bar;
  63.             }
  64.             else if (($rotulo >= 19) && ($rotulo <= 59))
  65.             {
  66.                 $bar = new TProgressBar;
  67.                 $bar->setMask('<b>'.$rotulo.'</b>');
  68.                 $bar->setValue(100);
  69.                 $bar->setClass('success');
  70.                 return $bar;
  71.             }
  72.             else
  73.             {
  74.                 $bar = new TProgressBar;
  75.                 $bar->setMask('<b>'.$rotulo.'</b>');
  76.                 $bar->setValue(100);
  77.                 $bar->setClass('danger');
  78.                 return $bar
  79.             }                  
  80.         }); 
  81.         $status->setTransformer(function($value$object$row)
  82.         {       
  83.             if ($value == 1)
  84.             { 
  85.                 $bar = new TProgressBar;
  86.                 $bar->setMask('<b>Coletado</b>');
  87.                 $bar->setValue(100);
  88.                 $bar->setClass('warning');
  89.                 return $bar;
  90.             }
  91.             else if ($value == 0)
  92.             { 
  93.                 $bar = new TProgressBar;
  94.                 $bar->setMask('<b>Solicitado</b>');
  95.                 $bar->setValue(100);
  96.                 $bar->setClass('success');
  97.                 return $bar;
  98.             }
  99.         });
  100.         
  101.         $check       $this->cartgrid->addColumn( new TDataGridColumn('check',  'ID',  'center') );
  102.         $referencia  $this->cartgrid->addColumn( new TDataGridColumn('{referencia->procedimento}',  'Procedimento',  'left') );
  103.         $material    $this->cartgrid->addColumn( new TDataGridColumn('{material->nome}',  'Material',  'left') );
  104.         // creates datagrid actions        
  105.         $action1 = new TDataGridAction([$this'onSelect'], ['id' => '{id}','CARTAO' => '{CARTAO}']  );
  106.         //$action2 = new TDataGridAction([$this, 'onSave'], ['id' => '{id}'] );
  107.         
  108.         $this->datagrid->addAction($action1'Select''far:check-circle green');
  109.   
  110.         // create the datagrid model
  111.         $this->datagrid->createModel();
  112.         $this->cartgrid->createModel();
  113.         
  114.        // create the page navigation
  115.         $this->pageNavigation = new TPageNavigation;
  116.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  117.         
  118.         $this->postAction = new TAction(array($this'onPost'));       
  119.         $post = new TButton('post');
  120.         $post->setAction($this->postAction);
  121.         $post->setImage('far:check-circle green');
  122.         $post->setLabel('Send');
  123.         
  124.         $this->formDatagrid->addField($post);
  125.         
  126.         // create the page container
  127.         $container = new TVBox;
  128.         $container->style 'width: 100%';
  129.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  130.         $container->add($this->form);
  131.         $container->add($panel TPanelGroup::pack(''$this->formDatagrid$this->pageNavigation));
  132.         $panel->getBody()->style 'overflow-x: auto';
  133.         $container->add($post);
  134.         
  135.         parent::add($container);
  136.     }
  137.      public function onSelect($param)
  138.     {
  139.     }
  140.     
  141.     public function onReload$param NULL )
  142.     {
  143.         try
  144.         {  
  145.             // open a transaction with database 'samples'
  146.             TTransaction::open('marca');
  147.             
  148.             // creates a repository for Product
  149.             $repository = new TRepository('Exame');
  150.             $limit 10;
  151.             
  152.             // creates a criteria
  153.             $criteria = new TCriteria;
  154.             $criteria->setProperties($param); // order, offset
  155.             $criteria->setProperty('limit'$limit);
  156.             $criteria->setProperty('order''paciente');
  157.             
  158.             if (TSession::getValue('product_filter1'))
  159.             {
  160.                 // add the filter stored in the session to the criteria
  161.                 $criteria->add(TSession::getValue('product_filter1'));
  162.             }
  163.             
  164.             $conn TTransaction::get();
  165.             $sth $conn->prepare("SELECT * FROM exame GROUP BY paciente");                                                    
  166.             $sth->execute(); 
  167.             $resultado =  $sth->fetchAll(PDO::FETCH_CLASS);
  168.             $this->datagrid->clear();
  169.             if ($resultado)
  170.             { 
  171.                 foreach ($resultado as $product)
  172.                 { 
  173.                     $criteria = new TCriteria;  
  174.                     $criteria->add(new TFilter('CARTAO''='$product->paciente));
  175.                    
  176.                     // load using repository
  177.                     $repository = new TRepository('Paciente'); 
  178.                     $customers $repository->load($criteria); 
  179.                    
  180.                     foreach ($customers as $obj)
  181.                     { 
  182.                       $obj->status $product->status;
  183.                       $this->datagrid->addItem($obj);                                                
  184.                     }
  185.                 } 
  186.             }
  187.            ///////////////////////////////
  188.             if(isset($param['CARTAO']))
  189.             {  
  190.                 $criteriab = new TCriteria
  191.                 $criteriab->add(new TFilter('paciente''='$param['CARTAO'])); 
  192.                 $repositoryb = new TRepository('Exame'); 
  193.                 $customerss $repositoryb->load($criteriab); 
  194.                 $this->cartgrid->clear();
  195.                 if ($customerss)
  196.                 {
  197.                     foreach ($customerss as $item)
  198.                     {
  199.                         $this->cartgrid->addItem($item);
  200.                     }
  201.                 }
  202.             } 
  203.               
  204.             // reset the criteria for record count
  205.             $criteria->resetProperties();
  206.             $count$repository->count($criteria);
  207.              
  208.             $this->pageNavigation->setCount($count); // count of records
  209.             $this->pageNavigation->setProperties($param); // order, page
  210.             $this->pageNavigation->setLimit($limit); // limit
  211.            
  212.             // close the transaction
  213.             TTransaction::close();
  214.             $this->loaded true;
  215.              
  216.              $this->postAction->setParameters($param); // important!
  217.              return parent::onReload$param );            
  218.         }
  219.         catch (Exception $e// in case of exception
  220.         {
  221.             // shows the exception error message
  222.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  223.             // undo all pending operations
  224.             TTransaction::rollback();
  225.         }
  226.     }
  227.     
  228.     /**
  229.      * Transform the objects before load them into the datagrid
  230.      */
  231.     public function onBeforeLoad$objects )
  232.     {   
  233.         foreach ($objects as $object)
  234.         {
  235.             $object->check = new TCheckButton('check_'.$object->id);
  236.             $object->check->setIndexValue('on');
  237.             $this->form->addField($object->check); // important! 
  238.         }
  239.     }
  240.     
  241.     /**
  242.      * Get post data and redirects to the next screen
  243.      */
  244.     public function onPost$param )
  245.     {
  246.         $data $this->form->getData();
  247.         $this->form->setData($data);
  248.         $selected_products = array();
  249.         
  250.         foreach ($this->form->getFields() as $name => $field)
  251.         {
  252.             if ($field instanceof TCheckButton)
  253.             {
  254.                 $parts explode('_'$name);
  255.                 $id $parts[1];
  256.                 
  257.                 if ($field->getValue() == 'on')
  258.                 {
  259.                     $selected_products[] = $id
  260.                 }
  261.             }
  262.         }
  263.         TSession::setValue('selected_products'$selected_products );
  264.         TApplication::loadPage('MultiCheck2View');
  265.     }
  266. }
  1. <?php
  2. class ExameList extends TStandardList
  3. {
  4.     protected $form;     // registration form
  5.     protected $datagrid;
  6.     protected $cartgrid// listing
  7.     protected $pageNavigation;
  8.     protected $formDatagrid;
  9.     protected $postAction;
  10.     
  11.     public function __construct($param)
  12.     {
  13.         parent::__construct();
  14.         
  15.         parent::setDatabase('marca');                // defines the database
  16.         parent::setActiveRecord('Exame');            // defines the active record
  17.         parent::setDefaultOrder('id''asc');          // defines the default order
  18.         parent::addFilterField('description''like'); // add a filter field
  19.         parent::setTransformer( array($this'onBeforeLoad') );
  20.         
  21.         // creates the form, with a table inside
  22.         $this->form = new BootstrapFormBuilder('form_search_Product');
  23.         //$this->form->setFormTitle(_t('Multi check form'));
  24.         
  25.         // create the form fields
  26.         $description = new TEntry('NOME_PAC');
  27.         
  28.         // add a row for the filter field
  29.         $this->form->addFields( [new TLabel('Description')], [$description] );
  30.         
  31.         $this->form->setDataTSession::getValue('Product_filter_data') );
  32.         $this->form->addAction_t('Find'), new TAction(array($this'onSearch')), 'fa:search');
  33.         
  34.         // create the datagrid form wrapper
  35.         $this->formDatagrid = new TForm('datagrid_form');
  36.         
  37.         // creates a DataGrid
  38.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  39.         $this->datagrid->style='width:65%;float:left;margin:2px';
  40.         $this->formDatagrid->add($this->datagrid);
  41.         $this->datagrid->disableDefaultClick();
  42.         $this->cartgrid = new BootstrapDatagridWrapper(new TDataGrid);
  43.         $this->cartgrid->style 'width:30%;float:left;margin:2px';'30%';
  44.         $this->formDatagrid->add($this->cartgrid);
  45.         $this->cartgrid->disableDefaultClick();
  46.         // creates the datagrid columns
  47.         $cartao  $this->datagrid->addColumn( new TDataGridColumn('CARTAO',  'Cartão SUS',  'left') );
  48.         $paciente  $this->datagrid->addColumn( new TDataGridColumn('NOME_PAC',  'Nome',  'left') );
  49.         $sexo $this->datagrid->addColumn( new TDataGridColumn('sexo->nome',  'Sexo',  'left') );
  50.         $DATA_NASC $this->datagrid->addColumn( new TDataGridColumn('DATA_NASC',  'Idade',  'center') );
  51.         $status $this->datagrid->addColumn( new TDataGridColumn('status',  'Status',  'center') );
  52.         
  53.         $DATA_NASC->setTransformer(function($value$object$row)
  54.         {        
  55.             $rotulo calcIdade::calcularIdade($value);               
  56.             if ($rotulo <= 18)
  57.             {
  58.                 $bar = new TProgressBar;
  59.                 $bar->setMask('<b>'.$rotulo.'</b>');
  60.                 $bar->setValue(100);
  61.                 $bar->setClass('warning');
  62.                 return $bar;
  63.             }
  64.             else if (($rotulo >= 19) && ($rotulo <= 59))
  65.             {
  66.                 $bar = new TProgressBar;
  67.                 $bar->setMask('<b>'.$rotulo.'</b>');
  68.                 $bar->setValue(100);
  69.                 $bar->setClass('success');
  70.                 return $bar;
  71.             }
  72.             else
  73.             {
  74.                 $bar = new TProgressBar;
  75.                 $bar->setMask('<b>'.$rotulo.'</b>');
  76.                 $bar->setValue(100);
  77.                 $bar->setClass('danger');
  78.                 return $bar
  79.             }                  
  80.         }); 
  81.         $status->setTransformer(function($value$object$row)
  82.         {       
  83.             if ($value == 1)
  84.             { 
  85.                 $bar = new TProgressBar;
  86.                 $bar->setMask('<b>Coletado</b>');
  87.                 $bar->setValue(100);
  88.                 $bar->setClass('warning');
  89.                 return $bar;
  90.             }
  91.             else if ($value == 0)
  92.             { 
  93.                 $bar = new TProgressBar;
  94.                 $bar->setMask('<b>Solicitado</b>');
  95.                 $bar->setValue(100);
  96.                 $bar->setClass('success');
  97.                 return $bar;
  98.             }
  99.         });
  100.         
  101.         $check       $this->cartgrid->addColumn( new TDataGridColumn('check',  'ID',  'center') );
  102.         $referencia  $this->cartgrid->addColumn( new TDataGridColumn('{referencia->procedimento}',  'Procedimento',  'left') );
  103.         $material    $this->cartgrid->addColumn( new TDataGridColumn('{material->nome}',  'Material',  'left') );
  104.         // creates datagrid actions        
  105.         $action1 = new TDataGridAction([$this'onSelect'], ['id' => '{id}','CARTAO' => '{CARTAO}']  );
  106.         //$action2 = new TDataGridAction([$this, 'onSave'], ['id' => '{id}'] );
  107.         
  108.         $this->datagrid->addAction($action1'Select''far:check-circle green');
  109.   
  110.         // create the datagrid model
  111.         $this->datagrid->createModel();
  112.         $this->cartgrid->createModel();
  113.         
  114.        // create the page navigation
  115.         $this->pageNavigation = new TPageNavigation;
  116.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  117.         
  118.         $this->postAction = new TAction(array($this'onPost'));       
  119.         $post = new TButton('post');
  120.         $post->setAction($this->postAction);
  121.         $post->setImage('far:check-circle green');
  122.         $post->setLabel('Send');
  123.         
  124.         $this->formDatagrid->addField($post);
  125.         
  126.         // create the page container
  127.         $container = new TVBox;
  128.         $container->style 'width: 100%';
  129.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  130.         $container->add($this->form);
  131.         $container->add($panel TPanelGroup::pack(''$this->formDatagrid$this->pageNavigation));
  132.         $panel->getBody()->style 'overflow-x: auto';
  133.         $container->add($post);
  134.         
  135.         parent::add($container);
  136.     }
  137.      public function onSelect($param)
  138.     {
  139.     }
  140.     
  141.     public function onReload$param NULL )
  142.     {
  143.         try
  144.         {  
  145.             // open a transaction with database 'samples'
  146.             TTransaction::open('marca');
  147.             
  148.             // creates a repository for Product
  149.             $repository = new TRepository('Exame');
  150.             $limit 10;
  151.             
  152.             // creates a criteria
  153.             $criteria = new TCriteria;
  154.             $criteria->setProperties($param); // order, offset
  155.             $criteria->setProperty('limit'$limit);
  156.             $criteria->setProperty('order''paciente');
  157.             
  158.             if (TSession::getValue('product_filter1'))
  159.             {
  160.                 // add the filter stored in the session to the criteria
  161.                 $criteria->add(TSession::getValue('product_filter1'));
  162.             }
  163.             
  164.             $conn TTransaction::get();
  165.             $sth $conn->prepare("SELECT * FROM exame GROUP BY paciente");                                                    
  166.             $sth->execute(); 
  167.             $resultado =  $sth->fetchAll(PDO::FETCH_CLASS);
  168.             $this->datagrid->clear();
  169.             if ($resultado)
  170.             { 
  171.                 foreach ($resultado as $product)
  172.                 { 
  173.                     $criteria = new TCriteria;  
  174.                     $criteria->add(new TFilter('CARTAO''='$product->paciente));
  175.                    
  176.                     // load using repository
  177.                     $repository = new TRepository('Paciente'); 
  178.                     $customers $repository->load($criteria); 
  179.                    
  180.                     foreach ($customers as $obj)
  181.                     { 
  182.                       $obj->status $product->status;
  183.                       $this->datagrid->addItem($obj);                                                
  184.                     }
  185.                 } 
  186.             }
  187.            ///////////////////////////////
  188.             if(isset($param['CARTAO']))
  189.             {  
  190.                 $criteriab = new TCriteria
  191.                 $criteriab->add(new TFilter('paciente''='$param['CARTAO'])); 
  192.                 $repositoryb = new TRepository('Exame'); 
  193.                 $customerss $repositoryb->load($criteriab); 
  194.                 $this->cartgrid->clear();
  195.                 if ($customerss)
  196.                 {
  197.                     foreach ($customerss as $item)
  198.                     {
  199.                         $this->cartgrid->addItem($item);
  200.                     }
  201.                 }
  202.             } 
  203.               
  204.             // reset the criteria for record count
  205.             $criteria->resetProperties();
  206.             $count$repository->count($criteria);
  207.              
  208.             $this->pageNavigation->setCount($count); // count of records
  209.             $this->pageNavigation->setProperties($param); // order, page
  210.             $this->pageNavigation->setLimit($limit); // limit
  211.            
  212.             // close the transaction
  213.             TTransaction::close();
  214.             $this->loaded true;
  215.              
  216.              $this->postAction->setParameters($param); // important!
  217.              return parent::onReload$param );            
  218.         }
  219.         catch (Exception $e// in case of exception
  220.         {
  221.             // shows the exception error message
  222.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  223.             // undo all pending operations
  224.             TTransaction::rollback();
  225.         }
  226.     }
  227.     
  228.     /**
  229.      * Transform the objects before load them into the datagrid
  230.      */
  231.     public function onBeforeLoad$objects )
  232.     {   
  233.         foreach ($objects as $object)
  234.         {
  235.             $object->check = new TCheckButton('check_'.$object->id);
  236.             $object->check->setIndexValue('on');
  237.             $this->form->addField($object->check); // important! 
  238.         }
  239.     }
  240.     
  241.     /**
  242.      * Get post data and redirects to the next screen
  243.      */
  244.     public function onPost$param )
  245.     {
  246.         $data $this->form->getData();
  247.         $this->form->setData($data);
  248.         $selected_products = array();
  249.         
  250.         foreach ($this->form->getFields() as $name => $field)
  251.         {
  252.             if ($field instanceof TCheckButton)
  253.             {
  254.                 $parts explode('_'$name);
  255.                 $id $parts[1];
  256.                 
  257.                 if ($field->getValue() == 'on')
  258.                 {
  259.                     $selected_products[] = $id
  260.                 }
  261.             }
  262.         }
  263.         TSession::setValue('selected_products'$selected_products );
  264.         TApplication::loadPage('MultiCheck2View');
  265.     }
  266. }