Exibir TImage no Form Galera, estou tentando exibir uma imagem armazenada no banco de dados, utilizando um método onChangeAction, consigo exibir a imagem utilizando um TMessage, porém, quero que ela fique em um campo no form. Segue meu código: ...
IC
Exibir TImage no Form  
Galera, estou tentando exibir uma imagem armazenada no banco de dados, utilizando um método onChangeAction, consigo exibir a imagem utilizando um TMessage, porém, quero que ela fique em um campo no form. Segue meu código:

 
  1. <?php
  2. class TrocaSolicitado extends TPage
  3. {
  4. protected $form; // form
  5. /**
  6. * Class constructor
  7. * Creates the page and the registration form
  8. */
  9. function __construct()
  10. {
  11. parent::__construct();
  12. // creates the form
  13. $this->form = new BootstrapFormBuilder('form_troca_solicitado');
  14. $this->form->setFormTitle('Solicitado');
  15. $SETOR = new TEntry('SETOR');
  16. $SETOR->setValue(TSession::getValue('SETOR'));
  17. $MES_DA_ESCALA = new TEntry('MES_DA_ESCALA');
  18. $MES_DA_ESCALA->setValue(TSession::getValue('MES_ESCALA'));
  19. $NOME = new TCombo('NOME');
  20. $CPF = new TEntry('CPF');
  21. $FOTO = new TImage('FOTO');
  22. base64_encode($FOTO);
  23. $SETOR->setExitAction( new TAction( array($this, 'onExitAction') ) );
  24. $CPF->setExitAction( new TAction( array($this, 'onFotoAction') ) );
  25. $NOME->setChangeAction(new TAction([$this, 'onChangeAction']));
  26. // add the fields
  27. $this->form->addFields(['SETOR: '], [$SETOR] );
  28. $this->form->addFields(['MES DA ESCALA: '], [$MES_DA_ESCALA] );
  29. $this->form->addFields(['NOME: '], [$NOME]);
  30. $this->form->addFields(['CPF: '], [$CPF], ['FOTO'], [$FOTO]);
  31. // validations
  32. $NOME->addValidation('NOME: ', new TRequiredValidator);
  33. $NOME->setSize('40%');
  34. $MES_DA_ESCALA->setSize('40%');
  35. $SETOR->setSize('40%');
  36. $CPF->setSize('105%');
  37. $this->form->addAction('Next', new TAction(array($this, 'onConfirm')), 'far:check-circle green');
  38. $this->form->addAction('Back', new TAction(array($this, 'onBackForm')), 'far:check-circle red');
  39. $pagestep = new TPageStep;
  40. $pagestep->addItem('SOLICITACAO');
  41. $pagestep->addItem('SETOR');
  42. $pagestep->addItem('SOLICITADO');
  43. $pagestep->addItem('CONFIRMAR');
  44. $pagestep->select('SOLICITADO');
  45. // wrap the page content using vertical box
  46. $vbox = new TVBox;
  47. $vbox->style = 'width: 100%';
  48. // $vbox->add(new TXMLBreadCrumb('menu.xml', 'MultiStepRegistration1View'));
  49. $vbox->add( $pagestep );
  50. $vbox->add( $this->form );
  51. parent::add($vbox);
  52. }
  53. public static function onExitAction($param){
  54. $SETOR = $param['SETOR'];
  55. $MES_DA_ESCALA = $param['MES_DA_ESCALA'];
  56. TTransaction::open('parametros_gente');
  57. $servidores = Escalas::select('NOME','CPF')->where('MES_DA_ESCALA', '=', $MES_DA_ESCALA)->where('SETOR', '=', $SETOR)->orderBy('NOME')
  58. ->load();
  59. $result = array();
  60. foreach ($servidores as $obj)
  61. {
  62. $result[$obj->CPF] = $obj->NOME;
  63. }
  64. TCombo::reload('form_troca_solicitado', 'NOME', $result);
  65. TTransaction::close();
  66. }
  67. public static function onChangeAction($param)
  68. {
  69. @$NOME = $param['NOME'];
  70. TTransaction::open('pessoal');
  71. $servidores = Servidores::where('CPF', '=',$NOME)->load();
  72. $result = new stdClass;
  73. foreach($servidores as $obj)
  74. {
  75. $result->CPF = $obj->CPF;
  76. }
  77. TForm::sendData('form_troca_solicitado', $result);
  78. TTransaction::close();
  79. }
  80. public static function onFotoAction($param)
  81. {
  82. $CPF = $param['CPF'];
  83. TTransaction::open('pessoal');
  84. $fotos = ServidorFoto::where('SEQ_SERVIDOR','in',"(SELECT SEQ_SERVIDOR FROM SERVIDORES WHERE CPF = '$CPF' AND SERVIDORES.SEQ_SITUACAO = 46)")->load();
  85. $resultfotos = new stdClass;
  86. foreach($fotos as $objfotos)
  87. {
  88. $resultfotos->FOTO = new TMessage('info', '<img src="data:image/png;base64,' . base64_encode($objfotos->FOTO) . '" />' );
  89. //TScript::create(($objfotos->FOTO));
  90. }
  91. TForm::sendData('form_troca_solicitado', $resultfotos);
  92. TTransaction::close();
  93. }
  94. public function onBackForm()
  95. {
  96. // Load another page
  97. AdiantiCoreApplication::loadPage('SetorTroca');
  98. }
  99. /**
  100. * confirmation screen
  101. */
  102. public function onConfirm()
  103. {
  104. try
  105. {
  106. $this->form->validate();
  107. $data = $this->form->getData();
  108. TSession::setValue('registration_data', (array) $data);
  109. TSession::setValue('NOMESOLICITADO', $data->NOME);
  110. TSession::setValue('SETORSOLICITADO', $data->SETOR);
  111. AdiantiCoreApplication::loadPage('Confirmacao');
  112. }
  113. catch (Exception $e)
  114. {
  115. new TMessage('error', $e->getMessage());
  116. }
  117. }
  118. }
  119. ?>

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 (2)


NR

Acho que usar javascript é mais fácil nesse caso, pois o TImage não é um input e com isso não é possível enviar informações via sendData/setData:
 
  1. <?php
  2. // construct
  3. $FOTO = new TImage('');
  4. $FOTO->id = 'minhafoto';
  5. //onFotoAction
  6. $base64 = base64_encode($objfotos->FOTO);
  7. TScript::create("$('#minhafoto').attr('src','data:image/png;base64,{$base64}');");
  8. ?>
IC

Nataniel, deu muito certo! Muito obrigado, brother! Agora só resta enquadra as imagens pra ficar certinho no form. Vlw mesmo!