Skip to content

Commit

Permalink
Fix ordering, display
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Sep 7, 2023
1 parent 36ae029 commit 47eb348
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{% set openingHourJoinString = "&" %}

<div class="card-panel">
<p style="margin-top:0;text-align:center;">{{ openingHourKind.name }}</p>
<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>
{% endif %}
</p>
{% include "/admin/openinghour/_partial/table.html.twig" with { openingHours: openingHourKind.openingHours } %}
</div>
3 changes: 2 additions & 1 deletion app/Resources/views/openinghour/_partial/widget.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<p style="margin-top:0;{% if align != "left" %}text-align:center;"{% endif %}>
{{ openingHourKind.name }}
{% if openingHourKind.startDate and openingHourKind.endDate %}
(du {{ openingHourKind.startDate | date_fr_long }} au {{ openingHourKind.endDate | date_fr_long }})
<br />
<i>du {{ openingHourKind.startDate | date_fr_long }} au {{ openingHourKind.endDate | date_fr_long }}
{% endif %}
</p>
{% endif %}
Expand Down
18 changes: 7 additions & 11 deletions src/AppBundle/Controller/AdminOpeningHourController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,18 @@ public function editAction(Request $request, OpeningHour $openingHour)
$form = $this->createForm(OpeningHourType::class, $openingHour);
$form->handleRequest($request);

$closed = $form->get('closed');
$closed = $form->get('closed')->getData();

if ($request->isMethod('GET')) {
if (!$closed) {
$form->get('start')->setData($openingHour->getStart()->format('H:i'));
$form->get('end')->setData($openingHour->getEnd()->format('H:i'));
}
$form->get('start')->setData($closed ? null : $openingHour->getStart()->format('H:i'));
$form->get('end')->setData($closed ? null : $openingHour->getEnd()->format('H:i'));
}

if ($form->isSubmitted() && $form->isValid()) {
if (!$closed) {
$start = $form->get('start')->getData();
$openingHour->setStart(new \DateTime($start));
$end = $form->get('end')->getData();
$openingHour->setEnd(new \DateTime($end));
}
$start = $form->get('start')->getData();
$end = $form->get('end')->getData();
$openingHour->setStart($closed ? null : new \DateTime($start));
$openingHour->setEnd($closed ? null : new \DateTime($end));

$em->persist($openingHour);
$em->flush();
Expand Down
2 changes: 2 additions & 0 deletions src/AppBundle/Entity/OpeningHourKind.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\OrderBy;
use Symfony\Component\Validator\Constraints as Assert;

/**
Expand Down Expand Up @@ -55,6 +56,7 @@ class OpeningHourKind

/**
* @ORM\OneToMany(targetEntity="OpeningHour", mappedBy="kind", cascade={"persist"})
* @OrderBy({"dayOfWeek" = "ASC", "start" = "ASC"})
*/
private $openingHours;

Expand Down
1 change: 0 additions & 1 deletion src/AppBundle/Form/OpeningHourType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
))
->add('closed', CheckboxType::class, array(
'required' => false,
'data' => false,
'label' => 'Fermé ?',
'attr' => array('class' => 'filled-in')
))
Expand Down

0 comments on commit 47eb348

Please sign in to comment.