Skip to content

Commit

Permalink
Pouvoir gérer une liste d'horaires d'ouvertures (elefan-grenoble#830)
Browse files Browse the repository at this point in the history
* OpeningHourController. Add templates. Add button on admin page

* Assert start < end. Order list by day & time

* rename to Horaires d'ouverture. rename listAction to indexAction

* Simple widget to display opening hours
  • Loading branch information
raphodn authored and OursDesCavernes committed Jan 20, 2024
1 parent 52ddb5e commit dcda2a0
Show file tree
Hide file tree
Showing 19 changed files with 646 additions and 26 deletions.
35 changes: 35 additions & 0 deletions app/DoctrineMigrations/Version20230423173822_opening_hour.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230423173822 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('CREATE TABLE opening_hour (id INT AUTO_INCREMENT NOT NULL, day_of_week SMALLINT NOT NULL, start TIME NOT NULL, end TIME NOT NULL, created_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('DROP TABLE opening_hour');
}
}
15 changes: 10 additions & 5 deletions app/Resources/views/admin/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@
</a>
{% endif %}

{% if is_granted("ROLE_ADMIN") %}
<h6><i class="material-icons">settings</i>&nbsp;Informations</h6>
<a href="{{ path("admin_openinghour_index") }}" class="waves-effect waves-light btn teal">
<i class="material-icons left">schedule</i>Horaires d'ouverture
</a>
<a href="{{ path("admin_socialnetwork_list") }}" class="waves-effect waves-light btn teal">
<i class="material-icons left">public</i>Réseaux sociaux
</a>
{% endif %}

{% if is_granted("ROLE_PROCESS_MANAGER") %}
<h6><i class="material-icons">content_paste</i>&nbsp;Contenus</h6>
<a href="{{ path("process_update_list") }}" class="waves-effect waves-light btn lime darken-1">
Expand All @@ -91,11 +101,6 @@
<a href="{{ path("email_template_list") }}" class="waves-effect waves-light btn teal">
<i class="material-icons left">mail</i>Modèles d'emails
</a>
{% if is_granted("ROLE_ADMIN") %}
<a href="{{ path("admin_socialnetwork_list") }}" class="waves-effect waves-light btn teal">
<i class="material-icons left">public</i>Réseaux sociaux
</a>
{% endif %}
{% endif %}

{% if is_granted("ROLE_FINANCE_MANAGER") %}
Expand Down
32 changes: 32 additions & 0 deletions app/Resources/views/admin/openinghour/_partial/form.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="errors">
{{ form_errors(form) }}
</div>
<div class="row">
<div class="col m4">
<div class="errors">
{{ form_errors(form.dayOfWeek) }}
</div>
<div class="input-field">
{{ form_widget(form.dayOfWeek) }}
{{ form_label(form.dayOfWeek) }}
</div>
</div>
<div class="col m4">
<div class="errors">
{{ form_errors(form.start) }}
</div>
<div class="input-field">
{{ form_widget(form.start) }}
{{ form_label(form.start) }}
</div>
</div>
<div class="col m4">
<div class="errors">
{{ form_errors(form.end) }}
</div>
<div class="input-field">
{{ form_widget(form.end) }}
{{ form_label(form.end) }}
</div>
</div>
</div>
22 changes: 22 additions & 0 deletions app/Resources/views/admin/openinghour/_partial/widget.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="card-panel">
<table style=" width: max-content; margin-top: 10px; margin-left: auto; margin-right: auto; border-collapse: separate; border-spacing: 10px 0px" class="no-padding">
<tbody>
{% set dayOfWeek = -1 %}
{% for openingHour in openingHours %}
{% if openingHour.dayOfWeek == dayOfWeek %}
& {{ openingHour.start | date('G\\hi') }}-{{ openingHour.end | date('G\\hi') }}
{% else %}
{# close previous day #}
{% if loop.index > 0 %}</td></tr>{% endif %}
{# open new day #}
<tr>
<td class="no-padding" style="text-align:right">{{ openingHour.dayOfWeekString | capitalize }} : </td>
<td class="no-padding">{{ openingHour.start | date('G\\hi') }}-{{ openingHour.end | date('G\\hi') }}
{% endif %}
{% set dayOfWeek = openingHour.dayOfWeek %}
{% endfor %}
</td>
</tr>
</tbody>
</table>
</div>
28 changes: 28 additions & 0 deletions app/Resources/views/admin/openinghour/edit.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'layout.html.twig' %}

{% block title %}Editer l'horaire d'ouverture - {{ site_name }}{% endblock %}

{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_openinghour_index') }}"><i class="material-icons">schedule</i>&nbsp;Horaires d'ouverture</a><i class="material-icons">chevron_right</i>
<i class="material-icons">edit</i>&nbsp;Editer
{% endblock %}

{% block content %}
<h4>Editer l'horaire d'ouverture</h4>

{{ form_start(form) }}
{% include "/admin/openinghour/_partial/form.html.twig" with { form: form } %}
<div>
<button type="submit" class="btn waves-effect waves-light"><i class="material-icons left">save</i>Enregistrer</button>
</div>
{{ form_end(form) }}

{{ form_start(delete_form) }}
{{ form_widget(delete_form) }}
<div>
<button type="submit" class="btn waves-effect waves-light red">Supprimer</button>
</div>
{{ form_end(delete_form) }}
{% endblock %}
57 changes: 57 additions & 0 deletions app/Resources/views/admin/openinghour/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% extends 'layout.html.twig' %}

{% block title %}Horaires d'ouverture - {{ site_name }}{% endblock %}

{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<i class="material-icons">schedule</i>&nbsp;Horaires d'ouverture
{% endblock %}

{% block content %}
<h4>Horaires d'ouverture</h4>

{% if openingHours %}
<div class="row">
<div class="col m6">
{% include "/admin/openinghour/_partial/widget.html.twig" with { openingHours: openingHours } %}
</div>
</div>
{% else %}
<div class="card-panel yellow lighten-3">
Aucune horaire d'ouverture à afficher.
</div>
{% endif %}

<h4>Liste des horaires d'ouverture ({{ openingHours | length }})</h4>

<table class="responsive-table">
<thead>
<tr>
<th>Jour d'ouverture</th>
<th>Heure de début</th>
<th>Heure de fin</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for openingHour in openingHours %}
<tr>
<td>{{ openingHour.dayOfWeekString | capitalize }}</td>
<td>{{ openingHour.start | date('H:i') }}</td>
<td>{{ openingHour.end | date('H:i') }}</td>
<td>
<a href="{{ path("admin_openinghour_edit", { 'id': openingHour.id }) }}">
<i class="material-icons">edit</i>editer
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>

<br />
<a href="{{ path('admin_openinghour_new') }}" class="btn">
<i class="material-icons left">add</i>Ajouter une horaire d'ouverture
</a>
{% endblock %}
21 changes: 21 additions & 0 deletions app/Resources/views/admin/openinghour/new.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'layout.html.twig' %}

{% block title %}Ajouter une horaire d'ouverture - {{ site_name }}{% endblock %}

{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_openinghour_index') }}"><i class="material-icons">schedule</i>&nbsp;Horaires d'ouverture</a><i class="material-icons">chevron_right</i>
<i class="material-icons">add</i>&nbsp;Ajouter
{% endblock %}

{% block content %}
<h4>Nouvelle horaire d'ouverture</h4>

{{ form_start(form) }}
{% include "/admin/openinghour/_partial/form.html.twig" with { form: form } %}
<div>
<button type="submit" class="btn waves-effect waves-light">Créer</button>
</div>
{{ form_end(form) }}
{% endblock %}
2 changes: 1 addition & 1 deletion app/Resources/views/admin/service/new.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h4>Nouveau service</h4>

{{ form_start(form) }}
{% include "/admin/service/_form.html.twig" with { form: form } %}
{% include "/admin/service/_form.html.twig" with { form: form } %}
<div>
<button type="submit" class="btn waves-effect waves-light">Créer</button>
</div>
Expand Down
3 changes: 3 additions & 0 deletions app/Resources/views/admin/socialnetwork/_form.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<div class="errors">
{{ form_errors(form) }}
</div>
<div class="row">
<div class="col s12">
<div class="errors">
Expand Down
2 changes: 1 addition & 1 deletion app/Resources/views/admin/socialnetwork/new.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h4>Nouveau réseau social</h4>

{{ form_start(form) }}
{% include "/admin/socialnetwork/_form.html.twig" with { form: form } %}
{% include "/admin/socialnetwork/_form.html.twig" with { form: form } %}
<div>
<button type="submit" class="btn waves-effect waves-light">Créer</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="card center">
<div class="card-content">
<span class="card-title">
{{ period_position.period.getDayOfWeekString() }} de {{ period_position.period.start | date('H:i') }} à {{ period_position.period.end | date('H:i') }}
{{ period_position.period.dayOfWeekString }} de {{ period_position.period.start | date('H:i') }} à {{ period_position.period.end | date('H:i') }}
<br />
<small>(Semaine {{ period_position.weekCycle }})</small>
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Controller/CommissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function removeBeneficiaryAction(Request $request,Commission $commission)
* @Route("/{id}", name="commission_delete", methods={"DELETE"})
* @Security("has_role('ROLE_SUPER_ADMIN')")
*/
public function removeAction(Request $request,Commission $commission)
public function deleteAction(Request $request,Commission $commission)
{
$session = new Session();
$form = $this->getDeleteForm($commission);
Expand Down
Loading

0 comments on commit dcda2a0

Please sign in to comment.