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 9734299
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 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 align != "left" %}style="text-align:center"{% endif %}>Horaires d'ouverture :</p>
{% endif %}
{% if align == "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 @@ -17,7 +17,7 @@
{{ form_errors(form) }}
</div>
<div class="row">
<div class="col s12">
<div class="col m6">
{{ form.title.vars.label }}
<div class="switch">
<label>
Expand All @@ -29,6 +29,12 @@
</div>
</div>
</div>
<div class="row">
<div class="col m6">
{{ form_label(form.align) }}
{{ form_widget(form.align) }}
</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
16 changes: 11 additions & 5 deletions src/AppBundle/Controller/OpeningHourController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

namespace AppBundle\Controller;


use AppBundle\Entity\OpeningHour;
use AppBundle\Form\OpeningHourType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
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;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;

/**
* OpeningHour controller
Expand All @@ -32,12 +31,14 @@ public function widgetAction(Request $request)
$em = $this->getDoctrine()->getManager();

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

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

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

Expand Down Expand Up @@ -165,13 +166,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) . '&align=' . $data['align'];

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

0 comments on commit 9734299

Please sign in to comment.