Grid não é adicionada Olá, Aguém pode me ajudar ? Estou criando uma tela que tem mais de uma TDataGrid, porém ao tentar selecionar usuário a grid não carrega e da erro na linha 268, porém não estou identificando o erro, segue abaixo código. erro [Tue Jan 02 01:22:08.765697 2018] [php7:error] [pid 16301] [client ::1:53778] PHP Fatal error: Uncaught Error: Cannot use object of type SystemUser as arra...
RB
Grid não é adicionada  
Olá,

Aguém pode me ajudar ?

Estou criando uma tela que tem mais de uma TDataGrid, porém ao tentar selecionar usuário a grid não carrega e da erro na linha 268, porém não estou identificando o erro, segue abaixo código.

erro
[Tue Jan 02 01:22:08.765697 2018] [php7:error] [pid 16301] [client ::1:53778] PHP Fatal error: Uncaught Error: Cannot use object of type SystemUser as array in /var/www/html/centinel/app/control/admin/SystemGroupBuilder.class.php:268nStack trace:n#0 [internal function]: SystemGroupBuilder->onSelectUser(Array)n#1 /var/www/html/centinel/lib/adianti/control/TPage.php(51): call_user_func(Array, Array)n#2 /var/www/html/centinel/lib/adianti/control/TPage.php(205): Adianti\Control\TPage->run()n#3 /var/www/html/centinel/app/control/admin/SystemGroupBuilder.class.php(486): Adianti\Control\TPage->show()n#4 /var/www/html/centinel/lib/adianti/core/AdiantiCoreApplication.php(62): SystemGroupBuilder->show(Array)n#5 /var/www/html/centinel/engine.php(29): Adianti\Core\AdiantiCoreApplication::run(true)n#6 /var/www/html/centinel/engine.php(43): TApplication::run(true)n#7 {main}n thrown in /var/www/html/centinel/app/control/admin/SystemGroupBuilder.class.php on line 268, referer: localhost/centinel/index.php?class=SystemGroupBuilder&method=onS


 
  1. <?php
  2. class SystemGroupBuilder extends TPage
  3. {
  4. protected $form;
  5. protected $form_grupo;
  6. protected $load;
  7. protected $load1;
  8. protected $datagrid;
  9. protected $cartgrid;
  10. protected $datagrid_group;
  11. protected $datagrid_user;
  12. protected $datagrid_alocacao_user;
  13. protected $pageNavigation;
  14. protected $pageNavigation2;
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. parent::include_css('app/resources/blue_modificado.css');
  19. parent::include_css('app/resources/custom-table.css');
  20. parent::include_css('app/resources/builder.css');
  21. // create form and table container
  22. $this->form_grupo = new BootstrapFormBuilder;
  23. $this->form_grupo->class = 'frm_gruop_usuario';
  24. $this->form = new TForm('frm_check');
  25. $this->style = 'width:100%';
  26. $this->form->class = 'frm_gruop_usuario';
  27. $dados_grupo = new TLabel('Detalhes do Grupo');
  28. $dados_grupo->class ='lbl_titulo';
  29. $this->form_grupo->addContent( [$dados_grupo] );
  30. $lbl_nome = new TLabel(_t('Group`s name'));
  31. $lbl_descrcica_grupo = new TLabel(_t('Description'));
  32. $lbl_empresa = new TLabel(_t('Company'));
  33. $lbl_unidade_negocio = new TLabel(_t('Unit'));
  34. $nome_grupo = new TEntry('nome_grupo');
  35. $descricao_grupo = new TEntry('descricao_grupo');
  36. $descricao_empresa = new TEntry('descricao_empresa');
  37. $descricao_unidade = new TEntry('descricao_unidade');
  38. $lbl_nome->class = 'lbl_text';
  39. $lbl_descrcica_grupo->class = 'lbl_text';
  40. $lbl_empresa->class = 'lbl_text';
  41. $lbl_unidade_negocio->class = 'lbl_text';
  42. $lbl_nome->setSize('100%');
  43. $lbl_descrcica_grupo->setSize('100%');
  44. $nome_grupo->setSize('100%');
  45. $descricao_grupo->setSize('100%');
  46. $descricao_empresa->setSize('100%');
  47. $descricao_unidade->setSize('100%');
  48. $this->form_grupo->addFields([$lbl_nome]);
  49. $this->form_grupo->addFields([$nome_grupo]);
  50. $this->form_grupo->addFields([$lbl_descrcica_grupo]);
  51. $this->form_grupo->addFields([$descricao_grupo]);
  52. $this->form_grupo->addFields([$lbl_empresa]);
  53. $this->form_grupo->addFields([$descricao_empresa]);
  54. $this->form_grupo->addFields([$lbl_unidade_negocio]);
  55. $this->form_grupo->addFields([$descricao_unidade]);
  56. $dados_grupo_configuracao = new TLabel('Configuração de menus e submenus');
  57. $dados_grupo_configuracao->class ='lbl_titulo';
  58. $this->form_grupo->addContent( [$dados_grupo_configuracao] );
  59. $this->form_grupo->addAction('Salvar',new TAction(array($this, 'onSave')),'fa:save blue');
  60. $this->form_grupo->addAction('Listar',new TAction(array('GrupoEmpresa','onReload')),'fa:table blue');
  61. // creates a DataGrid
  62. $this->datagrid = new TQuickGrid;
  63. $this->cartgrid = new TDataGrid;
  64. $this->cartgrid->disableDefaultClick(); // important!
  65. $this->datagrid_user = new TQuickGrid;
  66. $this->datagrid_alocacao_user = new TDataGrid;
  67. $this->datagrid->style = 'width:100%;';
  68. $this->cartgrid->style = 'width:100%;';
  69. $this->datagrid_user->style = 'width:100%;';
  70. // creates the datagrid columns
  71. $this->datagrid->addQuickColumn('ID', 'id','center','5%');
  72. $this->datagrid->addQuickColumn(_t('Name'),'name','left');
  73. $this->datagrid->addQuickColumn(_t('Description'),'controller','left');
  74. //cartgrid
  75. $id = new TDataGridColumn('id','ID','center','5%');
  76. $name = new TDataGridColumn('name',_t('Name'), 'left');
  77. $descricao = new TDataGridColumn('controller', _t('Description'),'left');
  78. $action_editar = new TDataGridColumn('action_editar', _t('Edit'),'center');
  79. $action_print = new TDataGridColumn('action_print', _t('Print'),'center');
  80. $action_visualizar = new TDataGridColumn('action_visualizar', _t('View'),'center');
  81. // creates the datagrid actions
  82. $order1 = new TAction(array($this, 'onReload'));
  83. $order2 = new TAction(array($this, 'onReload'));
  84. // define the ordering parameters
  85. $order1->setParameter('order', 'id');
  86. $order2->setParameter('order', 'name');
  87. // assign the ordering actions
  88. $id->setAction($order1);
  89. $name->setAction($order2);
  90. // add the columns to the datagrid
  91. $this->cartgrid->addColumn($id);
  92. $this->cartgrid->addColumn($name);
  93. $this->cartgrid->addColumn($descricao);
  94. $this->cartgrid->addColumn($action_editar);
  95. $this->cartgrid->addColumn($action_print);
  96. $this->cartgrid->addColumn($action_visualizar);
  97. $action = new TDataGridAction(array($this, 'onDelete'));
  98. $action->setLabel(_t('Delete'));
  99. $action->setImage('ico_delete.png');
  100. $action->setField('id');
  101. $this->cartgrid->addAction($action);
  102. // creates the datagrid columns
  103. $this->datagrid_user->addQuickColumn('ID', 'id','center','5%');
  104. $this->datagrid_user->addQuickColumn(_t('Name'),'name','left');
  105. // add the columns to the datagrid
  106. $this->datagrid_alocacao_user->addColumn($id);
  107. $this->datagrid_alocacao_user->addColumn($name);
  108. $action1 = new TDataGridAction(array($this, 'onDelete'));
  109. $action1->setLabel(_t('Delete'));
  110. $action1->setImage('ico_delete.png');
  111. $action1->setField('id');
  112. $this->datagrid_alocacao_user->addAction($action1);
  113. // creates datagrid actions
  114. $this->datagrid->addQuickAction(_t('Select'),new TDataGridAction(array($this,'onSelect')), 'id', 'ico_apply.png');
  115. $this->datagrid_user->addQuickAction(_t('Select').' '._t('user'),new TDataGridAction(array($this,'onSelectUser')), 'id', 'ico_apply.png');
  116. // create the datagrid model
  117. $this->datagrid->createModel();
  118. $this->cartgrid->createModel();
  119. $this->datagrid_user->createModel();
  120. $this->datagrid_alocacao_user->createModel();
  121. // creates the page navigation datagrid
  122. $this->pageNavigation = new TPageNavigation;
  123. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  124. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  125. // creates the page structure using a table
  126. $table1 = new TTable;
  127. $table1->style = 'width:100%;';
  128. $table1->addRow()->addCell($this->datagrid);
  129. $scroll1 = new TScroll;
  130. $scroll1->style = 'width:49.5%;float:left;height:300px;margin:0 0.5% 0 0;';
  131. $scroll1->add($table1);
  132. $div_paginacao = new TElement('div');
  133. $div_paginacao->id = 'div_paginacao';
  134. $div_paginacao->class = 'div_paginacao';
  135. $div_paginacao->add($this->pageNavigation) ;
  136. $scroll1->add($div_paginacao) ;
  137. $table2 = new TTable;
  138. $table2->style = 'width:100%;';
  139. $table2->addRow()->addCell($this->cartgrid);
  140. $scroll = new TScroll;
  141. $scroll->style = 'width:50%;height:300px;float:left;';
  142. $scroll->add($table2);
  143. // creates the page structure using a table
  144. $table3 = new TTable;
  145. $table3->style = 'width:100%;';
  146. $table3->addRow()->addCell($this->datagrid_user);
  147. $scroll2 = new TScroll;
  148. $scroll2->style = 'width:49.5%;float:left;height:300px;margin:0 0.5% 0 0;';
  149. $scroll2->add($table3);
  150. $table4 = new TTable;
  151. $table4->style = 'width:100%;';
  152. $table4->addRow()->addCell($this->datagrid_alocacao_user);
  153. $scroll3 = new TScroll;
  154. $scroll3->style = 'width:50%;height:300px;float:left;';
  155. $scroll3->add($table4);
  156. $hbox = new THBox;
  157. $hbox->add($scroll1)->style ='vertical-align:top;width:100%;';
  158. $hbox->add($scroll)->style ='vertical-align:top;width:100%;';
  159. // creates the page navigation
  160. $this->pageNavigation2 = new TPageNavigation;
  161. $this->pageNavigation2->setAction(new TAction(array($this, 'onReloadUser')));
  162. $this->pageNavigation2->setWidth($this->datagrid_user->getWidth());
  163. $div_paginacao1 = new TElement('div');
  164. $div_paginacao1->id = 'div_paginacao1';
  165. $div_paginacao1->class = 'div_paginacao';
  166. $div_paginacao1->add($this->pageNavigation2) ;
  167. $scroll2->add($div_paginacao1);
  168. $hbox1 = new THBox;
  169. $hbox1->add($scroll2)->style ='vertical-align:top;width:100%;';
  170. $hbox1->add($scroll3)->style ='vertical-align:top;width:100%;';
  171. $this->form_grupo->addFields([$hbox]);
  172. $titulo_alocacao_user = new TLabel('Alocação dos usuários');
  173. $titulo_alocacao_user->class ='lbl_titulo';
  174. $this->form_grupo->addContent( [$titulo_alocacao_user] );
  175. $this->form_grupo->addFields([$hbox1]);
  176. //wrap the page content using vertical box
  177. $vbox = new TVBox;
  178. $vbox->style = 'width:100%';
  179. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  180. $vbox->add($this->form_grupo);
  181. parent::add($vbox);
  182. }
  183. /**
  184. * Put a programs inside the cart
  185. */
  186. public function onSelect($param)
  187. {
  188. // get the cart objects from session
  189. $cart_objects = TSession::getValue('cart_objects');
  190. TTransaction::open('permission');
  191. $programs = new SystemProgram($param['key']); // load the programs
  192. $cart_objects[$programs->id] = $programs; // add the programs inside the array
  193. TSession::setValue('cart_objects', $cart_objects); // put the array back to the session
  194. TTransaction::close();
  195. // reload datagrids
  196. $this->onReload( func_get_arg(0) );
  197. }
  198. public function onSelectUser($param)
  199. {
  200. // get the cart objects from session
  201. $alocacao_objects = TSession::getValue('alocacao_objects');
  202. TTransaction::open('permission');
  203. $user_object = new SystemUser($param['key']); // load the user
  204. $alocacao_objects[$user_object->id] = $user_object; // add the user inside the array
  205. TSession::setValue('alocacao_objects', $user_object); // put the array back to the session
  206. TTransaction::close();
  207. // reload datagrids
  208. $this->onReloadUser( func_get_arg(0) );
  209. }
  210. /**
  211. * Remove a programs from the cart
  212. */
  213. public function onDelete($param)
  214. {
  215. // get the cart objects from session
  216. $cart_objects = TSession::getValue('cart_objects');
  217. unset($cart_objects[$param['key']]); // remove the programs from the array
  218. TSession::setValue('cart_objects', $cart_objects); // put the array back to the session
  219. // reload datagrids
  220. $this->onReload( func_get_arg(0) );
  221. }
  222. /**
  223. * method onReload()
  224. * Load the datagrid with the database objects
  225. */
  226. function onReload($param = NULL)
  227. {
  228. try
  229. {
  230. // open a transaction with database 'samples'
  231. TTransaction::open('permission');
  232. // creates a repository for Product
  233. $repository = new TRepository('SystemProgram');
  234. $limit = 5;
  235. // creates a criteria
  236. $criteria = new TCriteria;
  237. // default order
  238. if (empty($param['order']))
  239. {
  240. $param['order'] = 'id';
  241. $param['direction'] = 'asc';
  242. }
  243. $criteria->setProperties($param); // order, offset
  244. $criteria->setProperty('limit', $limit);
  245. $criteria->setProperty('order', 'controller');
  246. // load the objects according to criteria
  247. $objects = $repository->load($criteria);
  248. $this->datagrid->clear();
  249. if ($objects)
  250. {
  251. foreach ($objects as $object)
  252. {
  253. // add the object inside the datagrid
  254. $this->datagrid->addItem($object);
  255. }
  256. }
  257. //cartgrid
  258. $this->cartgrid->clear();
  259. $cart_objects = TSession::getValue('cart_objects');
  260. if ($cart_objects)
  261. {
  262. foreach ($cart_objects as $object)
  263. {
  264. $uniqid = mt_rand(1000000, 9999999);
  265. $object->action_editar = new TCheckButton('check'.$uniqid);
  266. $object->action_editar->setIndexValue('on');
  267. $this->form->addField($object->action_editar); // important!
  268. $uniqid1 = mt_rand(1000000, 9999999);
  269. $object->action_print = new TCheckButton('check'.$uniqid1);
  270. $object->action_print->setIndexValue('on');
  271. $this->form->addField($object->action_print); // important!
  272. $uniqid2 = mt_rand(1000000, 9999999);
  273. $object->action_visualizar = new TCheckButton('check'.$uniqid2);
  274. $object->action_visualizar->setIndexValue('on');
  275. $this->form->addField($object->action_visualizar); // important
  276. $this->cartgrid->addItem($object);
  277. }
  278. }
  279. // reset the criteria for record count
  280. $criteria->resetProperties();
  281. $count= $repository->count($criteria);
  282. $this->pageNavigation->setCount($count); // count of records
  283. $this->pageNavigation->setProperties($param); // order, page
  284. $this->pageNavigation->setLimit($limit); // limit
  285. // close the transaction
  286. TTransaction::close();
  287. $this->loaded = true;
  288. }
  289. catch (Exception $e) // in case of exception
  290. {
  291. // shows the exception error message
  292. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  293. // undo all pending operations
  294. TTransaction::rollback();
  295. }
  296. }
  297. public function onReloadUser($param = NULL)
  298. {
  299. try
  300. {
  301. // open a transaction with database 'samples'
  302. TTransaction::open('permission');
  303. // creates a repository for SystemUser
  304. $repository1 = new TRepository('SystemUser');
  305. $limit1 = 5;
  306. // creates a criteria
  307. $criteria1 = new TCriteria;
  308. // default order
  309. if (empty($param['order']))
  310. {
  311. $param['order'] = 'id';
  312. $param['direction'] = 'asc';
  313. }
  314. $criteria1->setProperties($param); // order, offset
  315. $criteria1->setProperty('limit1', $limit1);
  316. $criteria1->setProperty('order', 'name');
  317. // load the objects according to criteria
  318. $objects = $repository1->load($criteria1);
  319. $this->datagrid_user->clear();
  320. if ($objects)
  321. {
  322. foreach ($objects as $object)
  323. {
  324. // add the object inside the datagrid
  325. $this->datagrid_user->addItem($object);
  326. }
  327. }
  328. //datagrid_alocacao_user
  329. $this->datagrid_alocacao_user->clear();
  330. $alocacao_objects = TSession::getValue('alocacao_objects');
  331. if ($alocacao_objects)
  332. {
  333. foreach ($alocacao_objects as $object)
  334. {
  335. $this->datagrid_alocacao_user->addItem($object);
  336. }
  337. }
  338. // reset the criteria1 for record count
  339. $criteria1->resetProperties();
  340. $count1 = $repository1->count($criteria1);
  341. $this->pageNavigation2->setCount($count1); // count of records
  342. $this->pageNavigation2->setProperties($param); // order, page
  343. $this->pageNavigation2->setLimit($limit1); // limit
  344. // close the transaction
  345. TTransaction::close();
  346. $this->loaded1 = true;
  347. }
  348. catch (Exception $e)
  349. {
  350. // shows the exception error message
  351. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  352. // undo all pending operations
  353. TTransaction::rollback();
  354. }
  355. }
  356. public static function onSave($param)
  357. {
  358. // show form values inside a window
  359. $win = TWindow::create('test', 0.6, 0.8);
  360. $win->add( '<pre>'.str_replace("\n",'<br>', print_r(TSession::getValue('cart_objects'), true) ).'</pre><br/>'.$param['nome_grupo'].'<br>'.$param['descricao_grupo'].'<br/>'.$param['action_editar'] .'<br/>'.$param['action_print'].'<br/>'.$param['action_visualizar'] );
  361. $win->show();
  362. TForm::sendData('frm_gruop_usuario', $data);// keep form data
  363. TForm::sendData('frm_check', $data);// keep form data
  364. }
  365. public function onClear($param)
  366. {
  367. $this->form->clear(TRUE);
  368. }
  369. public function onEdit($param)
  370. {
  371. }
  372. /**
  373. * method show()
  374. * Shows the page
  375. */
  376. function show()
  377. {
  378. // check if the datagrid is already loaded
  379. if (!$this->loaded)
  380. {
  381. $this->onReload( func_get_arg(0));
  382. $this->onReloadUser(func_get_arg(0));
  383. }
  384. parent::show();
  385. }
  386. }
  387. ?>


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


NR

O erro diz que você está tentando usar um objeto como array, na linha 268:
 
  1. <?php
  2. $alocacao_objects = TSession::getValue('alocacao_objects');
  3. TTransaction::open('permission');
  4. $user_object = new SystemUser($param['key']); // load the user
  5. $alocacao_objects[$user_object->id] = $user_object; // add the user inside the array
  6. //TSession::setValue('alocacao_objects', $user_object); // aqui vc está passando um objeto para a sessao e nao um array
  7. TSession::setValue('alocacao_objects', $alocacao_objects); // acredito que vc queira passar o array $alocacao_objects
  8. ?>
RB

Nataniel, bom dia,

Mais uma vez muito obrigado, funcionou perfeito.

RB

Nataniel,

Como faço para separar a paginação ?

Pois a paginação esta sendo sincronizada entre as grids, tem como ?
NR

O problema é que a paginação usa os parâmetros passados via get(page, offset), que são os mesmos para todas as grids. Acho que o caminho mais simples é colocar as grids em arquivos diferentes e usar o conceito de "adianti_target_container", que permite que somente uma parte da tela seja recarregada. Veja o exemplo do tutor:
adianti.com.br/framework_files/tutor/index.php?class=SaleMultiValueF

Nesse exemplo, o detalhe "SaleDetailForm" está em um arquivo diferente do master "SaleMultiValueForm". Ao interagir com os detalhes, somente essa parte é recarregada.