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.
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.
- <?php
- /**
- * ocorrenciaForm Form
- * @author <your name here>
- */
- class ocorrenciaForm extends TPage
- {
- protected $form; // form
- /**
- * Form constructor
- * @param $param Request
- */
- use Adianti\base\AdiantiFileSaveTrait;
- public function __construct( $param )
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_ocorrencia');
- $this->form->setFormTitle('Cadastro de Ocorrências');
- // create the form fields
- $ID_OCORRENCIA = new TEntry('ID_OCORRENCIA');
- $id_navio_pk = new TDBCombo('id_navio_pk', 'datasiop', 'Navio', 'ID_NAVIO', 'NOME');
- $id_turno_pk = new TDBCombo('id_turno_pk', 'datasiop', 'Turno', 'ID_TURNO', 'DESCRICAO');
- $id_tp_ocorrencia = new TDBCombo('id_tp_ocorrencia', 'datasiop', 'tipo_ocorrencia', 'ID_TIPO_OCORRENCIA', 'DESCRICAO');
- $id_cliente_pk = new TDBCombo('id_cliente_pk', 'datasiop', 'cliente', 'ID_CLIENTE', 'NOME');
- $DESCRICAO = new TText('DESCRICAO');
- $ACAO_IMEDIATA = new TText('ACAO_IMEDIATA');
- $DATA_OCORRENCIA = new TDate('DATA_OCORRENCIA');
- $HORA_INI = new TEntry('HORA_INI');
- $HORA_FIM = new TEntry('HORA_FIM');
- $CHUVA_MM = new TEntry('CHUVA_MM');
- $ARQUIVOS_PATH = new TMultiFile('ARQUIVOS_PATH');
- // definição de mascaras
- $DATA_OCORRENCIA->setmask('dd/mm/yyyy');
- $DATA_OCORRENCIA->setdatabasemask('yyyy-mm-dd');
- /* setmask('hh:ii')
- setnumericmask(2,',','.',true)
- */
- $HORA_INI->setmask('00:00');
- $HORA_FIM->setmask('00:00');
- // adicionar itens numa Tcombo
- //$campo->addItems(['M'=>'Masculino','F'=>'Feminino']);
- $ARQUIVOS_PATH->enablefilehandling();
- $ARQUIVOS_PATH->setallowedextensions(['png','jpg','pdf','doc']);
- // add the fields
- $this->form->addFields( [ new TLabel('Id:') ], [ $ID_OCORRENCIA ] );
- $this->form->addFields( [ new TLabel('Navio:') ], [ $id_navio_pk ] );
- $this->form->addFields( [ new TLabel('Turno:') ], [ $id_turno_pk ] );
- $this->form->addFields( [ new TLabel('Tipo Ocorrência:') ], [ $id_tp_ocorrencia ] );
- $this->form->addFields( [ new TLabel('Cliente:') ], [ $id_cliente_pk ] );
- $this->form->addFields( [ new TLabel('Descrição:') ], [ $DESCRICAO ] );
- $this->form->addFields( [ new TLabel('Ação Imediata:') ], [ $ACAO_IMEDIATA ] );
- $this->form->addFields( [ new TLabel('Data Ocorrência:') ], [ $DATA_OCORRENCIA ] );
- $this->form->addFields( [ new TLabel('Hora Ini:') ], [ $HORA_INI ] );
- $this->form->addFields( [ new TLabel('Hora Fim:') ], [ $HORA_FIM ] );
- $this->form->addFields( [ new TLabel('Chuva MM') ], [ $CHUVA_MM ] );
- $this->form->addFields( [ new TLabel('Upload Evidências:') ], [ $ARQUIVOS_PATH ] );
- $id_navio_pk->addValidation('Id Navio Pk', new TRequiredValidator);
- $id_turno_pk->addValidation('Id Turno Pk', new TRequiredValidator);
- $id_tp_ocorrencia->addValidation('Id Tp Ocorrencia', new TRequiredValidator);
- $id_cliente_pk->addValidation('Id Cliente Pk', new TRequiredValidator);
- $DESCRICAO->addValidation('Descricao', new TRequiredValidator);
- $DATA_OCORRENCIA->addValidation('Data Ocorrencia', new TRequiredValidator);
- // set sizes
- $ID_OCORRENCIA->setSize('10%');
- $id_navio_pk->setSize('50%');
- $id_turno_pk->setSize('50%');
- $id_tp_ocorrencia->setSize('50%');
- $id_cliente_pk->setSize('50%');
- $DESCRICAO->setSize('70%');
- $ACAO_IMEDIATA->setSize('70%');
- $DATA_OCORRENCIA->setSize('15%');
- $HORA_INI->setSize('10%');
- $HORA_FIM->setSize('10%');
- $CHUVA_MM->setSize('10%');
- $ARQUIVOS_PATH->setSize('100%');
- if (!empty($ID_OCORRENCIA))
- {
- $ID_OCORRENCIA->setEditable(FALSE);
- }
- /** samples
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( '100%' ); // set size
- **/
- // create the form actions
- $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:save');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addActionLink(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 100%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- /**
- * Save form data
- * @param $param Request
- */
- public function onSave( $param )
- {
- try
- {
- TTransaction::open('datasiop'); // open a transaction
- /**
- // Enable Debug logger for SQL operations inside the transaction
- TTransaction::setLogger(new TLoggerSTD); // standard output
- TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
- **/
- $this->form->validate(); // validate form data
- $data = $this->form->getData(); // get form data as array
- $object = new ocorrencia; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- $this->saveFiles($object,$data,'ARQUIVOS_PATH','files/uploads','ocorrencia','ARQUIVOS_PATH','ID_OCORRENCIA');
- // get the generated ID_OCORRENCIA
- $data->ID_OCORRENCIA = $object->ID_OCORRENCIA;
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
- new TMessage('info', AdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear(TRUE);
- }
- /**
- * Load object to form data
- * @param $param Request
- */
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('datasiop'); // open a transaction
- $object = new ocorrencia($key); // instantiates the Active Record
- //$object->ARQUIVOS_PATH = ProductImage::where('ID_OCORRENCIA', '=', $param['key'])->getIndexedArray('image');
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear(TRUE);
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
Na verdade eu escolho dois arquivos de imagem, daí ele salva o caminho somente de 1 arquivo no banco