Pārlūkot izejas kodu

Merge branch 'feature/v-4029_fix_historical_update' into develop

Olivier Massot 2 gadi atpakaļ
vecāks
revīzija
589a8339ca
2 mainītis faili ar 22 papildinājumiem un 1 dzēšanām
  1. 0 0
      doc/internal_requests.md
  2. 22 1
      src/Entity/Access/Access.php

+ 0 - 0
doc/internal_requests.md


+ 22 - 1
src/Entity/Access/Access.php

@@ -422,9 +422,30 @@ class Access implements UserInterface, PasswordAuthenticatedUserInterface
     #[Groups(['my_access:input'])]
     public function setHistorical(array $historical): self
     {
-        if (!$historical['past'] && !$historical['present'] && !$historical['future']) {
+        // Une entrée dateStart mais pas de dateEnd, on retire dateEnd
+        if (array_key_exists('dateStart', $historical) && !array_key_exists('dateEnd', $historical)) {
+            unset($historical['dateStart']);
+        }
+        // Une entrée dateEnd mais pas de dateStart, on retire dateEnd
+        else if (!array_key_exists('dateStart', $historical) && array_key_exists('dateEnd', $historical)) {
+            unset($historical['dateEnd']);
+        }
+
+        // Les entrées dateStart et dateEnd existent mais ne sont pas toutes les deux renseignées, on retire les deux
+        if (
+            array_key_exists('dateStart', $historical) &&
+            array_key_exists('dateEnd', $historical) &&
+            (!$historical['dateStart'] || !$historical['dateEnd'])
+        ) {
+            unset($historical['dateStart']);
+            unset($historical['dateEnd']);
+        }
+
+        // Aucun temps ni période n'est défini, on définit par défaut present à vrai
+        if (!$historical['past'] && !$historical['present'] && !$historical['future'] && !array_key_exists('dateStart', $historical) ) {
             $historical['present'] = true;
         }
+
         $this->setting['historical'] = $historical;
         return $this;
     }