src/Controller/OsobaController.php line 114

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Osoba;
  4. use App\Form\OsobaType;
  5. use App\Repository\OsobaRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Mailer\MailerInterface;
  11. use Symfony\Component\Mime\Email;
  12. use Symfony\Component\HttpFoundation\Session\Session;
  13. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  14. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  15. /**
  16.  * @Route("/osoba")
  17.  */
  18. class OsobaController extends MyController
  19. {
  20.     /**
  21.      * @Route("/", name="osoba_index", methods={"GET"})
  22.      */
  23.     public function index(OsobaRepository $osobaRepository): Response
  24.     {   $ck=new \App\Entity\Jednostka();
  25.         $komorka$this->getUser()->getKomorka();
  26.         $ck=$komorka->getCk()->getSymbolNum();
  27.         
  28.         return $this->render('osoba/index.html.twig', [
  29.             'osobas' => $osobaRepository->findByCk($ck)
  30.         ]);
  31.     }
  32.     /**
  33.      * @Route("/mailtest", name="mailtest", methods={"GET","POST"})
  34.      * 
  35.      */
  36.     public function mailTest(MailerInterface $mailer): Response
  37.     {
  38.         $email = (new Email())
  39.             ->from('zapisy@zdz.com.pl')
  40.             ->to('mkolodziejczak@gmail.com')
  41.             //->cc('cc@example.com')
  42.             //->bcc('bcc@example.com')
  43.             //->replyTo('fabien@example.com')
  44.             //->priority(Email::PRIORITY_HIGH)
  45.             ->subject('Time for Symfony Mailer!')
  46.             ->text('Sending emails is fun again!')
  47.             ->html('<p>See Twig integration for better HTML integration!</p>');
  48.         $mailer->send($email);
  49.         
  50.         return $this->redirectToRoute('homepage');
  51.     }
  52.     
  53.     
  54.     /**
  55.      * @Route("/new/{grupaId}", name="osoba_new", methods={"GET","POST"})
  56.      */
  57.     public function new(Request $request$grupaId=nullMailerInterface $mailer): Response
  58.     {
  59.         $osoba = new Osoba();
  60.         $osoba->setStatus("nowy");
  61.         $entityManager $this->getDoctrine()->getManager();
  62.         
  63.         
  64.         $wersjaZaswiadczenia=1;
  65.         if($grupaId){
  66.             $grupa=$this->getRepo('Grupa')->find($grupaId);
  67.             $osoba->setGrupa($grupa);
  68.             $ck=$grupa->getCk();
  69.             $osoba->setCk($ck);
  70.         }
  71.         
  72.         $form $this->createForm(OsobaType::class, $osoba);
  73.         $form->handleRequest($request);
  74.         if ($form->isSubmitted() ) {
  75.             $entityManager $this->getDoctrine()->getManager();
  76.             $osoba->setZgodaRodo(true);
  77.             $entityManager->persist($osoba);
  78.             $entityManager->flush();
  79.             return $this->redirectToRoute('grupa_show', ['id'=>$grupaId], Response::HTTP_SEE_OTHER);
  80.         }
  81.         return $this->renderForm('osoba/nowa.html.twig', [
  82.             'osoba' => $osoba,
  83.             'form' => $form,
  84.         ]);
  85.     }
  86.     
  87.     
  88.         /**
  89.      * @Route("/intnew/{grupaId}", name="osoba_newinternet", methods={"GET","POST"})
  90.      */
  91.     public function newInternet(Request $request$grupaId=nullMailerInterface $mailerSession $ses): Response
  92.     {
  93.         $osoba = new Osoba();
  94.         $osoba->setDataZapisu(new \DateTime());
  95.         $osoba->setStatus("nowy");
  96.         $entityManager $this->getDoctrine()->getManager();
  97.         $l1random_int(19);
  98.         $l2random_int(19);
  99.         $wynik=$l1+$l2;
  100.         
  101.         
  102.         if($grupaId){
  103.             $grupa=$this->getRepo('Grupa')->find($grupaId);
  104.             $osoba->setGrupa($grupa);
  105.             $ck=$grupa->getCk();
  106.             $osoba->setCk($ck);
  107.         }else{
  108.             return $this->redirectToRoute('home404');
  109.         }
  110.         
  111.         $form $this->createForm(OsobaType::class."_internet"$osoba);
  112. //        $form->add("wynik",NumberType::class,[
  113. //            //'mapped'=>false,
  114. //            'label'=>"Podaj wynik $l1 + $l2=",
  115. //            'required'=>true
  116. //        ] );
  117. //        
  118. //        $form->add("wtoken",NumberType::class,[
  119. //            //'mapped'=>false,
  120. //            'attr'=>['value'=>$wynik*1234]
  121. //            
  122. //        ] );
  123.         $form->handleRequest($request);
  124.         if ($form->isSubmitted() && $form->isValid()) {
  125.             $entityManager $this->getDoctrine()->getManager();
  126.             $entityManager->persist($osoba);
  127.             $entityManager->flush();
  128.             
  129.             $opiekunEmail=$osoba->getGrupa()->getOrganizator()->getKomorka()->getEmail();
  130.             $dane=$form->getData();
  131.             //dd($dane);
  132.             
  133.             /* Mail uczestnik */
  134.             if(true){
  135.                 $osobaEmail $osoba->getEmail();
  136.                 $opiekun=$osoba->getGrupa()->getOrganizator()->getImie() . " ".$osoba->getGrupa()->getOrganizator()->getNazwisko();
  137.                 $opiekunEmail=$osoba->getGrupa()->getOrganizator()->getEmail();
  138.                 $komorkaEmail=$osoba->getGrupa()->getOrganizator()->getKomorka()->getEmail();
  139.                 $opiekunTelefon=$osoba->getGrupa()->getOrganizator()->getKomorka()->getTelefon();
  140.                 $jednostka=$osoba->getGrupa()->getKomorka()->getNazwa();
  141.                 $ckNumer=$osoba->getGrupa()->getJednostka()->getSymbol();
  142.                 $grupaNazwa=$osoba->getGrupa()->getNazwa();
  143.                 $numerZapisu=$osoba->getGrupa()->getId()."/".$osoba->getId();
  144.                 
  145.                 $temat="Zapis na szkolenie ZDZ #".$numerZapisu;
  146.                 
  147.                 $tresc=$this->renderView(
  148.                         // templates/emails/registration.html.twig
  149.                         'osoba/_mail-uczestnik.html.twig', [
  150.                             'opiekun' => $opiekun,
  151.                             'opiekunEmail' => $opiekunEmail,
  152.                             'opiekunTelefon' => $opiekunTelefon,
  153.                             'jednostka' => $jednostka,
  154.                             'ckNumer' => $ckNumer,
  155.                             'nazwaGrupy'=>$grupaNazwa,
  156.                             'numerZapisu'=>$numerZapisu,
  157.                            ]
  158.                 );
  159.                 
  160.                 $temat1="Zapis eZDZ: #".$numerZapisu." / ".$grupaNazwa;
  161.                 
  162.                 $tresc1=$this->renderView(
  163.                         // templates/emails/registration.html.twig
  164.                         'osoba/_mail-organizator.html.twig', [
  165.                             'opiekun' => $opiekun,
  166.                             'opiekunImie' => $osoba->getGrupa()->getOrganizator()->getImie(),
  167.                             'opiekunEmail' => $opiekunEmail,
  168.                             'opiekunTelefon' => $opiekunTelefon,
  169.                             'jednostka' => $jednostka,
  170.                             'ckNumer' => $ckNumer,
  171.                             'nazwaGrupy'=>$grupaNazwa,
  172.                             'numerZapisu'=>$numerZapisu,
  173.                             'grupa'=>$osoba->getGrupa(),
  174.                             'osoba'=>$osoba
  175.                            ]
  176.                 );
  177.                 
  178.                 
  179.                 $email = (new Email())
  180.                     ->from('zapisy@zdz.com.pl')
  181.                     ->to(strtolower($osobaEmail))
  182.                     //->cc('cc@example.com')
  183.                     ->bcc('frnt.monitoring@gmail.com')
  184.                     //->bcc('zapisy@zdz.com.pl')
  185.                     //->replyTo('fabien@example.com')
  186.                     //->priority(Email::PRIORITY_HIGH)
  187.                     ->subject($temat)
  188.                     //->text($tresc)
  189.                     ->html($tresc);
  190.             
  191.             
  192.         $mailer->send($email);
  193.         
  194.         $emailOrg = (new Email())
  195.                 ->from('zapisy@zdz.com.pl')
  196.                 ->to(strtolower($komorkaEmail))
  197.                 ->addTo(strtolower($opiekunEmail))
  198.                 //->cc('cc@example.com')
  199.                 ->bcc('frnt.monitoring@gmail.com')
  200.                 //->addBcc('zapisy@zdz.com.pl')
  201.                 //->replyTo('fabien@example.com')
  202.                 //->priority(Email::PRIORITY_HIGH)
  203.                 ->subject($temat1)
  204.                 //->text($tresc)
  205.                 ->html($tresc1);
  206.             
  207.             
  208.         $mailer->send($emailOrg);
  209.         
  210.             }
  211.             
  212.             return $this->render('osoba/new_internet-thx.html.twig', [
  213.             'osoba' => $osoba,
  214.             'grupa' => $grupa,
  215.             
  216.                 ]);
  217.         }
  218.         return $this->renderForm('osoba/new_internet.html.twig', [
  219.             'osoba' => $osoba,
  220.             'grupa' => $grupa,
  221.             'form' => $form,
  222.         ]);
  223.     }
  224.     /**
  225.      * @Route("/{id}", name="osoba_show", methods={"GET"})
  226.      */
  227.     public function show(Osoba $osoba): Response
  228.     {
  229.         return $this->render('osoba/show.html.twig', [
  230.             'osoba' => $osoba,
  231.         ]);
  232.     }
  233.     /**
  234.      * @Route("/{id}/edit", name="osoba_edit", methods={"GET","POST"})
  235.      */
  236.     public function edit(Request $requestOsoba $osoba): Response
  237.     {   $em=$this->getDoctrine()->getManager();
  238.         $form $this->createForm(OsobaType::class, $osoba);
  239.         $form->handleRequest($request);
  240.         
  241.         if ($form->isSubmitted() ) {
  242.             
  243.             $em->persist($osoba);
  244.             $em->flush();
  245.             return $this->redirectToRoute('grupa_show', ['id'=>$osoba->getGrupa()->getId()], Response::HTTP_SEE_OTHER);
  246.         }
  247.         
  248.         return $this->renderForm('osoba/edit.html.twig', [
  249.             'osoba' => $osoba,
  250.             'form' => $form,
  251.         ]);
  252.     }
  253.     /**
  254.      * @Route("/{id}", name="osoba_delete", methods={"POST"})
  255.      */
  256.     public function delete(Request $requestOsoba $osoba): Response
  257.     {
  258.         if ($this->isCsrfTokenValid('delete'.$osoba->getId(), $request->request->get('_token'))) {
  259.             $entityManager $this->getDoctrine()->getManager();
  260.             $entityManager->remove($osoba);
  261.             $entityManager->flush();
  262.         }
  263.         return $this->redirectToRoute('osoba_index', [], Response::HTTP_SEE_OTHER);
  264.     }
  265. }