Dificuldade em salvar check da grid Olá, Pessoal, estou não estou conseguindo pegar os itens (valores )checks da grid, algumé pode me ajudar ? segue código abaixo. ...
RB
Dificuldade em salvar check da grid  
Olá,

Pessoal, estou não estou conseguindo pegar os itens (valores )checks da grid, algumé pode me ajudar ?

segue código abaixo.

 
  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('form_grupo_usuario');
  23. $this->form_grupo->class = 'form_grupo_usuario';
  24. $this->form_grupo->id = 'form_grupo_usuario';
  25. $this->form = new TForm('frm_check');
  26. $this->style = 'width:100%';
  27. $this->form->class = 'form_grupo_usuario';
  28. $dados_grupo = new TLabel('Detalhes do Grupo');
  29. $dados_grupo->class ='lbl_titulo';
  30. $this->form_grupo->addContent( [$dados_grupo] );
  31. $lbl_nome = new TLabel(_t('Group`s name'));
  32. $lbl_descrcica_grupo = new TLabel(_t('Description'));
  33. $lbl_empresa = new TLabel(_t('Company'));
  34. $lbl_unidade_negocio = new TLabel(_t('Unit'));
  35. $id_grupo = new THidden('id_grupo');
  36. $nome_grupo = new TEntry('nome_grupo',new TRequiredValidator);
  37. $nome_grupo->placeholder = "Exemplo_empresa";
  38. $descricao_grupo = new TEntry('descricao_grupo');
  39. $nome_grupo->addValidation('nome do grupo', new TRequiredValidator); // required field
  40. $descricao_grupo->addValidation('descricao do grupo', new TRequiredValidator); // required field
  41. //$filter = new TCriteria;
  42. //$filter->add(new TFilter('id', '=',TSession::getValue('organizacion_id')));
  43. //combo 1(master)
  44. $organizacao_id = new TDBCombo('organizacao_id' ,'centinel','ViewOrganizacaoJuridica','id','nome','nome asc');
  45. $organizacao_id->setDefaultOption(false);
  46. $organizacao_id->setChangeAction( new TAction( array($this, 'onChangeActionFilial')) );
  47. $filter1 = new TCriteria;
  48. $filter1->add(new TFilter('id', '<','0'));
  49. //combo 2 (detail)
  50. $unidade_id = new TDBCombo('unidade_id','centinel','ViewOrganizacaoUnidade','id','name','name asc',$filter1);
  51. $unidade_id->setDefaultOption(false);
  52. $lbl_nome->class = 'lbl_text';
  53. $lbl_descrcica_grupo->class = 'lbl_text';
  54. $lbl_empresa->class = 'lbl_text';
  55. $lbl_unidade_negocio->class = 'lbl_text';
  56. $lbl_nome->setSize('100%');
  57. $lbl_descrcica_grupo->setSize('100%');
  58. $nome_grupo->setSize('100%');
  59. $descricao_grupo->setSize('100%');
  60. $organizacao_id->setSize('100%');
  61. $unidade_id->setSize('100%');
  62. $this->form_grupo->addFields([$lbl_nome]);
  63. $this->form_grupo->addFields([$nome_grupo]);
  64. $this->form_grupo->addFields([$lbl_descrcica_grupo]);
  65. $this->form_grupo->addFields([$descricao_grupo]);
  66. $this->form_grupo->addFields([$lbl_empresa]);
  67. $this->form_grupo->addFields([$organizacao_id]);
  68. $this->form_grupo->addFields([$lbl_unidade_negocio]);
  69. $this->form_grupo->addFields([$unidade_id]);
  70. $dados_grupo_configuracao = new TLabel('Configuração de menus e submenus');
  71. $dados_grupo_configuracao->class ='lbl_titulo';
  72. $this->form_grupo->addContent( [$dados_grupo_configuracao] );
  73. $this->form_grupo->addAction('Salvar',new TAction(array($this, 'onSave')),'fa:save blue');
  74. $this->form_grupo->addAction('Listar',new TAction(array('GrupoEmpresa','onReload')),'fa:table blue');
  75. // creates a DataGrid
  76. $this->datagrid = new TQuickGrid;
  77. $this->cartgrid = new TDataGrid;
  78. $this->datagrid_user = new TQuickGrid;
  79. $this->datagrid_alocacao_user = new TDataGrid;
  80. $this->datagrid->disableDefaultClick(); // important!
  81. $this->cartgrid->disableDefaultClick(); // important!
  82. $this->datagrid_user->disableDefaultClick(); // important!
  83. $this->datagrid_alocacao_user->disableDefaultClick(); // important!
  84. $this->datagrid->style = 'width:100%;';
  85. $this->cartgrid->style = 'width:100%;';
  86. $this->datagrid_user->style = 'width:100%;';
  87. $this->datagrid_alocacao_user->style = 'width:100%;';
  88. // creates the datagrid columns
  89. $this->datagrid->addQuickColumn(_t('Name'),'name','left');
  90. //cartgrid
  91. $id = new TDataGridColumn('id','ID','center','5%');
  92. $name = new TDataGridColumn('name',_t('Name'), 'left');
  93. $action_editar = new TDataGridColumn('action_editar', _t('Edit'),'center');
  94. $action_print = new TDataGridColumn('action_print', _t('Print'),'center');
  95. $action_visualizar = new TDataGridColumn('action_visualizar', _t('View'),'center');
  96. $action_aprovar = new TDataGridColumn('action_aprovar', _t('to approve'),'center');
  97. $system_menu = new TDataGridColumn('system_menu', 'menu','center');
  98. // creates the datagrid actions
  99. $order1 = new TAction(array($this, 'onReload'));
  100. $order2 = new TAction(array($this, 'onReload'));
  101. // define the ordering parameters
  102. $order1->setParameter('order', 'id');
  103. $order2->setParameter('order', 'name');
  104. // assign the ordering actions
  105. $id->setAction($order1);
  106. $name->setAction($order2);
  107. // add the columns to the datagrid
  108. $this->cartgrid->addColumn($name);
  109. $this->cartgrid->addColumn($action_editar);
  110. $this->cartgrid->addColumn($action_print);
  111. $this->cartgrid->addColumn($action_visualizar);
  112. $this->cartgrid->addColumn($action_aprovar);
  113. $this->cartgrid->addColumn($system_menu);
  114. $action = new TDataGridAction(array($this, 'onDelete'));
  115. $action->setLabel(_t('Delete'));
  116. $action->setImage('ico_delete.png');
  117. $action->setField('id');
  118. $this->cartgrid->addAction($action);
  119. // creates the datagrid columns
  120. $this->datagrid_user->addQuickColumn(_t('Name'),'name','left');
  121. // add the columns to the datagrid
  122. $this->datagrid_alocacao_user->addColumn($name);
  123. $action1 = new TDataGridAction(array($this, 'onDeleteUser'));
  124. $action1->setLabel(_t('Delete'));
  125. $action1->setImage('ico_delete.png');
  126. $action1->setField('id');
  127. $this->datagrid_alocacao_user->addAction($action1);
  128. // creates datagrid actions
  129. $this->datagrid->addQuickAction(_t('Select'),new TDataGridAction(array($this,'onSelect')), 'id','fa:plus-circle green','5%');
  130. $this->datagrid_user->addQuickAction(_t('Select').' '._t('user'),new TDataGridAction(array($this,'onSelectUser')), 'id','fa:plus-circle green','5%');
  131. // create the datagrid model
  132. $this->datagrid->createModel();
  133. $this->cartgrid->createModel();
  134. $this->datagrid_user->createModel();
  135. $this->datagrid_alocacao_user->createModel();
  136. // creates the page navigation datagrid
  137. $this->pageNavigation = new TPageNavigation;
  138. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  139. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  140. // creates the page structure using a table
  141. $table1 = new TTable;
  142. $table1->style = 'width:100%;';
  143. $table1->addRow()->addCell($this->datagrid);
  144. $scroll1 = new TScroll;
  145. $scroll1->style = 'width:49.5%;float:left;height:300px;margin:0 0.5% 0 0;';
  146. $scroll1->add($table1);
  147. $div_paginacao = new TElement('div');
  148. $div_paginacao->id = 'div_paginacao';
  149. $div_paginacao->class = 'div_paginacao';
  150. $div_paginacao->add($this->pageNavigation) ;
  151. $scroll1->add($div_paginacao) ;
  152. $table2 = new TTable;
  153. $table2->style = 'width:100%;';
  154. $table2->addRow()->addCell($this->cartgrid);
  155. $scroll = new TScroll;
  156. $scroll->style = 'width:50%;height:300px;float:left;';
  157. $scroll->add($table2);
  158. // creates the page structure using a table
  159. $table3 = new TTable;
  160. $table3->style = 'width:100%;';
  161. $table3->addRow()->addCell($this->datagrid_user);
  162. $scroll2 = new TScroll;
  163. $scroll2->style = 'width:49.5%;float:left;height:300px;margin:0 0.5% 0 0;';
  164. $scroll2->add($table3);
  165. $table4 = new TTable;
  166. $table4->style = 'width:100%;';
  167. $table4->addRow()->addCell($this->datagrid_alocacao_user);
  168. $scroll3 = new TScroll;
  169. $scroll3->style = 'width:50%;height:300px;float:left;';
  170. $scroll3->add($table4);
  171. $hbox = new THBox;
  172. $hbox->add($scroll1)->style ='vertical-align:top;width:100%;';
  173. $hbox->add($scroll)->style ='vertical-align:top;width:100%;';
  174. // creates the page navigation
  175. $this->pageNavigation2 = new TPageNavigation;
  176. $this->pageNavigation2->setAction(new TAction(array($this, 'onReloadUser')));
  177. $this->pageNavigation2->setWidth($this->datagrid_user->getWidth());
  178. $div_paginacao1 = new TElement('div');
  179. $div_paginacao1->id = 'div_paginacao1';
  180. $div_paginacao1->class = 'div_paginacao';
  181. $div_paginacao1->add($this->pageNavigation2) ;
  182. $scroll2->add($div_paginacao1);
  183. $hbox1 = new THBox;
  184. $hbox1->add($scroll2)->style ='vertical-align:top;width:100%;';
  185. $hbox1->add($scroll3)->style ='vertical-align:top;width:100%;';
  186. $this->form_grupo->addFields([$hbox]);
  187. $titulo_alocacao_user = new TLabel('Alocação dos usuários');
  188. $titulo_alocacao_user->class ='lbl_titulo';
  189. $this->form_grupo->addContent( [$titulo_alocacao_user] );
  190. $this->form_grupo->addFields([$hbox1]);
  191. //wrap the page content using vertical box
  192. $vbox = new TVBox;
  193. $vbox->style = 'width:100%';
  194. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  195. $vbox->add($this->form_grupo);
  196. parent::add($vbox);
  197. }
  198. /**
  199. * Put a programs inside the cart
  200. */
  201. public function onSelect($param)
  202. {
  203. // get the cart objects from session
  204. $cart_objects = TSession::getValue('cart_objects');
  205. TTransaction::open('permission');
  206. $programs = new SystemProgram($param['key']); // load the programs
  207. $cart_objects[$programs->id] = $programs; // add the programs inside the array
  208. TSession::setValue('cart_objects', $cart_objects); // put the array back to the session
  209. TTransaction::close();
  210. // reload datagrids
  211. $this->onReload( func_get_arg(0) );
  212. }
  213. public function onSelectUser($param)
  214. {
  215. // get the cart objects from session
  216. $alocacao_objects = TSession::getValue('alocacao_objects');
  217. TTransaction::open('permission');
  218. $user_object = new SystemUser($param['key']); // load the user
  219. $alocacao_objects[$user_object->id] = $user_object; // add the user inside the array
  220. TSession::setValue('alocacao_objects', $alocacao_objects);
  221. TTransaction::close();
  222. // reload datagrids
  223. $this->onReloadUser( func_get_arg(0) );
  224. }
  225. /**
  226. * Remove a programs from the cart
  227. */
  228. public function onDelete($param)
  229. {
  230. // get the cart objects from session
  231. $cart_objects = TSession::getValue('cart_objects');
  232. unset($cart_objects[$param['key']]); // remove the programs from the array
  233. TSession::setValue('cart_objects', $cart_objects); // put the array back to the session
  234. // reload datagrids
  235. $this->onReload( func_get_arg(0) );
  236. }
  237. public function onDeleteUser($param)
  238. {
  239. // get the cart objects from session
  240. $alocacao_objects = TSession::getValue('alocacao_objects');
  241. unset($alocacao_objects[$param['key']]); // remove the programs from the array
  242. TSession::setValue('alocacao_objects', $alocacao_objects); // put the array back to the session
  243. // reload datagrids
  244. $this->onReloadUser( func_get_arg(0) );
  245. }
  246. /**
  247. * method onReload()
  248. * Load the datagrid with the database objects
  249. */
  250. function onReload($param = NULL)
  251. {
  252. try
  253. {
  254. // open a transaction with database 'samples'
  255. TTransaction::open('permission');
  256. // creates a repository for Product
  257. $repository = new TRepository('SystemProgram');
  258. $limit = 5;
  259. // creates a criteria
  260. $criteria = new TCriteria;
  261. // default order
  262. if (empty($param['order']))
  263. {
  264. $param['order'] = 'id';
  265. $param['direction'] = 'asc';
  266. }
  267. $criteria->setProperties($param); // order, offset
  268. $criteria->setProperty('limit', $limit);
  269. $criteria->setProperty('order', 'controller');
  270. // load the objects according to criteria
  271. $objects = $repository->load($criteria);
  272. $this->datagrid->clear();
  273. if ($objects)
  274. {
  275. foreach ($objects as $object)
  276. {
  277. // add the object inside the datagrid
  278. $this->datagrid->addItem($object);
  279. }
  280. }
  281. //cartgrid
  282. $this->cartgrid->clear();
  283. $cart_objects = TSession::getValue('cart_objects');
  284. if ($cart_objects)
  285. {
  286. $cont = 1;
  287. foreach ($cart_objects as $object)
  288. {
  289. $uniqid = mt_rand(1000000, 9999999);
  290. $object->action_editar = new TCheckButton('check'.$uniqid);
  291. $object->action_editar->setIndexValue('on');
  292. $this->form->addField($object->action_editar); // important!
  293. $uniqid1 = mt_rand(1000000, 9999999);
  294. $object->action_print = new TCheckButton('check'.$uniqid1);
  295. $object->action_print->setIndexValue('on');
  296. $this->form->addField($object->action_print); // important!
  297. $uniqid2 = mt_rand(1000000, 9999999);
  298. $object->action_visualizar = new TCheckButton('check'.$uniqid2);
  299. $object->action_visualizar->setIndexValue('on');
  300. $this->form->addField($object->action_visualizar); // important
  301. $uniqid3 = mt_rand(1000000, 9999999);
  302. $object->action_aprovar = new TCheckButton('check'.$uniqid3);
  303. $object->action_aprovar->setIndexValue('on');
  304. $this->form->addField($object->action_aprovar); // important
  305. $uniqid4 = mt_rand(1000000, 9999999);
  306. $object->system_menu = new TDBCombo('system_menu'.$uniqid4, 'permission', 'SystemMenu', 'id', 'name');
  307. $this->form->addField($object->system_menu); // important
  308. $this->cartgrid->addItem($object);
  309. }
  310. }
  311. // reset the criteria for record count
  312. $criteria->resetProperties();
  313. $count= $repository->count($criteria);
  314. $this->pageNavigation->setCount($count); // count of records
  315. $this->pageNavigation->setProperties($param); // order, page
  316. $this->pageNavigation->setLimit($limit); // limit
  317. // close the transaction
  318. TTransaction::close();
  319. $this->loaded = true;
  320. }
  321. catch (Exception $e) // in case of exception
  322. {
  323. // shows the exception error message
  324. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  325. // undo all pending operations
  326. TTransaction::rollback();
  327. }
  328. }
  329. public function onReloadUser($param = NULL)
  330. {
  331. try
  332. {
  333. // open a transaction with database 'samples'
  334. TTransaction::open('permission');
  335. // creates a repository for SystemUser
  336. $repository1 = new TRepository('SystemUser');
  337. $limit1 = 5;
  338. // creates a criteria
  339. $criteria1 = new TCriteria;
  340. // default order
  341. if (empty($param['order']))
  342. {
  343. $param['order'] = 'id';
  344. $param['direction'] = 'asc';
  345. }
  346. $criteria1->setProperties($param); // order, offset
  347. $criteria1->setProperty('limit', $limit1);
  348. $criteria1->setProperty('order', 'name');
  349. // load the objects according to criteria
  350. $objects = $repository1->load($criteria1);
  351. $this->datagrid_user->clear();
  352. if ($objects)
  353. {
  354. foreach ($objects as $object)
  355. {
  356. // add the object inside the datagrid
  357. $this->datagrid_user->addItem($object);
  358. }
  359. }
  360. //datagrid_alocacao_user
  361. $this->datagrid_alocacao_user->clear();
  362. $alocacao_objects = TSession::getValue('alocacao_objects');
  363. if ($alocacao_objects)
  364. {
  365. foreach ($alocacao_objects as $object)
  366. {
  367. $this->datagrid_alocacao_user->addItem($object);
  368. }
  369. }
  370. // reset the criteria1 for record count
  371. $criteria1->resetProperties();
  372. $count1 = $repository1->count($criteria1);
  373. $this->pageNavigation2->setCount($count1); // count of records
  374. $this->pageNavigation2->setProperties($param); // order, page
  375. $this->pageNavigation2->setLimit($limit1); // limit
  376. // close the transaction
  377. TTransaction::close();
  378. $this->loaded1 = true;
  379. }
  380. catch (Exception $e)
  381. {
  382. // shows the exception error message
  383. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  384. // undo all pending operations
  385. TTransaction::rollback();
  386. }
  387. }
  388. public function onSave($param)
  389. {
  390. try
  391. {
  392. $data = $this->form_grupo->getData(); // get form data
  393. $this->form_grupo->validate(); // validate form data
  394. // open a transaction with database 'permission'
  395. TTransaction::open('permission');
  396. // get the form data into an active record System_group
  397. $object = new SystemGroup;
  398. $object->name = $param['nome_grupo'];
  399. $object->description = $param['descricao_grupo'];
  400. $object->organization_id = $param['organizacao_id'];
  401. $object->unit_id = $param['unidade_id'];
  402. $object->active = 1;
  403. $object->store();
  404. $object->clearParts();
  405. $programs = TSession::getValue('cart_objects');
  406. if (!empty($programs))
  407. {
  408. foreach ($programs as $program)
  409. {
  410. $obj = $object->addSystemProgram( new SystemProgram( $program->id ) );
  411. //$object->system_edit = $check; //não estou conseguindo pegar este valores
  412. //$object->system_print = $check; //não estou conseguindo pegar este valores
  413. //$object->system_view = $check; //não estou conseguindo pegar este valores
  414. //print_r($programs).'<br/>';
  415. }
  416. }
  417. //adicionar usuários ao grupo
  418. $alocacao_objects = TSession::getValue('alocacao_objects');
  419. if (!empty($alocacao_objects))
  420. {
  421. foreach($alocacao_objects as $alocacao_object )
  422. {
  423. $object = new SystemUserGroup;
  424. $object->system_group_id = $obj;
  425. $object->system_user_id = $alocacao_object->id;
  426. $object->store();
  427. }
  428. }
  429. $data = new stdClass;
  430. $data->id_grupo = $object->id;
  431. TForm::sendData('form_grupo_usuario', $data);
  432. TTransaction::close(); // close the transaction
  433. new TMessage('info', _t('Record saved')); // shows the success message
  434. }
  435. catch (Exception $e) // in case of exception
  436. {
  437. // shows the exception error message
  438. new TMessage('error', $e->getMessage());
  439. // undo all pending operations
  440. TTransaction::rollback();
  441. }
  442. /*
  443. // show form values inside a window
  444. $win = TWindow::create('test', 0.6, 0.8);
  445. $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'] );
  446. $win->show();
  447. TForm::sendData('frm_gruop_usuario', $data);// keep form data
  448. TForm::sendData('frm_check', $data);// keep form data
  449. */
  450. }
  451. static function onChangeActionFilial($param)
  452. {
  453. try
  454. {
  455. TTransaction::open('centinel'); //base de dados
  456. if ($param['organizacao_id'])//se existe parâmetro da primeira combo(nome da primeira combo)
  457. {
  458. $criteria = TCriteria::create( ['organizacao_id' => $param['organizacao_id'] ] );
  459. //organizacao_id = parametro chave estrangeira da tabela master
  460. // formname,field(nome do campo),database , nome da model,key,value,ordercolumn = NULL,criteria, startEmpty = FALSE
  461. TDBCombo::reloadFromModel('form_grupo_usuario','unidade_id','centinel','ViewOrganizacaoUnidade','id','name', 'name',$criteria,TRUE);
  462. }
  463. else
  464. {
  465. TCombo::clearField('form_grupo_usuario', 'unidade_id'); //reload do formulario form_grupo_usuario na segunda combo "unidade_id"
  466. }
  467. TTransaction::close();
  468. }
  469. catch (Exception $e)
  470. {
  471. new TMessage('error', $e->getMessage());
  472. }
  473. }
  474. static function fireEvents( $object )
  475. {
  476. $obj = new stdClass;
  477. if(get_class($object) == 'stdClass')
  478. {
  479. if(isset($object->organizacao_id))
  480. {
  481. $obj->organizacao_id = $object->organizacao_id;
  482. }
  483. if(isset($object->unidade_id))
  484. {
  485. $obj->unidade_id = $object->unidade_id;
  486. }
  487. }
  488. else
  489. {
  490. if(isset($object->organizacao_id))
  491. {
  492. $obj->organizacao_id = $object->organizacao_id;
  493. }
  494. if(isset($object->unidade_id))
  495. {
  496. $obj->unidade_id = $object->unidade_id;
  497. }
  498. }
  499. TForm::sendData('form_grupo_usuario', $obj);
  500. }
  501. public function onClear($param)
  502. {
  503. $this->form->clear(TRUE);
  504. $this->form_grupo->clear(TRUE);
  505. }
  506. public function onEdit($param)
  507. {
  508. self::fireEvents($object);
  509. }
  510. /**
  511. * method show()
  512. * Shows the page
  513. */
  514. function show()
  515. {
  516. // check if the datagrid is already loaded
  517. if (!$this->loaded)
  518. {
  519. $this->onReload( func_get_arg(0));
  520. $this->onReloadUser(func_get_arg(0));
  521. }
  522. parent::show();
  523. }
  524. }
  525. ?>


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)


NR

Os campos estão sendo registrados no formulário errado:
 
  1. <?php
  2. // funcao onReload
  3. // $this->form nao esta sendo usado
  4. $this->form->addField($object->action_editar);
  5. // trocar por
  6. $this->form_grupo->addField($object->action_editar);
  7. ?>

E evite usar uniqid para definir o nome dos campos, pois como esse valor muda a cada ação, não será possível capturar os dados do post na função onSave.
RB

Nataniel,

Neste caso, como utilizo, pois quando usei pelo id, dava erro, "Você já adicionou um campo check ao formulário " .
NR

Você pode usar o id, desde que mude o prefixo para não repetir o nome dos campos:
 
  1. <?php
  2. //$object->action_editar = new TCheckButton('check'.$object->id);
  3. $object->action_editar = new TCheckButton('checkedit'.$object->id);
  4. $object->action_editar->setIndexValue('on');
  5. $this->form->addField($object->action_editar); // important!
  6. //$object->action_print = new TCheckButton('check'.$object->id);
  7. $object->action_print = new TCheckButton('checkprint'.$object->id);
  8. $object->action_print->setIndexValue('on');
  9. $this->form->addField($object->action_print); // important!
  10. ?>
RB

Nataniel,

Então, fiz como indicado porém continuo com o mesmo problema.


Veja a imagem no link : sgo.net.br/index.php?class=PublicView&PHPSESSID=feba6dc14b4c5dca
NR

Tente:
 
  1. <?php
  2. if (! $this->loaded)
  3. {
  4. $this->form->addField($object->action_editar);
  5. $this->form->addField($object->action_print);
  6. ...
  7. }
  8. ?>
RB

Nataniel,

Não deu certo,

Undefined variable: object in /var/www/html/centinel/app/control/admin/SystemGroupBuilder.class.php on line 744, referer: localhost/centinel/index.php?class=SystemGroupList

Veja como ficou o código, talvez esteja fazendo errado.

 
  1. <?php
  2. //onReload
  3. function onReload($param = NULL)
  4. {
  5. try
  6. {
  7. // open a transaction with database 'samples'
  8. TTransaction::open('permission');
  9. // creates a repository for Product
  10. $repository = new TRepository('SystemProgram');
  11. $limit = 5;
  12. // creates a criteria
  13. $criteria = new TCriteria;
  14. // default order
  15. if (empty($param['order']))
  16. {
  17. $param['order'] = 'id';
  18. $param['direction'] = 'asc';
  19. }
  20. $criteria->setProperties($param); // order, offset
  21. $criteria->setProperty('limit', $limit);
  22. $criteria->setProperty('order', 'controller');
  23. // load the objects according to criteria
  24. $objects = $repository->load($criteria);
  25. $this->datagrid->clear();
  26. $items = new stdClass;
  27. $items = $objects;
  28. if ($objects)
  29. {
  30. foreach ($items as $object)
  31. {
  32. // add the object inside the datagrid
  33. $this->datagrid->addItem($object);
  34. }
  35. }
  36. //cartgrid
  37. $this->cartgrid->clear();
  38. $cart_objects = TSession::getValue('cart_objects');
  39. if ($cart_objects)
  40. {
  41. foreach ($cart_objects as $object)
  42. {
  43. $object->action_editar = new TCheckButton('checkedit'.$object->id);
  44. $object->action_editar->setIndexValue('on');
  45. $this->form_grupo->addField($object->action_editar); // important!
  46. $object->action_print = new TCheckButton('checkprint'.$object->id);
  47. $object->action_print->setIndexValue('on');
  48. $this->form_grupo->addField($object->action_print); // important
  49. $object->action_visualizar = new TCheckButton('checkvisualizar'.$object->id);
  50. $object->action_visualizar->setIndexValue('on');
  51. $this->form_grupo->addField($object->action_visualizar); // important
  52. $object->action_aprovar = new TCheckButton('checkaprovar'.$object->id);
  53. $object->action_aprovar->setIndexValue('on');
  54. $this->form_grupo->addField($object->action_aprovar); // important
  55. $object->system_menu = new TDBCombo('system_menu'.$object->id, 'permission', 'SystemMenu', 'id', 'name');
  56. $this->form_grupo->addField($object->system_menu); // important
  57. $this->cartgrid->addItem($object);
  58. }
  59. }
  60. // reset the criteria for record count
  61. $criteria->resetProperties();
  62. $count= $repository->count($criteria);
  63. $this->pageNavigation->setCount($count); // count of records
  64. $this->pageNavigation->setProperties($param); // order, page
  65. $this->pageNavigation->setLimit($limit); // limit
  66. // close the transaction
  67. TTransaction::close();
  68. $this->loaded = true;
  69. }
  70. catch (Exception $e) // in case of exception
  71. {
  72. // shows the exception error message
  73. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  74. // undo all pending operations
  75. TTransaction::rollback();
  76. }
  77. }
  78. function show()
  79. {
  80. // check if the datagrid is already loaded
  81. if (!$this->loaded)
  82. {
  83. $this->onReload( func_get_arg(0));
  84. $this->form_grupo->addField($object->action_editar);
  85. $this->form_grupo->addField($object->action_print);
  86. }
  87. parent::show();
  88. }
  89. ?>
NR

Era pra acrescentar o if na função onReload, dentro do foreach:
 
  1. <?php
  2. if ($cart_objects)
  3. {
  4. foreach ($cart_objects as $object)
  5. {
  6. $object->action_editar = new TCheckButton('checkedit'.$object->id);
  7. ...
  8. if (! $this->loaded)
  9. {
  10. $this->form->addField($object->action_editar);
  11. ....
  12. }
  13. }
  14. ?>

A função show pode deixar como estava antes
RB

Nataniel,


Funcionou, mais uma vez muito obrigado pelo apoio.