src/Controller/ApplicantController.php line 117

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Applicant;
  4. use App\Form\ApplicantType;
  5. use App\Repository\ApplicantRepository;
  6. use App\Repository\RefrenceRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use App\Entity\Refrence;
  14. //PHPMailer Package
  15. //Import PHPMailer classes into the global namespace
  16. //These must be at the top of your script, not inside a function
  17. use PHPMailer\PHPMailer\PHPMailer;
  18. use PHPMailer\PHPMailer\SMTP;
  19. use PHPMailer\PHPMailer\Exception;
  20. //Load Composer's autoloader
  21. //require 'vendor/autoload.php';
  22. /**
  23.  * @Route("/applicant")
  24.  */
  25. class ApplicantController extends AbstractController
  26. {
  27. /*    protected function sendrefmail($mail,$refEmail,$subject, $message)
  28.     {
  29. //Create an instance; passing `true` enables exceptions
  30.     //Email Ref1
  31.     
  32.     $mail->addAddress($refEmail, 'Reference Email');     //Add a recipient
  33.    // $mail->addAddress('ellen@example.com');               //Name is optional
  34.    // $mail->addReplyTo('info@example.com', 'Information');
  35.    // $mail->addCC('mndang@health.ucsd.edu');
  36.     //$mail->addBCC('bcc@example.com');
  37.     //Attachments
  38.    // $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
  39.     //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name
  40.     //Content
  41.     $mail->Subject =  $subject;
  42.     $mail->Body    =  $message;
  43.   //  $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  44.     $mail->send();
  45.     echo 'Message has been sent';
  46.     }
  47. */
  48.     /**
  49.      * @Route("/", name="app_applicant_index", methods={"GET"})
  50.      */
  51.     public function index(ApplicantRepository $applicantRepository): Response
  52.     {
  53.         if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  54.             $user $this->container->get('security.token_storage')->getToken()->getUser();
  55.             $username $user->getUsername();
  56.            // $useremail = $user->getEmail();
  57.             $UserRoles $user->getRoles();
  58.             
  59.         }
  60.         if (in_array("ROLE_ADMIN",$UserRoles))
  61.         {
  62.             $applicants =  $applicantRepository->findAll();
  63.         } elseif (in_array("ROLE_BODY",$UserRoles)) {
  64.             $applicants =  $applicantRepository->findByDivision('Body');
  65.         } elseif (in_array("ROLE_MSK",$UserRoles)) {
  66.             $applicants =  $applicantRepository->findByDivision('MSK');
  67.         } elseif (in_array("ROLE_MRI",$UserRoles)) {
  68.         $applicants =  $applicantRepository->findByDivision('MRI');
  69.         } elseif (in_array("ROLE_WOMEN",$UserRoles)) {
  70.             $applicants =  $applicantRepository->findByDivision('Women');
  71.     } elseif (in_array("ROLE_BREAST",$UserRoles)) {
  72.         $applicants =  $applicantRepository->findByDivision('Breast');
  73. }elseif (in_array("ROLE_CHEST",$UserRoles)) {
  74.     $applicants =  $applicantRepository->findByDivision('Chest');
  75. }
  76.         for ($i=0$i<count($applicants);$i++)
  77.         {
  78.             $refs $applicants[$i]->getRef();
  79.             $num 0;
  80.             foreach ($refs as $ref)
  81.             {
  82.                 if ($ref->getRefLetter() == 'Please upload')
  83.                 {
  84.                     
  85.                 }else {
  86.                     $num $num+1;
  87.                 }
  88.             }
  89.             $applicants[$i]->setRefLtNum($num);
  90.         }
  91.         return $this->render('applicant/index.html.twig', [
  92.             'applicants' => $applicants,
  93.         ]);
  94.     }
  95.     /**
  96.      * @Route("/new", name="app_applicant_new", methods={"GET", "POST"})
  97.      */
  98.     public function new(Request $requestApplicantRepository $applicantRepositoryRefrenceRepository $refrenceRepository): Response
  99.     {
  100.         $applicant = new Applicant();
  101.         $form $this->createForm(ApplicantType::class, $applicant);
  102.         $form->handleRequest($request);
  103.         if ($form->isSubmitted() && $form->isValid()) {
  104. //get App Form File name
  105.             $appFile $form->get('appForm')->getData();
  106.             print $appFile;
  107.             if ($appFile){
  108.                 
  109.                 $newAFilename md5(uniqid()).'.'.$appFile->guessClientExtension();
  110.                 // Move the file to the directory where brochures are stored
  111.                 try {
  112.                     $appFile->move(
  113.                         $this->getParameter('brochures_directory'),
  114.                         $newAFilename
  115.                     );
  116.                 } catch (FileException $e) {
  117.                     // ... handle exception if something happens during file upload
  118.                 }
  119.             }
  120.             $applicant->setApplicationForm($newAFilename);
  121. //get personal statment filename
  122. $psFile $form->get('PersonalStat')->getData();
  123.           
  124.             if ($psFile){
  125.                 
  126.                 $newpsFilename md5(uniqid()).'.'.$psFile->guessClientExtension();
  127.                 // Move the file to the directory where brochures are stored
  128.                 try {
  129.                     $psFile->move(
  130.                         $this->getParameter('brochures_directory'),
  131.                         $newpsFilename
  132.                     );
  133.                 } catch (FileException $e) {
  134.                     // ... handle exception if something happens during file upload
  135.                 }
  136.             }
  137.             $applicant->setPersonal($newpsFilename);
  138. //get CV filename
  139. $cvFile $form->get('CVLink')->getData();
  140.           
  141.             if ($cvFile){
  142.                 
  143.                 $newcvFilename md5(uniqid()).'.'.$cvFile->guessClientExtension();
  144.                 // Move the file to the directory where brochures are stored
  145.                 try {
  146.                     $cvFile->move(
  147.                         $this->getParameter('brochures_directory'),
  148.                         $newcvFilename
  149.                     );
  150.                 } catch (FileException $e) {
  151.                     // ... handle exception if something happens during file upload
  152.                 }
  153.             }
  154.             $applicant->setCV($newcvFilename);
  155. //get Dean's letter filename
  156. $dlFile $form->get('dlFile')->getData();
  157.           
  158.             if ($dlFile){
  159.                 
  160.                 $newdlFilename md5(uniqid()).'.'.$dlFile->guessClientExtension();
  161.                 // Move the file to the directory where brochures are stored
  162.                 try {
  163.                     $dlFile->move(
  164.                         $this->getParameter('brochures_directory'),
  165.                         $newdlFilename
  166.                     );
  167.                 } catch (FileException $e) {
  168.                     // ... handle exception if something happens during file upload
  169.                 }
  170.             }
  171.             $applicant->setDeanLetter($newdlFilename);
  172. //get Medical School Diploma filename
  173. $mdFile $form->get('mdFile')->getData();
  174.           
  175.             if ($mdFile){
  176.                 
  177.                 $newmdFilename md5(uniqid()).'.'.$mdFile->guessClientExtension();
  178.                 // Move the file to the directory where brochures are stored
  179.                 try {
  180.                     $mdFile->move(
  181.                         $this->getParameter('brochures_directory'),
  182.                         $newmdFilename
  183.                     );
  184.                 } catch (FileException $e) {
  185.                     // ... handle exception if something happens during file upload
  186.                 }
  187.             }
  188.             $applicant->setMedSchoolD($newmdFilename);
  189. //get USMLE file name
  190. $usmleFile $form->get('usfile')->getData();
  191.           
  192.             if ($usmleFile){
  193.                 
  194.                 $newusmleFilename md5(uniqid()).'.'.$usmleFile->guessClientExtension();
  195.                 // Move the file to the directory where brochures are stored
  196.                 try {
  197.                     $usmleFile->move(
  198.                         $this->getParameter('brochures_directory'),
  199.                         $newusmleFilename
  200.                     );
  201.                 } catch (FileException $e) {
  202.                     // ... handle exception if something happens during file upload
  203.                 }
  204.             }
  205.             $applicant->setUSMLE($newusmleFilename);
  206.             $refrence = new Refrence();
  207.             $refrence->setName($form->get('Ref1Name')->getData());
  208.             $refrence->setEmail($form->get('Ref1Email')->getData());
  209.             $refrence->setJobTitle($form->get('Ref1Letter')->getData());
  210.             $refrence->setAffiliation('Please add');
  211.             $refrence->setPhone('Please add');
  212.             $refrence->setAddress('Please add');
  213.             $refrence->setRefLetter('Please upload');
  214.             $refrenceRepository->add($refrencetrue);
  215.             
  216.             // add applicant to database
  217.             $applicantRepository->add($applicanttrue);
  218.             $applicant->addRef($refrence);
  219.             $refID $refrence->getId();
  220.             //local URL 
  221.            //$url = 'http://127.0.0.1:8000/refrence/'.$refID.'/edit';
  222.           $url 'http://rad-sdsc.ucsd.edu/refrence/'.$refID.'/edit';
  223.             $to $form->get('Ref1Email')->getData();
  224.             $headers 'From: eghobrial@ucsd.edu' '\r\n' 'CC: eghobrial@ucsd.edu';
  225.             $appName $form->get('Name')->getData();
  226.             $appEmail $form->get('Email')->getData();
  227.             $appDiv $form->get('Division')->getData();
  228.             $ref1Name $form->get('Ref1Name')->getData();
  229.             $ref1Email $form->get('Ref1Email')->getData();
  230.             $ref2Name $form->get('Ref2Name')->getData();
  231.             $ref2Email $form->get('Ref2Email')->getData();
  232.             $ref3Name $form->get('Ref3Name')->getData();
  233.             $ref3Email $form->get('Ref3Email')->getData();
  234.             $refrence2 = new Refrence();
  235.             $refrence2->setName($form->get('Ref2Name')->getData());
  236.             $refrence2->setEmail($form->get('Ref2Email')->getData());
  237.             $refrence2->setJobTitle($form->get('Ref2Letter')->getData());
  238.             $refrence2->setAffiliation('Please add');
  239.             $refrence2->setPhone('Please add');
  240.             $refrence2->setAddress('Please add');
  241.             $refrence2->setRefLetter('Please upload');
  242.             $refrenceRepository->add($refrence2true);
  243.             $applicant->addRef($refrence2);
  244.             $refID2 $refrence2->getId();
  245.             //local URL
  246.           //     $url2 = 'http://127.0.0.1:8000/refrence/'.$refID2.'/edit';
  247.             $url2 'http://rad-sdsc.ucsd.edu/refrence/'.$refID2.'/edit';
  248.             $refrence3 = new Refrence();
  249.             $refrence3->setName($form->get('Ref3Name')->getData());
  250.             $refrence3->setEmail($form->get('Ref3Email')->getData());
  251.             $refrence3->setJobTitle($form->get('Ref3Letter')->getData());
  252.             $refrence3->setAffiliation('Please add');
  253.             $refrence3->setPhone('Please add');
  254.             $refrence3->setAddress('Please add');
  255.             $refrence3->setRefLetter('Please upload');
  256.             $refrenceRepository->add($refrence3true);
  257.            
  258.             
  259.             $applicant->addRef($refrence3);
  260.             $refID3 $refrence3->getId();
  261.             //local URL
  262.             //  $url3 = 'http://127.0.0.1:8000/refrence/'.$refID3.'/edit';
  263.            $url3 'http://rad-sdsc.ucsd.edu/refrence/'.$refID3.'/edit';
  264.             $subject 'Recommendation Letter Request -- UCSD Radiology -- '.$appDiv.' Division Fellowship for Dr. '.$appName;
  265.             $message $appName.' has selected you to provide a letter of recommendation as they apply for a fellowship position with 
  266.             the Department of Radiology at UCSD'$appDiv.'. Please submit a letter of recommendation as a PDF to the following URL: '.$url.' Feel free to reach out to 
  267.             Myra Dang (mndang@health.ucsd.edu), Radiology Fellowship Coordinator, if you have any questions. *1*';
  268.             $message2 $appName.' has selected you to provide a letter of recommendation as they apply for a fellowship position with 
  269.             the Department of Radiology at UCSD'$appDiv.'. Please submit a letter of recommendation as a PDF to the following URL: '.$url2.' Feel free to reach out to 
  270.             Myra Dang (mndang@health.ucsd.edu), Radiology Fellowship Coordinator, if you have any questions. *2*';
  271.             $message3 $appName.' has selected you to provide a letter of recommendation as they apply for a fellowship position with 
  272.             the Department of Radiology at UCSD'$appDiv.'. Please submit a letter of recommendation as a PDF to the following URL: '.$url3.' Feel free to reach out to 
  273.             Myra Dang (mndang@health.ucsd.edu), Radiology Fellowship Coordinator, if you have any questions. *3*';
  274.          //   $mailsent = mail($to,$subject,$message);
  275.       /*   $mail = new PHPMailer(true);
  276.          //Server settings
  277.          $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
  278.          $mail->isSMTP();                                            //Send using SMTP
  279.          $mail->Host       = 'smtp.ucsd.edu';                     //Set the SMTP server to send through
  280.          $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
  281.          $mail->Username   = 'eghobrial@ucsd.edu';                     //SMTP username
  282.          $mail->Password   = 'Secret';                               //SMTP password
  283.          $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
  284.          $mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
  285.          //Recipients
  286.          $mail->setFrom('eghobrial@ucsd.edu', 'UCSD Radiology Dept Reference Request');
  287.          $mail->isHTML(true); 
  288.          $this->sendrefmail($mail,$ref1Email,$subject, $message);
  289.          $this->sendrefmail($mail,$ref2Email,$subject, $message2);
  290.          $this->sendrefmail($mail,$ref3Email,$subject, $message3);*/
  291.          $mailref1 mail($ref1Email,$subject$message);
  292.          $mailref2 mail($ref2Email,$subject$message2);
  293.          $mailref3 mail($ref3Email,$subject$message3);
  294.             
  295.         $mailrefa1 mail('eghobrial@ucsd.edu',$subject$message);
  296.         $mailrefa2 mail('eghobrial@ucsd.edu',$subject$message2);
  297.         $mailrefa3 mail('eghobrial@ucsd.edu',$subject$message3);
  298. if ($appDiv == 'MSK')
  299. {
  300.     //send a confirmation message
  301.         $appSub 'UCSD MSK Fellowship Application has been received';
  302.         $appmessage 'We appreciate your interest in our Musculoskeletal Imaging Fellowship and received your application. Please be patient as we process all applications, 
  303.         and we will keep you updated on your status as we start scheduling our virtual interviews for January 2023.';
  304.         $mailapp mail($appEmail,$appSub$appmessage);
  305. } elseif ($appDiv == 'Body')
  306. {
  307.     //send a confirmation message
  308.     $appSub 'UCSD Body Fellowship Application has been received';
  309.     $appmessage 'We appreciate your interest in our Body Imaging Fellowship and received your application. Please be patient as we process all applications, 
  310.     and we will keep you updated on your status as we start scheduling our virtual interviews for January 2024.';
  311.     $mailapp mail($appEmail,$appSub$appmessage);
  312. }elseif ($appDiv == 'Breast')
  313. {
  314.     //send a confirmation message
  315.     $appSub 'UCSD Breast Fellowship Application has been received';
  316.     $appmessage 'We appreciate your interest in our Breast Imaging Fellowship and received your application. Please be patient as we process all applications, 
  317.     and we will keep you updated on your status as we start scheduling our virtual interviews for January 2024.';
  318.     $mailapp mail($appEmail,$appSub$appmessage);
  319.     //replace email address
  320.     $subjectapp 'We received Dr. '.$appName.' for '.$appDiv' Division';
  321.             $mailsentApp mail('eghobrial@ucsd.edu',$subjectapp,'Application received and ready to be viewed on the portal');
  322. }elseif ($appDiv == 'Women')
  323. {
  324.     //send a confirmation message
  325.     $appSub 'UCSD Women Imaging Fellowship Application has been received';
  326.     $appmessage 'We appreciate your interest in our Women Imaging Fellowship and received your application. Please be patient as we process all applications, 
  327.     and we will keep you updated on your status as we start scheduling our virtual interviews for January 2024.';
  328.     $mailapp mail($appEmail,$appSub$appmessage);
  329.     //replace email address
  330.     $subjectapp 'We received Dr. '.$appName.' for '.$appDiv' Division';
  331.             $mailsentApp mail('eghobrial@ucsd.edu',$subjectapp,'Application received and ready to be viewed on the portal');
  332. }elseif ($appDiv == 'Chest')
  333. {
  334.     //send a confirmation message
  335.     $appSub 'UCSD Cardiothoracic Fellowship Application has been received';
  336.     $appmessage 'We appreciate your interest in our Cardiothoracic Imaging Fellowship and received your application. Please be patient as we process all applications, 
  337.     and we will keep you updated on your status as we start scheduling our virtual interviews for January 2024.';
  338.     $mailapp mail($appEmail,$appSub$appmessage);
  339.      //replace email address
  340.      $subjectapp 'We received Dr. '.$appName.' for '.$appDiv' Division';
  341.      $mailsentApp mail('eghobrial@ucsd.edu',$subjectapp,'Application received and ready to be viewed on the portal');
  342. } elseif ($appDiv == 'MRI')
  343. {
  344.     //send a confirmation message
  345.     $appSub 'UCSD MRI Fellowship Application has been received';
  346.     $appmessage 'We appreciate your interest in our MRI Imaging Fellowship and received your application. Please be patient as we process all applications, 
  347.     and we will keep you updated on your status as we start scheduling our virtual interviews for January 2024.';
  348.     $mailapp mail($appEmail,$appSub$appmessage);
  349.      //replace email address
  350.      $subjectapp 'We received Dr. '.$appName.' for '.$appDiv' Division';
  351.      $mailsentApp mail('eghobrial@ucsd.edu',$subjectapp,'Application received and ready to be viewed on the portal');
  352. }
  353.     return $this->redirectToRoute('app_applicant_sucess', [], Response::HTTP_SEE_OTHER);
  354.         }
  355.     return $this->renderForm('applicant/new.html.twig', [
  356.         'applicant' => $applicant,
  357.         'form' => $form,
  358.     ]);
  359.        
  360.   
  361. }
  362. /**
  363.      * @Route("/sucess", name="app_applicant_sucess", methods={"GET"})
  364.      */
  365.     public function showsucess(): Response
  366.     {
  367.         return $this->render('applicant/sucess.html.twig');
  368.     }
  369.     /**
  370.      * @Route("/{id}", name="app_applicant_show", methods={"GET"})
  371.      */
  372.    public function show(Applicant $applicant): Response
  373.     {
  374.        
  375.         return $this->render('applicant/show.html.twig', [
  376.             'applicant' => $applicant,
  377.             'References' => $applicant->getRef(),
  378.         ]);
  379.     }
  380.     /**
  381.      * @Route("/{id}/edit", name="app_applicant_edit", methods={"GET", "POST"})
  382.      */
  383.   public function edit(Request $requestApplicant $applicantApplicantRepository $applicantRepository): Response
  384.     {
  385.         $form $this->createForm(ApplicantType::class, $applicant);
  386.         $form->handleRequest($request);
  387.         if ($form->isSubmitted() && $form->isValid()) {
  388. //get USMLE letter filename
  389. /*$usmleFile = $form->get('usfile')->getData();
  390.           
  391.             if ($usmleFile){
  392.                 
  393.                 $newusmleFilename = md5(uniqid()).'.'.$usmleFile->guessClientExtension();
  394.                 // Move the file to the directory where brochures are stored
  395.                 try {
  396.                     $usmleFile->move(
  397.                         $this->getParameter('brochures_directory'),
  398.                         $newusmleFilename
  399.                     );
  400.                 } catch (FileException $e) {
  401.                     // ... handle exception if something happens during file upload
  402.                 }
  403.             }
  404.             $applicant->setUSMLE($newusmleFilename);*/
  405. //get Dean's letter filename
  406. $dlFile $form->get('dlFile')->getData();
  407.           
  408.             if ($dlFile){
  409.                 
  410.                 $newdlFilename md5(uniqid()).'.'.$dlFile->guessClientExtension();
  411.                 // Move the file to the directory where brochures are stored
  412.                 try {
  413.                     $dlFile->move(
  414.                         $this->getParameter('brochures_directory'),
  415.                         $newdlFilename
  416.                     );
  417.                 } catch (FileException $e) {
  418.                     // ... handle exception if something happens during file upload
  419.                 }
  420.             }
  421.             $applicant->setDeanLetter($newdlFilename);
  422.             $applicantRepository->add($applicanttrue);
  423.             return $this->redirectToRoute('app_applicant_index', [], Response::HTTP_SEE_OTHER);
  424.         }
  425.         return $this->renderForm('applicant/edit.html.twig', [
  426.             'applicant' => $applicant,
  427.             'form' => $form,
  428.         ]);
  429.     }
  430.     /**
  431.      * @Route("/{id}/review", name="app_applicant_review", methods={"GET", "POST"})
  432.      */
  433.   public function review(Request $requestApplicant $applicantApplicantRepository $applicantRepository): Response
  434.   {
  435.  /*   $form = $this->createFormBuilder()
  436.     ->add('status', TextType::class,[
  437.         'label' => 'Status'])
  438.     ->add('status', TextType::class,[
  439.         'label' => 'Status'])
  440.     ->add('Review', SubmitType::class)
  441.     ->getForm();
  442.     $form->handleRequest($request);
  443. */
  444. if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  445.     $user $this->container->get('security.token_storage')->getToken()->getUser();
  446.     $username $user->getUsername();
  447.    // $useremail = $user->getEmail();
  448.     $UserRoles $user->getRoles();
  449.     
  450. }
  451. $form $this->createForm(ApplicantType::class, $applicant);
  452. $form->handleRequest($request);    
  453.       if ($form->isSubmitted() && $form->isValid()) {
  454.         
  455.       $mynotes =   $form->get('Notes')->getData()." added by ".$username." on ".date("m-d-Y");
  456. $applicant->setNotes($mynotes);
  457.           $applicantRepository->add($applicanttrue);
  458.         //  return $this->redirectToRoute('app_applicant_index', [], Response::HTTP_SEE_OTHER);
  459.       }
  460.       return $this->renderForm('applicant/review.html.twig', [
  461.           'applicant' => $applicant,
  462.           'form' => $form,
  463.       ]);
  464.   }
  465.     /**
  466.      * @Route("/{id}", name="app_applicant_delete", methods={"POST"})
  467.      */
  468.   /*  public function delete(Request $request, Applicant $applicant, ApplicantRepository $applicantRepository): Response
  469.     {
  470.         if ($this->isCsrfTokenValid('delete'.$applicant->getId(), $request->request->get('_token'))) {
  471.             $applicantRepository->remove($applicant, true);
  472.         }
  473.         return $this->redirectToRoute('app_applicant_index', [], Response::HTTP_SEE_OTHER);
  474.     }
  475.     */
  476. }