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