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.
Desde já obrigado.
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.
<?php/** * SystemSubscriptionForm * * @package control * @subpackage ps * @author Hellton Lacerda * @copyright Serviço Social da Indústria - Paraíba */class SystemSubscriptionForm extends TPage{ protected $form; public $var; function __construct() { parent::__construct(); $this->form = new BootstrapFormBuilder('form_System_subscription'); $this->form->setFormTitle(('Inscrição processo seletivo') ); $id = new TEntry('id'); $name = new TEntry('nome'); $dtinscricao = new TDate('dtinscricao'); $nome_resp = new TEntry('nome_resp'); $cpf_resp = new TEntry('cpf_resp'); $empresa_resp = new TEntry('empresa_resp'); $cnpj_resp = new TEntry('cnpj_resp'); $escolaridade = new TCombo('escolaridade'); $estadocivil = new TCombo('estadocivil'); $renda = new TCombo('renda'); $tipo_escola = new TCombo('tipo_escola'); $escolaanterior = new TEntry('escolaanterior'); $nt6lp = new TEntry('nt6lp'); $nt6mt = new TEntry('nt6mt'); $nt6geo = new TEntry('nt6geo'); $nt6his = new TEntry('nt6his'); $nt7lp = new TEntry('nt7lp'); $nt7mt = new TEntry('nt7mt'); $nt7geo = new TEntry('nt7geo'); $nt7his = new TEntry('nt7his'); $nt8lp = new TEntry('nt8lp'); $nt8mt = new TEntry('nt8mt'); $nt8geo = new TEntry('nt8geo'); $nt8his = new TEntry('nt8his'); $ntflp = new TEntry('ntflp'); $ntfmt = new TEntry('ntfmt'); $ntfgeo = new TEntry('ntfgeo'); $ntfhis = new TEntry('ntfhis'); $ntf = new TEntry('ntf'); $system_notice_id = new TEntry('system_notice_id'); $system_unit_id = new TDBCombo('system_unit_id', 'permission', 'SystemUnit', 'id', 'cidade', 'name asc'); $system_curso_id = new TCombo('system_curso_id'); $system_user_id = new TEntry('system_user_id'); $situacao = new TEntry('situacao'); $motivo_cancelamento = new TEntry('motivo_cancelamento'); $name->setEditable(FALSE); $ntflp->setEditable(FALSE); $ntfmt->setEditable(FALSE); $ntfgeo->setEditable(FALSE); $ntfhis->setEditable(FALSE); $ntf->setEditable(FALSE); $name->setSize('100%'); $ntflp->setSize('100%'); $ntfmt->setSize('100%'); $ntfgeo->setSize('100%'); $ntfhis->setSize('100%'); $cpf_resp->setMask('999.999.999-99'); $cnpj_resp->setMask('99.999.999/9999-99'); $nt6lp->setMask('9!'); $nt7lp->setMask('9!'); $nt8lp->setMask('9!'); $nt6mt->setMask('9!'); $nt7mt->setMask('9!'); $nt8mt->setMask('9!'); $nt6geo->setMask('9!'); $nt7geo->setMask('9!'); $nt8geo->setMask('9!'); $nt6his->setMask('9!'); $nt7his->setMask('9!'); $nt8his->setMask('9!'); $escolaanterior->forceUpperCase(); $nome_resp->forceUpperCase(); $empresa_resp->forceUpperCase(); $escolaridade->addItems(['5' =>'ENSINO FUNDAMENTAL COMPLETO', '6' => 'ENSINO MÉDIO INCOMPLETO']); $estadocivil->addItems(['C' =>'CASADO', 'D' => 'DIVORCIADO', 'S' => 'SOLTEIRO', 'V' => 'VIÚVO', 'O' => 'OUTRO']); $renda->addItems(['1' =>'ATÉ 1 SÁLARIO MÍNIMO', '2' => 'DE 1 À 2 SÁLARIOS MÍNIMO', '3' => 'DE 2 À 3 SÁLARIOS MÍNIMO', '4' => 'DE 3 À 4 SÁLARIOS MÍNIMO', '5' => 'MAIS DE 4 SÁLARIOS MÍNIMO']); $tipo_escola->addItems(['1' =>'TODO ENSINO FUNDAMENTAL II EM ESCOLA PÚBLICA', '2' => 'TODO ENSINO FUNDAMENTAL II EM ESCOLA PRIVADA', '3' => 'MAIOR PARTE DO ENSINO FUNDAMENTAL II EM ESCOLA PÚBLICA', '4' => 'MAIOR PARTE DO ENSINO FUNDAMENTAL II EM ESCOLA PRIVADA']); $name->setValue(TSession::getValue('username')); $cpf_resp->addValidation(('CPF'), new TCPFValidator); $cnpj_resp->addValidation(('CNPJ'), new TCNPJValidator); $this->form->addFields( [new TLabel(('Candidato'))], [$name] ); $this->form->addFields( [new TFormSeparator(('Informações básicas'))]); $this->form->addFields( [new TLabel(('Escolaridade'))], [$escolaridade], [new TLabel(('Estado covil'))], [$estadocivil]); $this->form->addFields( [new TLabel(('Renda'))], [$renda], [new TLabel(('Tipo escola'))], [$tipo_escola]); $this->form->addFields( [new TLabel(('Escola anterior'))], [$escolaanterior] ); $this->form->addFields( [new TFormSeparator(('Informações do responsável'))]); $this->form->addFields( [new TLabel(('CPF PAI'))], [$cpf_resp], [new TLabel(('nome PAI'))], [$nome_resp] ); $this->form->addFields( [new TLabel(('cnpj empresa'))], [$cnpj_resp], [new TLabel(('empresa'))], [$empresa_resp]); $this->form->addFields( [new TFormSeparator(('Informações '))]); $this->form->addFields( [new TLabel(('Cidade'))], [$system_unit_id], [new TLabel(('Curso'))], [$system_curso_id] ); $this->form->addFields( [new TFormSeparator(('Notas'))]); $this->form->addFields( [new TLabel(('6º ano - Lingua Portuguesa'))], [$nt6lp], [new TLabel(('7º ano - Lingua Portuguesa'))], [$nt7lp], [new TLabel(('8º ano - Lingua Portuguesa'))], [$nt8lp] ); $this->form->addFields( [new TLabel(('6º ano - Matemática'))], [$nt6mt], [new TLabel(('7º ano - Matemática'))], [$nt7mt], [new TLabel(('8º ano - Matemática'))], [$nt8mt] ); $this->form->addFields( [new TLabel(('6º ano - Geografia'))], [$nt6geo], [new TLabel(('7º ano - Geografia'))], [$nt7geo], [new TLabel(('8º ano - Geografia'))], [$nt8geo] ); $this->form->addFields( [new TLabel(('6º ano - História'))], [$nt6his], [new TLabel(('7º ano - História'))], [$nt7his], [new TLabel(('8º ano - História'))], [$nt8his] ); $this->form->addFields( [new TFormSeparator(('Média'))]); $this->form->addFields( [new TLabel(('Língua Portuguesa'))], [$ntflp], [new TLabel(('Matemática'))], [$ntfmt]); $this->form->addFields( [new TLabel(('Geografia'))], [$ntfgeo], [new TLabel(('História'))], [$ntfhis]); $this->form->addFields( [new TFormSeparator(('Média Final'))]); $this->form->addFields( [new TLabel(('Média Final'))], [$ntf]); $nt6lp->onBlur = 'calculate_lp()'; $nt7lp->onBlur = 'calculate_lp()'; $nt8lp->onBlur = 'calculate_lp()'; $nt6mt->onBlur = 'calculate_mt()'; $nt7mt->onBlur = 'calculate_mt()'; $nt8mt->onBlur = 'calculate_mt()'; $nt6geo->onBlur = 'calculate_geo()'; $nt7geo->onBlur = 'calculate_geo()'; $nt8geo->onBlur = 'calculate_geo()'; $nt6his->onBlur = 'calculate_his()'; $nt7his->onBlur = 'calculate_his()'; $nt8his->onBlur = 'calculate_his()'; $btn = $this->form->addAction(('Salvar'), new TAction(array($this, 'onSave')), 'fa:floppy-o'); $btn->class = 'btn btn-sm btn-primary'; $course_action = new TAction(array($this, 'onChangeActionCourse')); $system_unit_id->setChangeAction($course_action); $container = new TVBox; $container->style = 'margin: 100px'; $container->add($this->form); parent::add($container); } public static function onChangeActionCourse($param) { TTransaction::open('permission'); $criteria_course = new TCriteria; $criteria_course->add(new TFilter('system_unit_id', '=', $param['system_unit_id'])); $repository_course = new TRepository('ViewSystemUnitCurso'); $courses = $repository_course->load($criteria_course); foreach($courses as $course){ $option_course[$course->system_curso_id] = $course->course; } TCombo::reload('form_System_subscription', 'system_curso_id', $option_course); TTransaction::close(); } public function onView($param) { try { if (isset($param['key'])) { var_dump($result->system_notice_id); TForm::sendData('form_System_subscription', $result); TTransaction::open('permission'); } else { $this->form->clear(); } } catch (Exception $e) { new TMessage('error', $e->getMessage()); } } public function onSave($param) { try { TTransaction::open('permission'); $object = $this->form->getData('SystemSubscription'); $object->system_user_id = TSession::getValue('userid'); $object->situacao = 'INSCRITO'; $object->dtinscricao = date('Y-m-d'); $object->system_notice_id = 8; $object->ntflp = ($object->nt6lp + $object->nt7lp + $object->nt8lp)/3; $object->ntfmt = ($object->nt6mt + $object->nt7mt + $object->nt8mt)/3; $object->ntfgeo = ($object->nt6geo + $object->nt7geo + $object->nt8geo)/3; $object->ntfhis = ($object->nt6his + $object->nt7his + $object->nt8his)/3; $object->ntf = ($object->ntflp + $object->ntfmt + $object->ntfgeo + $object->ntfhis)/4; $object->store(); $this->form->setData($object); TTransaction::close(); } catch (Exception $e) { new TMessage('error', $e->getMessage()); TTransaction::rollback(); } } }</code>
Desde já obrigado.
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.
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');
como vc quer pegar o param key então seta assim:
TSession::setValue('nomedasessao',$param['key'] );
Da forma que o Thiago Cavalcante explicou rodou corretamente.
A função onView ficou:
Já na função onSave ficou:
Obrigado pela ajuda.