From 8626387473b85af790effaf18e09c02d2443d77f Mon Sep 17 00:00:00 2001 From: Joshua Date: Fri, 4 Apr 2025 14:18:09 +0200 Subject: [PATCH] Ajout calendrier + modif controller / css sur plats pour ressembler a un menu --- public/css/Plats/plats.css | 120 ++++++++++++++++++ .../css/Reservations/reservationCalendar.css | 36 ++++++ src/Controller/ReservationsController.php | 27 +++- src/Entity/Reservations.php | 2 +- src/Entity/Tables.php | 4 +- src/Form/ReservationsType.php | 2 +- src/Repository/ReservationsRepository.php | 15 +++ templates/base.html.twig | 3 +- templates/plats/index.html.twig | 2 +- templates/reservations/index.html.twig | 67 +++++----- templates/reservations/new.html.twig | 2 +- 11 files changed, 241 insertions(+), 39 deletions(-) create mode 100644 public/css/Plats/plats.css create mode 100644 public/css/Reservations/reservationCalendar.css diff --git a/public/css/Plats/plats.css b/public/css/Plats/plats.css new file mode 100644 index 0000000..16d7225 --- /dev/null +++ b/public/css/Plats/plats.css @@ -0,0 +1,120 @@ +/* Table styles */ +table { + width: 100%; + border-collapse: collapse; + margin-bottom: 20px; + background-color: #fafafa; + font-family: 'Arial', sans-serif; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + border-radius: 10px; + overflow: hidden; +} + +/* Table headers */ +table th, table td { + padding: 15px; + text-align: left; + border: 1px solid #e1e1e1; +} + +table th { + background-color: #d9534f; + color: white; + font-weight: bold; + text-transform: uppercase; + letter-spacing: 1px; +} + +/* Even rows */ +table tr:nth-child(even) { + background-color: #f8f8f8; +} + +/* Row hover effect */ +table tr:hover { + background-color: #f1f1f1; + cursor: pointer; +} + +/* Action links */ +a { + text-decoration: none; + color: #d9534f; + font-weight: bold; + transition: color 0.3s ease; +} + +a:hover { + color: #fff; + text-decoration: underline; +} + +/* New client button */ +a[href*="app_clients_new"] { + display: inline-block; + margin-top: 20px; + padding: 12px 25px; + background-color: #28a745; + color: white; + border-radius: 8px; + font-size: 16px; + text-align: center; + transition: background-color 0.3s ease, transform 0.2s ease; +} + +a[href*="app_clients_new"]:hover { + background-color: #218838; + transform: scale(1.05); +} + +/* Empty table row message */ +table td[colspan="6"] { + text-align: center; + font-style: italic; + color: #999; + padding: 20px; + font-size: 18px; +} + +/* Button container */ +.btn-container { + display: flex; + justify-content: center; + margin-bottom: 20px; +} + +/* Button styles */ +.btn { + padding: 10px 20px; + text-decoration: none; + color: white; + background-color: #d9534f; + border-radius: 8px; + font-weight: bold; + margin-top: 25px; + text-transform: uppercase; + letter-spacing: 1px; + transition: background-color 0.3s ease, transform 0.2s ease; +} + +.btn:hover { + background-color: #c9302c; + transform: scale(1.05); +} + +/* For card-like container around the table */ +.card { + background-color: #fff; + padding: 20px; + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15); + border-radius: 15px; + margin-bottom: 30px; +} + +/* Card title */ +.card h2 { + font-size: 24px; + color: #333; + margin-bottom: 15px; + font-family: 'Roboto', sans-serif; +} diff --git a/public/css/Reservations/reservationCalendar.css b/public/css/Reservations/reservationCalendar.css new file mode 100644 index 0000000..d045ab1 --- /dev/null +++ b/public/css/Reservations/reservationCalendar.css @@ -0,0 +1,36 @@ +.calendar { + display: flex; + flex-direction: column; +} + +.calendar-header { + display: flex; +} + +.calendar-day { + flex: 1; + text-align: center; + font-weight: bold; + padding: 10px; + border: 1px solid #ddd; +} + +.calendar-body { + display: flex; +} + +.calendar-column { + flex: 1; + min-height: 400px; + border: 1px solid #ddd; + padding: 5px; + position: relative; +} + +.reservation { + margin: 5px 0; + padding: 5px; + border-radius: 5px; + font-size: 14px; + text-align: center; +} diff --git a/src/Controller/ReservationsController.php b/src/Controller/ReservationsController.php index b0287fd..8a9ec8b 100644 --- a/src/Controller/ReservationsController.php +++ b/src/Controller/ReservationsController.php @@ -33,7 +33,7 @@ final class ReservationsController extends AbstractController $entityManager->persist($reservation); $entityManager->flush(); - return $this->redirectToRoute('app_reservations_index', [], Response::HTTP_SEE_OTHER); + return $this->redirectToRoute('calendar_week', [], Response::HTTP_SEE_OTHER); } return $this->render('reservations/new.html.twig', [ @@ -71,4 +71,29 @@ final class ReservationsController extends AbstractController return $this->redirectToRoute('app_reservations_index', [], Response::HTTP_SEE_OTHER); } + + #[Route('/calendar/{year}/{week}', name: 'calendar_week', requirements: ['year' => '\d+', 'week' => '\d+'])] + public function calendar(ReservationsRepository $reservationsRepository, int $year = null, int $week = null): Response + { + if ($year === null || $week === null) { + $currentDate = new \DateTime(); + $year = (int) $currentDate->format('Y'); + $week = (int) $currentDate->format('W'); + } + + setlocale(LC_TIME, 'fr_FR.UTF-8'); + $startDate = new \DateTime(); + $startDate->setISODate($year, $week); + $endDate = (clone $startDate)->modify('+6 days'); + + $reservations = $reservationsRepository->findByDateRange($startDate, $endDate); + +// dd($reservations); + + return $this->render('reservations/index.html.twig', [ + 'reservations' => $reservations, + 'startDate' => $startDate, // Passe startDate + 'endDate' => $endDate, // Passe endDate + ]); + } } diff --git a/src/Entity/Reservations.php b/src/Entity/Reservations.php index 757d358..9dbc8e2 100644 --- a/src/Entity/Reservations.php +++ b/src/Entity/Reservations.php @@ -70,7 +70,7 @@ class Reservations return $this->tables; } - public function setTable(?Tables $tables): static + public function setTables(?Tables $tables): static { $this->tables = $tables; diff --git a/src/Entity/Tables.php b/src/Entity/Tables.php index 762528e..ce68a84 100644 --- a/src/Entity/Tables.php +++ b/src/Entity/Tables.php @@ -94,7 +94,7 @@ class Tables { if (!$this->reservations->contains($reservation)) { $this->reservations->add($reservation); - $reservation->setTable($this); + $reservation->setTables($this); } return $this; @@ -105,7 +105,7 @@ class Tables if ($this->reservations->removeElement($reservation)) { // set the owning side to null (unless already changed) if ($reservation->getTables() === $this) { - $reservation->setTable(null); + $reservation->setTables(null); } } diff --git a/src/Form/ReservationsType.php b/src/Form/ReservationsType.php index d6b4e99..4a2bc09 100644 --- a/src/Form/ReservationsType.php +++ b/src/Form/ReservationsType.php @@ -25,7 +25,7 @@ class ReservationsType extends AbstractType ]) ->add('utilisateurs', EntityType::class, [ 'class' => Utilisateurs::class, - 'choice_label' => 'id', + 'choice_label' => 'prenom', 'multiple' => true, 'expanded' => true, ]) diff --git a/src/Repository/ReservationsRepository.php b/src/Repository/ReservationsRepository.php index 67fb065..237c8af 100644 --- a/src/Repository/ReservationsRepository.php +++ b/src/Repository/ReservationsRepository.php @@ -40,4 +40,19 @@ class ReservationsRepository extends ServiceEntityRepository // ->getOneOrNullResult() // ; // } + +// src/Repository/ReservationRepository.php + + public function findByDateRange(\DateTime $startDate, \DateTime $endDate): array + { + return $this->createQueryBuilder('r') + ->where('r.DateHeure BETWEEN :start AND :end') + ->setParameter('start', $startDate->format('Y-m-d 00:00:00')) + ->setParameter('end', $endDate->format('Y-m-d 23:59:59')) + ->orderBy('r.DateHeure', 'ASC') + ->getQuery() + ->getResult(); + } + + } diff --git a/templates/base.html.twig b/templates/base.html.twig index f85d77c..1e9a86e 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -15,6 +15,7 @@ + {% endblock %} {# {% block javascripts %}#} @@ -100,7 +101,7 @@
  • - + {{ ux_icon('fluent-mdl2:reservation-orders') }} Réservation diff --git a/templates/plats/index.html.twig b/templates/plats/index.html.twig index 9ca141c..025f1ba 100644 --- a/templates/plats/index.html.twig +++ b/templates/plats/index.html.twig @@ -13,7 +13,7 @@ {% block stylesheets %} - + {% endblock %} diff --git a/templates/reservations/index.html.twig b/templates/reservations/index.html.twig index b0ac723..74602b0 100644 --- a/templates/reservations/index.html.twig +++ b/templates/reservations/index.html.twig @@ -13,45 +13,50 @@ {% block stylesheets %} + {% endblock %} {% block container_modal %}
    -

    Reservations index

    +

    Calendrier de la semaine du {{ startDate|date('d/m/Y') }} au {{ endDate|date('d/m/Y') }}

    - - - - - - - - - - - {% for reservation in reservations %} - - - - - - - {% else %} - - - - {% endfor %} - -
    IdDateHeureNb_de_prsnactions
    {{ reservation.id }}{{ reservation.DateHeure ? reservation.DateHeure|date('Y-m-d H:i:s') : '' }}{{ reservation.NbDePrsn }} -
    - - {{ include('reservations/_delete_form.html.twig') }} -
    - Modifier -
    Aucun enregistrement trouvé
    + + Semaine précédente + + + Semaine suivante + +
    +
    + {% for i in 0..6 %} +
    + {{ (startDate|date_modify("+" ~ i ~ " days"))|date('D d/m') }} +
    + {% endfor %} +
    +
    + {% for i in 0..6 %} +
    + {% set currentDate = startDate|date_modify("+" ~ i ~ " days") %} + + {% for reservation in reservations %} + {% set res_date = reservation.dateHeure|date('Y-m-d') %} + {% set res_time = reservation.dateHeure|date('H:i') %} + + {% if res_date == currentDate|date('Y-m-d') %} +
    + {{ res_time }} - {{ reservation.nbdeprsn }} pers. +
    + {% endif %} + {% endfor %} +
    + {% endfor %} +
    +
    Créer une réservation +
    {% endblock %} diff --git a/templates/reservations/new.html.twig b/templates/reservations/new.html.twig index 3a8a5b7..b1f6e39 100644 --- a/templates/reservations/new.html.twig +++ b/templates/reservations/new.html.twig @@ -24,6 +24,6 @@ {{ include('reservations/_form.html.twig') }} - Retour à la liste + Retour à la liste {% endblock %}