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


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 (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.