src/JuridicusBundle/Controller/PrueferController.php line 568

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