Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horaires d'ouverture : afficher un bandeau ouvert/fermé en fonction des données #886

Merged
merged 10 commits into from
Sep 13, 2023
11 changes: 8 additions & 3 deletions app/Resources/views/_partial/header.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
</nav>
</div>
{% endif %}
{% include "admin/openinghour/_partial/open_closed_surheader.html.twig" %}
<nav class="main-navigation" role="navigation" style="background-color: {{ main_color }}">
<div class="nav-wrapper container">
<a id="logo-container" href="{{ path('homepage') }}" class="brand-logo hide-on-med-and-down">{{ site_name }}</a>
<a id="logo-container" href="{{ path('homepage') }}" class="brand-logo hide-on-large-only">{{ project_name }}</a>
<a id="logo-container" href="{{ path('homepage') }}" class="brand-logo hide-on-med-and-down">
{{ site_name }}
</a>
<a id="logo-container" href="{{ path('homepage') }}" class="brand-logo hide-on-large-only">
{{ project_name }}
</a>
<ul id="nav-desktop" class="right hide-on-med-and-down">
{% if is_granted("ROLE_ADMIN_PANEL") %}
<li class="highlight">
Expand All @@ -44,7 +49,7 @@
{% endif %}
<li>
<a href="{{ path('fos_user_security_logout') }}">
<i class="material-icons small right">exit_to_app</i>
<i class="material-icons small">exit_to_app</i>
</a>
</li>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% if opening_hour_kind_service.hasEnabled %}
{% if opening_hour_service.isOpen %}
<span class="badge green white-text" style="font-family:'Raleway',sans-serif;float:unset;">Ouvert</span>
{% else %}
<span class="badge red white-text" style="font-family:'Raleway',sans-serif;float:unset;">Fermé</span>
{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% if opening_hour_kind_service.hasEnabled %}
<div class="wrapper center-align {% if opening_hour_service.isOpen %}green{% else %}red{% endif %}">
<div class="col s12">
{% if opening_hour_service.isOpen %}
<span class="white-text">Ouvert</span>
{% else %}
<span class="white-text">Fermé</span>
{% endif %}
</div>
</div>
{% endif %}
7 changes: 4 additions & 3 deletions app/Resources/views/card_reader/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

{% block beforecontainer %}
<nav class="main-navigation" role="navigation" style="background-color: {{ main_color }}">
<a id="logo-container" class="brand-logo hide-on-med-and-down" style="margin-left: 10px">Lecteur carte membre</a>
<div class="nav-wrapper" style="margin-right: 20px; font-size: 16px; font-weight: 600">
<ul class="right">
<div class="nav-wrapper">
<a id="logo-container" class="brand-logo hide-on-med-and-down" style="margin-left: 10px">Lecteur carte membre</a>
<ul class="right" style="margin-right:10px;">
<li>{{ date('now') | date_fr_full_with_time }}</li>
<li>{% include "admin/openinghour/_partial/open_closed_badge.html.twig" %}</li>
</ul>
</div>
</nav>
Expand Down
2 changes: 2 additions & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ twig:
shift_service: "@shift_service"
period_service: "@period_service"
time_log_service: "@time_log_service"
opening_hour_service: "@opening_hour_service"
opening_hour_kind_service: "@opening_hour_kind_service"

# Doctrine Configuration
doctrine:
Expand Down
6 changes: 6 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ services:
event_service:
class: AppBundle\Service\EventService
public: true
opening_hour_service:
class: AppBundle\Service\OpeningHourService
public: true
opening_hour_kind_service:
class: AppBundle\Service\OpeningHourKindService
public: true

search_user_form_helper:
class: AppBundle\Service\SearchUserFormHelper
Expand Down
5 changes: 5 additions & 0 deletions src/AppBundle/Repository/OpeningHourKindRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public function findAll()
{
return $this->findBy(array(), array('id' => 'ASC'));
}

public function findEnabled()
{
return $this->findBy(array('enabled' => 1));
}
}
12 changes: 8 additions & 4 deletions src/AppBundle/Repository/OpeningHourRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function findOngoing(OpeningHourKind $openingHourKind = null)
->getResult();
}

public function findByDay(\DateTime $date, OpeningHourKind $openingHourKind = null, bool $openingHourKindEnabled = null)
public function findByDay(\DateTime $date, OpeningHourKind $openingHourKind = null, bool $onlyOpeningHourKindEnabled = false, bool $excludeClosed = false)
{
$qb = $this->createQueryBuilder('oh')
->leftJoin('oh.kind', 'ohk')
Expand All @@ -71,10 +71,14 @@ public function findByDay(\DateTime $date, OpeningHourKind $openingHourKind = nu
->setParameter('kind', $openingHourKind);
}

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

if ($excludeClosed) {
$qb
->andwhere('oh.closed = 0');
}

$qb
Expand Down
23 changes: 23 additions & 0 deletions src/AppBundle/Service/OpeningHourKindService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace AppBundle\Service;

use DateTime;
use AppBundle\Entity\OpeningHour;
use Doctrine\ORM\EntityManagerInterface;

class OpeningHourKindService
{
protected $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

public function hasEnabled()
{
$openingHourKindEnabled = $this->em->getRepository('AppBundle:OpeningHourKind')->findEnabled();
return count($openingHourKindEnabled) > 0;
}
}
51 changes: 51 additions & 0 deletions src/AppBundle/Service/OpeningHourService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace AppBundle\Service;

use DateTime;
use AppBundle\Entity\OpeningHour;
use Doctrine\ORM\EntityManagerInterface;

class OpeningHourService
{
protected $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

public function isOpen(\DateTime $date = null)
{
if (!$date) {
$date = new \DateTime('now');
}

// filter on day
$openingHoursEnabledDay = $this->em->getRepository('AppBundle:OpeningHour')->findByDay($date, null, true, true);

// filter on time
if (count($openingHoursEnabledDay) > 0) {
$openingHoursEnabledDayTime = array_filter($openingHoursEnabledDay, function($openingHour) use ($date) {
$openingHourStart = $openingHour->getStart()->setDate($date->format('Y'), $date->format('m'), $date->format('d'));
$openingHourEnd = $openingHour->getEnd()->setDate($date->format('Y'), $date->format('m'), $date->format('d'));
return ($openingHourStart <= $date) && ($openingHourEnd >= $date);
});

// final check on closing exceptions
if (count($openingHoursEnabledDayTime) > 0) {
$closingExceptions = $this->em->getRepository('AppBundle:ClosingException')->findOngoing($date);
if (!$closingExceptions) {
return True;
}
}
}

return False;
}

public function isClosed(\DateTime $date = null)
{
return !$this->isOpen($date);
}
}
Loading