diff --git a/module/Application/src/Application/Controller/ExportController.php b/module/Application/src/Application/Controller/ExportController.php index c8d2f5122fa68e8146b077443e36fb4fc003d499..8396fc5e8d758b1d70e19eec9ddccb16116cb208 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 132ee4d5e4bef8343ae04a23bd9d9412dfab6572..bda4ef5b36221836672cc64a4bde96aadf93fa79 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 */