Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Passagem de valor entre funções Boa tarde! Gostaria de informações como posso pegar o param[‘key’] da função onView, e passar para $object->system_notice_id que estar na função onSave. Já tentei utilizar variável global e outros métodos, porém nenhum surtiu efeito. Segue o código. ...
HL
Passagem de valor entre funções  
Boa tarde!
Gostaria de informações como posso pegar o param[‘key’] da função onView, e passar para $object->system_notice_id que estar na função onSave.

Já tentei utilizar variável global e outros métodos, porém nenhum surtiu efeito.

Segue o código.
  1. <?php
  2. /**
  3.  * SystemSubscriptionForm
  4.  *
  5.  * @package    control
  6.  * @subpackage ps
  7.  * @author     Hellton Lacerda
  8.  * @copyright  Serviço Social da Indústria - Paraíba
  9.  */
  10. class SystemSubscriptionForm extends TPage
  11. {
  12.     protected $form
  13.    
  14.     public $var;
  15.    
  16.     function __construct()
  17.     {
  18.         parent::__construct();
  19.         
  20.         $this->form = new BootstrapFormBuilder('form_System_subscription');
  21.         $this->form->setFormTitle(('Inscrição processo seletivo') );
  22.         
  23.         $id                        = new TEntry('id');
  24.         $name                      = new TEntry('nome');
  25.     
  26.         $dtinscricao               = new TDate('dtinscricao');
  27.         
  28.         $nome_resp                 = new TEntry('nome_resp');
  29.         $cpf_resp                  = new TEntry('cpf_resp');
  30.         $empresa_resp                 = new TEntry('empresa_resp');
  31.         $cnpj_resp                  = new TEntry('cnpj_resp');
  32.         
  33.         $escolaridade              = new TCombo('escolaridade');
  34.         $estadocivil               = new TCombo('estadocivil');
  35.         $renda                     = new TCombo('renda');
  36.         $tipo_escola               = new TCombo('tipo_escola');
  37.         $escolaanterior            = new TEntry('escolaanterior');
  38.         
  39.         $nt6lp                     = new TEntry('nt6lp');
  40.         $nt6mt                     = new TEntry('nt6mt');
  41.         $nt6geo                    = new TEntry('nt6geo');
  42.         $nt6his                    = new TEntry('nt6his');
  43.         
  44.         $nt7lp                     = new TEntry('nt7lp');
  45.         $nt7mt                     = new TEntry('nt7mt');
  46.         $nt7geo                    = new TEntry('nt7geo');
  47.         $nt7his                    = new TEntry('nt7his');
  48.         
  49.         $nt8lp                     = new TEntry('nt8lp');
  50.         $nt8mt                     = new TEntry('nt8mt');
  51.         $nt8geo                    = new TEntry('nt8geo');
  52.         $nt8his                    = new TEntry('nt8his');
  53.         
  54.         $ntflp                     = new TEntry('ntflp');
  55.         $ntfmt                     = new TEntry('ntfmt');
  56.         $ntfgeo                    = new TEntry('ntfgeo');
  57.         $ntfhis                    = new TEntry('ntfhis');
  58.         
  59.         $ntf                       = new TEntry('ntf');
  60.         
  61.         $system_notice_id          = new TEntry('system_notice_id');
  62.         $system_unit_id            = new TDBCombo('system_unit_id''permission''SystemUnit''id''cidade''name asc');
  63.         $system_curso_id           = new TCombo('system_curso_id');
  64.         $system_user_id            = new TEntry('system_user_id');
  65.         $situacao                  = new TEntry('situacao');
  66.         $motivo_cancelamento       = new TEntry('motivo_cancelamento'); 
  67.         
  68.         $name->setEditable(FALSE);
  69.         $ntflp->setEditable(FALSE);
  70.         $ntfmt->setEditable(FALSE);
  71.         $ntfgeo->setEditable(FALSE);
  72.         $ntfhis->setEditable(FALSE);        
  73.         
  74.         $ntf->setEditable(FALSE);
  75.         
  76.         $name->setSize('100%'); 
  77.         
  78.         $ntflp->setSize('100%');
  79.         $ntfmt->setSize('100%');
  80.         $ntfgeo->setSize('100%');    
  81.         $ntfhis->setSize('100%');
  82.         $cpf_resp->setMask('999.999.999-99');
  83.         $cnpj_resp->setMask('99.999.999/9999-99');
  84.         
  85.         $nt6lp->setMask('9!');
  86.         $nt7lp->setMask('9!');
  87.         $nt8lp->setMask('9!');
  88.         
  89.         $nt6mt->setMask('9!');
  90.         $nt7mt->setMask('9!');
  91.         $nt8mt->setMask('9!');
  92.         
  93.         $nt6geo->setMask('9!');
  94.         $nt7geo->setMask('9!');
  95.         $nt8geo->setMask('9!');
  96.         
  97.         $nt6his->setMask('9!');
  98.         $nt7his->setMask('9!');
  99.         $nt8his->setMask('9!');
  100.         
  101.       $escolaanterior->forceUpperCase();
  102.       $nome_resp->forceUpperCase();
  103.       $empresa_resp->forceUpperCase();
  104.          
  105.          
  106.       $escolaridade->addItems(['5' =>'ENSINO FUNDAMENTAL COMPLETO''6' => 'ENSINO MÉDIO INCOMPLETO']);
  107.       $estadocivil->addItems(['C' =>'CASADO'
  108.                'D' => 'DIVORCIADO',
  109.                'S' => 'SOLTEIRO',
  110.                'V' => 'VIÚVO',
  111.                'O' => 'OUTRO']);
  112.       $renda->addItems(['1' =>'ATÉ 1 SÁLARIO MÍNIMO'
  113.                '2' => 'DE 1 À 2 SÁLARIOS MÍNIMO',
  114.                '3' => 'DE 2 À 3 SÁLARIOS MÍNIMO',
  115.                '4' => 'DE 3 À 4 SÁLARIOS MÍNIMO',
  116.                '5' => 'MAIS DE 4 SÁLARIOS MÍNIMO']);
  117.                
  118.       $tipo_escola->addItems(['1' =>'TODO ENSINO FUNDAMENTAL II EM ESCOLA PÚBLICA'
  119.                '2' => 'TODO ENSINO FUNDAMENTAL II EM ESCOLA PRIVADA',
  120.                '3' => 'MAIOR PARTE DO ENSINO FUNDAMENTAL II EM ESCOLA PÚBLICA',
  121.                '4' => 'MAIOR PARTE DO ENSINO FUNDAMENTAL II EM ESCOLA PRIVADA']);
  122.                
  123.        $name->setValue(TSession::getValue('username')); 
  124.            
  125.        $cpf_resp->addValidation(('CPF'), new TCPFValidator);
  126.        $cnpj_resp->addValidation(('CNPJ'), new TCNPJValidator);        
  127.        
  128.         
  129.         $this->form->addFields( [new TLabel(('Candidato'))], [$name] ); 
  130.         $this->form->addFields( [new TFormSeparator(('Informações básicas'))]);
  131.         $this->form->addFields( [new TLabel(('Escolaridade'))], [$escolaridade], [new TLabel(('Estado covil'))], [$estadocivil]);
  132.         $this->form->addFields( [new TLabel(('Renda'))], [$renda], [new TLabel(('Tipo escola'))], [$tipo_escola]);
  133.         $this->form->addFields( [new TLabel(('Escola anterior'))], [$escolaanterior] );        
  134.         
  135.         $this->form->addFields( [new TFormSeparator(('Informações do responsável'))]);
  136.         $this->form->addFields( [new TLabel(('CPF PAI'))], [$cpf_resp], [new TLabel(('nome PAI'))], [$nome_resp] );
  137.         $this->form->addFields( [new TLabel(('cnpj empresa'))], [$cnpj_resp], [new TLabel(('empresa'))], [$empresa_resp]); 
  138.         
  139.         $this->form->addFields( [new TFormSeparator(('Informações '))]);
  140.         $this->form->addFields( [new TLabel(('Cidade'))], [$system_unit_id], [new TLabel(('Curso'))], [$system_curso_id] );
  141.         
  142.         $this->form->addFields( [new TFormSeparator(('Notas'))]);
  143.         $this->form->addFields( [new TLabel(('6º ano - Lingua Portuguesa'))], [$nt6lp], [new TLabel(('7º ano - Lingua Portuguesa'))], [$nt7lp], [new TLabel(('8º ano - Lingua Portuguesa'))], [$nt8lp] );
  144.         $this->form->addFields( [new TLabel(('6º ano - Matemática'))], [$nt6mt], [new TLabel(('7º ano - Matemática'))], [$nt7mt], [new TLabel(('8º ano - Matemática'))], [$nt8mt] );
  145.         $this->form->addFields( [new TLabel(('6º ano - Geografia'))], [$nt6geo], [new TLabel(('7º ano - Geografia'))], [$nt7geo], [new TLabel(('8º ano - Geografia'))], [$nt8geo] );
  146.         $this->form->addFields( [new TLabel(('6º ano - História'))], [$nt6his], [new TLabel(('7º ano - História'))], [$nt7his], [new TLabel(('8º ano - História'))], [$nt8his] );
  147.         
  148.         $this->form->addFields( [new TFormSeparator(('Média'))]);
  149.         $this->form->addFields( [new TLabel(('Língua Portuguesa'))], [$ntflp], [new TLabel(('Matemática'))], [$ntfmt]);
  150.         $this->form->addFields( [new TLabel(('Geografia'))], [$ntfgeo], [new TLabel(('História'))], [$ntfhis]);
  151.      
  152.         $this->form->addFields( [new TFormSeparator(('Média Final'))]);
  153.         $this->form->addFields( [new TLabel(('Média Final'))], [$ntf]);
  154.         
  155.         $nt6lp->onBlur   'calculate_lp()';
  156.         $nt7lp->onBlur   'calculate_lp()';
  157.         $nt8lp->onBlur   'calculate_lp()';
  158.         
  159.         $nt6mt->onBlur   'calculate_mt()';
  160.         $nt7mt->onBlur   'calculate_mt()';
  161.         $nt8mt->onBlur   'calculate_mt()';
  162.         
  163.         $nt6geo->onBlur   'calculate_geo()';
  164.         $nt7geo->onBlur   'calculate_geo()';
  165.         $nt8geo->onBlur   'calculate_geo()';
  166.         
  167.         $nt6his->onBlur   'calculate_his()';
  168.         $nt7his->onBlur   'calculate_his()';
  169.         $nt8his->onBlur   'calculate_his()';
  170.         
  171.         
  172.         $btn $this->form->addAction(('Salvar'), new TAction(array($this'onSave')), 'fa:floppy-o');
  173.         $btn->class 'btn btn-sm btn-primary';
  174.         
  175.         $course_action = new TAction(array($this'onChangeActionCourse'));
  176.         $system_unit_id->setChangeAction($course_action);
  177.         
  178.         $container = new TVBox;
  179.         $container->style 'margin: 100px';
  180.         
  181.         $container->add($this->form);
  182.      
  183.         parent::add($container);
  184.     }
  185.     
  186.     public static function onChangeActionCourse($param)
  187.     {
  188.         TTransaction::open('permission');
  189.         $criteria_course = new TCriteria;
  190.         $criteria_course->add(new TFilter('system_unit_id''='$param['system_unit_id']));
  191.         $repository_course = new TRepository('ViewSystemUnitCurso');
  192.         $courses $repository_course->load($criteria_course);
  193.         foreach($courses as $course){
  194.             $option_course[$course->system_curso_id] = $course->course
  195.         }
  196.         TCombo::reload('form_System_subscription''system_curso_id'$option_course);
  197.         TTransaction::close();
  198.     }
  199.     
  200.    public function  onView($param)
  201.     {
  202.         try
  203.         {
  204.             if (isset($param['key']))
  205.             {
  206.                 
  207.                 
  208.                 var_dump($result->system_notice_id);
  209.                 TForm::sendData('form_System_subscription'$result);
  210.                
  211.                 
  212.                 
  213.                 TTransaction::open('permission');
  214.                            }
  215.             else
  216.             {
  217.                 $this->form->clear();
  218.             }
  219.         }
  220.         catch (Exception $e
  221.         {
  222.            
  223.             new TMessage('error'$e->getMessage());
  224.         }
  225.     }
  226.     
  227.     public function onSave($param)
  228.     {
  229.         try
  230.         {
  231.             TTransaction::open('permission');
  232.             
  233.             $object $this->form->getData('SystemSubscription');
  234.             $object->system_user_id TSession::getValue('userid');
  235.             $object->situacao 'INSCRITO';
  236.             $object->dtinscricao date('Y-m-d');
  237.             $object->system_notice_id 8;
  238.             
  239.             
  240.             $object->ntflp = ($object->nt6lp $object->nt7lp $object->nt8lp)/3;
  241.             $object->ntfmt = ($object->nt6mt $object->nt7mt $object->nt8mt)/3;
  242.             $object->ntfgeo = ($object->nt6geo $object->nt7geo $object->nt8geo)/3;
  243.             $object->ntfhis = ($object->nt6his $object->nt7his $object->nt8his)/3;
  244.             
  245.             $object->ntf = ($object->ntflp $object->ntfmt $object->ntfgeo $object->ntfhis)/4;
  246.             
  247.             $object->store();
  248.             
  249.             $this->form->setData($object); 
  250.            
  251.             TTransaction::close(); 
  252.            
  253.             
  254.        
  255.         }
  256.         catch (Exception $e
  257.         {
  258.             
  259.             new TMessage('error'$e->getMessage());
  260.             
  261.             
  262.             TTransaction::rollback();
  263.         }
  264.     }
  265.     
  266.     
  267.     
  268.     
  269. }
  270. </code>


Desde já obrigado.

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)


MG

Olá, todos os campos do formulário (form) são passados no array $param.

Use o "var_dump($param)" no onSave e poderá ver o conteúdo chegando neste método.
TC

Helton Faz Assim:

no onView vc joga o system_notice_id na sessão, assim:

TSession::setValue('nomedasessao',$result->system_notice_id->system_notice_id );

no onSave vc recupera assim:
$object->system_notice_id = TSession::getValue('nomedasessao');
TC

como vc quer pegar o param key então seta assim:
TSession::setValue('nomedasessao',$param['key'] );
HL

Da forma que o Thiago Cavalcante explicou rodou corretamente.

A função onView ficou:

TSession::setValue('editalDesejado',$param['key']);


Já na função onSave ficou:

$object->system_notice_id = TSession::getValue('editalDesejado');


Obrigado pela ajuda.