src/Controller/ProfilController.php line 198

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use App\Entity\User;
  7. use App\Entity\Agences;
  8. use App\Entity\Hotels;
  9. use App\Entity\Contact;
  10. use App\Form\ProfilType;
  11. use App\Form\ImageProfilType;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use App\Controller\Fonctions\Fonctions;
  14. use App\Repository\UserRepository;
  15. use Doctrine\Persistence\ManagerRegistry;
  16. use Symfony\Component\String\Slugger\SluggerInterface;
  17. #[Route('/profil'name'app_profil')]
  18. class ProfilController extends AbstractController
  19. {
  20.     #[Route('/new'name'app_profil_new'methods: ['GET''POST'])]
  21.     public function new(Request $requestUserRepository $userRepositoryManagerRegistry $doctrineSluggerInterface $slugger): Response
  22.     {
  23.         $fonction = new Fonctions();
  24.         $logo =  $fonction->FonctionLogo();
  25.         $user $this->getUser();
  26.         $domaine =  $fonction->FonctionUrl();
  27.         $entityManager $doctrine->getManager();
  28.         $userRepo $entityManager->getRepository(User::class);
  29.         $iduser $userRepo->find($user);
  30.         $message = new User();
  31.         $form $this->createForm(ProfilType::class, $message);
  32.         $form->handleRequest($request);
  33.         if ($form->isSubmitted() && $form->isValid()) {
  34.             $nom $message->getNom();
  35.             $prenom $message->getPrenom();
  36.             $adresse $message->getAdresse();
  37.             $telephone $message->getTelephone();
  38.             $facebook $message->getFacebook();
  39.             $instagram $message->getInstagram();
  40.             $linkedin $message->getLinkedin();
  41.             $twitter $message->getTwitter();
  42.             $siteperso $message->getSiteperso();
  43.             $psedo $message->getPsedo();
  44.             $slug $slugger->slug($psedo);
  45.             $user $userRepo->find($iduser);
  46.             $user->setNom($nom);
  47.             $user->setPrenom($prenom);
  48.             $user->setAdresse($adresse);
  49.             $user->setTelephone($telephone);
  50.             $user->setFacebook($facebook);
  51.             $user->setInstagram($instagram);
  52.             $user->setLinkedin($linkedin);
  53.             $user->setTwitter($twitter);
  54.             $user->setSiteperso($siteperso);
  55.             $user->setPsedo($psedo);
  56.             $user->setSlug($slug);
  57.             $user->setCredits(10);
  58.             $user->setValidation(1);
  59.             $user->setDomaine($domaine);
  60.             $entityManager->flush();
  61.             return $this->redirectToRoute('app_messages_index', [], Response::HTTP_SEE_OTHER);
  62.         }
  63.         return $this->renderForm('profil/new.html.twig', [
  64.             'message' => $message,
  65.             'form' => $form,
  66.             'logo' => $logo,
  67.         ]);
  68.     }
  69.     #[Route('/image'name'app_profil_image'methods: ['GET''POST'])]
  70.     public function image(Request $requestUserRepository $userRepositoryManagerRegistry $doctrineSluggerInterface $slugger): Response
  71.     {
  72.         $fonction = new Fonctions();
  73.         $logo =  $fonction->FonctionLogo();
  74.         $user $this->getUser();
  75.         $domaine =  $fonction->FonctionUrl();
  76.         $entityManager $doctrine->getManager();
  77.         $userRepo $entityManager->getRepository(User::class);
  78.         $iduser $userRepo->find($user);
  79.         $message = new User();
  80.         $form $this->createForm(ImageProfilType::class, $message);
  81.         $form->handleRequest($request);
  82.         if ($form->isSubmitted() && $form->isValid()) {
  83.             $image $form->get('image')->getData();
  84.             $fichier md5(uniqid()) . '.' $image->guessExtension();
  85.             $user->setImage($fichier);
  86.             $entityManager->flush();
  87.             $image->move(
  88.                 $this->getParameter('images_directory'),
  89.                 $fichier
  90.             );
  91.             return $this->redirectToRoute('app_messages_index', [], Response::HTTP_SEE_OTHER);
  92.         }
  93.         return $this->renderForm('profil/new.html.twig', [
  94.             'message' => $message,
  95.             'form' => $form,
  96.             'logo' => $logo,
  97.         ]);
  98.     }
  99.     #[Route('/account'name'profil_account')]
  100.     public function account(): Response
  101.     {
  102.         return $this->render('profil/index.html.twig', []);
  103.     }
  104.     #[Route('/profil/{type}/{id}'name'profil_profil')]
  105.     public function profil(ManagerRegistry $doctrine$type$id): Response
  106.     {
  107.         // calcule du nombre de crédit 
  108.         $entityManager $doctrine->getManager();
  109.         if ($type ==  'profil') {
  110.             $profil = new User();
  111.             $userRepo $entityManager->getRepository(User::class);
  112.             $usersByRole $userRepo->findBy(["id" => $id]);
  113.             foreach ($usersByRole as $user) {
  114.                 $nom $user->getNom();
  115.                 $id $user->getId();
  116.             }
  117.         }
  118.         if ($type ==  'agence') {
  119.             $profil = new Agences();
  120.             $userRepo $entityManager->getRepository(User::class);
  121.             $usersByRole $userRepo->findBy(["id" => $id]);
  122.             foreach ($usersByRole as $user) {
  123.                 $nom $user->getNom();
  124.                 $id $user->getId();
  125.             }
  126.         }
  127.         if ($type ==  'hotel') {
  128.             $profil = new Hotels();
  129.             $userRepo $entityManager->getRepository(Hotels::class);
  130.             $usersByRole $userRepo->findBy(["id" => $id]);
  131.             foreach ($usersByRole as $user) {
  132.                 $nom $user->getNom();
  133.                 $id $user->getId();
  134.             }
  135.         }
  136.         return $this->render('profil/index.html.twig', ['type' => $type'profil' => $id'nom' => $nom,]);
  137.     }
  138.     #[Route('/contact'name'profil_contact')]
  139.     public function contact(ManagerRegistry $doctrine): Response
  140.     {
  141.         $user $this->getUser();
  142.         $entityManager $doctrine->getManager();
  143.         // création de la gallerie image 
  144.         $userRepo $entityManager->getRepository(Contact::class);
  145.         $contacts $userRepo->findBy(["agence" => $user]);
  146.         return $this->render('profil/contact.html.twig', ['contacts' => $contacts,]);
  147.     }
  148. }