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


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