From 25a35889b6a49ea41bc37b6928e6d017c018b5ff Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Wed, 5 Jun 2019 13:20:47 +0200 Subject: [PATCH] bugfix/improve EXPORT CSV --- src/Controller/MaterielsController.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/src/Controller/MaterielsController.php b/src/Controller/MaterielsController.php index c1121a7..67c8732 100755 --- a/src/Controller/MaterielsController.php +++ b/src/Controller/MaterielsController.php @@ -2234,6 +2234,8 @@ class MaterielsController extends AppController } } + + /** * Export method * Generation d'un fichier .csv comportant la date du jour @@ -2247,6 +2249,12 @@ class MaterielsController extends AppController */ public function export() { + + function getElementFromList($listName, $materiel, $fkName) { + $ISOK = ( !is_null($materiel->$fkName) && !is_null($listName[$materiel->$fkName]) ); + return $ISOK ? $listName[$materiel->$fkName] : ""; + } + $materiels = NULL; $surCategories = $this->Materiels->SurCategories->find('list', [ 'keyField' => 'id', @@ -2439,33 +2447,63 @@ class MaterielsController extends AppController $result->designation ]; + array_push($row, getElementFromList($surCategories, $result, 'sur_categorie_id')); + /* + $fkName = 'sur_categorie_id'; + $listName = $surCategories; + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); + */ + /* if ($surCategories[$result->sur_categorie_id] !== null) { array_push($row, $surCategories[$result->sur_categorie_id]); } else { array_push($row, ""); } + */ + array_push($row, getElementFromList($categories, $result, 'categorie_id')); + /* + $fkName = 'categorie_id'; + $listName = $categories; + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); //if ($categories[$result->categorie_id] !== null) { if ($result->categorie_id !== null && $categories[$result->categorie_id] !== null) { array_push($row, $categories[$result->categorie_id]); } else { array_push($row, ""); } - + */ + + array_push($row, getElementFromList($sousCategories, $result, 'sous_categorie_id')); + /* + $fkName = 'sous_categorie_id'; + $listName = $sousCategories; + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); if ($result->sous_categorie_id !== null && $sousCategories[$result->sous_categorie_id] !== null) { array_push($row, $sousCategories[$result->sous_categorie_id]); } else { array_push($row, ""); } + */ array_push($row, $result->numero_laboratoire); array_push($row, $result->description); - + + array_push($row, getElementFromList($organismes, $result, 'organisme_id')); + /* + $fkName = 'organisme_id'; + $listName = $organismes; + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); if ( !is_null($result->organisme_id) && !is_null($organismes[$result->organisme_id] ) ) { array_push($row, $organismes[$result->organisme_id]); } else { array_push($row, ""); } + */ array_push($row, $result->materiel_administratif); array_push($row, $result->materiel_technique); @@ -2480,26 +2518,42 @@ class MaterielsController extends AppController array_push($row, $result->code_comptable); array_push($row, $result->numero_serie); - if ($groupesThematiques[$result->groupes_thematique_id] !== null) { - array_push($row, $groupesThematiques[$result->groupes_thematique_id]); - } else { - array_push($row, ""); - } + array_push($row, getElementFromList($groupesThematiques, $result, 'groupes_thematique_id')); + /* + $fkName = 'groupes_thematique_id'; + $listName = $groupesThematiques; + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); + */ + array_push($row, getElementFromList($groupesMetiers, $result, 'groupes_metier_id')); + /* + $fkName = 'groupes_metier_id'; + $listName = $groupesMetiers; + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); if ($groupesMetiers[$result->groupes_metier_id] !== null) { array_push($row, $groupesMetiers[$result->groupes_metier_id]); } else { array_push($row, ""); } + */ array_push($row, $result->numero_inventaire_organisme); array_push($row, $result->numero_inventaire_old); + array_push($row, getElementFromList($sites, $result, 'site_id')); + /* + $fkName = 'site_id'; + $listName = $sites; + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); + array_push($row, $ISOK ? $listName[$result->$fkName] . '-' . $result->lieu_detail : ""); if ($sites[$result->site_id] !== null) { array_push($row, $sites[$result->site_id] . '-' . $result->lieu_detail); } else { array_push($row, ""); } + */ array_push($row, $result->nom_responsable); array_push($row, $result->email_responsable); -- libgit2 0.21.2