-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Horaires d'ouverture : afficher un badge ouvert/fermé en fonction des…
… données (#886) * New OpeningHourService and OpeningHourKindService * New open_closed_badge template * Replace badge with header wrapper * Show header only if enabled kind * Add parameter to hide header: display_opening_hour_open_closed_header
- Loading branch information
Showing
11 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/Resources/views/admin/openinghour/_partial/open_closed_badge.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
13 changes: 13 additions & 0 deletions
13
app/Resources/views/admin/openinghour/_partial/open_closed_surheader.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% if display_opening_hour_open_closed_header %} | ||
{% 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 %} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |