finish export thanato statistique filename

This commit is contained in:
Tiavina 2024-12-29 19:18:25 +03:00
parent 881546f4bf
commit 7b24241278
3 changed files with 35 additions and 4 deletions

View File

@ -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);

View File

@ -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());

View File

@ -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'.';'.