TMULTIFILE - OnEdit não mostra os arquivos salvos Pessoal, Quando salvo os arquivos selecionados fica tudo OK nas devidas pastas, porém quando chamo o registro para edição, os arquivos que foram salvos não são mostrados na tela para que sejam excluídos. Por favor, peço ajuda aos feras do PHP. ...
CD
TMULTIFILE - OnEdit não mostra os arquivos salvos  
Pessoal,

Quando salvo os arquivos selecionados fica tudo OK nas devidas pastas, porém quando chamo o registro para edição, os arquivos que foram salvos não são mostrados na tela para que sejam excluídos.

Por favor, peço ajuda aos feras do PHP.


 
  1. <?php
  2. /**
  3. * ocorrenciaForm Form
  4. * @author <your name here>
  5. */
  6. class ocorrenciaForm extends TPage
  7. {
  8. protected $form; // form
  9. /**
  10. * Form constructor
  11. * @param $param Request
  12. */
  13. use Adianti\base\AdiantiFileSaveTrait;
  14. public function __construct( $param )
  15. {
  16. parent::__construct();
  17. // creates the form
  18. $this->form = new BootstrapFormBuilder('form_ocorrencia');
  19. $this->form->setFormTitle('Cadastro de Ocorrências');
  20. // create the form fields
  21. $ID_OCORRENCIA = new TEntry('ID_OCORRENCIA');
  22. $id_navio_pk = new TDBCombo('id_navio_pk', 'datasiop', 'Navio', 'ID_NAVIO', 'NOME');
  23. $id_turno_pk = new TDBCombo('id_turno_pk', 'datasiop', 'Turno', 'ID_TURNO', 'DESCRICAO');
  24. $id_tp_ocorrencia = new TDBCombo('id_tp_ocorrencia', 'datasiop', 'tipo_ocorrencia', 'ID_TIPO_OCORRENCIA', 'DESCRICAO');
  25. $id_cliente_pk = new TDBCombo('id_cliente_pk', 'datasiop', 'cliente', 'ID_CLIENTE', 'NOME');
  26. $DESCRICAO = new TText('DESCRICAO');
  27. $ACAO_IMEDIATA = new TText('ACAO_IMEDIATA');
  28. $DATA_OCORRENCIA = new TDate('DATA_OCORRENCIA');
  29. $HORA_INI = new TEntry('HORA_INI');
  30. $HORA_FIM = new TEntry('HORA_FIM');
  31. $CHUVA_MM = new TEntry('CHUVA_MM');
  32. $ARQUIVOS_PATH = new TMultiFile('ARQUIVOS_PATH');
  33. // definição de mascaras
  34. $DATA_OCORRENCIA->setmask('dd/mm/yyyy');
  35. $DATA_OCORRENCIA->setdatabasemask('yyyy-mm-dd');
  36. /* setmask('hh:ii')
  37. setnumericmask(2,',','.',true)
  38. */
  39. $HORA_INI->setmask('00:00');
  40. $HORA_FIM->setmask('00:00');
  41. // adicionar itens numa Tcombo
  42. //$campo->addItems(['M'=>'Masculino','F'=>'Feminino']);
  43. $ARQUIVOS_PATH->enablefilehandling();
  44. $ARQUIVOS_PATH->setallowedextensions(['png','jpg','pdf','doc']);
  45. // add the fields
  46. $this->form->addFields( [ new TLabel('Id:') ], [ $ID_OCORRENCIA ] );
  47. $this->form->addFields( [ new TLabel('Navio:') ], [ $id_navio_pk ] );
  48. $this->form->addFields( [ new TLabel('Turno:') ], [ $id_turno_pk ] );
  49. $this->form->addFields( [ new TLabel('Tipo Ocorrência:') ], [ $id_tp_ocorrencia ] );
  50. $this->form->addFields( [ new TLabel('Cliente:') ], [ $id_cliente_pk ] );
  51. $this->form->addFields( [ new TLabel('Descrição:') ], [ $DESCRICAO ] );
  52. $this->form->addFields( [ new TLabel('Ação Imediata:') ], [ $ACAO_IMEDIATA ] );
  53. $this->form->addFields( [ new TLabel('Data Ocorrência:') ], [ $DATA_OCORRENCIA ] );
  54. $this->form->addFields( [ new TLabel('Hora Ini:') ], [ $HORA_INI ] );
  55. $this->form->addFields( [ new TLabel('Hora Fim:') ], [ $HORA_FIM ] );
  56. $this->form->addFields( [ new TLabel('Chuva MM') ], [ $CHUVA_MM ] );
  57. $this->form->addFields( [ new TLabel('Upload Evidências:') ], [ $ARQUIVOS_PATH ] );
  58. $id_navio_pk->addValidation('Id Navio Pk', new TRequiredValidator);
  59. $id_turno_pk->addValidation('Id Turno Pk', new TRequiredValidator);
  60. $id_tp_ocorrencia->addValidation('Id Tp Ocorrencia', new TRequiredValidator);
  61. $id_cliente_pk->addValidation('Id Cliente Pk', new TRequiredValidator);
  62. $DESCRICAO->addValidation('Descricao', new TRequiredValidator);
  63. $DATA_OCORRENCIA->addValidation('Data Ocorrencia', new TRequiredValidator);
  64. // set sizes
  65. $ID_OCORRENCIA->setSize('10%');
  66. $id_navio_pk->setSize('50%');
  67. $id_turno_pk->setSize('50%');
  68. $id_tp_ocorrencia->setSize('50%');
  69. $id_cliente_pk->setSize('50%');
  70. $DESCRICAO->setSize('70%');
  71. $ACAO_IMEDIATA->setSize('70%');
  72. $DATA_OCORRENCIA->setSize('15%');
  73. $HORA_INI->setSize('10%');
  74. $HORA_FIM->setSize('10%');
  75. $CHUVA_MM->setSize('10%');
  76. $ARQUIVOS_PATH->setSize('100%');
  77. if (!empty($ID_OCORRENCIA))
  78. {
  79. $ID_OCORRENCIA->setEditable(FALSE);
  80. }
  81. /** samples
  82. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  83. $fieldX->setSize( '100%' ); // set size
  84. **/
  85. // create the form actions
  86. $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:save');
  87. $btn->class = 'btn btn-sm btn-primary';
  88. $this->form->addActionLink(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
  89. // vertical box container
  90. $container = new TVBox;
  91. $container->style = 'width: 100%';
  92. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  93. $container->add($this->form);
  94. parent::add($container);
  95. }
  96. /**
  97. * Save form data
  98. * @param $param Request
  99. */
  100. public function onSave( $param )
  101. {
  102. try
  103. {
  104. TTransaction::open('datasiop'); // open a transaction
  105. /**
  106. // Enable Debug logger for SQL operations inside the transaction
  107. TTransaction::setLogger(new TLoggerSTD); // standard output
  108. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  109. **/
  110. $this->form->validate(); // validate form data
  111. $data = $this->form->getData(); // get form data as array
  112. $object = new ocorrencia; // create an empty object
  113. $object->fromArray( (array) $data); // load the object with data
  114. $object->store(); // save the object
  115. $this->saveFiles($object,$data,'ARQUIVOS_PATH','files/uploads','ocorrencia','ARQUIVOS_PATH','ID_OCORRENCIA');
  116. // get the generated ID_OCORRENCIA
  117. $data->ID_OCORRENCIA = $object->ID_OCORRENCIA;
  118. $this->form->setData($data); // fill form data
  119. TTransaction::close(); // close the transaction
  120. new TMessage('info', AdiantiCoreTranslator::translate('Record saved'));
  121. }
  122. catch (Exception $e) // in case of exception
  123. {
  124. new TMessage('error', $e->getMessage()); // shows the exception error message
  125. $this->form->setData( $this->form->getData() ); // keep form data
  126. TTransaction::rollback(); // undo all pending operations
  127. }
  128. }
  129. /**
  130. * Clear form data
  131. * @param $param Request
  132. */
  133. public function onClear( $param )
  134. {
  135. $this->form->clear(TRUE);
  136. }
  137. /**
  138. * Load object to form data
  139. * @param $param Request
  140. */
  141. public function onEdit( $param )
  142. {
  143. try
  144. {
  145. if (isset($param['key']))
  146. {
  147. $key = $param['key']; // get the parameter $key
  148. TTransaction::open('datasiop'); // open a transaction
  149. $object = new ocorrencia($key); // instantiates the Active Record
  150. //$object->ARQUIVOS_PATH = ProductImage::where('ID_OCORRENCIA', '=', $param['key'])->getIndexedArray('image');
  151. $this->form->setData($object); // fill the form
  152. TTransaction::close(); // close the transaction
  153. }
  154. else
  155. {
  156. $this->form->clear(TRUE);
  157. }
  158. }
  159. catch (Exception $e) // in case of exception
  160. {
  161. new TMessage('error', $e->getMessage()); // shows the exception error message
  162. TTransaction::rollback(); // undo all pending operations
  163. }
  164. }
  165. }

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


CD

Na verdade eu escolho dois arquivos de imagem, daí ele salva o caminho somente de 1 arquivo no banco