From 7b2424127836cd6a3879015fbc4419a031e79cdb Mon Sep 17 00:00:00 2001 From: Tiavina Date: Sun, 29 Dec 2024 19:18:25 +0300 Subject: [PATCH] finish export thanato statistique filename --- gestion/lib/Controller/PageController.php | 7 +++---- gestion/lib/Db/Bdd.php | 20 +++++++++++++++++++ .../Service/ExportThanatoStatisticService.php | 12 +++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index da648a1..946ca0b 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -2559,7 +2559,7 @@ class PageController extends Controller { try{ $current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud)); $clean_folder = html_entity_decode($current_config[0]->path).'/'; - $_clean_folder = $clean_folder.'STATISTIQUES/'; + $_clean_folder = $clean_folder.'STATISTIQUES/THANATOS/'; try { $this->storage->newFolder($_clean_folder); } @@ -2568,9 +2568,8 @@ class PageController extends Controller { } $fileHeader = $this->exportThanatoStatisticService->getExportThanatoFileHeader(); $fileContent = $this->exportThanatoStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader); - $thanatoIdsString = implode('-', $thanatoIdsToExport); - $uuid = Uuid::uuid4()->toString(); - $fileNamePath = $_clean_folder."STAT-ThanatoIds-" . $thanatoIdsString . '-' . $uuid . '.csv'; + $filename = $this->exportThanatoStatisticService->getFilename($thanatoIdsToExport); + $fileNamePath = $_clean_folder."STAT-THANATOS-" . $filename . '.csv'; $this->storage->newFile($fileNamePath); $file = $this->storage->get($fileNamePath); $file->putContent($fileContent); diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index a20a230..ab30d13 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -86,6 +86,26 @@ class Bdd { return $this->execSQL($sql, array()); } + public function getThanatoByIds(array $thanatoIds){ + if(empty($thanatoIds)){ + return []; + } + + $sqlConditionsPlaceholder = implode(',', array_fill(0, count($thanatoIds), '?')); + + $sql = "SELECT + thanato.id, + thanato.nom as thanato_nom, + thanato.prenom as thanato_prenom + FROM ".$this->tableprefix."thanato as thanato + WHERE thanato.id IN ($sqlConditionsPlaceholder)"; + $thanatoList = $this->execSQLNoJsonReturn( + $sql, + $thanatoIds); + + return $thanatoList; + } + public function getBibliotheques($idNextcloud) { $sql = "SELECT * FROM ".$this->tableprefix."bibliotheque;"; return $this->execSQL($sql, array()); diff --git a/gestion/lib/Service/ExportThanatoStatisticService.php b/gestion/lib/Service/ExportThanatoStatisticService.php index b3f6b67..3459197 100644 --- a/gestion/lib/Service/ExportThanatoStatisticService.php +++ b/gestion/lib/Service/ExportThanatoStatisticService.php @@ -43,6 +43,18 @@ class ExportThanatoStatisticService { $this->gestionBdd = $gestionBdd; } + public function getFilename(array $thanatoIds){ + $thanatoList = $this->gestionBdd->getThanatoByIds($thanatoIds); + $currentYear = date('Y'); + $currentMonth = date('m'); + $filename = "$currentYear-$currentMonth-"; + foreach($thanatoList as $thanato){ + $filename .= $thanato['thanato_nom'] . '-' . $thanato['thanato_prenom'] . '--'; + } + $filename = rtrim($filename, '-'); + return $filename; + } + public function getExportThanatoFileHeader(): string{ $fileHeader = 'Thanatopracteur'.';'.