Commit 25a35889b6a49ea41bc37b6928e6d017c018b5ff
1 parent
faf8170b
Exists in
master
and in
2 other branches
bugfix/improve EXPORT CSV
Showing
1 changed file
with
61 additions
and
7 deletions
Show diff stats
src/Controller/MaterielsController.php
... | ... | @@ -2234,6 +2234,8 @@ class MaterielsController extends AppController |
2234 | 2234 | } |
2235 | 2235 | } |
2236 | 2236 | |
2237 | + | |
2238 | + | |
2237 | 2239 | /** |
2238 | 2240 | * Export method |
2239 | 2241 | * Generation d'un fichier .csv comportant la date du jour |
... | ... | @@ -2247,6 +2249,12 @@ class MaterielsController extends AppController |
2247 | 2249 | */ |
2248 | 2250 | public function export() |
2249 | 2251 | { |
2252 | + | |
2253 | + function getElementFromList($listName, $materiel, $fkName) { | |
2254 | + $ISOK = ( !is_null($materiel->$fkName) && !is_null($listName[$materiel->$fkName]) ); | |
2255 | + return $ISOK ? $listName[$materiel->$fkName] : ""; | |
2256 | + } | |
2257 | + | |
2250 | 2258 | $materiels = NULL; |
2251 | 2259 | $surCategories = $this->Materiels->SurCategories->find('list', [ |
2252 | 2260 | 'keyField' => 'id', |
... | ... | @@ -2439,33 +2447,63 @@ class MaterielsController extends AppController |
2439 | 2447 | $result->designation |
2440 | 2448 | ]; |
2441 | 2449 | |
2450 | + array_push($row, getElementFromList($surCategories, $result, 'sur_categorie_id')); | |
2451 | + /* | |
2452 | + $fkName = 'sur_categorie_id'; | |
2453 | + $listName = $surCategories; | |
2454 | + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); | |
2455 | + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); | |
2456 | + */ | |
2457 | + /* | |
2442 | 2458 | if ($surCategories[$result->sur_categorie_id] !== null) { |
2443 | 2459 | array_push($row, $surCategories[$result->sur_categorie_id]); |
2444 | 2460 | } else { |
2445 | 2461 | array_push($row, ""); |
2446 | 2462 | } |
2463 | + */ | |
2447 | 2464 | |
2465 | + array_push($row, getElementFromList($categories, $result, 'categorie_id')); | |
2466 | + /* | |
2467 | + $fkName = 'categorie_id'; | |
2468 | + $listName = $categories; | |
2469 | + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); | |
2470 | + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); | |
2448 | 2471 | //if ($categories[$result->categorie_id] !== null) { |
2449 | 2472 | if ($result->categorie_id !== null && $categories[$result->categorie_id] !== null) { |
2450 | 2473 | array_push($row, $categories[$result->categorie_id]); |
2451 | 2474 | } else { |
2452 | 2475 | array_push($row, ""); |
2453 | 2476 | } |
2454 | - | |
2477 | + */ | |
2478 | + | |
2479 | + array_push($row, getElementFromList($sousCategories, $result, 'sous_categorie_id')); | |
2480 | + /* | |
2481 | + $fkName = 'sous_categorie_id'; | |
2482 | + $listName = $sousCategories; | |
2483 | + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); | |
2484 | + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); | |
2455 | 2485 | if ($result->sous_categorie_id !== null && $sousCategories[$result->sous_categorie_id] !== null) { |
2456 | 2486 | array_push($row, $sousCategories[$result->sous_categorie_id]); |
2457 | 2487 | } else { |
2458 | 2488 | array_push($row, ""); |
2459 | 2489 | } |
2490 | + */ | |
2460 | 2491 | |
2461 | 2492 | array_push($row, $result->numero_laboratoire); |
2462 | 2493 | array_push($row, $result->description); |
2463 | - | |
2494 | + | |
2495 | + array_push($row, getElementFromList($organismes, $result, 'organisme_id')); | |
2496 | + /* | |
2497 | + $fkName = 'organisme_id'; | |
2498 | + $listName = $organismes; | |
2499 | + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); | |
2500 | + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); | |
2464 | 2501 | if ( !is_null($result->organisme_id) && !is_null($organismes[$result->organisme_id] ) ) { |
2465 | 2502 | array_push($row, $organismes[$result->organisme_id]); |
2466 | 2503 | } else { |
2467 | 2504 | array_push($row, ""); |
2468 | 2505 | } |
2506 | + */ | |
2469 | 2507 | |
2470 | 2508 | array_push($row, $result->materiel_administratif); |
2471 | 2509 | array_push($row, $result->materiel_technique); |
... | ... | @@ -2480,26 +2518,42 @@ class MaterielsController extends AppController |
2480 | 2518 | array_push($row, $result->code_comptable); |
2481 | 2519 | array_push($row, $result->numero_serie); |
2482 | 2520 | |
2483 | - if ($groupesThematiques[$result->groupes_thematique_id] !== null) { | |
2484 | - array_push($row, $groupesThematiques[$result->groupes_thematique_id]); | |
2485 | - } else { | |
2486 | - array_push($row, ""); | |
2487 | - } | |
2521 | + array_push($row, getElementFromList($groupesThematiques, $result, 'groupes_thematique_id')); | |
2522 | + /* | |
2523 | + $fkName = 'groupes_thematique_id'; | |
2524 | + $listName = $groupesThematiques; | |
2525 | + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); | |
2526 | + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); | |
2527 | + */ | |
2488 | 2528 | |
2529 | + array_push($row, getElementFromList($groupesMetiers, $result, 'groupes_metier_id')); | |
2530 | + /* | |
2531 | + $fkName = 'groupes_metier_id'; | |
2532 | + $listName = $groupesMetiers; | |
2533 | + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); | |
2534 | + array_push($row, $ISOK ? $listName[$result->$fkName] : ""); | |
2489 | 2535 | if ($groupesMetiers[$result->groupes_metier_id] !== null) { |
2490 | 2536 | array_push($row, $groupesMetiers[$result->groupes_metier_id]); |
2491 | 2537 | } else { |
2492 | 2538 | array_push($row, ""); |
2493 | 2539 | } |
2540 | + */ | |
2494 | 2541 | |
2495 | 2542 | array_push($row, $result->numero_inventaire_organisme); |
2496 | 2543 | array_push($row, $result->numero_inventaire_old); |
2497 | 2544 | |
2545 | + array_push($row, getElementFromList($sites, $result, 'site_id')); | |
2546 | + /* | |
2547 | + $fkName = 'site_id'; | |
2548 | + $listName = $sites; | |
2549 | + $ISOK = ( !is_null($result->$fkName) && !is_null($listName[$result->$fkName]) ); | |
2550 | + array_push($row, $ISOK ? $listName[$result->$fkName] . '-' . $result->lieu_detail : ""); | |
2498 | 2551 | if ($sites[$result->site_id] !== null) { |
2499 | 2552 | array_push($row, $sites[$result->site_id] . '-' . $result->lieu_detail); |
2500 | 2553 | } else { |
2501 | 2554 | array_push($row, ""); |
2502 | 2555 | } |
2556 | + */ | |
2503 | 2557 | |
2504 | 2558 | array_push($row, $result->nom_responsable); |
2505 | 2559 | array_push($row, $result->email_responsable); | ... | ... |