123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Controller;
- use App\Entity\Profile;
- use Doctrine\ORM\EntityManagerInterface;
- use App\Form\UserEditProfilType;
- use App\Form\ProfileType;
- use App\Repository\ProfileRepository;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Routing\Annotation\Route;
- class ProfilController extends AbstractController
- {
-
- #[Route("/profil", name: "user_profil")]
- public function monProfilAction(Request $request, EntityManagerInterface $em): Response
- {
- $user = $this->getUser();
- $form = $this->createForm(UserEditProfilType::class , $user);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid())
- {
- $user = $form->getData();
- $em->flush();
- $this->addFlash('success', "Votre profil a été modifié");
- }
- return $this->render('profil/monprofil.html.twig', array (
- 'form' => $form
- ));
- }
- #[Route("/preferences", name: "user_preferences")]
- public function mesPreferencesAction(Request $request, EntityManagerInterface $em, ProfileRepository $profileRepo): Response
- {
- $profile = $profileRepo->findByUser($this->getUser());
- $form = $this->createForm(ProfileType::class , $profile);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid())
- {
- $profile = $form->getData();
- $em->flush();
- $this->addFlash('success', "Les préférences ont été modifiées");
- }
- return $this->render('profil/mespreferences.html.twig', [
- 'form' => $form
- ]);
- }
- #[Route("/changeview", name: "user_changeview")]
- public function changeView(EntityManagerInterface $em): JsonResponse
- {
- /** @var \App\Entity\User $user */
- $user = $this->getUser();
- $profile = $user->getProfile();
- if ($profile->getView() == Profile::$VIEW['liste']) {
- $profile->setView(Profile::$VIEW['vignette']);
- } else {
- $profile->setView(Profile::$VIEW['liste']);
- }
- $em->flush();
- return $this->json($profile->getView());
- }
- #[Route("/getview", name: "user_getview")]
- public function getView(): JsonResponse
- {
- /** @var \App\Entity\User $user */
- $user = $this->getUser();
- return $this->json($user->getProfile()->getView());
- }
- }
|