src/JuridicusBundle/Controller/PRController.php line 307

Open in your IDE?
  1. <?php
  2. namespace JF\JuridicusBundle\Controller;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  6. use JMS\SecurityExtraBundle\Annotation\Secure;
  7. use JMS\DiExtraBundle\Annotation as DI;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use JF\JuridicusBundle\Form\AboType;
  11. use JF\JuridicusBundle\Entity\Abo;
  12. use JF\JuridicusBundle\Entity\AboZeitraum;
  13. use JF\JuridicusBundle\Form\LockaboType;
  14. use JF\JuridicusBundle\Services\AboManager;
  15. use JF\JuridicusBundle\Entity\ProtokollInfothekPruefer;
  16. use JF\JuridicusBundle\Repository\PdfZeitschriftPRRepository;
  17. use Doctrine\ORM\EntityManagerInterface;
  18. /**
  19.  * @Route("/PR")
  20.  */
  21. class PRController extends BaseController
  22. {
  23.     /**
  24.      * @DI\Inject("jf_juridicus.pr_repository")
  25.      *
  26.      * @var PdfZeitschriftPRRepository
  27.      */
  28.     protected $repo;
  29.     /**
  30.      * @DI\Inject("jf_juridicus.abo_manager")
  31.      *
  32.      * @var AboManager
  33.      */
  34.     protected $aboManager;
  35.     /**
  36.      * @Route("/", name="pr_main")
  37.      */
  38.     public function showAction()
  39.     {
  40.         /* Felix Baltes, Zeitschriften entfernen, 2017-06 pr_konzept */
  41.         return $this->redirect($this->generateUrl('pr_archiv'));
  42.     }
  43.     /**
  44.      * @Route("/konzept.html", name="pr_konzept")
  45.      */
  46.     public function showKonzeptAction()
  47.     {
  48.         /* Felix Baltes, Zeitschriften entfernen, 2017-06  */
  49.         return $this->redirect($this->generateUrl('pr_main'));
  50.         /*
  51.         $response = $this->render('JFJuridicusBundle:PR:konzept.html.twig');
  52.         $response->setETag(md5($response->getContent()));
  53.         $response->isNotModified($this->getRequest());
  54.         return $response;
  55.         */
  56.     }
  57.     /**
  58.      * @Route("/bezugspreise.html", name="pr_bezugspreise")
  59.      */
  60.     public function showBezugspreiseAction()
  61.     {
  62.         /* Felix Baltes, Zeitschriften entfernen, 2017-06  */
  63.         return $this->redirect($this->generateUrl('pr_main'));
  64.         /*
  65.         $response = $this->render('JFJuridicusBundle:PR:bezugspreise.html.twig');
  66.         $response->setETag(md5($response->getContent()));
  67.         $response->isNotModified($this->getRequest());
  68.         return $response;
  69.         */
  70.     }
  71.     /**
  72.      * @Route("/leseprobe", name="pr_leseprobe")
  73.      */
  74.     public function showLeseprobeAction()
  75.     {
  76.         /* Felix Baltes, Zeitschriften entfernen, 2017-06  */
  77.         return $this->redirect($this->generateUrl('pr_main'));
  78.         /*
  79.         $response = $this->render('JFJuridicusBundle:PR:leseprobe.html.twig');
  80.         $response->setETag(md5($response->getContent()));
  81.         $response->isNotModified($this->getRequest());
  82.         return $response;
  83.         */
  84.     }
  85.     /**
  86.      * @Route("/Leseprobe_PR.pdf", name="pr_leseprobe_pdf")
  87.      */
  88.     public function leseprobePdfAction()
  89.     {
  90.         // letzten PR aus dem Archiv holen
  91.         $pdf $this->repo->findLastBefore(new \DateTime('today -6 months'));
  92.         if (!$pdf) {
  93.             throw $this->createNotFoundException();
  94.         }
  95.         return $pdf->createResponse(true);
  96.     }
  97.     /**
  98.      * bestellscheinAction
  99.      * URL existiert nicht mehr
  100.      *
  101.      * @Route("/Bestellung", name="pr_bestellschein")
  102.      */
  103.     public function bestellscheinAction()
  104.     {
  105.         return new Response(''410);
  106.         
  107.         $datumStartOnline $this->getDefaultStartDatumOnline();
  108.         $datumStartPrint  $this->getDefaultStartDatumPrint();
  109.         $abo = new Abo();
  110.         $abo->setDatumStart($datumStartOnline);
  111.         
  112.         $form $this->createForm(AboType::class, $abo, array(
  113.             'em' => $this->getDoctrine()->getManager()
  114.         ));
  115.         return $this->render('@JFJuridicusBundle/PR/bestellschein.html.twig', array(
  116.             'form'                => $form->createView(),
  117.             'default_date_online' => $datumStartOnline,
  118.             'default_date_print'  => $datumStartPrint,
  119.         ));
  120.     }
  121.     /**
  122.      * @Method({"POST"})
  123.      */
  124.     public function createLockBestellungAction(Request $request)
  125.     {
  126.         $this->denyAccessUnlessGranted('ROLE_KUNDE');
  127.         return new Response(''410);
  128.         
  129.         $em $this->getDoctrine()->getManager();
  130.         $kunde $this->getKunde();
  131.         $datumStart $this->getDefaultStartDatumOnline();
  132.         $abo = new Abo();
  133.         $abo
  134.             ->setZeitschrift('PR')
  135.             ->setOnline(true)
  136.             ->setTyp(Abo::ABO_LOCKABO_6)
  137.             ->setIp($request->getClientIp())
  138.             ->setDatumStart($datumStart)
  139.             ->setKunde($kunde)
  140.             ->setVorname($kunde->getVorname())
  141.             ->setNachname($kunde->getNachname())
  142.             ->setStrasse($kunde->getStrasse())
  143.             ->setHausnummer($kunde->getHausnummer())
  144.             ->setPlz($kunde->getPlz())
  145.             ->setOrt($kunde->getOrt())
  146.             ->setGeburtsdatum($kunde->getGeburtsdatum())
  147.             ->setEmail($kunde->getEmail())
  148.             ->setTelefon($kunde->getHandynummer())
  149.         ;
  150.         $form $this->createForm(LockaboType::class, array(), array());
  151.         $form->handleRequest($request); //changedFrom bind
  152.         if ($form->isValid()) {
  153.             $em->getConnection()->beginTransaction();
  154.             // speichern, um eine Abo-Id zu gewährleisten
  155.             $abo->calculateDatumEnde();
  156.             $em->persist($abo);
  157.             $em->flush();
  158.             $this->get('session')->set('abo_id'$abo->getId());
  159.             // Lockabos sind immer kostenlose Online-Abos
  160.             $aboZeitraum $this->aboManager->createRestrictedAboZeitraum($abo);
  161.             $aboAusgaben $this->aboManager->createAboAusgaben($aboZeitraum);
  162.             $this->aboManager->sendAboZeitschriften($aboZeitraum);
  163.             $em->flush();
  164.             $em->getConnection()->commit();
  165.             return $this->redirect($this->generateUrl('pr_bestellung_create_success'));
  166.         }
  167.         return $this->redirect($this->generateUrl('homepage'));
  168.     }
  169.     /**
  170.      * @Route("/Bestellung/create", name="pr_bestellung_create")
  171.      * @Method({"POST"})
  172.      */
  173.     public function createBestellungAction(Request $request)
  174.     {
  175.         return new Response(''410);
  176.         
  177.         $em $this->getDoctrine()->getManager();
  178.         $abo = new Abo();
  179.         $abo
  180.             ->setZeitschrift('PR')
  181.             ->setIp($request->getClientIp())
  182.         ;
  183.         $form $this->createForm(AboType::class, $abo, array('em' => $em));
  184.         $form->handleRequest($request); //changedFrom bind
  185.         if ($form->isValid()) {
  186.             $em->getConnection()->beginTransaction();
  187.             $abo->calculateDatumEnde();
  188.             // speichern, um eine Abo-Id zu gewährleisten
  189.             $em->persist($abo);
  190.             $em->flush();
  191.             $this->get('session')->set('abo_id'$abo->getId());
  192.             if ($abo->getOnline()) {
  193.                 // ersten Abo-Zeitraum hinzufügen
  194.                 $aboZeitraum $this->aboManager->createRestrictedAboZeitraum($abo);
  195.                 $aboAusgaben $this->aboManager->createAboAusgaben($aboZeitraum);
  196.                 $this->aboManager->sendAboZeitschriften($aboZeitraum);
  197.                 if ($abo->getTyp() === Abo::ABO_FULL) {
  198.                    // bei Vollabos ggfs auch zweiten Abo-Zeitraum, falls Jahresgrenze überschritten wird
  199.                     $januaryFirst = new \DateTime('first day of january this year 00:00:00');
  200.                     if ($abo->getDatumStart() < $januaryFirst) {
  201.                         // zweiten Abo-Zeitraum hinzufügen
  202.                         $decemberLast = new \DateTime('last day of december this year 00:00:00');
  203.                         $aboZeitraum2 $this->aboManager->createRestrictedAboZeitraum($abo$januaryFirst$decemberLast);
  204.                         $aboAusgaben2 $this->aboManager->createAboAusgaben($aboZeitraum2);
  205.                         $this->aboManager->sendAboZeitschriften($aboZeitraum2);
  206.                     }
  207.                 }
  208.             }
  209.             $em->flush();
  210.             $em->getConnection()->commit();
  211.             return $this->redirect($this->generateUrl('pr_bestellung_create_success'));
  212.         }
  213.         return $this->render('@JFJuridicusBundle/PR/bestellschein.html.twig', array(
  214.             'form' => $form->createView(),
  215.             'default_date_online' => $this->getDefaultStartDatumOnline(),
  216.             'default_date_print'  => $this->getDefaultStartDatumPrint(),
  217.         ));
  218.     }
  219.     /**
  220.      * @Route("/Bestellung/success", name="pr_bestellung_create_success")
  221.      */
  222.     public function createBestellungSuccessAction()
  223.     {        
  224.         $session $this->get('session');
  225.         $abo_id $session->get('abo_id');
  226.         $session->remove('abo_id');
  227.         if (!$abo_id) {
  228.             return $this->redirect($this->generateUrl('homepage'));
  229.         }
  230.         $em $this->getDoctrine()->getManager();
  231.         $abo $em->getRepository('JFJuridicusBundle:Abo')->find($abo_id);
  232.         $content $this->renderView(
  233.             'JFJuridicusBundle:Abo:show.html.twig',
  234.             array('abo' => $abo)
  235.         );
  236.         $mailer $this->get('jf_juridicus.system_mailer');
  237.         $message \Swift_Message::newInstance()
  238.             ->setSubject('Systemnachricht: Neues PR Abo')
  239.             ->setBody($content'text/html')
  240.         ;
  241.         $mailer->send($message);
  242.         return $this->render('@JFJuridicusBundle/PR/bestellschein_success.html.twig', array('abo' => $abo));
  243.     }
  244.     /**
  245.      * bestellscheinPdfAction
  246.      * URL existiert nicht mehr => umleiten
  247.      *
  248.      * @Route("/PR-Bestellung.pdf", name="pr_bestellschein_pdf")
  249.      */
  250.     public function bestellscheinPdfAction()
  251.     {
  252.         return new Response(''410);        
  253.     }
  254.     /**
  255.      * archivAction
  256.      *
  257.      * Stellt alle Ausgaben zur Verfügung, die älter als 6 Monate ist.
  258.      *
  259.      * @Route("/archiv", name="pr_archiv")
  260.      */
  261.     public function archivAction(PdfZeitschriftPRRepository $repo)
  262.     {
  263.         $entitiesByYear $repo->findArchivSince(new \DateTime('-6 months'));
  264.         return $this->render('@JFJuridicusBundle/PR/archiv.html.twig', array('entities_by_year' => $entitiesByYear));
  265.     }
  266.     /**
  267.      * @Route("/{date}.pdf", name="pr_download")
  268.      * @ParamConverter("date", options={"format": "d-m-Y"})
  269.      */
  270.     public function downloadAction(\DateTime $datePdfZeitschriftPRRepository $repo)
  271.     {
  272.         $pdf $repo->findOneBy(array('released_at' => $date));
  273.         if (!$pdf) {
  274.             throw $this->createNotFoundException('Die Zeitschrift wurde nicht gefunden.');
  275.         }
  276.         // check Download Permissions
  277.         $restrict_date = new \DateTime('today -6 months');
  278.         if ($date $restrict_date) {
  279.             // Archiv-Zeitschriften (älter als 6 Monate) immer erlaubt
  280.             return $pdf->createResponse(true);
  281.         } else {
  282.             throw $this->createAccessDeniedException();
  283.         }
  284.     }
  285.     /**
  286.      * @return \DateTime
  287.      */
  288.     protected function getDefaultStartDatumOnline(PdfZeitschriftPRRepository $repo)
  289.     {
  290.         $datumLastRelease $repo->findLast()->getReleasedAt();
  291.         $datumStart = new \DateTime('first day of this month 00:00:00');
  292.         if ($datumLastRelease $datumStart) {
  293.             $datumStart->modify('-1 month');
  294.         }
  295.         return $datumStart;
  296.     }
  297.     /**
  298.      * @return \DateTime
  299.      */
  300.     protected function getDefaultStartDatumPrint()
  301.     {
  302.         $datumStart = new \DateTime('first day of next month 00:00:00');
  303.         return $datumStart;
  304.     }
  305. }