src/JuridicusBundle/Controller/PrueferController.php line 188

Open in your IDE?
  1. <?php
  2. namespace JF\JuridicusBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  7. use Symfony\Component\Process\Process;
  8. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  13. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  14. use JF\JuridicusBundle\Entity\Kunde;
  15. use JF\JuridicusBundle\Entity\KundePruefung;
  16. use JF\JuridicusBundle\Entity\PrueferEmail;
  17. use JF\JuridicusBundle\Entity\Pruefer;
  18. use JF\JuridicusBundle\Entity\PrueferUser;
  19. use JF\JuridicusBundle\Entity\User;
  20. use JF\JuridicusBundle\Entity\Pruefung;
  21. use JF\JuridicusBundle\Entity\PdfProtokollmappePruefer;
  22. use JF\JuridicusBundle\Entity\ProtokollInfothekPruefer;
  23. use JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefer;
  24. use JF\JuridicusBundle\Entity\ProtokollInfothekPruefung;
  25. use JF\JuridicusBundle\Entity\Download;
  26. use JF\JuridicusBundle\Entity\Pruefungsamt;
  27. use JF\JuridicusBundle\Entity\Bundesland;
  28. use JF\JuridicusBundle\Form\PrueferType;
  29. use JF\JuridicusBundle\Form\PrueferUserType;
  30. use JF\JuridicusBundle\Form\PruefungsamtPreSelectType;
  31. use Symfony\Component\Form\Extension\Core\Type\DateType;
  32. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  33. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  34. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  35. use Swift_Mailer;
  36. use Swift_Message;
  37. use Doctrine\ORM\EntityManagerInterface;
  38. use JF\JuridicusBundle\Services\Sms;
  39. use JF\JuridicusBundle\Entity\MailTemplate;
  40. /**
  41.  * Pruefer controller.
  42.  */
  43. class PrueferController extends AbstractController
  44. {
  45.     /**
  46.      * Lists all Pruefungsamt entities.
  47.      *
  48.      * @Route("/pruefungsprotokolle-{examNr}-staatsexamen", name="pruefer")
  49.      */
  50.     public function indexAction($examNr 1)
  51.     {
  52.         $em $this->getDoctrine()->getManager();
  53.         if ($examNr == 1) {
  54.             $examType Pruefung::TYP_EXAMEN_1;
  55.         } else {
  56.             $examType Pruefung::TYP_EXAMEN_2;
  57.         }
  58.         
  59.         $pip_repo $em->getRepository(ProtokollInfothekPruefer::class);
  60.         $statistik $pip_repo->filterParagraphsByExamen($examType);
  61.         $bundeslaender $em->getRepository(Bundesland::class)->findAll();
  62.         
  63.         $entities $em->getRepository(Pruefung::class)->findNewest(8$examType);
  64.         $entities_indexed1 = array();
  65.         $entities_indexed2 = array();
  66.         $index 0;
  67.         foreach ($entities as $entity) {
  68.             $datum $entity->getDatum()->format('d.m.Y');
  69.             if ($index%== 0) {
  70.                 $entities_indexed1[$datum][] = $entity;
  71.             } else {
  72.                 $entities_indexed2[$datum][] = $entity;
  73.             }
  74.             $index++;
  75.         }
  76.         
  77.         $filter_form $this->createParagraphFilterForm($examNr);
  78.         
  79.         return $this->render('@JFJuridicusBundle/Pruefer/pruefungsamt_index.html.twig', array(
  80.             'statistik'         => $statistik,
  81.             'filter_form'       => $filter_form->createView(),
  82.             'entities_indexed1' => $entities_indexed1,
  83.             'entities_indexed2' => $entities_indexed2,
  84.             'examType'             => $examType,
  85.             'entities' => $bundeslaender,
  86.         ));
  87.     }
  88.     
  89.         /**
  90.      *
  91.      * @param array $data
  92.      * @return \Symfony\Component\Form\Form
  93.      */
  94.     private function createParagraphFilterForm($examNr)
  95.     {
  96.         $data = array('examen'=>$examNr);
  97.         return $this->createFormBuilder($data)
  98.                 ->add('bundesland'EntityType::class, array(
  99.                      'label'       => false,
  100.                     'class' => 'JF\JuridicusBundle\Entity\Bundesland',
  101.                     'placeholder' => 'Bundesland wählen...',
  102.                     'required' => false,
  103.                     
  104.                 ))
  105.                 ->add('fach'ChoiceType::class, array(
  106.                     'label'       => false,
  107.                     'placeholder' => 'Fach auswählen...',
  108.                     'choices' => array(
  109.                         'Strafrecht' => 'Strafrecht',
  110.                         'Öffentliches Recht' => 'Öffentliches Recht',
  111.                         'Zivilrecht' => 'Zivilrecht',
  112.                         'Arbeitsrecht' => 'Arbeitsrecht',
  113.                         'Verwaltungsrecht' => 'Verwaltungsrecht',
  114.                     ),
  115.                     'required' => false,
  116.                     
  117.                 ))
  118.                 ->add('startdatum'DateType::class, array(
  119.                     'label'       => false,
  120.                     'placeholder' => 'Zeitraum von',
  121.                     'widget'      => 'single_text',
  122.                     //'format'      => 'dd.MM.yyyy',
  123.                     'required'    => false,
  124.                     'attr'        => ['class' => 'js-datepicker''placeholder' => 'Zeitraum von ...',],
  125.                 ))
  126.                 ->add('endedatum'DateType::class, array(
  127.                     'label'       => false,
  128.                     'placeholder' => 'bis ...',
  129.                     'widget'      => 'single_text',
  130.                     //'format'      => 'dd.MM.yyyy',
  131.                     'placeholder' => '',
  132.                     'required'    => false,
  133.                     'attr'        => ['class' => 'js-datepicker''placeholder' => 'bis',],
  134.                 ))
  135.                 ->add('examen'HiddenType::class, array(
  136.                     'label'       => false,
  137.                     
  138.                     'required' => false,
  139.                     
  140.                 ))
  141.                 ->getForm();
  142.     }
  143.     /**
  144.      * Finds and displays Pruefer entities for a given Prüfungsamt
  145.      *
  146.      * @Route("/pruefungsprotokolle-{examen}-staatsexamen/{bslug}", 
  147.      *  name="pruefer_index_pruefungsamt", 
  148.      *  requirements={"examen"="[12]"}
  149.      * )
  150.      */
  151.     public function showPruefungsamtAction($bslug$examen)
  152.     {
  153.         $em $this->getDoctrine()->getManager();
  154.         $pruefungsamt $em->getRepository(Pruefungsamt::class)->findByExamenAndBSlug($examen$bslug);
  155.         if (!$pruefungsamt) {
  156.             throw $this->createNotFoundException('Prüfungsamt wurde nicht gefunden.');
  157.         }
  158.         $pruefer_liste $em->getRepository(Pruefer::class)
  159.                 ->findByPruefungsamt($pruefungsamt->getId(), $pruefungsamt->hasVollbestand());
  160.         $statistik $em->getRepository(ProtokollInfothekPruefer::class)->filterParagraphsByPruefungsamt($pruefungsamt);
  161.         return $this->render('@JFJuridicusBundle/Pruefer/index.html.twig', array(
  162.             'pruefungsamt' => $pruefungsamt,
  163.             'pruefer_liste' => $pruefer_liste,
  164.             'typ_options' => Pruefung::getTypOptions(),
  165.             'statistik' => $statistik,
  166.         ));
  167.     }
  168.     /**
  169.      * Finds and displays a Pruefer entity.
  170.      *
  171.      * @Route("/pruefungsprotokolle-{examen}-staatsexamen/{bslug}/{pslug}_pruefer_protokolle_pruefung_jura",
  172.      *         name="pruefer_show",
  173.      *      requirements={"examen"="[12]"}
  174.      * )
  175.      */
  176.     public function showAction($examen$bslug$pslug)
  177.     {
  178.         $em $this->getDoctrine()->getManager();
  179.         $bundesland $em->getRepository(Bundesland::class)->findOneBySlug($bslug);
  180.         if (!$bundesland) {
  181.             throw $this->createNotFoundException('Bundesland wurde nicht gefunden.');            
  182.         }
  183.         $pruefungsamt $em->getRepository(Pruefungsamt::class)->findByExamenAndBSlug($examen$bslug);
  184.         if (!$pruefungsamt) {
  185.             throw $this->createNotFoundException('Prüfungsamt wurde nicht gefunden.');
  186.         }
  187.         // Bei Vollbestand werden Prüfer ohne Protokolle umgeleitet - eventuell ändern?
  188.         $pruefer $em->getRepository(Pruefer::class)
  189.             ->findByPruefungsamtAndSlug($pruefungsamt->getId(), $pslug$pruefungsamt->hasVollbestand());
  190.         if (!$pruefer) {
  191.             return $this->redirect($this->generateUrl('pruefer_index_pruefungsamt', array(
  192.                 'examen' => $examen'bslug' => $bslug,
  193.             )));
  194.         }
  195.         $kunde = new Kunde();
  196.         $kunde->setBundesland($bundesland);
  197.         $kunde->setExamen($examen);
  198.         
  199.         $form $this->createForm(PruefungsamtPreSelectType::class, $kunde);
  200.               
  201.         return $this->render('@JFJuridicusBundle/Pruefer/show.html.twig', array(
  202.             'bundesland' => $bundesland,
  203.             'examen' => $examen,
  204.             'pruefungsamt' => $pruefungsamt,
  205.             'pruefer' => $pruefer,
  206.             'form' => $form->createView(),
  207.             'typ_options' => Pruefung::getTypOptions(),
  208.         ));
  209.     }
  210.     /**
  211.      * Finds and displays a Pruefer and shows download text
  212.      *
  213.      * @Route("/pruefer/download/success", name="pruefer_download_success")
  214.      * @Method({"POST"})
  215.      */
  216.     public function downloadSuccessAction(Request $request)
  217.     {
  218.         $this->denyAccessUnlessGranted('ROLE_KUNDE');
  219.         $em $this->getDoctrine()->getManager();
  220.         $user $this->getUser();
  221.         $kunde $user->getKunde();
  222.         /* @var $kunde \JF\JuridicusBundle\Entity\Kunde */
  223.         $pruefer_id $request->request->getInt('pruefer_id');
  224.         $pruefung_id $request->request->getInt('pruefung_id');
  225.         $examen $request->request->getInt('examen');
  226.         if (!$pruefer_id or !$examen or !$pruefung_id) {
  227.             throw new AccessDeniedException();
  228.         }
  229.         $pruefer $em->getRepository(Pruefer::class)->find($pruefer_id);
  230.         if (!$pruefer) {
  231.             throw $this->createNotFoundException('Prüfer nicht gefunden');
  232.         }
  233.         if ($pruefer->getAliasFor()) {
  234.             $pruefer $pruefer->getAliasFor();
  235.         }
  236.         // Berechtigung checken
  237.         $buchung $em->getRepository(KundePruefung::class)->getDownloadPermission($kunde->getId(), $pruefer->getId());
  238.         /* @var $buchung \JF\JuridicusBundle\Entity\KundePruefung */
  239.         if (!$buchung) {
  240.             // Donwload nicht erlaubt
  241.             throw new AccessDeniedException();
  242.         } else if ($buchung->needsFacebookPost()) {
  243.             // umleiten
  244.             return $this->redirect($this->generateUrl('facebook_write_post', array(
  245.                 'id' => $buchung->getId(),
  246.                 'pruefer_id' => $pruefer_id,
  247.                 'pruefung_id' => $pruefung_id,
  248.                 'examen' => $examen
  249.             )));
  250.         } else if ($buchung->needsKlausurprotokoll()) {
  251.             // umleiten
  252.             return $this->redirect($this->generateUrl('protokoll_klausur_edit', array('id' => $buchung->getId())));
  253.         } else {
  254.             // Download erlaubt
  255.             $pdf $em->getRepository(PdfProtokollmappePruefer::class)->findOneByPrueferAndExamen($pruefer->getId(), $examen);
  256.             if (!$pdf) {
  257.                 throw $this->createNotFoundException('Protokolldatei nicht gefunden');
  258.             }
  259.         }
  260.         return $this->render("@JFJuridicusBundle/Pruefer/download_success.html.twig", array(
  261.             'pruefer' => $pruefer,
  262.             'examen' => $examen,
  263.             'pdf_id' => $pdf->getId()
  264.         ));
  265.     }
  266.     /**
  267.      * shows download error text
  268.      *
  269.      * @Route("/pruefer/download/error", name="pruefer_download_error")
  270.      */
  271.     public function downloadErrorAction(Request $request)
  272.     {
  273.         $this->denyAccessUnlessGranted('ROLE_KUNDE');
  274.         return $this->render('@JFJuridicusBundle/Pruefer/download_error.html.twig', array());
  275.     }
  276.     /**
  277.      * @Route("/pruefer/download/success/protokollmappe-{id}.pdf", name="pruefer_download")
  278.      */
  279.     public function downloadAction(PdfProtokollmappePruefer $pdf)
  280.     {
  281.         $this->denyAccessUnlessGranted('ROLE_KUNDE');
  282.         $em $this->getDoctrine()->getManager();
  283.         $user $this->getUser();
  284.         $kunde $user->getKunde();
  285.         /* @var $kunde \JF\JuridicusBundle\Entity\Kunde */
  286.         $pruefer $pdf->getPruefer();
  287.         // Berechtigung checken
  288.         $buchung $em->getRepository(KundePruefung::class)->getDownloadPermission($kunde->getId(), $pruefer->getId());
  289.         /* @var $buchung \JF\JuridicusBundle\Entity\KundePruefung */
  290.         if (!$buchung || $buchung->needsKlausurprotokoll()) {
  291.             throw new AccessDeniedException();
  292.         }
  293.         // Dateiname für private Kopie
  294.         $dir $pdf->getDir();
  295.         $stamped_path tempnam($dir'protokoll_stamped_');
  296.         
  297.         //print_r($kunde->getPdfStempel()->getPath());
  298.         //exit();
  299.         // Protokoll stempeln
  300.         $process = new Process([
  301.             'pdftk',
  302.             $pdf->getPath(),
  303.             'stamp',
  304.             $kunde->getPdfStempel()->getPath(),
  305.             'output',
  306.             $stamped_path,
  307.             'owner_pw',
  308.             'stucha5Ac3ep'// später: $bag->get('tcpdf_owner_pw')
  309.             'allow',
  310.             'printing',
  311.         ]);
  312.         $process->run();
  313.         if (!$process->isSuccessful()) {
  314.                 var_dump($process->getErrorOutput());
  315.                 exit();
  316.             return $this->redirect($this->generateUrl('pruefer_download_error'));
  317.         }
  318.         $download $em->getRepository(Download::class)->findOneBy(array(
  319.             'kunde' => $kunde->getId(), 'pruefer' => $pruefer->getId(), 'examen' => $pdf->getExamen()
  320.         ));
  321.         /* @var $download \JF\JuridicusBundle\Entity\Download */
  322.         if (!$download) {
  323.             $download = new Download();
  324.             $download->setKunde($kunde)->setPruefer($pruefer)->setExamen($pdf->getExamen());
  325.         }
  326.         $download->setBuchung($buchung);
  327.         $download->setAnzahlProtokolle($pdf->getAnzahlProtokolle());
  328.         $em->persist($download);
  329.         $em->flush();
  330.         $filename sprintf('%s-%d-examen.pdf'$pruefer->getSlug(), $pdf->getExamen());
  331.         $response = new Response();
  332.         $disposition $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT$filename);
  333.         $response->headers->set('Content-Disposition'$disposition);
  334.         $response->headers->set('Content-Type'$pdf->getMimeType());
  335.         $response->setContent(@file_get_contents($stamped_path));
  336.         unlink($stamped_path);
  337.         return $response;
  338.     }
  339.     /**
  340.      * Displays a form to create a new Pruefer entity.
  341.      *
  342.      * @Route("/pruefer/ajax/new", name="pruefer_ajax_new")
  343.      */
  344.     public function newAjaxAction()
  345.     {
  346.         $this->denyAccessUnlessGranted('ROLE_KUNDE');
  347.         $em $this->getDoctrine()->getManager();
  348.         $dienststellung_typeaheads $em->getRepository(Dienststellung::class)->getTypeaheads();
  349.         $titel_typeaheads $em->getRepository(Titel::class)->getTypeaheads();
  350.         
  351.         $entity = new Pruefer();
  352.         $form $this->createForm(PrueferType::class, $entity);
  353.         return $this->render("JFJuridicusBundle:Pruefer:new.html.twig", array(
  354.             'entity' => $entity,
  355.             'form' => $form->createView(),
  356.             'dienststellungNames' => array_keys($dienststellung_typeaheads),
  357.             'titelNames' => array_keys($titel_typeaheads),
  358.         ));
  359.     }
  360.     /**
  361.      * Creates a new Pruefer entity per ajax
  362.      *
  363.      * @Route("/pruefer/ajax/create", name="pruefer_ajax_create")
  364.      * @Method({"POST"})
  365.      */
  366.     public function createAjaxAction(Request $request)
  367.     {
  368.         $this->denyAccessUnlessGranted('ROLE_KUNDE');
  369.         $em $this->getDoctrine()->getManager();
  370.         $user $this->getUser();
  371.         $kunde $user->getKunde();
  372.         $pruefungsamt $em->getRepository(Pruefungsamt::class)->findOneByUser($user->getId());
  373.         $entity = new Pruefer();
  374.         $entity->setQuelle('man');
  375.         $entity->setCreator($user);
  376.         $pruefungsamt_candidates $kunde->getBundesland()->getPruefungsaemter();
  377.         foreach ($pruefungsamt_candidates as $candidate) {
  378.             $entity->addPruefungsaemter($candidate);
  379.         }
  380.         $form $this->createForm(PrueferType::class, $entity);
  381.         $form->handleRequest($request); //changedFrom bind
  382.         if ($form->isValid()) {
  383.             // Prüfungsämter abgleichen
  384.             $existing_pruefer $em->getRepository(Pruefer::class)->findExisting($entity$pruefungsamt);
  385.             if (empty($existing_pruefer)) {
  386.                 $entity->setAliasFor(
  387.                     $em->getRepository(Pruefer::class)->findAlias($entitynull$pruefungsamt)
  388.                 );
  389.                 $em->persist($entity);
  390.                 $em->flush();
  391.             } else {
  392.                 foreach ($pruefungsamt_candidates as $candidate) {
  393.                     $candidate->removePruefer($entity);
  394.                 }
  395.                 foreach ($existing_pruefer as $p) {
  396.                     /* @var $p \JF\JuridicusBundle\Entity\Pruefer */
  397.                     foreach ($pruefungsamt_candidates as $candidate) {
  398.                         if (!$p->getPruefungsaemter()->contains($candidate)) {
  399.                             $p->addPruefungsaemter($candidate);
  400.                         }
  401.                     }
  402.                     $em->persist($p);
  403.                 }
  404.                 $em->flush();
  405.                 $entity $existing_pruefer[0];
  406.             }
  407.             return new JsonResponse(array(
  408.                 'success' => true,
  409.                 'objectId' => $entity->getId(),
  410.                 'objectName' => $entity->getFullTextWithOrt()
  411.             ));
  412.         }
  413.         $dienststellung_typeaheads $em->getRepository(Dienststellung::class)->getTypeaheads();
  414.         $titel_typeaheads $em->getRepository(Titel::class)->getTypeaheads();
  415.         $html $this->get('templating')->render("@JFJuridicusBundle/Pruefer/new.html.twig", array(
  416.             'entity' => $entity,
  417.             'form' => $form->createView(),
  418.             'dienststellungNames' => array_keys($dienststellung_typeaheads),
  419.             'titelNames' => array_keys($titel_typeaheads),
  420.         ));
  421.         return new JsonResponse(array(
  422.             'success' => false,
  423.             'html' => $html
  424.         ));
  425.     }
  426.     
  427.     /**
  428.      * Lists all Pruefungsamt entities.
  429.      * @Method({"GET"})
  430.      * @Route("/pruefer/protokolle", name="pruefer_protokolle")
  431.      */
  432.     public function prueferBereichAction()
  433.     {
  434.         $this->denyAccessUnlessGranted('ROLE_PRUEFER');
  435.         $em             $this->getDoctrine()->getManager();
  436.         $user             $this->getUser();
  437.         $prueferUser     $em->getRepository(PrueferUser::class)->findOneByUser($user);
  438.         if (!$prueferUser) {
  439.             return $this->render('@JFJuridicusBundle/PrueferBereich/not_yet_verified.html.twig', array(
  440.             
  441.             ));
  442.         }
  443.         $pruefer         $prueferUser->getPruefer();
  444.         if (!$pruefer) {
  445.             return $this->render('@JFJuridicusBundle/PrueferBereich/not_yet_verified.html.twig', array(
  446.             
  447.             ));
  448.         }
  449.         
  450.         $lastDate = new \DateTime("01-01-2011");
  451.             //$output->writeln("Prüfer: ".$pruefer->getId()." Pruefungen: ".count($pruefer->getPrueferPruefungen())); 
  452.             foreach($pruefer->getPrueferPruefungen() as $prueferPruefung) {
  453.                 if ($lastDate $prueferPruefung->getPruefung()->getDatum()) {
  454.                         //prüfe ob dazu auch ein Protokoll gibt
  455.                         $infothekPruefung     $em->getRepository(ProtokollInfothekPruefung::class)->findBy(['pruefung'=>$prueferPruefung->getPruefung()]);
  456.                         if($infothekPruefung) {
  457.                             $lastDate $prueferPruefung->getPruefung()->getDatum();
  458.                         }
  459.                 }
  460.             }
  461.             foreach($pruefer->getAliases() as $allias) {
  462.                 //$output->writeln("Alias: ".$allias->getId()."  Pruefungen: ".count($allias->getPrueferPruefungen())); 
  463.                 foreach($allias->getPrueferPruefungen() as $prueferPruefung) {
  464.                     if ($lastDate $prueferPruefung->getPruefung()->getDatum()) {
  465.                         $infothekPruefung     $em->getRepository(ProtokollInfothekPruefung::class)->findBy(['pruefung'=>$prueferPruefung->getPruefung()]);
  466.                         if($infothekPruefung) {
  467.                             $lastDate $prueferPruefung->getPruefung()->getDatum();
  468.                         }
  469.                     }
  470.                     
  471.                 }
  472.             }
  473.             
  474.         
  475.         
  476.         //Letztes Protokoll
  477.         //$lastProtocol     = $em->getRepository('JFJuridicusBundle:Pruefer')->findLastProtocol($pruefer);
  478.         $pdf1Exam         $em->getRepository(PdfProtokollmappePruefer::class)->findOneByPrueferAndExamen($pruefer->getId(), 1);
  479.         $pdf2Exam         $em->getRepository(PdfProtokollmappePruefer::class)->findOneByPrueferAndExamen($pruefer->getId(), 2);
  480.         
  481.         return $this->render('@JFJuridicusBundle/PrueferBereich/index.html.twig', array(
  482.             "lastProtocol"    =>     $lastDate,
  483.             "pruererUser"     =>    $prueferUser,
  484.             "pruefer"        =>    $pruefer,
  485.             "pdf1Exam"         =>     $pdf1Exam,
  486.             "pdf2Exam"         =>     $pdf2Exam
  487.         ));
  488.     }
  489.     /**
  490.      * @Method({"GET"})
  491.      * @Route("/pruefer/protokolle/download/{exam}", name="pruefer_protokolle_download")
  492.      */
  493.     public function prueferBereichDownloadAction($exam) {
  494.         $this->denyAccessUnlessGranted('ROLE_PRUEFER');
  495.         $em             $this->getDoctrine()->getManager();
  496.         $user             $this->getUser();
  497.         $prueferUser     $em->getRepository(PrueferUser::class)->findOneByUser($user);
  498.         $pruefer         $prueferUser->getPruefer();
  499.         if (!$pruefer) {
  500.             throw $this->createNotFoundException('Pruefer noch nicht verifiziert');
  501.         }
  502.         
  503.         // Download erlaubt
  504.         $pdf $em->getRepository(PdfProtokollmappePruefer::class)->findOneByPrueferAndExamen($pruefer->getId(), $exam);
  505.     
  506.         return $pdf->createResponse();
  507.     }
  508.     /**
  509.      * @Method({"GET"})
  510.      * @Route("/pruefer/registration", name="pruefer_registration")
  511.      */
  512.     public function prueferRegistrationAction()
  513.     {
  514.         $form $this->createForm(PrueferUserType::class, new PrueferUser());
  515.         
  516.         return $this->render('@JFJuridicusBundle/PrueferBereich/registration.html.twig', array( 
  517.             "form" => $form->createView()
  518.         ));
  519.     }
  520.     
  521.     /**
  522.      * @Method({"POST"})
  523.      * @Route("/pruefer/registration/save", name="pruefer_registration_save")
  524.      */
  525.     public function prueferRegistrationSaveAction(Request $request)
  526.     {
  527.         $form $this->createForm(PrueferUserType::class, new PrueferUser()); //changedFrom
  528.         $form->handleRequest($request); //changedFrom bind
  529.     
  530.         if ($form->isSubmitted() && $form->isValid()) {
  531.             $em $this->getDoctrine()->getManager();
  532.             $prueferUser $form->getData();
  533.             //dump($prueferUser);
  534.             //früher fos_user - nicht sicher ob es jetzt user ist Hier [TODO] - wie war unterschied fos_user und prueferUser?
  535.             $user                 $em->getRepository(User::class)->findOneBy(['email'=>$prueferUser->getEmail()]);
  536.             $prueferUserOld     $em->getRepository(PrueferUser::class)->findOneByEmail($prueferUser->getEmail());
  537.             
  538.             if ($prueferUserOld) {
  539.                 return $this->render('@JFJuridicusBundle/PrueferBereich/email_in_use.html.twig', array( 
  540.                     
  541.                 ));
  542.                 //throw $this->createNotFoundException('Die von Ihnen genutzte E-Mail-Adresse ist bei juridicus bereits registriert. Bitte nutzen Sie die „Passwort vergessen“- Funktion. Sollte Ihnen wider Erwarten kein neues Passwort zugestellt werden, nehmen Sie bitte über info@juridicus.de Kontakt mit uns auf.');
  543.             }
  544.             // alten User ggfs. umbiegen
  545.             if ($user) {
  546.                 $kunde_old $user->getKunde();
  547.                 if ($kunde_old) {
  548.                     $kunde_old->setUser(null);
  549.                     $em->persist($kunde_old);
  550.                     $em->flush();
  551.                 } else {
  552.                     $user->addRole("ROLE_PRUEFER");
  553.                 }
  554.             } else {
  555.                 // entsprechenden User neu erstellen
  556.                 $user = new User();
  557.                 $user->addRole("ROLE_PRUEFER");
  558.                 $user->setUsername($prueferUser->getEmail());
  559.                 $user->setEmail($prueferUser->getEmail());
  560.                 $user->setPlainPassword(substr(uniqid(md5(rand())), 88));
  561.             }
  562.             $token uniqid(md5(rand()));
  563.             $user->setConfirmationToken($token);
  564.             $user->setEnabled(false);
  565.             $em->persist($user);
  566.             
  567.             $prueferUser->setUser($user);
  568.             $em->persist($prueferUser);
  569.             $em->flush();
  570.             
  571.             // finde neuestes Template
  572.             $template $em->getRepository(MailTemplate::class)->findCurrentByTyp(PrueferEmail::PRUEFER_BEREICH_REGISTRIERUNG);
  573.             
  574.             $link $this->generateUrl('pruefer_registration_activate', array('token' => $token), UrlGeneratorInterface::ABSOLUTE_URL); //chagngedFrom true
  575.             
  576.             $replacements = array(
  577.                 'vorname' => $prueferUser->getVorname(),
  578.                 'nachname' => $prueferUser->getNachname(),
  579.                 'titel'    => $prueferUser->getTitel(),
  580.                 'email' => $prueferUser->getEmail(),
  581.                // 'handynummer' => $prueferUser->getHandynummer(),
  582.                 'link' => $link
  583.             );
  584.             
  585.             $this->logger->info(sprintf('Link: %s '$link));
  586.       
  587.             $mailerBcc $this->getParameter('mailer_bcc');
  588.             $mailUser     $this->getParameter('mailer_user');
  589.             
  590.             $message = (new Swift_Message($template->getBetreff()))
  591.                     ->setFrom(array($mailUser => 'Juridicus'))
  592.                     ->setReplyTo('info@juridicus.de')
  593.                     ->setTo($prueferUser->getEmail())
  594.                     ->setBcc('info@juridicus.de')
  595.                     ->setBody($template->replace($replacements), 'text/html')
  596.             ;
  597.              if (isset($mailerBcc)) {
  598.                 $message->setBcc(array($mailerBcc));
  599.             }
  600.             if ($this->mailer->send($message)) {
  601.                 // Versand speichern
  602.                 $email = new PrueferEmail();
  603.                 $email
  604.                     ->setTyp(PrueferEmail::PRUEFER_BEREICH_REGISTRIERUNG)
  605.                     ->setPrueferUser($prueferUser)
  606.                 ;
  607.                 $em->persist($email);
  608.                 $em->flush();
  609.                 $this->get('session')->set('registration_email_success'$prueferUser->getEmail());
  610.                 return $this->redirect($this->generateUrl('pruefer_registration_email_success'));
  611.             } else {
  612.                 
  613.                 $this->get('session')->set('registration_email_error'$prueferUser->getEmail());
  614.                 return $this->redirect($this->generateUrl('pruefer_registration_email_error'));
  615.             }
  616.             
  617.         }
  618.         
  619.         return $this->render('@JFJuridicusBundle/PrueferBereich/registration.html.twig', array( 
  620.             "form" => $form->createView()
  621.         ));
  622.     }
  623.     
  624.     
  625.         /**
  626.      * Tell the user to check his email provider
  627.      *
  628.      * @Route("/pruefer/email/success", name="pruefer_registration_email_success")
  629.      */
  630.     public function prueferEmailSuccessAction()
  631.     {
  632.         $user_manager $this->container->get('fos_user.user_manager');
  633.         $session $this->container->get('session');
  634.         $email $session->get('registration_email_success');
  635.         $session->remove('registration_email_success');
  636.         if (empty($email)) {
  637.             // the user does not come from the sendEmail action
  638.             return $this->redirect($this->generateUrl('homepage'));
  639.         }
  640.         return $this->render('@JFJuridicusBundle/PrueferBereich/email_success.html.twig', array(
  641.             'email' => $email
  642.         ));
  643.     }
  644.     /**
  645.      * Tell the prueferUser that email sending failed
  646.      *
  647.      * @Route("/pruefer/email/error", name="pruefer_registration_email_error")
  648.      */
  649.     public function prueferEmailErrorAction()
  650.     {
  651.         $user_manager $this->container->get('fos_user.user_manager');
  652.         $session $this->container->get('session');
  653.         $email $session->get('registration_email_error');
  654.         $session->remove('registration_email_error');
  655.         if (empty($email)) {
  656.             // the user does not come from the sendEmail action
  657.             return $this->redirect($this->generateUrl('homepage'));
  658.         }
  659.         return $this->render('@JFJuridicusBundle/PrueferBereich/email_error.html.twig', array(
  660.             'email' => $email
  661.         ));
  662.     }
  663.     /**
  664.      * Tell the user to check his sms
  665.      *
  666.      * @Route("/pruefer/sms/success", name="pruefer_registration_sms_success")
  667.      */
  668.     public function prueferSmsSuccessAction()
  669.     {
  670.         $user_manager $this->get('fos_user.user_manager');
  671.         $session $this->get('session');
  672.         $email $session->get('registration_email_success');
  673.         $session->remove('registration_email_success');
  674.         $em $this->getDoctrine()->getManager();
  675.         if (empty($email)) {
  676.             // the user does not come from the sendEmail action
  677.             return $this->redirect($this->generateUrl('homepage'));
  678.         }
  679.         $prueferUser     $em->getRepository(PrueferUser::class)->findOneByEmail($email);
  680.         return $this->render('@JFJuridicusBundle/PrueferBereich/sms_success.html.twig', array(
  681.             'prueferUser' => $prueferUser
  682.         ));
  683.     }
  684.     /**
  685.      * Tell the user that email is checked
  686.      *
  687.      * @Route("/pruefer/email/check/success", name="pruefer_registration_email_check_success")
  688.      */
  689.     public function prueferEmailCheckSuccessAction()
  690.     {
  691.         $session $this->container->get('session');
  692.         $email $session->get('registration_email_success');
  693.         $session->remove('registration_email_success');
  694.         $em $this->getDoctrine()->getManager();
  695.         if (empty($email)) {
  696.             // the user does not come from the sendSms action
  697.             return $this->redirect($this->generateUrl('homepage'));
  698.         }
  699.         $prueferUser     $em->getRepository(PrueferUser::class)->findOneByEmail($email);
  700.         
  701.         return $this->render('@JFJuridicusBundle/PrueferBereich/email_checked.html.twig', array(
  702.             'email' => $email
  703.         ));
  704.     }
  705.     /**
  706.      * Tell the user that sms sending failed
  707.      *
  708.      * @Route("/pruefer/sms/error", name="pruefer_registration_sms_error")
  709.      */
  710.     public function prueferSmsErrorAction()
  711.     {
  712.         $user_manager $this->container->get('fos_user.user_manager');
  713.         $session $this->container->get('session');
  714.         $email $session->get('registration_sms_error');
  715.         $code $session->get('registration_sms_code');
  716.         $message $session->get('registration_sms_message');
  717.         $session->remove('registration_sms_error');
  718.         $session->remove('registration_sms_code');
  719.         $session->remove('registration_sms_message');
  720.         $em $this->getDoctrine()->getManager();
  721.         if (empty($email) || empty($code) || empty($message)) {
  722.             // the user does not come from the sendSms action
  723.             return $this->redirect($this->generateUrl('homepage'));
  724.         }
  725.         $prueferUser     $em->getRepository(PrueferUser::class)->findOneByEmail($email);
  726.         
  727.         return $this->render('@JFJuridicusBundle/PrueferBereich/sms_error.html.twig', array(
  728.             'prueferUser' => $prueferUser,
  729.             'code' => $code,
  730.             'message' => $message,
  731.         ));
  732.     }
  733.     
  734.        /**
  735.      * Receive the confirmation token and send SMS with password
  736.      *
  737.      * @Route("pruefer/activate/{token}", name="pruefer_registration_activate")
  738.      */
  739.     public function prueferActivateAction($token)
  740.     {
  741.         $em $this->getDoctrine()->getManager();
  742.         $user_manager $this->container->get('fos_user.user_manager');
  743.         /* @var $user_manager \FOS\UserBundle\Model\UserManager */
  744.         $sms_service $this->container->get('jf_juridicus.sms');
  745.         /* @var $sms_service \JF\JuridicusBundle\Services\Sms */
  746.         $user $user_manager->findUserByConfirmationToken($token);
  747.         if (null === $user) {
  748.             throw $this->createNotFoundException('Der Aktivierungscode ist ungültig oder wurde schon verwendet.');
  749.         }
  750.         $prueferUser $em->getRepository(PrueferUser::class)->findOneByUser($user);
  751.         if (null === $prueferUser) {
  752.             throw $this->createNotFoundException('Der Benutzer zu diesem Aktivierungscode ist nicht mehr vorhanden.');
  753.         }
  754.         /* Hier wurde die E-Mail mit dem Passwort versendet, jetzt wird diese E-Mail erst nach verifizierung versendet */
  755.         
  756.         $password_plain substr(uniqid(md5(rand())), 88);
  757.         $user->setConfirmationToken(null);
  758.         $user->setPlainPassword($password_plain);
  759.         $user->setEnabled(true);
  760.         $em->persist($user);
  761.         $this->get('logger')->info(sprintf('User: %s PW: %s'$user->getEmail(), $password_plain));
  762.         // Senden des Passwords per SMS
  763.         $template $em->getRepository(MailTemplate::class)->findCurrentByTyp(PrueferEmail::PRUEFER_BEREICH_REGISTRIERUNG_PASSWORT);
  764.         $replacements = array(
  765.             'titel'            => $prueferUser->getTitel(),
  766.             'vorname'         => $prueferUser->getVorname(),
  767.             'nachname'         => $prueferUser->getNachname(),
  768.             'email'         => $prueferUser->getEmail(),
  769.             'link'             => 'https://juridicus.de/pruefer/login',
  770.             'password'         => $password_plain
  771.         );
  772.         // NEW send E-Mail with PW 
  773.         $mailer_user $this->container->getParameter('mailer_user');
  774.         $mailer_bcc $this->container->getParameter('mailer_bcc');
  775.         $mailer $this->get('mailer');
  776.             $message \Swift_Message::newInstance()
  777.                     ->setSubject($template->getBetreff())
  778.                     ->setFrom(array($mailer_user => 'Juridicus'))
  779.                     ->setReplyTo('info@juridicus.de')
  780.                     ->setTo($prueferUser->getEmail())
  781.                     ->setBcc('info@juridicus.de')
  782.                     ->setBody($template->replace($replacements), 'text/html')
  783.             ;
  784.             if ($mailer->send($message)) {
  785.                 // Versand speichern
  786.                 $email = new PrueferEmail();
  787.                 $email
  788.                     ->setTyp(PrueferEmail::PRUEFER_BEREICH_REGISTRIERUNG_PASSWORT)
  789.                     ->setPrueferUser($prueferUser)
  790.                 ;
  791.                 $em->persist($email);
  792.                 $em->flush();
  793.                 $this->get('session')->set('registration_email_success'$prueferUser->getEmail());
  794.                 return $this->redirect($this->generateUrl('pruefer_registration_sms_success'));
  795.             } else {
  796.                 
  797.                 $this->get('session')->set('registration_email_error'$prueferUser->getEmail());
  798.                 return $this->redirect($this->generateUrl('pruefer_registration_sms_error'));
  799.             }
  800.         
  801.         /*$this->get('session')->set('registration_email_success', $prueferUser->getEmail());
  802.         return $this->redirect($this->generateUrl('pruefer_registration_email_check_success'));
  803.         */
  804.     }
  805. }