Skip to content
Merged
13 changes: 13 additions & 0 deletions db/migrations/20260319115804_site_feuille_dates_publication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class SiteFeuilleDatesPublication extends AbstractMigration
{
public function change(): void
{
$this->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');
}
}
22 changes: 22 additions & 0 deletions db/seeds/Feuilles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
19 changes: 19 additions & 0 deletions sources/AppBundle/Site/Form/SheetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
35 changes: 34 additions & 1 deletion sources/AppBundle/Site/Model/Repository/SheetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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',
Expand Down
25 changes: 25 additions & 0 deletions sources/AppBundle/Site/Model/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions templates/admin/site/sheet_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}
Expand Down
4 changes: 4 additions & 0 deletions templates/admin/site/sheet_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
Nom
</a>
</th>
<th>Début publication</th>
<th>Fin publication</th>
<th class="center aligned">
<a href="{{ path('admin_site_rubriques_list', {'sort': 'etat' , 'direction' : ((direction == 'asc' and sort == 'date') ? 'desc': 'asc')}) }}">
Etat
Expand All @@ -58,6 +60,8 @@
<br/><img src="../../templates/site/images/{{ sheet.image }}" alt="{{ sheet.image_alt|default('') }}" width="125" />
{% endif %}
</td>
<td>{% if sheet.date_debut_publication is not null %}{{ sheet.date_debut_publication|date('d-m-Y') }}{% endif %}</td>
<td>{% if sheet.date_fin_publication is not null %}{{ sheet.date_fin_publication|date('d-m-Y') }}{% endif %}</td>
<td class="center aligned">
{% if sheet.etat == 1 %}
<a class="ui orange label">En ligne</a>
Expand Down
17 changes: 17 additions & 0 deletions tests/behat/features/Admin/Site/AdminSiteFeuilles.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ Feature: Administration - Partie Site
And I am on "/admin/site/feuilles/delete/1/foo"
Then the response status code should be 403

@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"
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"
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
Expand Down
8 changes: 8 additions & 0 deletions tests/behat/features/PublicSite/Feuilles.feature
Original file line number Diff line number Diff line change
@@ -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"
Loading