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

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