This commit is contained in:
ExostFlash 2023-11-29 14:58:03 +01:00
parent 0a96aa5cbd
commit 10e297e1e4
12 changed files with 417 additions and 45 deletions

View file

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231129091443 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->addSql('CREATE TABLE resa (id INT AUTO_INCREMENT NOT NULL, id_resto INT NOT NULL, id_user INT NOT NULL, nb_user INT NOT NULL, jour DATE NOT NULL, heur TIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE resa');
}
}

View file

@ -3,7 +3,9 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\Ticket; use App\Entity\Ticket;
use App\Entity\Resa;
use App\Form\Ticket2Type; use App\Form\Ticket2Type;
use App\Form\ResaUserType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
@ -71,10 +73,27 @@ class HomeController extends AbstractController
} }
#[Route('/resa/{idresto}', name: 'app_home_resa')] #[Route('/resa/{idresto}', name: 'app_home_resa')]
public function resa(): Response public function resas($idresto, Request $request, EntityManagerInterface $entityManager): Response
{ {
return $this->render('home/resa.html.twig', [ $id_user = $this->id_user;
'controller_name' => 'Home',
$resa = new Resa();
$resa->setIdUser($id_user);
$resa->setIdResto($idresto);
$form = $this->createForm(ResaUserType::class, $resa);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($resa);
$entityManager->flush();
return $this->redirectToRoute('app_home', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('home/resa.html.twig', [
'resa' => $resa,
'form' => $form,
]); ]);
} }

View file

@ -4,7 +4,10 @@ namespace App\Controller;
use App\Entity\Resa; use App\Entity\Resa;
use App\Form\ResaType; use App\Form\ResaType;
use Symfony\Component\Security\Core\Security;
use App\Repository\ResaRepository; use App\Repository\ResaRepository;
use App\Repository\UserRepository;
use App\Repository\RestoRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -14,11 +17,117 @@ use Symfony\Component\Routing\Annotation\Route;
#[Route('/service/resa')] #[Route('/service/resa')]
class ResaServiceController extends AbstractController class ResaServiceController extends AbstractController
{ {
private $id_resto;
private $id_user;
private $userRepository;
private $restoRepository;
private $role_user;
public function __construct(userRepository $userRepository, restoRepository $restoRepository, Security $security)
{
$utilisateur = $security->getUser();
$email_user = $utilisateur->getUserIdentifier();
$user = $userRepository->findOneBy(['email' => $email_user]);
$role_user = $user->getGrade();
$id_resto = $user->getIdResto();
$id_user = $user->getId();
$this->role_user = $role_user;
$this->id_resto = $id_resto;
$this->id_user = $id_user;
$this->userRepository = $userRepository;
$this->restoRepository = $restoRepository;
}
#[Route('/', name: 'app_resa_service_index', methods: ['GET'])] #[Route('/', name: 'app_resa_service_index', methods: ['GET'])]
public function index(ResaRepository $resaRepository): Response public function index(ResaRepository $resaRepository): Response
{ {
// Obtenez la date d'aujourd'hui
$today = new \DateTime('today');
if ($this->role_user != 'Root') {
$resasDuJour = $resaRepository->findBy([
'jour' => $today,
'id_resto' => $this->id_resto,
]);
} else {
$resasDuJour = $resaRepository->findBy([
'jour' => $today,
]);
}
$users = [];
foreach ($resasDuJour as $resa) {
$userId = $resa->getIdUser();
$user = $this->userRepository->find($userId);
if ($user !== null) {
$users[$userId] = $user;
}
}
return $this->render('resa_service/index.html.twig', [ return $this->render('resa_service/index.html.twig', [
'resas' => $resaRepository->findAll(), 'resas' => $resasDuJour,
'j1' => $today->modify('+1 day'),
'users' => $users,
]);
}
#[Route('/jour/{datej}', name: 'app_resa_service_jour', methods: ['GET'])]
public function byjour($datej, ResaRepository $resaRepository): Response
{
$today = \DateTime::createFromFormat('Y-m-d', $datej);;
if ($this->role_user != 'Root') {
$resasDuJour = $resaRepository->findBy([
'jour' => $today,
'id_resto' => $this->id_resto,
]);
} else {
$resasDuJour = $resaRepository->findBy([
'jour' => $today,
]);
}
$users = [];
foreach ($resasDuJour as $resa) {
$userId = $resa->getIdUser();
$user = $this->userRepository->find($userId);
if ($user !== null) {
$users[$userId] = $user;
}
}
return $this->render('resa_service/index.html.twig', [
'resas' => $resasDuJour,
'j1' => $today->modify('+1 day'),
'users' => $users,
]);
}
#[Route('/new', name: 'app_resa_service_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$id_user = $this->id_user;
$resa = new Resa();
$resa->setIdUser($id_user);
$form = $this->createForm(ResaType::class, $resa);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($resa);
$entityManager->flush();
return $this->redirectToRoute('app_resa_service_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('resa_service/new.html.twig', [
'resa' => $resa,
'form' => $form,
]); ]);
} }

View file

@ -17,11 +17,17 @@ class Resa
#[ORM\Column] #[ORM\Column]
private ?int $id_resto = null; private ?int $id_resto = null;
#[ORM\Column]
private ?int $id_user = null;
#[ORM\Column] #[ORM\Column]
private ?int $nb_user = null; private ?int $nb_user = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)] #[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $date_heur = null; private ?\DateTimeInterface $jour = null;
#[ORM\Column(type: Types::TIME_MUTABLE)]
private ?\DateTimeInterface $heur = null;
public function getId(): ?int public function getId(): ?int
{ {
@ -40,6 +46,18 @@ class Resa
return $this; return $this;
} }
public function getIdUser(): ?int
{
return $this->id_user;
}
public function setIdUser(int $id_user): static
{
$this->id_user = $id_user;
return $this;
}
public function getNbUser(): ?int public function getNbUser(): ?int
{ {
return $this->nb_user; return $this->nb_user;
@ -52,14 +70,26 @@ class Resa
return $this; return $this;
} }
public function getDateHeur(): ?\DateTimeInterface public function getJour(): ?\DateTimeInterface
{ {
return $this->date_heur; return $this->jour;
} }
public function setDateHeur(\DateTimeInterface $date_heur): static public function setJour(\DateTimeInterface $jour): static
{ {
$this->date_heur = $date_heur; $this->jour = $jour;
return $this;
}
public function getHeur(): ?\DateTimeInterface
{
return $this->heur;
}
public function setHeur(\DateTimeInterface $heur): static
{
$this->heur = $heur;
return $this; return $this;
} }

View file

@ -6,6 +6,13 @@ use App\Entity\Resa;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Validator\Constraints\Range;
class ResaType extends AbstractType class ResaType extends AbstractType
{ {
@ -13,8 +20,56 @@ class ResaType extends AbstractType
{ {
$builder $builder
->add('id_resto') ->add('id_resto')
->add('nb_user') ->add('id_user', HiddenType::class, [
->add('date_heur'); 'disabled' => true, // Désactive le champ
'data' => $options['data']->getIdUser() // Remplacez $valeurSpecifique par la valeur souhaitée
])
->add('nb_user', IntegerType::class, [
'attr' => [
'min' => 1,
'max' => 10,
'placeholder' => 'Nombre de personnes (entre 1 et 10)',
],
'constraints' => [
new NotBlank(['message' => 'Veuillez choisir un nombre de personnes.']),
new Range([
'min' => 1,
'max' => 10,
'minMessage' => 'Le nombre minimum de personnes est {{ limit }}.',
'maxMessage' => 'Le nombre maximum de personnes est {{ limit }}.',
]),
],
])
->add('jour', DateType::class, [
'widget' => 'single_text',
'html5' => false,
'attr' => ['class' => 'datepicker', 'placeholder' => 'Format date : AAAA-MM-JJ'],
'constraints' => [
new \Symfony\Component\Validator\Constraints\GreaterThanOrEqual([
'value' => 'today',
'message' => 'Vous ne pouvez pas choisir une date passée.',
]),
],
])
->add('heur', ChoiceType::class, [
'choices' => [
'12:00' => new \DateTime('12:00:00'),
'12:15' => new \DateTime('12:15:00'),
'12:30' => new \DateTime('12:30:00'),
'12:45' => new \DateTime('12:45:00'),
'13:00' => new \DateTime('13:00:00'),
'19:00' => new \DateTime('19:00:00'),
'19:15' => new \DateTime('19:15:00'),
'19:30' => new \DateTime('19:30:00'),
'19:45' => new \DateTime('19:45:00'),
'20:00' => new \DateTime('20:00:00'),
'20:15' => new \DateTime('20:15:00'),
'20:30' => new \DateTime('20:30:00'),
'20:45' => new \DateTime('20:45:00'),
'21:00' => new \DateTime('21:00:00'),
],
'placeholder' => 'Choisissez une heure',
]);
} }
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void

84
src/Form/ResaUserType.php Normal file
View file

@ -0,0 +1,84 @@
<?php
namespace App\Form;
use App\Entity\Resa;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Validator\Constraints\Range;
class ResaUserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('id_resto', HiddenType::class, [
'disabled' => true, // Désactive le champ
'data' => $options['data']->getIdResto() // Remplacez $valeurSpecifique par la valeur souhaitée
])
->add('id_user', HiddenType::class, [
'disabled' => true, // Désactive le champ
'data' => $options['data']->getIdUser() // Remplacez $valeurSpecifique par la valeur souhaitée
])
->add('nb_user', IntegerType::class, [
'attr' => [
'min' => 1,
'max' => 10,
'placeholder' => 'Nombre de personnes (entre 1 et 10)',
],
'constraints' => [
new NotBlank(['message' => 'Veuillez choisir un nombre de personnes.']),
new Range([
'min' => 1,
'max' => 10,
'minMessage' => 'Le nombre minimum de personnes est {{ limit }}.',
'maxMessage' => 'Le nombre maximum de personnes est {{ limit }}.',
]),
],
])
->add('jour', DateType::class, [
'widget' => 'single_text',
'html5' => false,
'attr' => ['class' => 'datepicker', 'placeholder' => 'Format date : AAAA-MM-JJ'],
'constraints' => [
new \Symfony\Component\Validator\Constraints\GreaterThanOrEqual([
'value' => 'today',
'message' => 'Vous ne pouvez pas choisir une date passée.',
]),
],
])
->add('heur', ChoiceType::class, [
'choices' => [
'12:00' => new \DateTime('12:00:00'),
'12:15' => new \DateTime('12:15:00'),
'12:30' => new \DateTime('12:30:00'),
'12:45' => new \DateTime('12:45:00'),
'13:00' => new \DateTime('13:00:00'),
'19:00' => new \DateTime('19:00:00'),
'19:15' => new \DateTime('19:15:00'),
'19:30' => new \DateTime('19:30:00'),
'19:45' => new \DateTime('19:45:00'),
'20:00' => new \DateTime('20:00:00'),
'20:15' => new \DateTime('20:15:00'),
'20:30' => new \DateTime('20:30:00'),
'20:45' => new \DateTime('20:45:00'),
'21:00' => new \DateTime('21:00:00'),
],
'placeholder' => 'Choisissez une heure',
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Resa::class,
]);
}
}

View file

@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}

View file

@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}
{% block title %}New Resa{% endblock %}
{% block body %}
<div class="center">
<h1>Create new Resa</h1>
<article>
{{ include('home/_form.html.twig') }}
</article>
</div>
{% endblock %}

View file

@ -3,11 +3,15 @@
{% block title %}Edit Resa{% endblock %} {% block title %}Edit Resa{% endblock %}
{% block body %} {% block body %}
<div class="center">
<h1>Edit Resa</h1> <h1>Edit Resa</h1>
<article>
{{ include('resa_service/_form.html.twig', {'button_label': 'Update'}) }} {{ include('resa_service/_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('app_resa_service_index') }}">back to list</a> <a href="{{ path('app_resa_service_index') }}">back to list</a>
{{ include('resa_service/_delete_form.html.twig') }} {{ include('resa_service/_delete_form.html.twig') }}
</article>
</div>
{% endblock %} {% endblock %}

View file

@ -5,13 +5,16 @@
{% block body %} {% block body %}
<h1>Resa index</h1> <h1>Resa index</h1>
<p>Jour suivant : <a href="{{ path('app_resa_service_jour', {'datej': j1|date('Y-m-d')}) }}">{{ j1|date('Y-m-d') }}</a></p>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>Id</th> <th>Id</th>
<th>Id_resto</th> <th>Id_resto</th>
<th>Id_user</th>
<th>Nb_user</th> <th>Nb_user</th>
<th>Date_heur</th> <th>Jour</th>
<th>Heur</th>
<th>actions</th> <th>actions</th>
</tr> </tr>
</thead> </thead>
@ -20,18 +23,24 @@
<tr> <tr>
<td>{{ resa.id }}</td> <td>{{ resa.id }}</td>
<td>{{ resa.idResto }}</td> <td>{{ resa.idResto }}</td>
{% if users[resa.idUser] is defined %}
<td>{{ users[resa.idUser].name }}</td>
{% else %}
<td>User Not Found</td>
{% endif %}
<td>{{ resa.nbUser }}</td> <td>{{ resa.nbUser }}</td>
<td>{{ resa.dateHeur ? resa.dateHeur|date('Y-m-d H:i:s') : '' }}</td> <td>{{ resa.jour ? resa.jour|date('Y-m-d') : '' }}</td>
<td>{{ resa.heur ? resa.heur|date('H:i:s') : '' }}</td>
<td> <td>
<a href="{{ path('app_resa_service_show', {'id': resa.id}) }}">show</a> <a href="{{ path('app_resa_service_show', {'id': resa.id}) }}">show</a>
<a href="{{ path('app_resa_service_edit', {'id': resa.id}) }}">edit</a>
</td> </td>
</tr> </tr>
{% else %} {% else %}
<tr> <tr>
<td colspan="5">no records found</td> <td colspan="7">no records found</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<a href="{{ path('app_resa_service_new') }}">Create new</a>
{% endblock %} {% endblock %}

View file

@ -3,9 +3,13 @@
{% block title %}New Resa{% endblock %} {% block title %}New Resa{% endblock %}
{% block body %} {% block body %}
<div class="center">
<h1>Create new Resa</h1> <h1>Create new Resa</h1>
<article>
{{ include('resa_service/_form.html.twig') }} {{ include('resa_service/_form.html.twig') }}
<a href="{{ path('app_resa_service_index') }}">back to list</a> <a href="{{ path('app_resa_service_index') }}">back to list</a>
</article>
</div>
{% endblock %} {% endblock %}

View file

@ -3,8 +3,10 @@
{% block title %}Resa{% endblock %} {% block title %}Resa{% endblock %}
{% block body %} {% block body %}
<div class="center">
<h1>Resa</h1> <h1>Resa</h1>
<article>
<table class="table"> <table class="table">
<tbody> <tbody>
<tr> <tr>
@ -15,20 +17,28 @@
<th>Id_resto</th> <th>Id_resto</th>
<td>{{ resa.idResto }}</td> <td>{{ resa.idResto }}</td>
</tr> </tr>
<tr>
<th>Id_user</th>
<td>{{ resa.idUser }}</td>
</tr>
<tr> <tr>
<th>Nb_user</th> <th>Nb_user</th>
<td>{{ resa.nbUser }}</td> <td>{{ resa.nbUser }}</td>
</tr> </tr>
<tr> <tr>
<th>Date_heur</th> <th>Jour</th>
<td>{{ resa.dateHeur ? resa.dateHeur|date('Y-m-d H:i:s') : '' }}</td> <td>{{ resa.jour ? resa.jour|date('Y-m-d') : '' }}</td>
</tr>
<tr>
<th>Heur</th>
<td>{{ resa.heur ? resa.heur|date('H:i:s') : '' }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<a href="{{ path('app_resa_service_index') }}">back to list</a>
<a href="{{ path('app_resa_service_edit', {'id': resa.id}) }}">edit</a>
{{ include('resa_service/_delete_form.html.twig') }} {{ include('resa_service/_delete_form.html.twig') }}
<a href="{{ path('app_resa_service_index') }}">back to list</a>
</article>
</div>
{% endblock %} {% endblock %}