From 128e4078b930e804b422ac9232d2eca3c9c4d5ad Mon Sep 17 00:00:00 2001 From: Tiavina Date: Tue, 21 Jan 2025 16:13:26 +0300 Subject: [PATCH] default value to escape null reference value on the generate pdf --- .../Certificate/CertificateService.php | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/gestion/lib/Service/Certificate/CertificateService.php b/gestion/lib/Service/Certificate/CertificateService.php index 3917121..4ccf921 100644 --- a/gestion/lib/Service/Certificate/CertificateService.php +++ b/gestion/lib/Service/Certificate/CertificateService.php @@ -85,6 +85,40 @@ class CertificateService { return base64_encode($file->getContent()); } + private function setDevisOfDefuntDefaultValue($devisOfDefunt){ + $devisOfDefunt["devis_date"] = new DateTimeImmutable($devisOfDefunt["devis_date"]); + $locationOfDevis = ""; + if($devisOfDefunt['lieu_nom'] != null){ + $locationOfDevis .= $devisOfDefunt['lieu_nom']; + } + if($devisOfDefunt['lieu_adresse'] != null){ + $locationOfDevis .= " ". $devisOfDefunt['lieu_adresse']; + } + $devisOfDefunt['location_of_devis'] = $locationOfDevis; + if($devisOfDefunt['thanato_nom'] == null){ + $devisOfDefunt['thanato_nom'] = ""; + } + if($devisOfDefunt['thanato_prenom'] == null){ + $devisOfDefunt['thanato_prenom'] = ""; + } + if($devisOfDefunt['thanato_reference'] == null){ + $devisOfDefunt['thanato_reference'] = ""; + } + if($devisOfDefunt['client_nom'] == null){ + $devisOfDefunt['client_nom'] = ""; + } + if($devisOfDefunt['client_prenom'] == null){ + $devisOfDefunt['client_prenom'] = ""; + } + if($devisOfDefunt['client_entreprise'] == null){ + $devisOfDefunt['client_entreprise'] = ""; + } + if($devisOfDefunt['client_adresse'] == null){ + $devisOfDefunt['client_adresse'] = ""; + } + return $devisOfDefunt; + } + public function generateCareCertificate($defuntId,$idNextCloud){ $storage = $this->rootFolder->getUserFolder($idNextCloud); $configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN)); @@ -95,17 +129,7 @@ class CertificateService { return null; } $devisOfDefunt["configuration"] = $currentConfig; - $devisOfDefunt["thanato_date_habilitation"] = new DateTimeImmutable($devisOfDefunt["thanato_date_habilitation"]); - $devisOfDefunt["devis_date"] = new DateTimeImmutable($devisOfDefunt["devis_date"]); - $locationOfDevis = ""; - if($devisOfDefunt['lieu_nom'] != null){ - $locationOfDevis .= $devisOfDefunt['lieu_nom']; - } - if($devisOfDefunt['lieu_adresse'] != null){ - $locationOfDevis .= " ". $devisOfDefunt['lieu_adresse']; - } - $devisOfDefunt['location_of_devis'] = $locationOfDevis; - + $devisOfDefunt = $this->setDevisOfDefuntDefaultValue($devisOfDefunt); $clean_folder = html_entity_decode(string: $currentConfig->path).'/'; $careCertificateFolder = $this->getCareCertificateFolder($devisOfDefunt); $folderDestination = $clean_folder.$careCertificateFolder; @@ -169,17 +193,7 @@ class CertificateService { return null; } $devisOfDefunt["configuration"] = $currentConfig; - $devisOfDefunt["thanato_date_habilitation"] = new DateTimeImmutable($devisOfDefunt["thanato_date_habilitation"]); - $devisOfDefunt["devis_date"] = new DateTimeImmutable($devisOfDefunt["devis_date"]); - $locationOfDevis = ""; - if($devisOfDefunt['lieu_nom'] != null){ - $locationOfDevis .= $devisOfDefunt['lieu_nom']; - } - if($devisOfDefunt['lieu_adresse'] != null){ - $locationOfDevis .= " ". $devisOfDefunt['lieu_adresse']; - } - $devisOfDefunt['location_of_devis'] = $locationOfDevis; - + $devisOfDefunt = $this->setDevisOfDefuntDefaultValue($devisOfDefunt); $clean_folder = html_entity_decode(string: $currentConfig->path).'/'; $pacemakerCertificateFolder = $this->getPacemakerCertificateFolder($devisOfDefunt); $folderDestination = $clean_folder.$pacemakerCertificateFolder;