Skip to content

Commit

Permalink
Display as table or list
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Aug 4, 2023
1 parent 2c89208 commit 0411b2c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
19 changes: 19 additions & 0 deletions app/Resources/views/admin/openinghour/_partial/list.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% set openingHourJoinString = "&" %}

<ul>
{% set dayOfWeek = -1 %}
{% for openingHour in openingHours %}
{% if openingHour.dayOfWeek != dayOfWeek %}
{# close previous day #}
{% if loop.index > 0 %}</li>{% endif %}
{# open new day #}
<li>{{ openingHour.dayOfWeekString | capitalize }} :
{{ openingHour.start | time_short }}-{{ openingHour.end | time_short }}
{% else %}
{# continue existing day #}
{{ openingHourJoinString | raw }} {{ openingHour.start | time_short }}-{{ openingHour.end | time_short }}
{% endif %}
{% set dayOfWeek = openingHour.dayOfWeek %}
{% endfor %}
</li>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

{% block content %}
{% if title %}
Horaires d'ouverture :
<p {% if display != "left" %}style="text-align:center"{% endif %}>Horaires d'ouverture :</p>
{% endif %}
{% if display == "left" %}
{% include "/admin/openinghour/_partial/list.html.twig" with { openingHours: openingHours } %}
{% else %}
{% include "/admin/openinghour/_partial/table.html.twig" with { openingHours: openingHours } %}
{% endif %}
{% include "/admin/openinghour/_partial/table.html.twig" with { openingHours: openingHours } %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
</div>
</div>
</div>
<div class="row">
<div class="input-field col m3">
{{ form_widget(form.display) }}
{{ form_label(form.display) }}
</div>
</div>
<br />
{{ form_widget(form.generate, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
{{ form_end(form) }}
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Controller/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private function adminFilterFormFactory($em, Request $request): array
'required' => false,
'choices' => array_combine($years, $years),
'label' => 'Année',
'data' => $defaultYear,
'data' => $defaultYear,
'placeholder' => false,
))
->add('week', IntegerType::class, array(
Expand Down
12 changes: 10 additions & 2 deletions src/AppBundle/Controller/OpeningHourController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Form\Form;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Session\Session;
Expand All @@ -32,12 +33,14 @@ public function widgetAction(Request $request)
$em = $this->getDoctrine()->getManager();

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

$openingHours = $em->getRepository('AppBundle:OpeningHour')->findAll();

return $this->render('admin/openinghour/_partial/widget.html.twig', [
'openingHours' => $openingHours,
'title' => $filter_title
'title' => $filter_title,
'display' => $filter_display,
]);
}

Expand Down Expand Up @@ -165,13 +168,18 @@ public function widgetGeneratorAction(Request $request)
{
$form = $this->createFormBuilder()
->add('title', CheckboxType::class, array('required' => false, 'data' => true, 'label' => 'Afficher le titre du widget ?'))
->add('align', ChoiceType::class, array(
'label' => 'alignement',
'choices' => array('centré' => 'center', 'gauche' => 'left'),
'data' => 'center'
))
->add('generate', SubmitType::class, array('label' => 'Générer'))
->getForm();

if ($form->handleRequest($request)->isValid()) {
$data = $form->getData();

$widgetQueryString = 'title='.($data['title'] ? 1 : 0);
$widgetQueryString = 'title='.($data['title'] ? 1 : 0) . '&display=' . $data['display'];

return $this->render('admin/openinghour/widget_generator.html.twig', array(
'query_string' => $widgetQueryString,
Expand Down

0 comments on commit 0411b2c

Please sign in to comment.