Skip to content

Commit ee8f82f

Browse files
authored
Horaires d'ouverture : ajouter un badge à coté des horaires d'ouvertures actives (#987)
* Show badge if OpeningHour kind is enabled * Message if no OpeningHourKind * Add help text on field
1 parent 6da35a0 commit ee8f82f

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

app/Resources/views/admin/openinghour/index.html.twig

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313

1414
{% if openingHours %}
1515
<div class="row">
16-
{% for openingHourKind in openingHourKinds %}
17-
<div class="col m6">
18-
{% include "/admin/openinghour/kind/_partial/card.html.twig" with { openingHourKind: openingHourKind } %}
16+
{% if openingHourKinds | length %}
17+
{% for openingHourKind in openingHourKinds %}
18+
<div class="col m6">
19+
{% include "/admin/openinghour/kind/_partial/card.html.twig" with { openingHourKind: openingHourKind } %}
20+
</div>
21+
{% endfor %}
22+
{% else %}
23+
<div class="card-panel yellow lighten-3">
24+
Il faut aussi créer un type d'horaire d'ouverture, et y rattacher les horaires correspondantes :)
1925
</div>
20-
{% endfor %}
26+
{% endif %}
2127
</div>
2228
{% else %}
2329
<div class="card-panel yellow lighten-3">

app/Resources/views/admin/openinghour/kind/_partial/card.html.twig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
<div class="card-panel">
44
<p style="margin-top:0;text-align:center;">
55
{{ openingHourKind.name }}
6-
{% if openingHourKind.startDate and openingHourKind.endDate %}
7-
<br />
8-
<i>du {{ openingHourKind.startDate | date_fr_long }} au {{ openingHourKind.endDate | date_fr_long }}</i>
6+
{% if openingHourKind.enabled %}
7+
<span class="badge deep-purple white-text">Actif</span>
98
{% endif %}
109
</p>
10+
{% if openingHourKind.startDate and openingHourKind.endDate %}
11+
<p style="text-align:center;">
12+
<i>du {{ openingHourKind.startDate | date_fr_long }} au {{ openingHourKind.endDate | date_fr_long }}</i>
13+
</p>
14+
{% endif %}
1115
{% include "/admin/openinghour/_partial/table.html.twig" with { openingHours: openingHourKind.openingHours } %}
1216
</div>

app/Resources/views/admin/openinghour/kind/_partial/form.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<label>
1818
{{ form_widget(form.enabled) }}
1919
<span>{{ form.enabled.vars.label }}</span>
20+
<span class="helper-text" data-error="wrong" data-success="right">Nécessaire pour le bandeau Ouvert / Fermé</span>
2021
</label>
2122
</div>
2223

src/AppBundle/Repository/OpeningHourRepository.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,57 @@ public function findAll(OpeningHourKind $openingHourKind = null)
3333
->getQuery()
3434
->getResult();
3535
}
36+
37+
public function findOngoing(OpeningHourKind $openingHourKind = null)
38+
{
39+
$qb = $this->createQueryBuilder('oh')
40+
->leftJoin('oh.kind', 'ohk')
41+
->addSelect('ohk')
42+
->andwhere('ohk.enabled = 1');
43+
44+
if ($openingHourKind) {
45+
$qb
46+
->andwhere('oh.kind = :kind')
47+
->setParameter('kind', $openingHourKind);
48+
}
49+
50+
$qb
51+
->addOrderBy('ohk.id', 'ASC')
52+
->addOrderBy('oh.dayOfWeek', 'ASC')
53+
->addOrderBy('oh.start', 'ASC');
54+
55+
return $qb
56+
->getQuery()
57+
->getResult();
58+
}
59+
60+
public function findByDay(\DateTime $date, OpeningHourKind $openingHourKind = null, bool $openingHourKindEnabled = null)
61+
{
62+
$qb = $this->createQueryBuilder('oh')
63+
->leftJoin('oh.kind', 'ohk')
64+
->addSelect('ohk')
65+
->where('oh.dayOfWeek = :dayOfWeek')
66+
->setParameter('dayOfWeek', $date->format('N') - 1);
67+
68+
if ($openingHourKind) {
69+
$qb
70+
->andwhere('oh.kind = :kind')
71+
->setParameter('kind', $openingHourKind);
72+
}
73+
74+
if ($openingHourKindEnabled != null) {
75+
$qb
76+
->andwhere('ohk.enabled = :enabled')
77+
->setParameter('enabled', $openingHourKindEnabled);
78+
}
79+
80+
$qb
81+
->addOrderBy('ohk.id', 'ASC')
82+
->addOrderBy('oh.dayOfWeek', 'ASC')
83+
->addOrderBy('oh.start', 'ASC');
84+
85+
return $qb
86+
->getQuery()
87+
->getResult();
88+
}
3689
}

0 commit comments

Comments
 (0)