From 04b960b0123342ebfd5bda0470f5204ef5c42f42 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 24 Jul 2020 18:16:35 +0200 Subject: [PATCH] Aggiunta salvataggio firma in formato PNG --- src/API/App/v1/Interventi.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/API/App/v1/Interventi.php b/src/API/App/v1/Interventi.php index 36ac34a04..470ec185e 100644 --- a/src/API/App/v1/Interventi.php +++ b/src/API/App/v1/Interventi.php @@ -3,16 +3,15 @@ namespace API\App\v1; use API\App\AppResource; -use API\Interfaces\CreateInterface; -use API\Interfaces\UpdateInterface; use Auth; use Carbon\Carbon; +use Intervention\Image\ImageManagerStatic; use Modules\Anagrafiche\Anagrafica; use Modules\Interventi\Intervento; use Modules\Interventi\Stato; use Modules\TipiIntervento\Tipo as TipoSessione; -class Interventi extends AppResource implements CreateInterface, UpdateInterface +class Interventi extends AppResource { protected function getCleanupData() { @@ -143,6 +142,16 @@ class Interventi extends AppResource implements CreateInterface, UpdateInterface $record->descrizione = $data['descrizione']; $record->informazioniaggiuntive = $data['informazioni_aggiuntive']; + // Salvataggio firma eventuale + if (empty($record->firma_nome) && !empty($data['firma_nome'])) { + $record->firma_nome = $data['firma_nome']; + $record->firma_data = $data['firma_data']; + + // Salvataggio fisico + $firma_file = $this->salvaFirma($data['firma_contenuto']); + $record->firma_file = $firma_file; + } + // Aggiornamento impianti collegati $database->query('DELETE FROM my_impianti_interventi WHERE idintervento = '.prepare($record->id)); foreach ($data['impianti'] as $id_impianto) { @@ -152,4 +161,21 @@ class Interventi extends AppResource implements CreateInterface, UpdateInterface ]); } } + + protected function salvaFirma($firma_base64) + { + // Salvataggio firma + $firma_file = 'firma_'.time().'.png'; + + $data = explode(',', $firma_base64); + + $img = ImageManagerStatic::make(base64_decode($data[1])); + $img->resize(680, 202, function ($constraint) { + $constraint->aspectRatio(); + }); + + $img->save(DOCROOT.'/files/interventi/'.$firma_file); + + return $firma_file; + } }