Skip to content

Commit

Permalink
Horaires d'ouverture : ajouter un badge à coté des horaires d'ouvertu…
Browse files Browse the repository at this point in the history
…res actives (#987)

* Show badge if OpeningHour kind is enabled

* Message if no OpeningHourKind

* Add help text on field
  • Loading branch information
raphodn authored Sep 12, 2023
1 parent 6da35a0 commit ee8f82f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 7 deletions.
14 changes: 10 additions & 4 deletions app/Resources/views/admin/openinghour/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@

{% if openingHours %}
<div class="row">
{% for openingHourKind in openingHourKinds %}
<div class="col m6">
{% include "/admin/openinghour/kind/_partial/card.html.twig" with { openingHourKind: openingHourKind } %}
{% if openingHourKinds | length %}
{% for openingHourKind in openingHourKinds %}
<div class="col m6">
{% include "/admin/openinghour/kind/_partial/card.html.twig" with { openingHourKind: openingHourKind } %}
</div>
{% endfor %}
{% else %}
<div class="card-panel yellow lighten-3">
Il faut aussi créer un type d'horaire d'ouverture, et y rattacher les horaires correspondantes :)
</div>
{% endfor %}
{% endif %}
</div>
{% else %}
<div class="card-panel yellow lighten-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
<div class="card-panel">
<p style="margin-top:0;text-align:center;">
{{ openingHourKind.name }}
{% if openingHourKind.startDate and openingHourKind.endDate %}
<br />
<i>du {{ openingHourKind.startDate | date_fr_long }} au {{ openingHourKind.endDate | date_fr_long }}</i>
{% if openingHourKind.enabled %}
<span class="badge deep-purple white-text">Actif</span>
{% endif %}
</p>
{% if openingHourKind.startDate and openingHourKind.endDate %}
<p style="text-align:center;">
<i>du {{ openingHourKind.startDate | date_fr_long }} au {{ openingHourKind.endDate | date_fr_long }}</i>
</p>
{% endif %}
{% include "/admin/openinghour/_partial/table.html.twig" with { openingHours: openingHourKind.openingHours } %}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<label>
{{ form_widget(form.enabled) }}
<span>{{ form.enabled.vars.label }}</span>
<span class="helper-text" data-error="wrong" data-success="right">Nécessaire pour le bandeau Ouvert / Fermé</span>
</label>
</div>

Expand Down
53 changes: 53 additions & 0 deletions src/AppBundle/Repository/OpeningHourRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,57 @@ public function findAll(OpeningHourKind $openingHourKind = null)
->getQuery()
->getResult();
}

public function findOngoing(OpeningHourKind $openingHourKind = null)
{
$qb = $this->createQueryBuilder('oh')
->leftJoin('oh.kind', 'ohk')
->addSelect('ohk')
->andwhere('ohk.enabled = 1');

if ($openingHourKind) {
$qb
->andwhere('oh.kind = :kind')
->setParameter('kind', $openingHourKind);
}

$qb
->addOrderBy('ohk.id', 'ASC')
->addOrderBy('oh.dayOfWeek', 'ASC')
->addOrderBy('oh.start', 'ASC');

return $qb
->getQuery()
->getResult();
}

public function findByDay(\DateTime $date, OpeningHourKind $openingHourKind = null, bool $openingHourKindEnabled = null)
{
$qb = $this->createQueryBuilder('oh')
->leftJoin('oh.kind', 'ohk')
->addSelect('ohk')
->where('oh.dayOfWeek = :dayOfWeek')
->setParameter('dayOfWeek', $date->format('N') - 1);

if ($openingHourKind) {
$qb
->andwhere('oh.kind = :kind')
->setParameter('kind', $openingHourKind);
}

if ($openingHourKindEnabled != null) {
$qb
->andwhere('ohk.enabled = :enabled')
->setParameter('enabled', $openingHourKindEnabled);
}

$qb
->addOrderBy('ohk.id', 'ASC')
->addOrderBy('oh.dayOfWeek', 'ASC')
->addOrderBy('oh.start', 'ASC');

return $qb
->getQuery()
->getResult();
}
}

0 comments on commit ee8f82f

Please sign in to comment.