Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Capturar dados de TMultiSearch Pessoal o TMultiSearch não funciona conforme o tutor, no tutor você realiza um print_r nele e ele retorna um vetor... não estou conseguindo capturar os dados desse componente... alguém ai já utilizou ele? Será que tem bug? Já perdi um tempão e nada... não consigo ler os itens adicionados nele em tela para adicionar ao banco de dados, pois estou utilizando ele de forma manual... me ajudem ...
AT
Capturar dados de TMultiSearch  
Fechado
Pessoal o TMultiSearch não funciona conforme o tutor, no tutor você realiza um print_r nele e ele retorna um vetor... não estou conseguindo capturar os dados desse componente... alguém ai já utilizou ele? Será que tem bug? Já perdi um tempão e nada... não consigo ler os itens adicionados nele em tela para adicionar ao banco de dados, pois estou utilizando ele de forma manual... me ajudem por favor.

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (8)


AT

Ela retorna isso:

object(Adianti\Widget\Form\TMultiSearch)#60 (13) { ["id":protected]=> string(25) "tmultisearch552590aa17e13" ["items":protected]=> NULL ["size":protected]=> int(731) ["height":protected]=> int(100) ["minLength":protected]=> int(5) ["maxSize":protected]=> int(0) ["initialItems":protected]=> NULL ["name":protected]=> string(6) "search" ["value":protected]=> NULL ["editable":protected]=> bool(true) ["tag":protected]=> object(Adianti\Widget\Base\TElement)#62 (6) { ["name":"Adianti\Widget\Base\TElement":private]=> string(5) "input" ["properties":"Adianti\Widget\Base\TElement":private]=> array(2) { ["type"]=> string(6) "hidden" ["component"]=> string(11) "multisearch" } ["wrapped":"Adianti\Widget\Base\TElement":private]=> bool(false) ["useLineBreaks":"Adianti\Widget\Base\TElement":private]=> bool(true) ["useSingleQuotes":"Adianti\Widget\Base\TElement":private]=> bool(false) ["children":protected]=> NULL } ["formName":protected]=> string(24) "VsUsuariosListPermissoes" ["validations":"Adianti\Widget\Form\TField":private]=> array(0) { } }
MG

Adriano

Post seu código para darmos analisarmos.

Abraços
AT

E não esse array "Search : Array ( [1] => Frequente [2] => Casual [3] => Varejista ) " conforme o exemplo do tutor.
AT

  1. <?php
  1. <?php
  2. /**
  3.  * VsUsuariosListPermissoes Listing
  4.  * @author  <Adriano Chaves Teodoro>
  5.  */
  6. class VsUsuariosListPermissoes extends TPage
  7. {
  8.     private $form;     // registration form
  9.     private $datagrid// listing
  10.     private $pageNavigation;
  11.     private $loaded;
  12.     public $search;
  13.     
  14.     /**
  15.      * Class constructor
  16.      * Creates the page, the form and the listing
  17.      */
  18.     public function __construct()
  19.     {
  20.         parent::__construct();
  21.         
  22.         // creates the form
  23.         $this->form = new TForm('VsUsuariosListPermissoes');
  24.         $this->form->class 'tform'// CSS class
  25.         
  26.         // creates a table
  27.         $table = new TTable;
  28.         $table-> width '100%';
  29.         $this->form->add($table);
  30.         
  31.         // add a row for the form title
  32.         $row $table->addRow();
  33.         $row->class 'tformtitle'// CSS class
  34.         $row->addCell( new TLabel('Usuários Tablets (Filtros)') )->colspan 2;
  35.         
  36.         // create the form fields
  37.         $id_usuario   = new TEntry('id_usuario');
  38.         $id_cliente   = new  ">TDBSeekButton('id_cliente''permission''VsUsuariosListPermissoes''VsClientes''razao_social''id_cliente''razao_social');        
  39.         $razao_social = new TEntry('razao_social');
  40.         $razao_social->setEditable(false);
  41.         $nome         = new TEntry('nome');
  42.         $login        = new TEntry('login');
  43.         $this->search = new TMultiSearch('search');
  44.         
  45.         $this->search->setSize(731);
  46.                
  47.         // define the sizes
  48.         $id_usuario->setSize(100);
  49.         $id_cliente->setSize(100);
  50.         $nome->setSize(200);
  51.         $login->setSize(200);
  52.         $razao_social->setSize(200);
  53.         // add one row for each form field
  54.         $table->addRowSet( new TLabel('ID Usuário:'), $id_usuario );
  55.         $table->addRowSet( new TLabel('Nome:'), $nome );
  56.         $table->addRowSet( new TLabel('Login:'), $login );
  57.         $table->addRowSet( new TLabel('Cliente:'), $id_cliente );
  58.         $table->addRowSet( new TLabel(''), $razao_social );
  59.         $this->form->setFields(array($id_usuario,$nome,$login,$id_cliente,$this->search));
  60.         // keep the form filled during navigation with session data
  61.         $this->form->setDataTSession::getValue('VsUsuarios_filter_data') );
  62.         
  63.         // create two action buttons to the form
  64.         $find_button  TButton::create('find', array($this'onSearch'), _t('Find'), 'ico_find.png');
  65.         $save_button  TButton::create('save', array($this'onSaveCatalogos'), _t('Save'), 'ico_save.png');
  66.         
  67.         $this->form->addField($find_button);
  68.         $this->form->addField($save_button);
  69.         
  70.         $buttons_box = new THBox;
  71.         $buttons_box->add($find_button);
  72.         $buttons_box->add($save_button);
  73.         
  74.         // add a row for the form action
  75.         $row $table->addRow();
  76.         $row->class 'tformaction'// CSS class
  77.         $row->addCell($buttons_box)->colspan 2;
  78.         
  79.         // creates a Datagrid
  80.         $this->datagrid = new TDataGrid;
  81.         $this->datagrid->setHeight(320);
  82.         
  83.         // creates the datagrid columns
  84.         $id_usuario   = new TDataGridColumn('id_usuario''ID Usuário''right'100);       
  85.         $nome         = new TDataGridColumn('nome',       'Nome',       'left',  200);
  86.         $login        = new TDataGridColumn('login',      'Login',      'left',  200);
  87.         $id_cliente   = new TDataGridColumn('id_cliente''ID Cliente''right'100);
  88.         // add the columns to the DataGrid
  89.         $this->datagrid->addColumn($id_usuario);
  90.         $this->datagrid->addColumn($nome);
  91.         $this->datagrid->addColumn($login);
  92.         $this->datagrid->addColumn($id_cliente);
  93.    
  94.         // creates the datagrid column actions
  95.         $order_id_usuario= new TAction(array($this'onReload'));
  96.         $order_id_usuario->setParameter('order''id_usuario');
  97.         $id_usuario->setAction($order_id_usuario);
  98.         $order_id_cliente= new TAction(array($this'onReload'));
  99.         $order_id_cliente->setParameter('order''id_cliente');
  100.         $id_cliente->setAction($order_id_cliente);
  101.         $order_nome= new TAction(array($this'onReload'));
  102.         $order_nome->setParameter('order''nome');
  103.         $nome->setAction($order_nome);
  104.         $order_login= new TAction(array($this'onReload'));
  105.         $order_login->setParameter('order''login');
  106.         $login->setAction($order_login);
  107.  
  108.         // creates two datagrid actions
  109.         $action1 = new TDataGridAction(array($this'onLoadCatalogos'));
  110.         $action1->setLabel('Permissões');
  111.         $action1->setField('id_usuario');
  112.         
  113.         $action2 = new TDataGridAction(array($this'onDelete'));
  114.         $action2->setLabel(_t('Delete'));
  115.         $action2->setImage('ico_delete.png');
  116.         $action2->setField('id_usuario');
  117.         
  118.         // add the actions to the datagrid
  119.         $this->datagrid->addAction($action1);
  120.         //$this->datagrid->addAction($action2);
  121.         
  122.         // create the datagrid model
  123.         $this->datagrid->createModel();
  124.         
  125.         // creates the page navigation
  126.         $this->pageNavigation = new TPageNavigation;
  127.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  128.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  129.         
  130.         // create the page container
  131.         $container TVBox::pack$this->form$this->datagrid'<br> Catálogos Permitidos'$this->search$this->pageNavigation);
  132.         parent::add($container);
  133.     }
  134.     
  135.     function onSaveCatalogos($param)
  136.     {
  137.         $id_usuario TSession::getValue('id_usuario_clicado_permissoes');
  138.         
  139.         try 
  140.         {           
  141.             //var_dump($this->search->geValue);
  142.             
  143.             TTransaction::open('permission'); 
  144.                         
  145.             
  146.             TTransaction::close(); 
  147.         } 
  148.         catch (Exception $e
  149.         { 
  150.             new TMessage('error onSaveCatalogos: '$e->getMessage()); 
  151.         } 
  152.     }
  153.     
  154.     function onLoadCatalogos($param)
  155.     {
  156.         try
  157.         {
  158.            var_dump($this->search);
  159.             
  160.             $key $param['key'];
  161.             TSession::setValue('id_usuario_clicado_permissoes'$key);
  162.             
  163.             //Alimenta catálogos geral do cliente
  164.             TTransaction::open('permission');
  165.             
  166.             $conn TTransaction::get();
  167.             
  168.             $result $conn->query('select
  169.                                         ct.*
  170.                                     from
  171.                                         vs_catalogos ct
  172.                                     where
  173.                                         ct.id_album in (select ab.id_album from vs_albuns ab where ab.id_cliente = (select us.id_cliente from vs_usuarios us where us.id_usuario = '.$key.'))');
  174.             $items = array();
  175.             foreach ($result as $row)
  176.             {
  177.                 $items[$row['id_catalogo']] = $row['descricao'];
  178.             }
  179.             
  180.             $this->search->addItems($items);
  181.             TTransaction::close();
  182.             //Alimenta catálogos já permitidos            
  183.             TTransaction::open('permission');
  184.             
  185.             $conn TTransaction::get();
  186.             
  187.             $result $conn->query('select
  188.                                         uc.*,
  189.                                         (select ct.descricao from vs_catalogos ct where ct.id_catalogo = uc.id_catalogo)
  190.                                     from
  191.                                         vs_usuarios_catalogos uc where uc.id_usuario = '.$key);
  192.             $items = array();
  193.             foreach ($result as $row)
  194.             {
  195.                 $items[$row['id_catalogo']] = $row['descricao'];
  196.             }
  197.             
  198.             $this->search->setValue($items);
  199.             TTransaction::close();
  200.         }
  201.         catch (Exception $e)
  202.         {
  203.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  204.             TTransaction::rollback();
  205.         }
  206.     
  207.     }
  208.     
  209.     /**
  210.      * method onInlineEdit()
  211.      * Inline record editing
  212.      * @param $param Array containing:
  213.      *              key: object ID value
  214.      *              field name: object attribute to be updated
  215.      *              value: new attribute content 
  216.      */
  217.     function onInlineEdit($param)
  218.     {
  219.         try
  220.         {
  221.             // get the parameter $key
  222.             $field $param['field'];
  223.             $key   $param['key'];
  224.             $value $param['value'];
  225.             
  226.             TTransaction::open('permission'); // open a transaction with database
  227.             $object = new VsUsuarios($key); // instantiates the Active Record
  228.             $object->{$field} = $value;
  229.             $object->store(); // update the object in the database
  230.             TTransaction::close(); // close the transaction
  231.             
  232.             $this->onReload($param); // reload the listing
  233.             new TMessage('info'"Record Updated");
  234.         }
  235.         catch (Exception $e// in case of exception
  236.         {
  237.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  238.             TTransaction::rollback(); // undo all pending operations
  239.         }
  240.     }
  241.     
  242.     /**
  243.      * method onSearch()
  244.      * Register the filter in the session when the user performs a search
  245.      */
  246.     function onSearch()
  247.     {
  248.         // get the search form data
  249.         $data $this->form->getData();
  250.         
  251.         // clear session filters
  252.         TSession::setValue('VsUsuariosListPermissoes_filter_id_usuario',   NULL);
  253.         TSession::setValue('VsUsuariosListPermissoes_filter_id_cliente',   NULL);
  254.         TSession::setValue('VsUsuariosListPermissoes_filter_nome',   NULL);
  255.         TSession::setValue('VsUsuariosListPermissoes_filter_login',   NULL);
  256.         if (isset($data->id_usuario) AND ($data->id_usuario)) {
  257.             $filter = new TFilter('id_usuario''='"$data->id_usuario"); // create the filter
  258.             TSession::setValue('VsUsuariosListPermissoes_filter_id_usuario',   $filter); // stores the filter in the session
  259.         }
  260.         if (isset($data->id_cliente) AND ($data->id_cliente)) {
  261.             $filter = new TFilter('id_cliente''='"$data->id_cliente"); // create the filter
  262.             TSession::setValue('VsUsuariosListPermissoes_filter_id_cliente',   $filter); // stores the filter in the session
  263.         }
  264.         if (isset($data->nome) AND ($data->nome)) {
  265.             $filter = new TFilter('nome''like'"%{$data->nome}%"); // create the filter
  266.             TSession::setValue('VsUsuariosListPermissoes_filter_nome',   $filter); // stores the filter in the session
  267.         }
  268.         if (isset($data->login) AND ($data->login)) {
  269.             $filter = new TFilter('login''like'"%{$data->login}%"); // create the filter
  270.             TSession::setValue('VsUsuariosListPermissoes_filter_login',   $filter); // stores the filter in the session
  271.         }
  272.         
  273.         // fill the form with data again
  274.         $this->form->setData($data);
  275.         
  276.         // keep the search data in the session
  277.         TSession::setValue('VsUsuarios_filter_data'$data);
  278.         
  279.         $param=array();
  280.         $param['offset']    =0;
  281.         $param['first_page']=1;
  282.         $this->onReload($param);
  283.     }
  284.     
  285.     /**
  286.      * method onReload()
  287.      * Load the datagrid with the database objects
  288.      */
  289.     function onReload($param NULL)
  290.     {
  291.         try
  292.         {
  293.             // open a transaction with database 'permission'
  294.             TTransaction::open('permission');
  295.             
  296.             // creates a repository for VsUsuarios
  297.             $repository = new TRepository('VsUsuarios');
  298.             $limit 10;
  299.             // creates a criteria
  300.             $criteria = new TCriteria;
  301.             
  302.             // default order
  303.             if (empty($param['order']))
  304.             {
  305.                 $param['order'] = 'id_usuario';
  306.                 $param['direction'] = 'asc';
  307.             }
  308.             $criteria->setProperties($param); // order, offset
  309.             $criteria->setProperty('limit'$limit);
  310.             
  311.             if (TSession::getValue('VsUsuariosListPermissoes_filter_id_usuario')) {
  312.                 $criteria->add(TSession::getValue('VsUsuariosListPermissoes_filter_id_usuario')); // add the session filter
  313.             }
  314.             if (TSession::getValue('VsUsuariosListPermissoes_filter_id_cliente')) {
  315.                 $criteria->add(TSession::getValue('VsUsuariosListPermissoes_filter_id_cliente')); // add the session filter
  316.             }
  317.             if (TSession::getValue('VsUsuariosListPermissoes_filter_nome')) {
  318.                 $criteria->add(TSession::getValue('VsUsuariosListPermissoes_filter_nome')); // add the session filter
  319.             }
  320.             if (TSession::getValue('VsUsuariosListPermissoes_filter_login')) {
  321.                 $criteria->add(TSession::getValue('VsUsuariosListPermissoes_filter_login')); // add the session filter
  322.             }
  323.             
  324.             // load the objects according to criteria
  325.             $objects $repository->load($criteriaFALSE);
  326.             
  327.             $this->datagrid->clear();
  328.             if ($objects)
  329.             {
  330.                 // iterate the collection of active records
  331.                 foreach ($objects as $object)
  332.                 {
  333.                     // add the object inside the datagrid
  334.                     $this->datagrid->addItem($object);
  335.                 }
  336.             }
  337.             
  338.             // reset the criteria for record count
  339.             $criteria->resetProperties();
  340.             $count$repository->count($criteria);
  341.             
  342.             $this->pageNavigation->setCount($count); // count of records
  343.             $this->pageNavigation->setProperties($param); // order, page
  344.             $this->pageNavigation->setLimit($limit); // limit
  345.             
  346.             // close the transaction
  347.             TTransaction::close();
  348.             $this->loaded true;
  349.         }
  350.         catch (Exception $e// in case of exception
  351.         {
  352.             // shows the exception error message
  353.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  354.             
  355.             // undo all pending operations
  356.             TTransaction::rollback();
  357.         }
  358.     }
  359.     
  360.     /**
  361.      * method onDelete()
  362.      * executed whenever the user clicks at the delete button
  363.      * Ask if the user really wants to delete the record
  364.      */
  365.     function onDelete($param)
  366.     {
  367.         // define the delete action
  368.         $action = new TAction(array($this'Delete'));
  369.         $action->setParameters($param); // pass the key parameter ahead
  370.         
  371.         // shows a dialog to the user
  372.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  373.     }
  374.     
  375.     /**
  376.      * method Delete()
  377.      * Delete a record
  378.      */
  379.     function Delete($param)
  380.     {
  381.         try
  382.         {
  383.             $key=$param['key']; // get the parameter $key
  384.             TTransaction::open('permission'); // open a transaction with database
  385.             $object = new VsUsuarios($keyFALSE); // instantiates the Active Record
  386.             $object->delete(); // deletes the object from the database
  387.             TTransaction::close(); // close the transaction
  388.             $this->onReload$param ); // reload the listing
  389.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted')); // success message
  390.         }
  391.         catch (Exception $e// in case of exception
  392.         {
  393.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  394.             TTransaction::rollback(); // undo all pending operations
  395.         }
  396.     }
  397.     
  398.     /**
  399.      * method show()
  400.      * Shows the page
  401.      */
  402.     function show()
  403.     {
  404.         // check if the datagrid is already loaded
  405.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  406.         {
  407.             $this->onReloadfunc_get_arg(0) );
  408.         }
  409.         parent::show();
  410.     }
  411. }
  412. ?>
</Adriano>
AT

Realizo o var_dum na linha 173...
PD

Adriano,

Somente ações de formulário (Buttons) postam os dados do formulário.
Ações de datagrid não enviam dados de formulário como parâmetro.

Att,
Pablo
PD

A única forma de fazer uma action de datagrid postar dados de um form, é criando ela na forma de botão e criando um formulário ao redor de tudo, como fiz nesse exemplo, um pouco mais complexo:
www.adianti.com.br/framework_files/tutor/index.php?class=SaleForm

Verifique os itens da venda, acrescente um e tente editar. Verifique que os dados do cabeçalho são preservados e inclusive enviados junto quando é editado um item.

Att,
Pablo
PD

Adriano,

Use títulos mais sugestivos para posts, ok?

Att,