From 4c1ac3e517fc8da8c9101f6e644c53e0210c2ee8 Mon Sep 17 00:00:00 2001
From: Bertrand Gauthier <bertrand.gauthier@unicaen.fr>
Date: Fri, 14 Feb 2020 13:51:30 +0100
Subject: [PATCH] =?UTF-8?q?Extraction=20CSV=20:=20virgule=20plut=C3=B4t=20?=
 =?UTF-8?q?que=20point=20dans=20la=20dur=C3=A9e=20de=20la=20th=C3=A8se.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Controller/ExportController.php            |  6 ++----
 .../src/Application/Entity/Db/These.php        | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/module/Application/src/Application/Controller/ExportController.php b/module/Application/src/Application/Controller/ExportController.php
index c8d2f5122..8396fc5e8 100644
--- a/module/Application/src/Application/Controller/ExportController.php
+++ b/module/Application/src/Application/Controller/ExportController.php
@@ -11,6 +11,7 @@ use Application\Service\FichierThese\FichierTheseServiceAwareTrait;
 use Application\Service\These\TheseRechercheServiceAwareTrait;
 use Application\Service\These\TheseServiceAwareTrait;
 use Application\SourceCodeStringHelperAwareTrait;
+use UnicaenApp\Exception\LogicException;
 use UnicaenApp\View\Model\CsvModel;
 
 class ExportController extends AbstractController
@@ -92,10 +93,7 @@ class ExportController extends AbstractController
             'Date de fin de confientialité'         => function (These $these) { return $these->getDateFinConfidentialite(); },
             'Date de dépôt version initiale'        => function (These $these) { $file = $these->hasVersionInitiale(); if ($file) return $file->getFichier()->getHistoCreation()->format('d/m/Y'); return "";},
             'Date de dépôt version corigée'         => function (These $these) { $file = $these->hasVersionCorrigee(); if ($file) return $file->getFichier()->getHistoCreation()->format('d/m/Y'); return "";},
-            'Durée en mois de la thèse'             => function (These $these) { if ($these->getDatePremiereInscription() !== null AND $these->getDateSoutenance() !== null)
-                return number_format(($these->getDateSoutenance())->diff($these->getDatePremiereInscription())->format('%a')/30.5, 2);
-            else return "";
-            },
+            'Durée en mois de la thèse'             => function (These $these) { try { return number_format($these->getDureeThese(), 2, ',', ''); } catch (LogicException $e) { return ""; } },
 
             //Flags
             'Etat de la thèse'                      => function (These $these) { return $these->getEtatTheseToString();},
diff --git a/module/Application/src/Application/Entity/Db/These.php b/module/Application/src/Application/Entity/Db/These.php
index 132ee4d5e..bda4ef5b3 100644
--- a/module/Application/src/Application/Entity/Db/These.php
+++ b/module/Application/src/Application/Entity/Db/These.php
@@ -9,6 +9,7 @@ use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\Common\Collections\Collection;
 use UnicaenApp\Entity\HistoriqueAwareInterface;
 use UnicaenApp\Entity\HistoriqueAwareTrait;
+use UnicaenApp\Exception\LogicException;
 use UnicaenApp\Exception\RuntimeException;
 use UnicaenApp\Util;
 use UnicaenImport\Entity\Db\Traits\SourceAwareTrait;
@@ -1193,6 +1194,23 @@ class These implements HistoriqueAwareInterface, ResourceInterface
         return $this->datePremiereInscription;
     }
 
+    /**
+     * Calcule la durée de la thèse en mois.
+     *
+     * @return float
+     */
+    public function getDureeThese()
+    {
+        if (! $this->getDateSoutenance()) {
+            throw new LogicException("Aucune date de soutenance renseignée");
+        }
+        if (! $this->getDatePremiereInscription()) {
+            throw new LogicException("Aucune date de première inscription renseignée");
+        }
+
+        return $this->getDateSoutenance()->diff($this->getDatePremiereInscription())->format('%a') / 30.5;
+    }
+
     /**
      * @return string
      */
-- 
GitLab