From ff9802e44eed1d68f874897472b44259504e26ca Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 19 Mar 2026 14:48:19 +0100 Subject: [PATCH 1/8] Ajout de la migration pour les dates de publication des feuilles --- ...0260319115804_site_feuille_dates_publication.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 db/migrations/20260319115804_site_feuille_dates_publication.php diff --git a/db/migrations/20260319115804_site_feuille_dates_publication.php b/db/migrations/20260319115804_site_feuille_dates_publication.php new file mode 100644 index 000000000..7d5ba8f47 --- /dev/null +++ b/db/migrations/20260319115804_site_feuille_dates_publication.php @@ -0,0 +1,13 @@ +query('ALTER TABLE afup_site_feuille ADD date_debut_publication int(11) DEFAULT NULL AFTER date, ADD date_fin_publication int(11) DEFAULT NULL AFTER date_debut_publication'); + } +} From 225a8330b610ba10d308ab75975fc4ff6980205c Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 19 Mar 2026 14:48:31 +0100 Subject: [PATCH 2/8] =?UTF-8?q?Ajout=20des=20dates=20de=20d=C3=A9but=20et?= =?UTF-8?q?=20fin=20de=20publication=20sur=20les=20feuilles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/AppBundle/Site/Form/SheetType.php | 19 +++++++++ .../Site/Model/Repository/SheetRepository.php | 30 +++++++++++++- sources/AppBundle/Site/Model/Sheet.php | 40 +++++++++++++++++++ templates/admin/site/sheet_form.html.twig | 2 + templates/admin/site/sheet_list.html.twig | 4 ++ 5 files changed, 94 insertions(+), 1 deletion(-) diff --git a/sources/AppBundle/Site/Form/SheetType.php b/sources/AppBundle/Site/Form/SheetType.php index 55105a848..6fc3589fc 100644 --- a/sources/AppBundle/Site/Form/SheetType.php +++ b/sources/AppBundle/Site/Form/SheetType.php @@ -113,6 +113,25 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]) + ->add('publicationStart', DateType::class, [ + 'required' => false, + 'label' => 'Date de début de publication', + 'input' => 'datetime', + 'years' => range(2001, date('Y') + 5), + 'constraints' => [ + new Assert\Type("datetime"), + ], + ]) + ->add('publicationEnd', DateType::class, [ + 'required' => false, + 'label' => 'Date de fin de publication', + 'input' => 'datetime', + 'years' => range(2001, date('Y') + 5), + 'constraints' => [ + new Assert\Type("datetime"), + ], + ]) + ->add('position', ChoiceType::class, [ 'required' => false, 'label' => 'Position', diff --git a/sources/AppBundle/Site/Model/Repository/SheetRepository.php b/sources/AppBundle/Site/Model/Repository/SheetRepository.php index b3da563ea..2f27cb8b3 100644 --- a/sources/AppBundle/Site/Model/Repository/SheetRepository.php +++ b/sources/AppBundle/Site/Model/Repository/SheetRepository.php @@ -73,7 +73,7 @@ private function getActiveChildrenByParentIdBuilder(): SelectInterface * @var SelectInterface $queryBuilder */ $queryBuilder = $this->getQueryBuilder(self::QUERY_SELECT); - $queryBuilder->cols(['*'])->from('afup_site_feuille')->where('id_parent = :parentId')->where('etat = 1'); + $queryBuilder->cols(['*'])->from('afup_site_feuille')->where('id_parent = :parentId')->where('etat = 1')->where('date_debut_publication IS NULL OR date_debut_publication <= UNIX_TIMESTAMP()')->where('date_fin_publication IS NULL OR date_fin_publication >= UNIX_TIMESTAMP()'); return $queryBuilder; } @@ -135,6 +135,34 @@ public static function initMetadata(SerializerFactoryInterface $serializerFactor ], ], ]) + ->addField([ + 'columnName' => 'date_debut_publication', + 'fieldName' => 'publicationStart', + 'type' => 'datetime', + 'serializer_options' => [ + 'unserialize' => [ + 'unSerializeUseFormat' => true, + 'format' => 'U', + ], + 'serialize' => [ + 'format' => 'U', + ], + ], + ]) + ->addField([ + 'columnName' => 'date_fin_publication', + 'fieldName' => 'publicationEnd', + 'type' => 'datetime', + 'serializer_options' => [ + 'unserialize' => [ + 'unSerializeUseFormat' => true, + 'format' => 'U', + ], + 'serialize' => [ + 'format' => 'U', + ], + ], + ]) ->addField([ 'columnName' => 'etat', 'fieldName' => 'state', diff --git a/sources/AppBundle/Site/Model/Sheet.php b/sources/AppBundle/Site/Model/Sheet.php index fdbba68e5..8339936cd 100644 --- a/sources/AppBundle/Site/Model/Sheet.php +++ b/sources/AppBundle/Site/Model/Sheet.php @@ -24,6 +24,9 @@ class Sheet implements NotifyPropertyInterface private ?int $position = null; private ?DateTime $creationDate = null; + private ?DateTime $publicationStart = null; + private ?DateTime $publicationEnd = null; + private ?int $state = null; private ?string $image = null; @@ -116,6 +119,28 @@ public function setCreationDate(?DateTime $creationDate): void $this->creationDate = $creationDate; } + public function getPublicationStart(): ?DateTime + { + return $this->publicationStart; + } + + public function setPublicationStart(?DateTime $publicationStart): void + { + $this->propertyChanged('publicationStart', $this->publicationStart, $publicationStart); + $this->publicationStart = $publicationStart; + } + + public function getPublicationEnd(): ?DateTime + { + return $this->publicationEnd; + } + + public function setPublicationEnd(?DateTime $publicationEnd): void + { + $this->propertyChanged('publicationEnd', $this->publicationEnd, $publicationEnd); + $this->publicationEnd = $publicationEnd; + } + public function getState(): ?int { return $this->state; @@ -159,4 +184,19 @@ public function setPatterns(?string $patterns): void $this->propertyChanged('patterns', $this->patterns, $patterns); $this->patterns = $patterns; } + + public function isPublished(?DateTime $now = null): bool + { + $now ??= new DateTime(); + + if ($this->publicationStart !== null && $now < $this->publicationStart) { + return false; + } + + if ($this->publicationEnd !== null && $now > $this->publicationEnd) { + return false; + } + + return true; + } } diff --git a/templates/admin/site/sheet_form.html.twig b/templates/admin/site/sheet_form.html.twig index e5cbe14c4..599074c7a 100644 --- a/templates/admin/site/sheet_form.html.twig +++ b/templates/admin/site/sheet_form.html.twig @@ -33,6 +33,8 @@ {% endif %} {{ form_row(form.imageAlt) }} {{ form_row(form.creationDate) }} + {{ form_row(form.publicationStart) }} + {{ form_row(form.publicationEnd) }} {{ form_row(form.position) }} {{ form_row(form.state) }} {{ form_row(form.patterns) }} diff --git a/templates/admin/site/sheet_list.html.twig b/templates/admin/site/sheet_list.html.twig index d50e4df80..e31db94ed 100644 --- a/templates/admin/site/sheet_list.html.twig +++ b/templates/admin/site/sheet_list.html.twig @@ -33,6 +33,8 @@ Nom + Début publication + Fin publication Etat @@ -58,6 +60,8 @@
{{ sheet.image_alt|default('') }} {% endif %} + {% if sheet.date_debut_publication is not null %}{{ sheet.date_debut_publication|date('d-m-Y') }}{% endif %} + {% if sheet.date_fin_publication is not null %}{{ sheet.date_fin_publication|date('d-m-Y') }}{% endif %} {% if sheet.etat == 1 %}
En ligne From d33c38509ce2d6526e37387e1f29545d46f68856 Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 19 Mar 2026 14:48:37 +0100 Subject: [PATCH 3/8] Ajout des tests pour les dates de publication des feuilles --- .../Admin/Site/AdminSiteFeuilles.feature | 23 ++++++++++++ tests/unit/AppBundle/Site/Model/SheetTest.php | 37 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/unit/AppBundle/Site/Model/SheetTest.php diff --git a/tests/behat/features/Admin/Site/AdminSiteFeuilles.feature b/tests/behat/features/Admin/Site/AdminSiteFeuilles.feature index f83e9d968..cae316a5d 100644 --- a/tests/behat/features/Admin/Site/AdminSiteFeuilles.feature +++ b/tests/behat/features/Admin/Site/AdminSiteFeuilles.feature @@ -13,6 +13,29 @@ Feature: Administration - Partie Site And I am on "/admin/site/feuilles/delete/1/foo" Then the response status code should be 403 + @reloadDbWithTestData + Scenario: Les champs de dates de publication sont présents dans le formulaire + Given I am logged in as admin and on the Administration + And I follow "Feuilles" + When I follow "Ajouter" + Then I should see "Ajouter une feuille" + And I should see "Date de début de publication" + And I should see "Date de fin de publication" + + @reloadDbWithTestData + Scenario: Ajout d'une feuille avec des dates de publication + Given I am logged in as admin and on the Administration + And I follow "Feuilles" + When I follow "Ajouter" + And I fill in "sheet[name]" with "Feuille avec dates" + And I fill in "sheet[link]" with "http://lien" + And I fill in "sheet[publicationStart]" with "2026-03-01" + And I fill in "sheet[publicationEnd]" with "2027-12-31" + And I press "Ajouter" + Then I should see "Liste des feuilles" + And the ".content table" element should contain "01-03-2026" + And the ".content table" element should contain "31-12-2027" + @reloadDbWithTestData Scenario: Ajout/modification/suppression d'une feuille Given I am logged in as admin and on the Administration diff --git a/tests/unit/AppBundle/Site/Model/SheetTest.php b/tests/unit/AppBundle/Site/Model/SheetTest.php new file mode 100644 index 000000000..3292392db --- /dev/null +++ b/tests/unit/AppBundle/Site/Model/SheetTest.php @@ -0,0 +1,37 @@ +setPublicationStart($start); + $sheet->setPublicationEnd($end); + + self::assertEquals($expected, $sheet->isPublished(new DateTime('2026-01-15'))); + } + + public static function dates(): \Generator + { + yield 'aucune date' => [null, null, true]; + yield 'début null, fin dans le futur' => [null, new DateTime('2026-02-01'), true]; + yield 'début null, fin dans le passé' => [null, new DateTime('2026-01-01'), false]; + yield 'début dans le passé, fin null' => [new DateTime('2026-01-01'), null, true]; + yield 'début dans le futur, fin null' => [new DateTime('2026-02-01'), null, false]; + yield 'dans la plage' => [new DateTime('2026-01-01'), new DateTime('2026-02-01'), true]; + yield 'avant la plage' => [new DateTime('2026-01-20'), new DateTime('2026-02-01'), false]; + yield 'après la plage' => [new DateTime('2026-01-01'), new DateTime('2026-01-10'), false]; + yield 'exactement à la date de début' => [new DateTime('2026-01-15'), null, true]; + yield 'exactement à la date de fin' => [null, new DateTime('2026-01-15'), true]; + } +} From efa87712368760261a2a1d95837084681172c999 Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 19 Mar 2026 15:53:19 +0100 Subject: [PATCH 4/8] =?UTF-8?q?D=C3=A9placer=20les=20asserts=20dans=20l'au?= =?UTF-8?q?tre=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/behat/features/Admin/Site/AdminSiteFeuilles.feature | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/behat/features/Admin/Site/AdminSiteFeuilles.feature b/tests/behat/features/Admin/Site/AdminSiteFeuilles.feature index cae316a5d..eb1b9ae30 100644 --- a/tests/behat/features/Admin/Site/AdminSiteFeuilles.feature +++ b/tests/behat/features/Admin/Site/AdminSiteFeuilles.feature @@ -14,19 +14,13 @@ Feature: Administration - Partie Site Then the response status code should be 403 @reloadDbWithTestData - Scenario: Les champs de dates de publication sont présents dans le formulaire + Scenario: Ajout d'une feuille avec des dates de publication Given I am logged in as admin and on the Administration And I follow "Feuilles" When I follow "Ajouter" Then I should see "Ajouter une feuille" And I should see "Date de début de publication" And I should see "Date de fin de publication" - - @reloadDbWithTestData - Scenario: Ajout d'une feuille avec des dates de publication - Given I am logged in as admin and on the Administration - And I follow "Feuilles" - When I follow "Ajouter" And I fill in "sheet[name]" with "Feuille avec dates" And I fill in "sheet[link]" with "http://lien" And I fill in "sheet[publicationStart]" with "2026-03-01" From 0aefd6d12f5114646eb7e42fdf7b50aa41aab525 Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 19 Mar 2026 15:56:01 +0100 Subject: [PATCH 5/8] =?UTF-8?q?Am=C3=A9liorer=20la=20lisibilit=C3=A9=20de?= =?UTF-8?q?=20la=20requ=C3=AAte=20en=20la=20passant=20en=20ligne=20par=20l?= =?UTF-8?q?igne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBundle/Site/Model/Repository/SheetRepository.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sources/AppBundle/Site/Model/Repository/SheetRepository.php b/sources/AppBundle/Site/Model/Repository/SheetRepository.php index 2f27cb8b3..c5fecc5d7 100644 --- a/sources/AppBundle/Site/Model/Repository/SheetRepository.php +++ b/sources/AppBundle/Site/Model/Repository/SheetRepository.php @@ -73,7 +73,12 @@ private function getActiveChildrenByParentIdBuilder(): SelectInterface * @var SelectInterface $queryBuilder */ $queryBuilder = $this->getQueryBuilder(self::QUERY_SELECT); - $queryBuilder->cols(['*'])->from('afup_site_feuille')->where('id_parent = :parentId')->where('etat = 1')->where('date_debut_publication IS NULL OR date_debut_publication <= UNIX_TIMESTAMP()')->where('date_fin_publication IS NULL OR date_fin_publication >= UNIX_TIMESTAMP()'); + $queryBuilder->cols(['*']) + ->from('afup_site_feuille') + ->where('id_parent = :parentId') + ->where('etat = 1') + ->where('date_debut_publication IS NULL OR date_debut_publication <= UNIX_TIMESTAMP()') + ->where('date_fin_publication IS NULL OR date_fin_publication >= UNIX_TIMESTAMP()'); return $queryBuilder; } From 6f778f5cd8f2f078a4341924e472dcb13342f82b Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 19 Mar 2026 17:15:06 +0100 Subject: [PATCH 6/8] =?UTF-8?q?Corriger=20la=20pr=C3=A9c=C3=A9dence=20SQL?= =?UTF-8?q?=20des=20conditions=20OR=20dans=20SheetRepository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/AppBundle/Site/Model/Repository/SheetRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/AppBundle/Site/Model/Repository/SheetRepository.php b/sources/AppBundle/Site/Model/Repository/SheetRepository.php index c5fecc5d7..39f36e9ed 100644 --- a/sources/AppBundle/Site/Model/Repository/SheetRepository.php +++ b/sources/AppBundle/Site/Model/Repository/SheetRepository.php @@ -77,8 +77,8 @@ private function getActiveChildrenByParentIdBuilder(): SelectInterface ->from('afup_site_feuille') ->where('id_parent = :parentId') ->where('etat = 1') - ->where('date_debut_publication IS NULL OR date_debut_publication <= UNIX_TIMESTAMP()') - ->where('date_fin_publication IS NULL OR date_fin_publication >= UNIX_TIMESTAMP()'); + ->where('(date_debut_publication IS NULL OR date_debut_publication <= UNIX_TIMESTAMP())') + ->where('(date_fin_publication IS NULL OR date_fin_publication >= UNIX_TIMESTAMP())'); return $queryBuilder; } From 207430ed583bbeb578f804a692b6c55a6b0b22b4 Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 19 Mar 2026 17:15:22 +0100 Subject: [PATCH 7/8] =?UTF-8?q?Supprimer=20la=20m=C3=A9thode=20isPublished?= =?UTF-8?q?=20et=20son=20test=20unitaire,=20le=20filtrage=20=C3=A9tant=20g?= =?UTF-8?q?=C3=A9r=C3=A9=20en=20SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/AppBundle/Site/Model/Sheet.php | 15 -------- tests/unit/AppBundle/Site/Model/SheetTest.php | 37 ------------------- 2 files changed, 52 deletions(-) delete mode 100644 tests/unit/AppBundle/Site/Model/SheetTest.php diff --git a/sources/AppBundle/Site/Model/Sheet.php b/sources/AppBundle/Site/Model/Sheet.php index 8339936cd..e908fae87 100644 --- a/sources/AppBundle/Site/Model/Sheet.php +++ b/sources/AppBundle/Site/Model/Sheet.php @@ -184,19 +184,4 @@ public function setPatterns(?string $patterns): void $this->propertyChanged('patterns', $this->patterns, $patterns); $this->patterns = $patterns; } - - public function isPublished(?DateTime $now = null): bool - { - $now ??= new DateTime(); - - if ($this->publicationStart !== null && $now < $this->publicationStart) { - return false; - } - - if ($this->publicationEnd !== null && $now > $this->publicationEnd) { - return false; - } - - return true; - } } diff --git a/tests/unit/AppBundle/Site/Model/SheetTest.php b/tests/unit/AppBundle/Site/Model/SheetTest.php deleted file mode 100644 index 3292392db..000000000 --- a/tests/unit/AppBundle/Site/Model/SheetTest.php +++ /dev/null @@ -1,37 +0,0 @@ -setPublicationStart($start); - $sheet->setPublicationEnd($end); - - self::assertEquals($expected, $sheet->isPublished(new DateTime('2026-01-15'))); - } - - public static function dates(): \Generator - { - yield 'aucune date' => [null, null, true]; - yield 'début null, fin dans le futur' => [null, new DateTime('2026-02-01'), true]; - yield 'début null, fin dans le passé' => [null, new DateTime('2026-01-01'), false]; - yield 'début dans le passé, fin null' => [new DateTime('2026-01-01'), null, true]; - yield 'début dans le futur, fin null' => [new DateTime('2026-02-01'), null, false]; - yield 'dans la plage' => [new DateTime('2026-01-01'), new DateTime('2026-02-01'), true]; - yield 'avant la plage' => [new DateTime('2026-01-20'), new DateTime('2026-02-01'), false]; - yield 'après la plage' => [new DateTime('2026-01-01'), new DateTime('2026-01-10'), false]; - yield 'exactement à la date de début' => [new DateTime('2026-01-15'), null, true]; - yield 'exactement à la date de fin' => [null, new DateTime('2026-01-15'), true]; - } -} From 911747540d9afb02fb8a2c9ecd8a97e3861c41aa Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 19 Mar 2026 17:15:30 +0100 Subject: [PATCH 8/8] Ajout des fixtures et du test Behat pour les dates de publication des feuilles --- db/seeds/Feuilles.php | 22 +++++++++++++++++++ .../features/PublicSite/Feuilles.feature | 8 +++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/behat/features/PublicSite/Feuilles.feature diff --git a/db/seeds/Feuilles.php b/db/seeds/Feuilles.php index b571a9702..a491be37c 100644 --- a/db/seeds/Feuilles.php +++ b/db/seeds/Feuilles.php @@ -131,6 +131,28 @@ public function run(): void 'alt' => 'Membres AFUP, profitez du meilleur de PHP et soyez à jour sur son actualité : abonnez-vous à notre newsletter La Veille de l’AFUP. Progrès du langage, conseils de spécialistes, nouvelles versions, l’AFUP fait la veille pour vous et vous l’envoie par mail.', 'etat' => 1, ], + [ + 'id_parent' => Feuille::ID_FEUILLE_HEADER, + 'nom' => 'Feuille publication passée', + 'lien' => '/feuille-publication-passee', + 'etat' => 1, + 'date_fin_publication' => strtotime('-1 day'), + ], + [ + 'id_parent' => Feuille::ID_FEUILLE_HEADER, + 'nom' => 'Feuille publication future', + 'lien' => '/feuille-publication-future', + 'etat' => 1, + 'date_debut_publication' => strtotime('+1 year'), + ], + [ + 'id_parent' => Feuille::ID_FEUILLE_HEADER, + 'nom' => 'Feuille publication courante', + 'lien' => '/feuille-publication-courante', + 'etat' => 1, + 'date_debut_publication' => strtotime('-1 year'), + 'date_fin_publication' => strtotime('+10 years'), + ], ]; $data = array_merge($data, $this->prepareFeuilles($this->getFooter(), Feuille::ID_FEUILLE_FOOTER)); diff --git a/tests/behat/features/PublicSite/Feuilles.feature b/tests/behat/features/PublicSite/Feuilles.feature new file mode 100644 index 000000000..96145c462 --- /dev/null +++ b/tests/behat/features/PublicSite/Feuilles.feature @@ -0,0 +1,8 @@ +Feature: Site Public - Feuilles + + @reloadDbWithTestData + Scenario: Les feuilles sont affichées selon leur date de publication + Given I am on the homepage + Then I should not see "Feuille publication passée" + And I should not see "Feuille publication future" + And I should see "Feuille publication courante"