src/Controller/CandidatureController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Candidature;
  4. use App\Entity\Offer;
  5. use App\Entity\Structure;
  6. use App\Form\CandidatureType;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use Knp\Snappy\Pdf;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class CandidatureController extends AbstractController
  15. {
  16.     #[Route('/postuler/{id}'name'app_candidature')]
  17.     public function candidateOffer(Request $requestEntityManagerInterface $entityManagerRegistry $doctrineint $idPdf $pdf): Response
  18.     {
  19.         $entityManager $doctrine->getManager();
  20.         $offer $entityManager->getRepository(Offer::class)->find($id);
  21.         $nomStruct $offer->getNomStructure();
  22.         $structure $entityManager->getRepository(Structure::class)->findStructureName($nomStruct);
  23.         $candidature= new Candidature();
  24.         $form $this->createForm(CandidatureType::class, $candidature);
  25.         $form->handleRequest($request);
  26.         if ($form->isSubmitted() && $form->isValid()) {
  27.             $file $form->get('cv')->getData();
  28.             $fileName md5(uniqid()) . '.' $file->guessExtension();
  29.             $file->move($this->getParameter('upload_directory'), $fileName);
  30.             $candidature->setCv($fileName);
  31.             $file $form->get('lettreMotivation')->getData();
  32.             $fileName md5(uniqid()) . '.' $file->guessExtension();
  33.             $file->move($this->getParameter('upload_directory'), $fileName);
  34.             $candidature->setLettreMotivation($fileName);
  35.             $user $this->getUser();
  36.             $candidature->setUser($user);
  37.             $candidature->setOffer($offer);
  38.             $nbCandidature $offer->getNombreCandidature();
  39.             $nbCandidature $nbCandidature +1;
  40.             $offer->setNombreCandidature($nbCandidature);
  41.             $entityManager->persist($candidature);
  42.             $entityManager->flush();
  43.             return $this->redirectToRoute('app_offers');
  44.         }
  45.        return $this->render ('home/viewjoboffer.html.twig', ['offer' => $offer'formCandidate' => $form->createView(), 'structure' => $structure ]);
  46.     }
  47.     /**
  48.      * @Route("/displayapply/{id}", name="app_displayapply")
  49.      */
  50.     public function displayapply(int $idManagerRegistry $doctrine): Response
  51.     {
  52.         $entityManager $doctrine->getManager();
  53.         $candidature $entityManager->getRepository(Candidature::class)->find($id);
  54.         return $this->render ('candidature/candidature.html.twig', ['candidature' => $candidature]);
  55.     }
  56.     /**
  57.      * @Route("/displayall", name="app_displayall")
  58.      */
  59.     public function displayall(ManagerRegistry $doctrine): Response
  60.     {
  61.         $entityManager $doctrine->getManager();
  62.         $candidature $entityManager->getRepository(Candidature::class)->findAll();
  63.         $user $this->getUser();
  64.         $userStruct $user->getStructureUser();
  65.         $structureName = array();
  66.         $i 0;
  67.         foreach($userStruct as $value) {
  68.             $structureName[] = $userStruct[$i]->getNomStructure();
  69.             $i++;
  70.         }
  71. //        dd($structureName);
  72.         return $this->render ('home/listallcandidature.html.twig', ['candidature' => $candidature'user'=>$structureName]);
  73.     }
  74.     /**
  75.      * @Route("/myapply", name="app_mescandidatures")
  76.      */
  77.     public function myapply(ManagerRegistry $doctrine): Response
  78.     {
  79.         $entityManager $doctrine->getManager();
  80.         $candidature $entityManager->getRepository(Candidature::class)->findAll();
  81.         $user $this->getUser();
  82.         return $this->render ('home/mescandidatures.html.twig', ['candidature' => $candidature'user'=>$user]);
  83.     }
  84.     #[Route('/deletecandidature/{id}'name'app_delete_candidature')]
  85.     public function DeleteOffer(ManagerRegistry $doctrineint $id): Response
  86.     {
  87.         $user $this->getUser();
  88.         $entityManager $doctrine->getManager();
  89.         $candidature $entityManager->getRepository(Candidature::class)->find($id);
  90.         $entityManager->remove($candidature);
  91.         $entityManager->flush();
  92.         $candidature $entityManager->getRepository(Candidature::class)->findAll();
  93.         return $this->render('home/mescandidatures.html.twig', ['candidature' => $candidature'user'=> $user]);
  94.     }
  95. }