Loading module/Application/src/Application/Controller/Rapport/RapportActiviteController.php +86 −11 Changes for module/Application/src/Application/Controller/Rapport/RapportActiviteController.php: 86 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Application\Controller\Rapport; use Application\Entity\AnneeUniv; use Application\Entity\Db\Rapport; use Application\Provider\Privilege\RapportPrivileges; Loading Loading @@ -33,10 +34,20 @@ class RapportActiviteController extends RapportController */ protected $rapportsTeleversesFintheses = []; /** * @var array [int => bool] */ protected $canTeleverserRapportAnnuel; /** * @var array [int => bool] */ protected $canTeleverserRapportFinthese; protected function loadRapportsTeleverses() protected function fetchRapportsTeleverses() { parent::loadRapportsTeleverses(); parent::fetchRapportsTeleverses(); $this->rapportsTeleversesAnnuels = array_filter($this->rapportsTeleverses, function(Rapport $rapport) { return $rapport->estFinal() === false; Loading @@ -44,31 +55,95 @@ class RapportActiviteController extends RapportController $this->rapportsTeleversesFintheses = array_filter($this->rapportsTeleverses, function(Rapport $rapport) { return $rapport->estFinal() === true; }); $this->canTeleverserRapportAnnuel = []; foreach ($this->anneesUnivs as $anneeUniv) { $this->canTeleverserRapportAnnuel[$anneeUniv->getPremiereAnnee()] = $this->canTeleverserRapportAnnuelForAnneeUniv($anneeUniv); } $this->canTeleverserRapportFinthese = []; foreach ($this->anneesUnivs as $anneeUniv) { $this->canTeleverserRapportFinthese[$anneeUniv->getPremiereAnnee()] = $this->canTeleverserRapportFintheseForAnneeUniv($anneeUniv); } } protected function isTeleversementPossible(): bool { return count(array_filter($this->canTeleverserRapportAnnuel)) > 0 || count(array_filter($this->canTeleverserRapportFinthese)) > 0; } protected function getAnneesPrises(): array { return array_keys( array_intersect_key( array_filter($this->canTeleverserRapportAnnuel, function(bool $can) { return $can === false; }), array_filter($this->canTeleverserRapportFinthese, function(bool $can) { return $can === false; }) ) ); } protected function canTeleverserRapport(Rapport $rapport): bool { if ($rapport->estFinal()) { return $this->canTeleverserRapportFintheseForAnneeUniv($rapport->getAnneeUniv()); } else { return $this->canTeleverserRapportAnnuelForAnneeUniv($rapport->getAnneeUniv()); } } protected function canTeleverserRapportAnnuel(): bool { // Peut être téléversé : 1 rapport annuel par année universitaire. $rapportsSurAnneeCourante = array_filter($this->rapportsTeleversesAnnuels, function(Rapport $rapport) { return $rapport->getAnneeUniv() === $this->anneeUnivCourante->getPremiereAnnee(); }); foreach ($this->anneesUnivs as $anneeUniv) { $rapportsTeleverses = array_filter( $this->rapportsTeleversesAnnuels, $this->rapportService->getFilterRapportsByAnneeUniv($anneeUniv) ); if (empty($rapportsTeleverses)) { return true; } } return count($rapportsSurAnneeCourante) === 0; return false; } protected function canTeleverserRapportAnnuelForAnneeUniv(AnneeUniv $anneeUniv): bool { // Peut être téléversé : 1 rapport annuel. $rapportsTeleverses = array_filter( $this->rapportsTeleversesAnnuels, $this->rapportService->getFilterRapportsByAnneeUniv($anneeUniv) ); return empty($rapportsTeleverses); } protected function canTeleverserRapportFinthese(): bool { // Peut être téléversé : 1 rapport de fin de thèse, toutes années univ confondues. // Dépôt d'1 rapport de fin de thèse maxi toutes années univ confondues. return count($this->rapportsTeleversesFintheses) === 0; } protected function isTeleversementPossible(): bool protected function canTeleverserRapportFintheseForAnneeUniv(AnneeUniv $anneeUniv): bool { return $this->canTeleverserRapportAnnuel() || $this->canTeleverserRapportFinthese(); // Dépôt d'un rapport de fin de thèse seulement sur la dernière année univ. if ($anneeUniv !== $this->getAnneeUnivMax()) { return false; } $rapportsTeleverses = array_filter( $this->rapportsTeleversesFintheses, $this->rapportService->getFilterRapportsByAnneeUniv($anneeUniv) ); return empty($rapportsTeleverses); } protected function initForm() Loading module/Application/src/Application/Controller/Rapport/RapportController.php +74 −14 Changes for module/Application/src/Application/Controller/Rapport/RapportController.php: 74 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Application\Controller\Rapport; use Application\Controller\AbstractController; use Application\Entity\AnneeUniv; use Application\Entity\Db\Interfaces\TypeRapportAwareTrait; use Application\Entity\Db\Interfaces\TypeValidationAwareTrait; use Application\Entity\Db\Rapport; Loading @@ -16,6 +17,7 @@ use Application\Service\Individu\IndividuServiceAwareTrait; use Application\Service\Notification\NotifierServiceAwareTrait; use Application\Service\Rapport\RapportServiceAwareTrait; use Application\Service\These\TheseServiceAwareTrait; use Application\Service\TheseAnneeUniv\TheseAnneeUnivService; use Application\Service\TheseAnneeUniv\TheseAnneeUnivServiceAwareTrait; use Application\Service\Validation\ValidationServiceAwareTrait; use Application\Service\VersionFichier\VersionFichierServiceAwareTrait; Loading Loading @@ -84,9 +86,24 @@ abstract class RapportController extends AbstractController protected $these; /** * @var \Application\Entity\AnneeUniv * Années univ proposables. * * @var \Application\Entity\AnneeUniv[] */ protected $anneeUnivCourante; protected $anneesUnivs; /** * @inheritDoc */ public function setTheseAnneeUnivService(TheseAnneeUnivService $service) { $this->theseAnneeUnivService = $service; $this->anneesUnivs = [ $this->theseAnneeUnivService->anneeUnivCourante(), $this->theseAnneeUnivService->anneeUnivPrecedente(), ]; } /** * @param RapportForm $form Loading @@ -96,23 +113,32 @@ abstract class RapportController extends AbstractController $this->form = $form; } /** * @return AnneeUniv */ protected function getAnneeUnivMax(): AnneeUniv { $annees = array_map(function(AnneeUniv $anneeUniv) { return $anneeUniv->getPremiereAnnee(); }, $this->anneesUnivs); return AnneeUniv::fromPremiereAnnee(max($annees)); } /** * @return Response|ViewModel */ public function consulterAction() { $this->these = $this->requestedThese(); $this->fetchRapportsTeleverses(); // gestion d'une éventuelle requête POST d'ajout d'un rapport $result = $this->ajouterAction(); if ($result instanceof Response) { return $result; } $this->anneeUnivCourante = $this->theseAnneeUnivService->anneeUnivCourante(); $this->these = $this->requestedThese(); $this->loadRapportsTeleverses(); $this->initForm(); return new ViewModel([ 'rapports' => $this->rapportsTeleverses, 'these' => $this->these, Loading @@ -139,19 +165,44 @@ abstract class RapportController extends AbstractController ]); } protected function loadRapportsTeleverses() protected function fetchRapportsTeleverses() { $this->rapportsTeleverses = $this->rapportService->findRapportsForThese($this->these, $this->typeRapport); } protected function isTeleversementPossible(): bool { return true; return count($this->getAnneesUnivsDisponibles()) > 0; } protected function initForm() { $this->form->setAnneesUnivs([$this->anneeUnivCourante]); $this->form->setAnneesUnivs($this->getAnneesUnivsDisponibles()); } /** * @return int[] */ protected function getAnneesPrises(): array { $rapportsParAnnees = $this->rapportService->findRapportsParAnneesForThese($this->these, $this->typeRapport); // Comportement par défaut : // si un rapport est déposé pour une année univ, cette dernière ne peut plus faire l'objet d'un dépôt. return array_keys($rapportsParAnnees); } /** * @return AnneeUniv[] */ protected function getAnneesUnivsDisponibles(): array { $anneesPrises = $this->getAnneesPrises(); return array_filter($this->anneesUnivs, function(AnneeUniv $annee) use ($anneesPrises) { $utilisee = in_array($annee->getPremiereAnnee(), $anneesPrises); return !$utilisee; }); } /** Loading @@ -159,7 +210,9 @@ abstract class RapportController extends AbstractController */ public function ajouterAction() { $these = $this->requestedThese(); $this->these = $this->requestedThese(); $this->initForm(); $request = $this->getRequest(); if ($request->isPost()) { Loading @@ -173,7 +226,8 @@ abstract class RapportController extends AbstractController /** @var Rapport $rapport */ $rapport = $this->form->getData(); $rapport->setTypeRapport($this->typeRapport); $rapport->setThese($these); $rapport->setThese($this->these); if ($this->canTeleverserRapport($rapport)) { $this->rapportService->saveRapport($rapport, $uploadData); // déclenchement d'un événement "rapport téléversé" Loading @@ -188,14 +242,20 @@ abstract class RapportController extends AbstractController "Rapport téléversé avec succès sous le nom suivant :<br>'%s'.", $rapport->getFichier()->getNom() )); } return $this->redirect()->toRoute($this->routeName . '/consulter', ['these' => IdifyFilter::id($these)]); return $this->redirect()->toRoute($this->routeName . '/consulter', ['these' => IdifyFilter::id($this->these)]); } } return false; // pas de vue pour cette action } protected function canTeleverserRapport(Rapport $rapport): bool { return $this->isTeleversementPossible(); } /** * Téléchargement d'un rapport. */ Loading module/Application/src/Application/Entity/AnneeUniv.php +65 −4 Changes for module/Application/src/Application/Entity/AnneeUniv.php: 65 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Application\Entity; use Application\Filter\AnneeUnivFormatter; use DateInterval; use DateTime; class AnneeUniv Loading Loading @@ -32,15 +33,75 @@ class AnneeUniv */ protected $formatter; /** * @var self[] */ static protected $instances = []; /** * Constructeur non public. */ protected function __construct() { $this->formatter = new AnneeUnivFormatter(); } /** * Construit une instance correspondant à l'année universitaire dont la 1ere année est spécifiée. * * @param int $premiereAnnee Ex : 2021 pour l'année universitaire 2021/2022 * @return \Application\Entity\AnneeUniv */ static public function fromPremiereAnnee(int $premiereAnnee): AnneeUniv { if (array_key_exists($premiereAnnee, static::$instances)) { return static::$instances[$premiereAnnee]; } $inst = new static(); $inst->setPremiereAnnee($premiereAnnee); return static::$instances[$premiereAnnee] = $inst; } /** * Construit une instance correspondant à l'année universitaire de la date est spécifiée, * ou à l'année universitaire courante. */ public function __construct(DateTime $date = null) static public function fromDate(DateTime $date): AnneeUniv { $this->formatter = new AnneeUnivFormatter(); $premiereAnnee = (new AnneeUniv)->computePremiereAnneeFromDate($date); $this->setPremiereAnnee($this->computePremiereAnneeFromDate($date ?: new DateTime())); return static::fromPremiereAnnee($premiereAnnee); } /** * Retourne une instance correspondant à l'année universitaire courante. * * @return \Application\Entity\AnneeUniv */ static public function courante(): AnneeUniv { return static::fromDate(new DateTime()); } /** * Retourne une instance correspondant à l'année universitaire précédent celle en cours. * * @return \Application\Entity\AnneeUniv */ static public function precedente(): AnneeUniv { return static::fromDate((new DateTime())->sub(new DateInterval('P1Y'))); } /** * @param string $separator * @return string */ public function toString(string $separator = '/'): string { return $this->formatter->filter($this->premiereAnnee, $separator); } /** Loading @@ -48,7 +109,7 @@ class AnneeUniv */ public function __toString(): string { return $this->formatter->filter($this->premiereAnnee); return $this->toString(); } /** Loading module/Application/src/Application/Entity/Db/Rapport.php +11 −13 Changes for module/Application/src/Application/Entity/Db/Rapport.php: 11 added lines, 13 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ namespace Application\Entity\Db; use Application\Entity\AnneeUniv; use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use UnicaenApp\Entity\HistoriqueAwareInterface; Loading Loading @@ -56,6 +58,7 @@ class Rapport implements ResourceInterface, HistoriqueAwareInterface public function __construct(TypeRapport $typeRapport = null) { $this->typeRapport = $typeRapport; $this->anneeUniv = (int) (new DateTime('today'))->format('Y'); $this->rapportValidations = new ArrayCollection(); } Loading @@ -80,28 +83,23 @@ class Rapport implements ResourceInterface, HistoriqueAwareInterface } /** * @return int * @return AnneeUniv */ public function getAnneeUniv() public function getAnneeUniv(): AnneeUniv { return $this->anneeUniv; return AnneeUniv::fromPremiereAnnee($this->anneeUniv); } /** * @param string $separator * @return string * @param int|AnneeUniv $anneeUniv * @return self */ public function getAnneeUnivToString($separator = '/') public function setAnneeUniv($anneeUniv): self { return $this->anneeUniv . $separator . ($this->anneeUniv + 1); if ($anneeUniv instanceof AnneeUniv) { $anneeUniv = $anneeUniv->getPremiereAnnee(); } /** * @param int $anneeUniv * @return self */ public function setAnneeUniv($anneeUniv) { $this->anneeUniv = $anneeUniv; return $this; } Loading module/Application/src/Application/Filter/NomFichierRapportFormatter.php +1 −1 Changes for module/Application/src/Application/Filter/NomFichierRapportFormatter.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ class NomFichierRapportFormatter extends AbstractNomFichierFormatter $parts['ed'] = 'ED' . $ed; $parts['nomDoctorant'] = $this->normalizedString($doctorant->getIndividu()->getNomUsuel()); $parts['prenomDoctorant'] = ucfirst(mb_strtolower($this->normalizedString($doctorant->getIndividu()->getPrenom()))); $parts['date'] = $this->rapport->getAnneeUnivToString('-'); $parts['date'] = $this->rapport->getAnneeUniv()->toString('-'); $parts['id'] = $fichier->getShortUuid(); // on inclue un id unique au cas où il y ait plusieurs fichiers de même nom déposés $name = implode($this->separator, $parts); Loading Loading
module/Application/src/Application/Controller/Rapport/RapportActiviteController.php +86 −11 Changes for module/Application/src/Application/Controller/Rapport/RapportActiviteController.php: 86 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Application\Controller\Rapport; use Application\Entity\AnneeUniv; use Application\Entity\Db\Rapport; use Application\Provider\Privilege\RapportPrivileges; Loading Loading @@ -33,10 +34,20 @@ class RapportActiviteController extends RapportController */ protected $rapportsTeleversesFintheses = []; /** * @var array [int => bool] */ protected $canTeleverserRapportAnnuel; /** * @var array [int => bool] */ protected $canTeleverserRapportFinthese; protected function loadRapportsTeleverses() protected function fetchRapportsTeleverses() { parent::loadRapportsTeleverses(); parent::fetchRapportsTeleverses(); $this->rapportsTeleversesAnnuels = array_filter($this->rapportsTeleverses, function(Rapport $rapport) { return $rapport->estFinal() === false; Loading @@ -44,31 +55,95 @@ class RapportActiviteController extends RapportController $this->rapportsTeleversesFintheses = array_filter($this->rapportsTeleverses, function(Rapport $rapport) { return $rapport->estFinal() === true; }); $this->canTeleverserRapportAnnuel = []; foreach ($this->anneesUnivs as $anneeUniv) { $this->canTeleverserRapportAnnuel[$anneeUniv->getPremiereAnnee()] = $this->canTeleverserRapportAnnuelForAnneeUniv($anneeUniv); } $this->canTeleverserRapportFinthese = []; foreach ($this->anneesUnivs as $anneeUniv) { $this->canTeleverserRapportFinthese[$anneeUniv->getPremiereAnnee()] = $this->canTeleverserRapportFintheseForAnneeUniv($anneeUniv); } } protected function isTeleversementPossible(): bool { return count(array_filter($this->canTeleverserRapportAnnuel)) > 0 || count(array_filter($this->canTeleverserRapportFinthese)) > 0; } protected function getAnneesPrises(): array { return array_keys( array_intersect_key( array_filter($this->canTeleverserRapportAnnuel, function(bool $can) { return $can === false; }), array_filter($this->canTeleverserRapportFinthese, function(bool $can) { return $can === false; }) ) ); } protected function canTeleverserRapport(Rapport $rapport): bool { if ($rapport->estFinal()) { return $this->canTeleverserRapportFintheseForAnneeUniv($rapport->getAnneeUniv()); } else { return $this->canTeleverserRapportAnnuelForAnneeUniv($rapport->getAnneeUniv()); } } protected function canTeleverserRapportAnnuel(): bool { // Peut être téléversé : 1 rapport annuel par année universitaire. $rapportsSurAnneeCourante = array_filter($this->rapportsTeleversesAnnuels, function(Rapport $rapport) { return $rapport->getAnneeUniv() === $this->anneeUnivCourante->getPremiereAnnee(); }); foreach ($this->anneesUnivs as $anneeUniv) { $rapportsTeleverses = array_filter( $this->rapportsTeleversesAnnuels, $this->rapportService->getFilterRapportsByAnneeUniv($anneeUniv) ); if (empty($rapportsTeleverses)) { return true; } } return count($rapportsSurAnneeCourante) === 0; return false; } protected function canTeleverserRapportAnnuelForAnneeUniv(AnneeUniv $anneeUniv): bool { // Peut être téléversé : 1 rapport annuel. $rapportsTeleverses = array_filter( $this->rapportsTeleversesAnnuels, $this->rapportService->getFilterRapportsByAnneeUniv($anneeUniv) ); return empty($rapportsTeleverses); } protected function canTeleverserRapportFinthese(): bool { // Peut être téléversé : 1 rapport de fin de thèse, toutes années univ confondues. // Dépôt d'1 rapport de fin de thèse maxi toutes années univ confondues. return count($this->rapportsTeleversesFintheses) === 0; } protected function isTeleversementPossible(): bool protected function canTeleverserRapportFintheseForAnneeUniv(AnneeUniv $anneeUniv): bool { return $this->canTeleverserRapportAnnuel() || $this->canTeleverserRapportFinthese(); // Dépôt d'un rapport de fin de thèse seulement sur la dernière année univ. if ($anneeUniv !== $this->getAnneeUnivMax()) { return false; } $rapportsTeleverses = array_filter( $this->rapportsTeleversesFintheses, $this->rapportService->getFilterRapportsByAnneeUniv($anneeUniv) ); return empty($rapportsTeleverses); } protected function initForm() Loading
module/Application/src/Application/Controller/Rapport/RapportController.php +74 −14 Changes for module/Application/src/Application/Controller/Rapport/RapportController.php: 74 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Application\Controller\Rapport; use Application\Controller\AbstractController; use Application\Entity\AnneeUniv; use Application\Entity\Db\Interfaces\TypeRapportAwareTrait; use Application\Entity\Db\Interfaces\TypeValidationAwareTrait; use Application\Entity\Db\Rapport; Loading @@ -16,6 +17,7 @@ use Application\Service\Individu\IndividuServiceAwareTrait; use Application\Service\Notification\NotifierServiceAwareTrait; use Application\Service\Rapport\RapportServiceAwareTrait; use Application\Service\These\TheseServiceAwareTrait; use Application\Service\TheseAnneeUniv\TheseAnneeUnivService; use Application\Service\TheseAnneeUniv\TheseAnneeUnivServiceAwareTrait; use Application\Service\Validation\ValidationServiceAwareTrait; use Application\Service\VersionFichier\VersionFichierServiceAwareTrait; Loading Loading @@ -84,9 +86,24 @@ abstract class RapportController extends AbstractController protected $these; /** * @var \Application\Entity\AnneeUniv * Années univ proposables. * * @var \Application\Entity\AnneeUniv[] */ protected $anneeUnivCourante; protected $anneesUnivs; /** * @inheritDoc */ public function setTheseAnneeUnivService(TheseAnneeUnivService $service) { $this->theseAnneeUnivService = $service; $this->anneesUnivs = [ $this->theseAnneeUnivService->anneeUnivCourante(), $this->theseAnneeUnivService->anneeUnivPrecedente(), ]; } /** * @param RapportForm $form Loading @@ -96,23 +113,32 @@ abstract class RapportController extends AbstractController $this->form = $form; } /** * @return AnneeUniv */ protected function getAnneeUnivMax(): AnneeUniv { $annees = array_map(function(AnneeUniv $anneeUniv) { return $anneeUniv->getPremiereAnnee(); }, $this->anneesUnivs); return AnneeUniv::fromPremiereAnnee(max($annees)); } /** * @return Response|ViewModel */ public function consulterAction() { $this->these = $this->requestedThese(); $this->fetchRapportsTeleverses(); // gestion d'une éventuelle requête POST d'ajout d'un rapport $result = $this->ajouterAction(); if ($result instanceof Response) { return $result; } $this->anneeUnivCourante = $this->theseAnneeUnivService->anneeUnivCourante(); $this->these = $this->requestedThese(); $this->loadRapportsTeleverses(); $this->initForm(); return new ViewModel([ 'rapports' => $this->rapportsTeleverses, 'these' => $this->these, Loading @@ -139,19 +165,44 @@ abstract class RapportController extends AbstractController ]); } protected function loadRapportsTeleverses() protected function fetchRapportsTeleverses() { $this->rapportsTeleverses = $this->rapportService->findRapportsForThese($this->these, $this->typeRapport); } protected function isTeleversementPossible(): bool { return true; return count($this->getAnneesUnivsDisponibles()) > 0; } protected function initForm() { $this->form->setAnneesUnivs([$this->anneeUnivCourante]); $this->form->setAnneesUnivs($this->getAnneesUnivsDisponibles()); } /** * @return int[] */ protected function getAnneesPrises(): array { $rapportsParAnnees = $this->rapportService->findRapportsParAnneesForThese($this->these, $this->typeRapport); // Comportement par défaut : // si un rapport est déposé pour une année univ, cette dernière ne peut plus faire l'objet d'un dépôt. return array_keys($rapportsParAnnees); } /** * @return AnneeUniv[] */ protected function getAnneesUnivsDisponibles(): array { $anneesPrises = $this->getAnneesPrises(); return array_filter($this->anneesUnivs, function(AnneeUniv $annee) use ($anneesPrises) { $utilisee = in_array($annee->getPremiereAnnee(), $anneesPrises); return !$utilisee; }); } /** Loading @@ -159,7 +210,9 @@ abstract class RapportController extends AbstractController */ public function ajouterAction() { $these = $this->requestedThese(); $this->these = $this->requestedThese(); $this->initForm(); $request = $this->getRequest(); if ($request->isPost()) { Loading @@ -173,7 +226,8 @@ abstract class RapportController extends AbstractController /** @var Rapport $rapport */ $rapport = $this->form->getData(); $rapport->setTypeRapport($this->typeRapport); $rapport->setThese($these); $rapport->setThese($this->these); if ($this->canTeleverserRapport($rapport)) { $this->rapportService->saveRapport($rapport, $uploadData); // déclenchement d'un événement "rapport téléversé" Loading @@ -188,14 +242,20 @@ abstract class RapportController extends AbstractController "Rapport téléversé avec succès sous le nom suivant :<br>'%s'.", $rapport->getFichier()->getNom() )); } return $this->redirect()->toRoute($this->routeName . '/consulter', ['these' => IdifyFilter::id($these)]); return $this->redirect()->toRoute($this->routeName . '/consulter', ['these' => IdifyFilter::id($this->these)]); } } return false; // pas de vue pour cette action } protected function canTeleverserRapport(Rapport $rapport): bool { return $this->isTeleversementPossible(); } /** * Téléchargement d'un rapport. */ Loading
module/Application/src/Application/Entity/AnneeUniv.php +65 −4 Changes for module/Application/src/Application/Entity/AnneeUniv.php: 65 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Application\Entity; use Application\Filter\AnneeUnivFormatter; use DateInterval; use DateTime; class AnneeUniv Loading Loading @@ -32,15 +33,75 @@ class AnneeUniv */ protected $formatter; /** * @var self[] */ static protected $instances = []; /** * Constructeur non public. */ protected function __construct() { $this->formatter = new AnneeUnivFormatter(); } /** * Construit une instance correspondant à l'année universitaire dont la 1ere année est spécifiée. * * @param int $premiereAnnee Ex : 2021 pour l'année universitaire 2021/2022 * @return \Application\Entity\AnneeUniv */ static public function fromPremiereAnnee(int $premiereAnnee): AnneeUniv { if (array_key_exists($premiereAnnee, static::$instances)) { return static::$instances[$premiereAnnee]; } $inst = new static(); $inst->setPremiereAnnee($premiereAnnee); return static::$instances[$premiereAnnee] = $inst; } /** * Construit une instance correspondant à l'année universitaire de la date est spécifiée, * ou à l'année universitaire courante. */ public function __construct(DateTime $date = null) static public function fromDate(DateTime $date): AnneeUniv { $this->formatter = new AnneeUnivFormatter(); $premiereAnnee = (new AnneeUniv)->computePremiereAnneeFromDate($date); $this->setPremiereAnnee($this->computePremiereAnneeFromDate($date ?: new DateTime())); return static::fromPremiereAnnee($premiereAnnee); } /** * Retourne une instance correspondant à l'année universitaire courante. * * @return \Application\Entity\AnneeUniv */ static public function courante(): AnneeUniv { return static::fromDate(new DateTime()); } /** * Retourne une instance correspondant à l'année universitaire précédent celle en cours. * * @return \Application\Entity\AnneeUniv */ static public function precedente(): AnneeUniv { return static::fromDate((new DateTime())->sub(new DateInterval('P1Y'))); } /** * @param string $separator * @return string */ public function toString(string $separator = '/'): string { return $this->formatter->filter($this->premiereAnnee, $separator); } /** Loading @@ -48,7 +109,7 @@ class AnneeUniv */ public function __toString(): string { return $this->formatter->filter($this->premiereAnnee); return $this->toString(); } /** Loading
module/Application/src/Application/Entity/Db/Rapport.php +11 −13 Changes for module/Application/src/Application/Entity/Db/Rapport.php: 11 added lines, 13 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ namespace Application\Entity\Db; use Application\Entity\AnneeUniv; use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use UnicaenApp\Entity\HistoriqueAwareInterface; Loading Loading @@ -56,6 +58,7 @@ class Rapport implements ResourceInterface, HistoriqueAwareInterface public function __construct(TypeRapport $typeRapport = null) { $this->typeRapport = $typeRapport; $this->anneeUniv = (int) (new DateTime('today'))->format('Y'); $this->rapportValidations = new ArrayCollection(); } Loading @@ -80,28 +83,23 @@ class Rapport implements ResourceInterface, HistoriqueAwareInterface } /** * @return int * @return AnneeUniv */ public function getAnneeUniv() public function getAnneeUniv(): AnneeUniv { return $this->anneeUniv; return AnneeUniv::fromPremiereAnnee($this->anneeUniv); } /** * @param string $separator * @return string * @param int|AnneeUniv $anneeUniv * @return self */ public function getAnneeUnivToString($separator = '/') public function setAnneeUniv($anneeUniv): self { return $this->anneeUniv . $separator . ($this->anneeUniv + 1); if ($anneeUniv instanceof AnneeUniv) { $anneeUniv = $anneeUniv->getPremiereAnnee(); } /** * @param int $anneeUniv * @return self */ public function setAnneeUniv($anneeUniv) { $this->anneeUniv = $anneeUniv; return $this; } Loading
module/Application/src/Application/Filter/NomFichierRapportFormatter.php +1 −1 Changes for module/Application/src/Application/Filter/NomFichierRapportFormatter.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ class NomFichierRapportFormatter extends AbstractNomFichierFormatter $parts['ed'] = 'ED' . $ed; $parts['nomDoctorant'] = $this->normalizedString($doctorant->getIndividu()->getNomUsuel()); $parts['prenomDoctorant'] = ucfirst(mb_strtolower($this->normalizedString($doctorant->getIndividu()->getPrenom()))); $parts['date'] = $this->rapport->getAnneeUnivToString('-'); $parts['date'] = $this->rapport->getAnneeUniv()->toString('-'); $parts['id'] = $fichier->getShortUuid(); // on inclue un id unique au cas où il y ait plusieurs fichiers de même nom déposés $name = implode($this->separator, $parts); Loading