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'); + } +} 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/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..39f36e9ed 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'); + $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 +140,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..e908fae87 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; 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 +