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
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
- <?php
- class SystemGroupBuilder extends TPage
- {
- protected $form;
- protected $form_grupo;
- protected $load;
- protected $load1;
- protected $datagrid;
- protected $cartgrid;
- protected $datagrid_group;
- protected $datagrid_user;
- protected $datagrid_alocacao_user;
- protected $pageNavigation;
- protected $pageNavigation2;
- public function __construct()
- {
- parent::__construct();
- parent::include_css('app/resources/blue_modificado.css');
- parent::include_css('app/resources/custom-table.css');
- parent::include_css('app/resources/builder.css');
- // create form and table container
- $this->form_grupo = new BootstrapFormBuilder;
- $this->form_grupo->class = 'frm_gruop_usuario';
- $this->form = new TForm('frm_check');
- $this->style = 'width:100%';
- $this->form->class = 'frm_gruop_usuario';
- $dados_grupo = new TLabel('Detalhes do Grupo');
- $dados_grupo->class ='lbl_titulo';
- $this->form_grupo->addContent( [$dados_grupo] );
- $lbl_nome = new TLabel(_t('Group`s name'));
- $lbl_descrcica_grupo = new TLabel(_t('Description'));
- $lbl_empresa = new TLabel(_t('Company'));
- $lbl_unidade_negocio = new TLabel(_t('Unit'));
- $nome_grupo = new TEntry('nome_grupo');
- $descricao_grupo = new TEntry('descricao_grupo');
- $descricao_empresa = new TEntry('descricao_empresa');
- $descricao_unidade = new TEntry('descricao_unidade');
- $lbl_nome->class = 'lbl_text';
- $lbl_descrcica_grupo->class = 'lbl_text';
- $lbl_empresa->class = 'lbl_text';
- $lbl_unidade_negocio->class = 'lbl_text';
- $lbl_nome->setSize('100%');
- $lbl_descrcica_grupo->setSize('100%');
- $nome_grupo->setSize('100%');
- $descricao_grupo->setSize('100%');
- $descricao_empresa->setSize('100%');
- $descricao_unidade->setSize('100%');
- $this->form_grupo->addFields([$lbl_nome]);
- $this->form_grupo->addFields([$nome_grupo]);
- $this->form_grupo->addFields([$lbl_descrcica_grupo]);
- $this->form_grupo->addFields([$descricao_grupo]);
- $this->form_grupo->addFields([$lbl_empresa]);
- $this->form_grupo->addFields([$descricao_empresa]);
- $this->form_grupo->addFields([$lbl_unidade_negocio]);
- $this->form_grupo->addFields([$descricao_unidade]);
- $dados_grupo_configuracao = new TLabel('Configuração de menus e submenus');
- $dados_grupo_configuracao->class ='lbl_titulo';
- $this->form_grupo->addContent( [$dados_grupo_configuracao] );
- $this->form_grupo->addAction('Salvar',new TAction(array($this, 'onSave')),'fa:save blue');
- $this->form_grupo->addAction('Listar',new TAction(array('GrupoEmpresa','onReload')),'fa:table blue');
- // creates a DataGrid
- $this->datagrid = new TQuickGrid;
- $this->cartgrid = new TDataGrid;
- $this->cartgrid->disableDefaultClick(); // important!
- $this->datagrid_user = new TQuickGrid;
- $this->datagrid_alocacao_user = new TDataGrid;
- $this->datagrid->style = 'width:100%;';
- $this->cartgrid->style = 'width:100%;';
- $this->datagrid_user->style = 'width:100%;';
- // creates the datagrid columns
- $this->datagrid->addQuickColumn('ID', 'id','center','5%');
- $this->datagrid->addQuickColumn(_t('Name'),'name','left');
- $this->datagrid->addQuickColumn(_t('Description'),'controller','left');
- //cartgrid
- $id = new TDataGridColumn('id','ID','center','5%');
- $name = new TDataGridColumn('name',_t('Name'), 'left');
- $descricao = new TDataGridColumn('controller', _t('Description'),'left');
- $action_editar = new TDataGridColumn('action_editar', _t('Edit'),'center');
- $action_print = new TDataGridColumn('action_print', _t('Print'),'center');
- $action_visualizar = new TDataGridColumn('action_visualizar', _t('View'),'center');
- // creates the datagrid actions
- $order1 = new TAction(array($this, 'onReload'));
- $order2 = new TAction(array($this, 'onReload'));
- // define the ordering parameters
- $order1->setParameter('order', 'id');
- $order2->setParameter('order', 'name');
- // assign the ordering actions
- $id->setAction($order1);
- $name->setAction($order2);
- // add the columns to the datagrid
- $this->cartgrid->addColumn($id);
- $this->cartgrid->addColumn($name);
- $this->cartgrid->addColumn($descricao);
- $this->cartgrid->addColumn($action_editar);
- $this->cartgrid->addColumn($action_print);
- $this->cartgrid->addColumn($action_visualizar);
- $action = new TDataGridAction(array($this, 'onDelete'));
- $action->setLabel(_t('Delete'));
- $action->setImage('ico_delete.png');
- $action->setField('id');
- $this->cartgrid->addAction($action);
- // creates the datagrid columns
- $this->datagrid_user->addQuickColumn('ID', 'id','center','5%');
- $this->datagrid_user->addQuickColumn(_t('Name'),'name','left');
- // add the columns to the datagrid
- $this->datagrid_alocacao_user->addColumn($id);
- $this->datagrid_alocacao_user->addColumn($name);
- $action1 = new TDataGridAction(array($this, 'onDelete'));
- $action1->setLabel(_t('Delete'));
- $action1->setImage('ico_delete.png');
- $action1->setField('id');
- $this->datagrid_alocacao_user->addAction($action1);
- // creates datagrid actions
- $this->datagrid->addQuickAction(_t('Select'),new TDataGridAction(array($this,'onSelect')), 'id', 'ico_apply.png');
- $this->datagrid_user->addQuickAction(_t('Select').' '._t('user'),new TDataGridAction(array($this,'onSelectUser')), 'id', 'ico_apply.png');
- // create the datagrid model
- $this->datagrid->createModel();
- $this->cartgrid->createModel();
- $this->datagrid_user->createModel();
- $this->datagrid_alocacao_user->createModel();
- // creates the page navigation datagrid
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // creates the page structure using a table
- $table1 = new TTable;
- $table1->style = 'width:100%;';
- $table1->addRow()->addCell($this->datagrid);
- $scroll1 = new TScroll;
- $scroll1->style = 'width:49.5%;float:left;height:300px;margin:0 0.5% 0 0;';
- $scroll1->add($table1);
- $div_paginacao = new TElement('div');
- $div_paginacao->id = 'div_paginacao';
- $div_paginacao->class = 'div_paginacao';
- $div_paginacao->add($this->pageNavigation) ;
- $scroll1->add($div_paginacao) ;
- $table2 = new TTable;
- $table2->style = 'width:100%;';
- $table2->addRow()->addCell($this->cartgrid);
- $scroll = new TScroll;
- $scroll->style = 'width:50%;height:300px;float:left;';
- $scroll->add($table2);
- // creates the page structure using a table
- $table3 = new TTable;
- $table3->style = 'width:100%;';
- $table3->addRow()->addCell($this->datagrid_user);
- $scroll2 = new TScroll;
- $scroll2->style = 'width:49.5%;float:left;height:300px;margin:0 0.5% 0 0;';
- $scroll2->add($table3);
- $table4 = new TTable;
- $table4->style = 'width:100%;';
- $table4->addRow()->addCell($this->datagrid_alocacao_user);
- $scroll3 = new TScroll;
- $scroll3->style = 'width:50%;height:300px;float:left;';
- $scroll3->add($table4);
- $hbox = new THBox;
- $hbox->add($scroll1)->style ='vertical-align:top;width:100%;';
- $hbox->add($scroll)->style ='vertical-align:top;width:100%;';
- // creates the page navigation
- $this->pageNavigation2 = new TPageNavigation;
- $this->pageNavigation2->setAction(new TAction(array($this, 'onReloadUser')));
- $this->pageNavigation2->setWidth($this->datagrid_user->getWidth());
- $div_paginacao1 = new TElement('div');
- $div_paginacao1->id = 'div_paginacao1';
- $div_paginacao1->class = 'div_paginacao';
- $div_paginacao1->add($this->pageNavigation2) ;
- $scroll2->add($div_paginacao1);
- $hbox1 = new THBox;
- $hbox1->add($scroll2)->style ='vertical-align:top;width:100%;';
- $hbox1->add($scroll3)->style ='vertical-align:top;width:100%;';
- $this->form_grupo->addFields([$hbox]);
- $titulo_alocacao_user = new TLabel('Alocação dos usuários');
- $titulo_alocacao_user->class ='lbl_titulo';
- $this->form_grupo->addContent( [$titulo_alocacao_user] );
- $this->form_grupo->addFields([$hbox1]);
- //wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->style = 'width:100%';
- $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($this->form_grupo);
- parent::add($vbox);
- }
- /**
- * Put a programs inside the cart
- */
- public function onSelect($param)
- {
- // get the cart objects from session
- $cart_objects = TSession::getValue('cart_objects');
- TTransaction::open('permission');
- $programs = new SystemProgram($param['key']); // load the programs
- $cart_objects[$programs->id] = $programs; // add the programs inside the array
- TSession::setValue('cart_objects', $cart_objects); // put the array back to the session
- TTransaction::close();
- // reload datagrids
- $this->onReload( func_get_arg(0) );
- }
- public function onSelectUser($param)
- {
- // get the cart objects from session
- $alocacao_objects = TSession::getValue('alocacao_objects');
- TTransaction::open('permission');
- $user_object = new SystemUser($param['key']); // load the user
- $alocacao_objects[$user_object->id] = $user_object; // add the user inside the array
- TSession::setValue('alocacao_objects', $user_object); // put the array back to the session
- TTransaction::close();
- // reload datagrids
- $this->onReloadUser( func_get_arg(0) );
- }
- /**
- * Remove a programs from the cart
- */
- public function onDelete($param)
- {
- // get the cart objects from session
- $cart_objects = TSession::getValue('cart_objects');
- unset($cart_objects[$param['key']]); // remove the programs from the array
- TSession::setValue('cart_objects', $cart_objects); // put the array back to the session
- // reload datagrids
- $this->onReload( func_get_arg(0) );
- }
- /**
- * method onReload()
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'samples'
- TTransaction::open('permission');
- // creates a repository for Product
- $repository = new TRepository('SystemProgram');
- $limit = 5;
- // creates a criteria
- $criteria = new TCriteria;
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- $criteria->setProperty('order', 'controller');
- // load the objects according to criteria
- $objects = $repository->load($criteria);
- $this->datagrid->clear();
- if ($objects)
- {
- foreach ($objects as $object)
- {
- // add the object inside the datagrid
- $this->datagrid->addItem($object);
- }
- }
- //cartgrid
- $this->cartgrid->clear();
- $cart_objects = TSession::getValue('cart_objects');
- if ($cart_objects)
- {
- foreach ($cart_objects as $object)
- {
- $uniqid = mt_rand(1000000, 9999999);
- $object->action_editar = new TCheckButton('check'.$uniqid);
- $object->action_editar->setIndexValue('on');
- $this->form->addField($object->action_editar); // important!
- $uniqid1 = mt_rand(1000000, 9999999);
- $object->action_print = new TCheckButton('check'.$uniqid1);
- $object->action_print->setIndexValue('on');
- $this->form->addField($object->action_print); // important!
- $uniqid2 = mt_rand(1000000, 9999999);
- $object->action_visualizar = new TCheckButton('check'.$uniqid2);
- $object->action_visualizar->setIndexValue('on');
- $this->form->addField($object->action_visualizar); // important
- $this->cartgrid->addItem($object);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count= $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- public function onReloadUser($param = NULL)
- {
- try
- {
- // open a transaction with database 'samples'
- TTransaction::open('permission');
- // creates a repository for SystemUser
- $repository1 = new TRepository('SystemUser');
- $limit1 = 5;
- // creates a criteria
- $criteria1 = new TCriteria;
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'id';
- $param['direction'] = 'asc';
- }
- $criteria1->setProperties($param); // order, offset
- $criteria1->setProperty('limit1', $limit1);
- $criteria1->setProperty('order', 'name');
- // load the objects according to criteria
- $objects = $repository1->load($criteria1);
- $this->datagrid_user->clear();
- if ($objects)
- {
- foreach ($objects as $object)
- {
- // add the object inside the datagrid
- $this->datagrid_user->addItem($object);
- }
- }
- //datagrid_alocacao_user
- $this->datagrid_alocacao_user->clear();
- $alocacao_objects = TSession::getValue('alocacao_objects');
- if ($alocacao_objects)
- {
- foreach ($alocacao_objects as $object)
- {
- $this->datagrid_alocacao_user->addItem($object);
- }
- }
- // reset the criteria1 for record count
- $criteria1->resetProperties();
- $count1 = $repository1->count($criteria1);
- $this->pageNavigation2->setCount($count1); // count of records
- $this->pageNavigation2->setProperties($param); // order, page
- $this->pageNavigation2->setLimit($limit1); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded1 = true;
- }
- catch (Exception $e)
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- public static function onSave($param)
- {
- // show form values inside a window
- $win = TWindow::create('test', 0.6, 0.8);
- $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'] );
- $win->show();
- TForm::sendData('frm_gruop_usuario', $data);// keep form data
- TForm::sendData('frm_check', $data);// keep form data
- }
- public function onClear($param)
- {
- $this->form->clear(TRUE);
- }
- public function onEdit($param)
- {
- }
- /**
- * method show()
- * Shows the page
- */
- function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded)
- {
- $this->onReload( func_get_arg(0));
- $this->onReloadUser(func_get_arg(0));
- }
- parent::show();
- }
- }
- ?>
O erro diz que você está tentando usar um objeto como array, na linha 268:
Nataniel, bom dia,
Mais uma vez muito obrigado, funcionou perfeito.
Nataniel,
Como faço para separar a paginação ?
Pois a paginação esta sendo sincronizada entre as grids, tem como ?
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.