Skip to content

Commit

Permalink
Fermetures exceptionnelles : améliorer l'affichage pour les fermeture…
Browse files Browse the repository at this point in the history
…s en cours (#986)

* Add ClosingException findOngoing query. Display if ongoing closing

* Widget: also show ongoing closing exceptions

* Additional fix to exclude ongoing from future & past queries
  • Loading branch information
raphodn authored Sep 12, 2023
1 parent 2a91700 commit 6da35a0
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 14 deletions.
6 changes: 6 additions & 0 deletions app/Resources/views/admin/closingexception/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
⚠️ Les créneaux étant générés à l'avance, il faut définir le jour de fermeture d'avantage en amont ⚠️
</div>

{% if closingExceptionsOngoing %}
<h4>Fermeture exceptionnelle en cours</h4>

{% include "admin/closingexception/_partial/table.html.twig" with { closingExceptions: [closingExceptionsOngoing] } %}
{% endif %}

<h4>Fermetures exceptionnelles à venir ({{ closingExceptionsFuture | length }})</h4>

{% if closingExceptionsFuture | length %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<span>-</span>
<strong>{{ closingException.date | date_fr_full }}</strong>
{% if closingException.reason %}<i>({{ closingException.reason }})</i>{% endif %}
{% if closingException.isOngoing %}
<span>[en cours]</span>
{% endif %}
</li>
{% endfor %}
</ul>
Expand Down
4 changes: 3 additions & 1 deletion src/AppBundle/Controller/AdminClosingExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function indexAction(Request $request)
$em = $this->getDoctrine()->getManager();

$closingExceptionsFuture = $em->getRepository('AppBundle:ClosingException')->findFutures();
$closingExceptionsPast = $em->getRepository('AppBundle:ClosingException')->findPast(10); # only the 10 last
$closingExceptionsOngoing = $em->getRepository('AppBundle:ClosingException')->findOngoing();
$closingExceptionsPast = $em->getRepository('AppBundle:ClosingException')->findPast(null, 10); # only the 10 last

$delete_forms = array();
foreach ($closingExceptionsFuture as $closingException) {
Expand All @@ -42,6 +43,7 @@ public function indexAction(Request $request)

return $this->render('admin/closingexception/index.html.twig', array(
'closingExceptionsFuture' => $closingExceptionsFuture,
'closingExceptionsOngoing' => $closingExceptionsOngoing,
'closingExceptionsPast' => $closingExceptionsPast,
'delete_forms' => $delete_forms
));
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Controller/ClosingExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function widgetAction(Request $request)

$filter_title = $request->query->has('title') ? ($request->get('title') == 1) : true;

$closingExceptions = $em->getRepository('AppBundle:ClosingException')->findFutures();
$closingExceptions = $em->getRepository('AppBundle:ClosingException')->findFuturesOrOngoing();

return $this->render('closingexception/_partial/widget.html.twig', [
'closingExceptions' => $closingExceptions,
Expand Down
4 changes: 2 additions & 2 deletions src/AppBundle/Controller/PeriodPositionFreeLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public function listAction(Request $request)
->orderBy('ppfl.' . $sort, $order);

if ($filter["created_at"]) {
$qb = $qb->andWhere("DATE_FORMAT(ppfl.createdAt, '%Y-%m-%d') = :created_at")
->setParameter('created_at', $filter['created_at']->format('Y-m-d'));
$qb = $qb->andWhere("DATE_FORMAT(ppfl.createdAt, '%Y-%m-%d') = :created_at_formatted")
->setParameter('created_at_formatted', $filter['created_at']->format('Y-m-d'));
}
if ($filter["beneficiary"]) {
$qb = $qb->andWhere('ppfl.beneficiary = :beneficiary')
Expand Down
8 changes: 4 additions & 4 deletions src/AppBundle/Controller/ShiftFreeLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ public function indexAction(Request $request)
->orderBy('sfl.' . $sort, $order);

if ($filter["created_at"]) {
$qb = $qb->andWhere("DATE_FORMAT(sfl.createdAt, '%Y-%m-%d') = :created_at")
->setParameter('created_at', $filter['created_at']->format('Y-m-d'));
$qb = $qb->andWhere("DATE_FORMAT(sfl.createdAt, '%Y-%m-%d') = :created_at_formatted")
->setParameter('created_at_formatted', $filter['created_at']->format('Y-m-d'));
}
if ($filter["shift_start_date"]) {
$qb = $qb->leftJoin('sfl.shift', 's')
->andWhere("DATE_FORMAT(s.start, '%Y-%m-%d') = :shift_start_date")
->setParameter('shift_start_date', $filter['shift_start_date']->format('Y-m-d'));
->andWhere("DATE_FORMAT(s.start, '%Y-%m-%d') = :shift_start_date_formatted")
->setParameter('shift_start_date_formatted', $filter['shift_start_date']->format('Y-m-d'));
}
if ($filter["beneficiary"]) {
$qb = $qb->andWhere('sfl.beneficiary = :beneficiary')
Expand Down
9 changes: 9 additions & 0 deletions src/AppBundle/Entity/ClosingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ public function getDate()
return $this->date;
}

/**
* @return boolean
*/
public function getIsOngoing()
{
$now = new \DateTime('now');
return ($this->date->format('Y-m-d') == $now->format('Y-m-d'));
}

public function setReason(?string $reason): self
{
$this->reason = $reason;
Expand Down
57 changes: 51 additions & 6 deletions src/AppBundle/Repository/ClosingExceptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ public function findAll()
return $this->findBy(array(), array('date' => 'DESC'));
}

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

$qb = $this->createQueryBuilder('ce')
->where('ce.date > :now')
->setParameter('now', new \Datetime('now'));
->where("ce.date > :date OR DATE_FORMAT(ce.date, '%Y-%m-%d') = :date_formatted")
->setParameter('date', $date)
->setParameter('date_formatted', $date->format('Y-m-d'));

$qb->orderBy('ce.date', 'ASC');

Expand All @@ -28,11 +33,51 @@ public function findFutures()
->getResult();
}

public function findPast(int $limit = null)
public function findFutures(\DateTime $date = null)
{
if (!$date) {
$date = new \DateTime('now');
}

$qb = $this->createQueryBuilder('ce')
->where('ce.date > :date')
->andWhere("DATE_FORMAT(ce.date, '%Y-%m-%d') != :date_formatted")
->setParameter('date', $date)
->setParameter('date_formatted', $date->format('Y-m-d'));

$qb->orderBy('ce.date', 'ASC');

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

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

$qb = $this->createQueryBuilder('ce')
->where("DATE_FORMAT(ce.date, '%Y-%m-%d') = :date")
->setParameter('date', $date->format('Y-m-d'));

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

public function findPast(\DateTime $date = null, int $limit = null)
{
if (!$date) {
$date = new \DateTime('now');
}

$qb = $this->createQueryBuilder('ce')
->where('ce.date < :now')
->setParameter('now', new \Datetime('now'));
->where('ce.date < :date')
->andWhere("DATE_FORMAT(ce.date, '%Y-%m-%d') != :date_formatted")
->setParameter('date', $date)
->setParameter('date_formatted', $date->format('Y-m-d'));

if ($limit) {
$qb->setMaxResults($limit);
Expand Down

0 comments on commit 6da35a0

Please sign in to comment.