Skip to content

Commit 1e15807

Browse files
authored
Ajout des dates de début et fin de publication sur les feuilles (#1774) (#2167)
* Ajout de la migration pour les dates de publication des feuilles * Ajout des dates de début et fin de publication sur les feuilles * Ajout des tests pour les dates de publication des feuilles * Déplacer les asserts dans l'autre test * Améliorer la lisibilité de la requête en la passant en ligne par ligne * Corriger la précédence SQL des conditions OR dans SheetRepository * Supprimer la méthode isPublished et son test unitaire, le filtrage étant géré en SQL * Ajout des fixtures et du test Behat pour les dates de publication des feuilles
1 parent 72956b3 commit 1e15807

File tree

9 files changed

+144
-1
lines changed

9 files changed

+144
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Migration\AbstractMigration;
6+
7+
final class SiteFeuilleDatesPublication extends AbstractMigration
8+
{
9+
public function change(): void
10+
{
11+
$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');
12+
}
13+
}

db/seeds/Feuilles.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,28 @@ public function run(): void
131131
'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.',
132132
'etat' => 1,
133133
],
134+
[
135+
'id_parent' => Feuille::ID_FEUILLE_HEADER,
136+
'nom' => 'Feuille publication passée',
137+
'lien' => '/feuille-publication-passee',
138+
'etat' => 1,
139+
'date_fin_publication' => strtotime('-1 day'),
140+
],
141+
[
142+
'id_parent' => Feuille::ID_FEUILLE_HEADER,
143+
'nom' => 'Feuille publication future',
144+
'lien' => '/feuille-publication-future',
145+
'etat' => 1,
146+
'date_debut_publication' => strtotime('+1 year'),
147+
],
148+
[
149+
'id_parent' => Feuille::ID_FEUILLE_HEADER,
150+
'nom' => 'Feuille publication courante',
151+
'lien' => '/feuille-publication-courante',
152+
'etat' => 1,
153+
'date_debut_publication' => strtotime('-1 year'),
154+
'date_fin_publication' => strtotime('+10 years'),
155+
],
134156
];
135157

136158
$data = array_merge($data, $this->prepareFeuilles($this->getFooter(), Feuille::ID_FEUILLE_FOOTER));

sources/AppBundle/Site/Form/SheetType.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,25 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
113113
],
114114
])
115115

116+
->add('publicationStart', DateType::class, [
117+
'required' => false,
118+
'label' => 'Date de début de publication',
119+
'input' => 'datetime',
120+
'years' => range(2001, date('Y') + 5),
121+
'constraints' => [
122+
new Assert\Type("datetime"),
123+
],
124+
])
125+
->add('publicationEnd', DateType::class, [
126+
'required' => false,
127+
'label' => 'Date de fin de publication',
128+
'input' => 'datetime',
129+
'years' => range(2001, date('Y') + 5),
130+
'constraints' => [
131+
new Assert\Type("datetime"),
132+
],
133+
])
134+
116135
->add('position', ChoiceType::class, [
117136
'required' => false,
118137
'label' => 'Position',

sources/AppBundle/Site/Model/Repository/SheetRepository.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ private function getActiveChildrenByParentIdBuilder(): SelectInterface
7373
* @var SelectInterface $queryBuilder
7474
*/
7575
$queryBuilder = $this->getQueryBuilder(self::QUERY_SELECT);
76-
$queryBuilder->cols(['*'])->from('afup_site_feuille')->where('id_parent = :parentId')->where('etat = 1');
76+
$queryBuilder->cols(['*'])
77+
->from('afup_site_feuille')
78+
->where('id_parent = :parentId')
79+
->where('etat = 1')
80+
->where('(date_debut_publication IS NULL OR date_debut_publication <= UNIX_TIMESTAMP())')
81+
->where('(date_fin_publication IS NULL OR date_fin_publication >= UNIX_TIMESTAMP())');
7782

7883
return $queryBuilder;
7984
}
@@ -135,6 +140,34 @@ public static function initMetadata(SerializerFactoryInterface $serializerFactor
135140
],
136141
],
137142
])
143+
->addField([
144+
'columnName' => 'date_debut_publication',
145+
'fieldName' => 'publicationStart',
146+
'type' => 'datetime',
147+
'serializer_options' => [
148+
'unserialize' => [
149+
'unSerializeUseFormat' => true,
150+
'format' => 'U',
151+
],
152+
'serialize' => [
153+
'format' => 'U',
154+
],
155+
],
156+
])
157+
->addField([
158+
'columnName' => 'date_fin_publication',
159+
'fieldName' => 'publicationEnd',
160+
'type' => 'datetime',
161+
'serializer_options' => [
162+
'unserialize' => [
163+
'unSerializeUseFormat' => true,
164+
'format' => 'U',
165+
],
166+
'serialize' => [
167+
'format' => 'U',
168+
],
169+
],
170+
])
138171
->addField([
139172
'columnName' => 'etat',
140173
'fieldName' => 'state',

sources/AppBundle/Site/Model/Sheet.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class Sheet implements NotifyPropertyInterface
2424
private ?int $position = null;
2525

2626
private ?DateTime $creationDate = null;
27+
private ?DateTime $publicationStart = null;
28+
private ?DateTime $publicationEnd = null;
29+
2730
private ?int $state = null;
2831
private ?string $image = null;
2932

@@ -116,6 +119,28 @@ public function setCreationDate(?DateTime $creationDate): void
116119
$this->creationDate = $creationDate;
117120
}
118121

122+
public function getPublicationStart(): ?DateTime
123+
{
124+
return $this->publicationStart;
125+
}
126+
127+
public function setPublicationStart(?DateTime $publicationStart): void
128+
{
129+
$this->propertyChanged('publicationStart', $this->publicationStart, $publicationStart);
130+
$this->publicationStart = $publicationStart;
131+
}
132+
133+
public function getPublicationEnd(): ?DateTime
134+
{
135+
return $this->publicationEnd;
136+
}
137+
138+
public function setPublicationEnd(?DateTime $publicationEnd): void
139+
{
140+
$this->propertyChanged('publicationEnd', $this->publicationEnd, $publicationEnd);
141+
$this->publicationEnd = $publicationEnd;
142+
}
143+
119144
public function getState(): ?int
120145
{
121146
return $this->state;

templates/admin/site/sheet_form.html.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
{% endif %}
3434
{{ form_row(form.imageAlt) }}
3535
{{ form_row(form.creationDate) }}
36+
{{ form_row(form.publicationStart) }}
37+
{{ form_row(form.publicationEnd) }}
3638
{{ form_row(form.position) }}
3739
{{ form_row(form.state) }}
3840
{{ form_row(form.patterns) }}

templates/admin/site/sheet_list.html.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
Nom
3434
</a>
3535
</th>
36+
<th>Début publication</th>
37+
<th>Fin publication</th>
3638
<th class="center aligned">
3739
<a href="{{ path('admin_site_rubriques_list', {'sort': 'etat' , 'direction' : ((direction == 'asc' and sort == 'date') ? 'desc': 'asc')}) }}">
3840
Etat
@@ -58,6 +60,8 @@
5860
<br/><img src="../../templates/site/images/{{ sheet.image }}" alt="{{ sheet.image_alt|default('') }}" width="125" />
5961
{% endif %}
6062
</td>
63+
<td>{% if sheet.date_debut_publication is not null %}{{ sheet.date_debut_publication|date('d-m-Y') }}{% endif %}</td>
64+
<td>{% if sheet.date_fin_publication is not null %}{{ sheet.date_fin_publication|date('d-m-Y') }}{% endif %}</td>
6165
<td class="center aligned">
6266
{% if sheet.etat == 1 %}
6367
<a class="ui orange label">En ligne</a>

tests/behat/features/Admin/Site/AdminSiteFeuilles.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ Feature: Administration - Partie Site
1313
And I am on "/admin/site/feuilles/delete/1/foo"
1414
Then the response status code should be 403
1515

16+
@reloadDbWithTestData
17+
Scenario: Ajout d'une feuille avec des dates de publication
18+
Given I am logged in as admin and on the Administration
19+
And I follow "Feuilles"
20+
When I follow "Ajouter"
21+
Then I should see "Ajouter une feuille"
22+
And I should see "Date de début de publication"
23+
And I should see "Date de fin de publication"
24+
And I fill in "sheet[name]" with "Feuille avec dates"
25+
And I fill in "sheet[link]" with "http://lien"
26+
And I fill in "sheet[publicationStart]" with "2026-03-01"
27+
And I fill in "sheet[publicationEnd]" with "2027-12-31"
28+
And I press "Ajouter"
29+
Then I should see "Liste des feuilles"
30+
And the ".content table" element should contain "01-03-2026"
31+
And the ".content table" element should contain "31-12-2027"
32+
1633
@reloadDbWithTestData
1734
Scenario: Ajout/modification/suppression d'une feuille
1835
Given I am logged in as admin and on the Administration
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Feature: Site Public - Feuilles
2+
3+
@reloadDbWithTestData
4+
Scenario: Les feuilles sont affichées selon leur date de publication
5+
Given I am on the homepage
6+
Then I should not see "Feuille publication passée"
7+
And I should not see "Feuille publication future"
8+
And I should see "Feuille publication courante"

0 commit comments

Comments
 (0)