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


Desde já obrigado.

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework 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.