diff --git a/config/packages/security.yaml b/config/packages/security.yaml
index fa1c71f..6a2fd4c 100644
--- a/config/packages/security.yaml
+++ b/config/packages/security.yaml
@@ -32,6 +32,7 @@ security:
# Note: Only the *first* access control that matches will be used
access_control:
- { path: ^/admin, roles: ROLE_Root }
+ - { path: ^/chef, roles: "ROLE_Root, ROLE_Chef" }
# - { path: ^/profile, roles: ROLE_USER }
when@test:
diff --git a/src/Controller/MenuChefController.php b/src/Controller/MenuChefController.php
new file mode 100644
index 0000000..16dcddf
--- /dev/null
+++ b/src/Controller/MenuChefController.php
@@ -0,0 +1,139 @@
+getUser();
+ $email_user = $utilisateur->getUserIdentifier();
+
+ $user = $userRepository->findOneBy(['email' => $email_user]);
+
+ $id_resto = $user->getIdResto();
+ $id_user = $user->getId();
+ $this->id_resto = $id_resto;
+ $this->id_user = $id_user;
+ $this->userRepository = $userRepository;
+ $this->restoRepository = $restoRepository;
+ }
+ #[Route('/', name: 'app_menu_chef_index', methods: ['GET'])]
+ public function index(MenuRepository $menuRepository): Response
+ {
+ if ($this->id_resto != '') {
+ $menus = $menuRepository->findBy(['id_resto' => $this->id_resto]);
+ } else {
+ $this->id_resto = 0;
+ $menus = $menuRepository->findAll();
+ }
+
+ $users = [];
+ foreach ($menus as $menu) {
+ $userId = $menu->getIdUsers();
+ $user = $this->userRepository->find($userId);
+ if ($user !== null) {
+ $users[$userId] = $user;
+ }
+ }
+
+ $restos = [];
+ foreach ($menus as $menu) {
+ $restoId = $menu->getIdResto();
+ $resto = $this->restoRepository->find($restoId);
+ if ($resto !== null) {
+ $restos[$restoId] = $resto;
+ }
+ }
+
+ return $this->render('menu_chef/index.html.twig', [
+ 'menus' => $menus,
+ 'users' => $users,
+ 'restos' => $restos,
+ 'id_resto' => $this->id_resto,
+ ]);
+ }
+
+ #[Route('/new', name: 'app_menu_chef_new', methods: ['GET', 'POST'])]
+ public function new(Request $request, EntityManagerInterface $entityManager): Response
+ {
+ $id_resto = $this->id_resto;
+ $id_user = $this->id_user;
+
+ $menu = new Menu();
+ $menu->setIdResto($id_resto);
+ $menu->setIdUsers($id_user);
+
+ $form = $this->createForm(MenuType::class, $menu);
+
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $entityManager->persist($menu);
+ $entityManager->flush();
+
+ return $this->redirectToRoute('app_menu_chef_index', [], Response::HTTP_SEE_OTHER);
+ }
+
+ return $this->renderForm('menu_chef/new.html.twig', [
+ 'menu' => $menu,
+ 'form' => $form,
+ ]);
+ }
+
+ #[Route('/{id}', name: 'app_menu_chef_show', methods: ['GET'])]
+ public function show(Menu $menu): Response
+ {
+ return $this->render('menu_chef/show.html.twig', [
+ 'menu' => $menu,
+ ]);
+ }
+
+ #[Route('/{id}/edit', name: 'app_menu_chef_edit', methods: ['GET', 'POST'])]
+ public function edit(Request $request, Menu $menu, EntityManagerInterface $entityManager): Response
+ {
+ $form = $this->createForm(MenuType::class, $menu);
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $entityManager->flush();
+
+ return $this->redirectToRoute('app_menu_chef_index', [], Response::HTTP_SEE_OTHER);
+ }
+
+ return $this->renderForm('menu_chef/edit.html.twig', [
+ 'menu' => $menu,
+ 'form' => $form,
+ ]);
+ }
+
+ #[Route('/{id}', name: 'app_menu_chef_delete', methods: ['POST'])]
+ public function delete(Request $request, Menu $menu, EntityManagerInterface $entityManager): Response
+ {
+ if ($this->isCsrfTokenValid('delete' . $menu->getId(), $request->request->get('_token'))) {
+ $entityManager->remove($menu);
+ $entityManager->flush();
+ }
+
+ return $this->redirectToRoute('app_menu_chef_index', [], Response::HTTP_SEE_OTHER);
+ }
+}
diff --git a/src/Controller/RestoAdminController.php b/src/Controller/RestoAdminController.php
new file mode 100644
index 0000000..1a17807
--- /dev/null
+++ b/src/Controller/RestoAdminController.php
@@ -0,0 +1,81 @@
+render('resto_admin/index.html.twig', [
+ 'restos' => $restoRepository->findAll(),
+ ]);
+ }
+
+ #[Route('/new', name: 'app_resto_admin_new', methods: ['GET', 'POST'])]
+ public function new(Request $request, EntityManagerInterface $entityManager): Response
+ {
+ $resto = new Resto();
+ $form = $this->createForm(RestoType::class, $resto);
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $entityManager->persist($resto);
+ $entityManager->flush();
+
+ return $this->redirectToRoute('app_resto_admin_index', [], Response::HTTP_SEE_OTHER);
+ }
+
+ return $this->renderForm('resto_admin/new.html.twig', [
+ 'resto' => $resto,
+ 'form' => $form,
+ ]);
+ }
+
+ #[Route('/{id}', name: 'app_resto_admin_show', methods: ['GET'])]
+ public function show(Resto $resto): Response
+ {
+ return $this->render('resto_admin/show.html.twig', [
+ 'resto' => $resto,
+ ]);
+ }
+
+ #[Route('/{id}/edit', name: 'app_resto_admin_edit', methods: ['GET', 'POST'])]
+ public function edit(Request $request, Resto $resto, EntityManagerInterface $entityManager): Response
+ {
+ $form = $this->createForm(RestoType::class, $resto);
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $entityManager->flush();
+
+ return $this->redirectToRoute('app_resto_admin_index', [], Response::HTTP_SEE_OTHER);
+ }
+
+ return $this->renderForm('resto_admin/edit.html.twig', [
+ 'resto' => $resto,
+ 'form' => $form,
+ ]);
+ }
+
+ #[Route('/{id}', name: 'app_resto_admin_delete', methods: ['POST'])]
+ public function delete(Request $request, Resto $resto, EntityManagerInterface $entityManager): Response
+ {
+ if ($this->isCsrfTokenValid('delete'.$resto->getId(), $request->request->get('_token'))) {
+ $entityManager->remove($resto);
+ $entityManager->flush();
+ }
+
+ return $this->redirectToRoute('app_resto_admin_index', [], Response::HTTP_SEE_OTHER);
+ }
+}
diff --git a/src/Form/MenuType.php b/src/Form/MenuType.php
new file mode 100644
index 0000000..674b019
--- /dev/null
+++ b/src/Form/MenuType.php
@@ -0,0 +1,35 @@
+add('entre')
+ ->add('plat')
+ ->add('dessert')
+ ->add('id_resto', HiddenType::class, [
+ 'disabled' => true, // Désactive le champ
+ 'data' => $options['data']->getIdResto() // Remplacez $valeurSpecifique par la valeur souhaitée
+ ])
+ ->add('id_users', HiddenType::class, [
+ 'disabled' => true, // Désactive le champ
+ 'data' => $options['data']->getIdUsers() // Remplacez $valeurSpecifique par la valeur souhaitée
+ ]);
+ }
+
+ public function configureOptions(OptionsResolver $resolver): void
+ {
+ $resolver->setDefaults([
+ 'data_class' => Menu::class,
+ ]);
+ }
+}
diff --git a/src/Form/RestoType.php b/src/Form/RestoType.php
new file mode 100644
index 0000000..d3f1fa4
--- /dev/null
+++ b/src/Form/RestoType.php
@@ -0,0 +1,27 @@
+add('pay')
+ ->add('ville')
+ ->add('address')
+ ;
+ }
+
+ public function configureOptions(OptionsResolver $resolver): void
+ {
+ $resolver->setDefaults([
+ 'data_class' => Resto::class,
+ ]);
+ }
+}
diff --git a/templates/menu_chef/_delete_form.html.twig b/templates/menu_chef/_delete_form.html.twig
new file mode 100644
index 0000000..e3bdb43
--- /dev/null
+++ b/templates/menu_chef/_delete_form.html.twig
@@ -0,0 +1,4 @@
+
diff --git a/templates/menu_chef/_form.html.twig b/templates/menu_chef/_form.html.twig
new file mode 100644
index 0000000..bf20b98
--- /dev/null
+++ b/templates/menu_chef/_form.html.twig
@@ -0,0 +1,4 @@
+{{ form_start(form) }}
+ {{ form_widget(form) }}
+
+{{ form_end(form) }}
diff --git a/templates/menu_chef/edit.html.twig b/templates/menu_chef/edit.html.twig
new file mode 100644
index 0000000..9a9e1e5
--- /dev/null
+++ b/templates/menu_chef/edit.html.twig
@@ -0,0 +1,13 @@
+{% extends 'base.html.twig' %}
+
+{% block title %}Edit Menu{% endblock %}
+
+{% block body %}
+ Edit Menu
+
+ {{ include('menu_chef/_form.html.twig', {'button_label': 'Update'}) }}
+
+ back to list
+
+ {{ include('menu_chef/_delete_form.html.twig') }}
+{% endblock %}
diff --git a/templates/menu_chef/index.html.twig b/templates/menu_chef/index.html.twig
new file mode 100644
index 0000000..41ba1d4
--- /dev/null
+++ b/templates/menu_chef/index.html.twig
@@ -0,0 +1,53 @@
+{% extends 'base.html.twig' %}
+
+{% block title %}Menu index{% endblock %}
+
+{% block body %}
+ Menu du resto {{ id_resto }}
+
+
+
+
+ | Id |
+ Entre |
+ Plat |
+ Dessert |
+ Adresse |
+ Chef |
+ actions |
+
+
+
+ {% for menu in menus %}
+
+ | {{ menu.id }} |
+ {{ menu.entre }} |
+ {{ menu.plat }} |
+ {{ menu.dessert }} |
+
+ {% if restos[menu.idResto] is defined %}
+ {{ restos[menu.idResto].address }} |
+ {% else %}
+ Resto Not Found |
+ {% endif %}
+
+ {% if users[menu.idUsers] is defined %}
+ {{ users[menu.idUsers].name }} {{ users[menu.idUsers].fullname }} |
+ {% else %}
+ User Not Found |
+ {% endif %}
+
+ show
+ edit
+ |
+
+ {% else %}
+
+ | no records found |
+
+ {% endfor %}
+
+
+
+ Create new
+{% endblock %}
diff --git a/templates/menu_chef/new.html.twig b/templates/menu_chef/new.html.twig
new file mode 100644
index 0000000..dcaf53e
--- /dev/null
+++ b/templates/menu_chef/new.html.twig
@@ -0,0 +1,11 @@
+{% extends 'base.html.twig' %}
+
+{% block title %}New Menu{% endblock %}
+
+{% block body %}
+ Create new Menu
+
+ {{ include('menu_chef/_form.html.twig') }}
+
+ back to list
+{% endblock %}
diff --git a/templates/menu_chef/show.html.twig b/templates/menu_chef/show.html.twig
new file mode 100644
index 0000000..81f4b9a
--- /dev/null
+++ b/templates/menu_chef/show.html.twig
@@ -0,0 +1,42 @@
+{% extends 'base.html.twig' %}
+
+{% block title %}Menu{% endblock %}
+
+{% block body %}
+ Menu
+
+
+
+
+ | Id |
+ {{ menu.id }} |
+
+
+ | Entre |
+ {{ menu.entre }} |
+
+
+ | Plat |
+ {{ menu.plat }} |
+
+
+ | Dessert |
+ {{ menu.dessert }} |
+
+
+ | Id_resto |
+ {{ menu.idResto }} |
+
+
+ | Id_users |
+ {{ menu.idUsers }} |
+
+
+
+
+ back to list
+
+ edit
+
+ {{ include('menu_chef/_delete_form.html.twig') }}
+{% endblock %}
diff --git a/templates/resto_admin/_delete_form.html.twig b/templates/resto_admin/_delete_form.html.twig
new file mode 100644
index 0000000..7ba5ca0
--- /dev/null
+++ b/templates/resto_admin/_delete_form.html.twig
@@ -0,0 +1,4 @@
+
diff --git a/templates/resto_admin/_form.html.twig b/templates/resto_admin/_form.html.twig
new file mode 100644
index 0000000..bf20b98
--- /dev/null
+++ b/templates/resto_admin/_form.html.twig
@@ -0,0 +1,4 @@
+{{ form_start(form) }}
+ {{ form_widget(form) }}
+
+{{ form_end(form) }}
diff --git a/templates/resto_admin/edit.html.twig b/templates/resto_admin/edit.html.twig
new file mode 100644
index 0000000..7a8a13b
--- /dev/null
+++ b/templates/resto_admin/edit.html.twig
@@ -0,0 +1,13 @@
+{% extends 'base.html.twig' %}
+
+{% block title %}Edit Resto{% endblock %}
+
+{% block body %}
+ Edit Resto
+
+ {{ include('resto_admin/_form.html.twig', {'button_label': 'Update'}) }}
+
+ back to list
+
+ {{ include('resto_admin/_delete_form.html.twig') }}
+{% endblock %}
diff --git a/templates/resto_admin/index.html.twig b/templates/resto_admin/index.html.twig
new file mode 100644
index 0000000..6f3199f
--- /dev/null
+++ b/templates/resto_admin/index.html.twig
@@ -0,0 +1,39 @@
+{% extends 'base.html.twig' %}
+
+{% block title %}Resto index{% endblock %}
+
+{% block body %}
+ Resto index
+
+
+
+
+ | Id |
+ Pay |
+ Ville |
+ Address |
+ actions |
+
+
+
+ {% for resto in restos %}
+
+ | {{ resto.id }} |
+ {{ resto.pay }} |
+ {{ resto.ville }} |
+ {{ resto.address }} |
+
+ show
+ edit
+ |
+
+ {% else %}
+
+ | no records found |
+
+ {% endfor %}
+
+
+
+ Create new
+{% endblock %}
diff --git a/templates/resto_admin/new.html.twig b/templates/resto_admin/new.html.twig
new file mode 100644
index 0000000..aedf13f
--- /dev/null
+++ b/templates/resto_admin/new.html.twig
@@ -0,0 +1,11 @@
+{% extends 'base.html.twig' %}
+
+{% block title %}New Resto{% endblock %}
+
+{% block body %}
+ Create new Resto
+
+ {{ include('resto_admin/_form.html.twig') }}
+
+ back to list
+{% endblock %}
diff --git a/templates/resto_admin/show.html.twig b/templates/resto_admin/show.html.twig
new file mode 100644
index 0000000..2b24151
--- /dev/null
+++ b/templates/resto_admin/show.html.twig
@@ -0,0 +1,34 @@
+{% extends 'base.html.twig' %}
+
+{% block title %}Resto{% endblock %}
+
+{% block body %}
+ Resto
+
+
+
+
+ | Id |
+ {{ resto.id }} |
+
+
+ | Pay |
+ {{ resto.pay }} |
+
+
+ | Ville |
+ {{ resto.ville }} |
+
+
+ | Address |
+ {{ resto.address }} |
+
+
+
+
+ back to list
+
+ edit
+
+ {{ include('resto_admin/_delete_form.html.twig') }}
+{% endblock %}