src/Controller/ContactController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use App\Repository\PostLikeRepository;
  9. use App\Entity\Contact;
  10. use App\Entity\Agences;
  11. use App\Repository\AnnoncesRepository;
  12. use App\Entity\User;
  13. use Doctrine\Persistence\ManagerRegistry;
  14. use App\Controller\Fonctions\Fonctions;
  15. /**
  16.  * Class ContactController
  17.  * @package App\Controller
  18.  */
  19. class ContactController extends AbstractController
  20. {
  21.     /**
  22.      * @Route(path="/contact/{type}/{id}", name="contact", methods={"GET"})
  23.      * @param Contact $contact
  24.      * @param PostLikeRepository $repository
  25.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  26.      */
  27.     public function index(Request $requestManagerRegistry $doctrineAnnoncesRepository $annoncesRepository,  $id): Response
  28.     {
  29.         // insertion 
  30.         $entityManager $doctrine->getManager();
  31.         $user $this->getUser();
  32.         $userRepoAgence $entityManager->getRepository(Agences::class);
  33.         $idagence $userRepoAgence->find($id);
  34.         $user $this->getUser();
  35.         $userRepo $entityManager->getRepository(User::class);
  36.         $iduser $userRepo->find($user);
  37.         // création de la relation contact 
  38.         $contact = new Contact();
  39.         $contact->setAgence($idagence);
  40.         $contact->setUser($iduser);
  41.         $contact->setType(1);
  42.         $contact->setIsVerified(0);
  43.         $entityManager->persist($contact);
  44.         $entityManager->flush();
  45.         $code 200;
  46.         return new JsonResponse([
  47.             'code' => $code,
  48.         ]);
  49.     }
  50.     /**
  51.      * @Route(path="/acceptation/{id}", name="acceptation", methods={"GET"})
  52.      * @param Contact $contact
  53.      * @param PostLikeRepository $repository
  54.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  55.      */
  56.     public function acceptation(Request $requestManagerRegistry $doctrine,  $id): Response
  57.     {
  58.         $entityManager $doctrine->getManager();
  59.         $userRepo $entityManager->getRepository(Contact::class);
  60.         $id $userRepo->findOneBy(["id" => $id]);
  61.         $idagence $id->getAgence();
  62.         $idcontact $id->getUser();
  63.         $user $userRepo->find($id);
  64.  
  65.         $user->setIsVerified(1);
  66.         $entityManager->flush();
  67.         // on met à jour le contact. 
  68.         $userRepo $entityManager->getRepository(User::class);
  69.         $user $userRepo->find($idcontact);
  70.         $user->setAgence($idagence);
  71.         $entityManager->flush();
  72.         $code 200;
  73.         return new JsonResponse([
  74.             'code' => $code,
  75.         ]);
  76.     }
  77.     /**
  78.      * @Route(path="/refu/{type}/{id}", name="refu", methods={"GET"})
  79.      * @param Contact $contact
  80.      * @param PostLikeRepository $repository
  81.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  82.      */
  83.     public function refu(): Response
  84.     {
  85.         $code 200;
  86.         return new JsonResponse([
  87.             'code' => $code,
  88.         ]);
  89.     }
  90. }