src/Controller/SkodaController.php line 218

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Services\CiselnikObci;
  5. use App\Services\Ciselniky;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use App\Controller\ActivityCheckController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use App\Entity\Skoda;
  11. use App\Entity\Notice;
  12. use App\Form\SkodaType;
  13. /**
  14.  * Skoda controller.
  15.  */
  16. class SkodaController extends AbstractController implements ActivityCheckController {
  17.     public function checkUser(): void {
  18.         $user $this->getUser();
  19.         if ($user instanceof User) {
  20.             $interval $this->getParameter('password_change_interval') ?? 30;
  21.             if ($user->getPasswordChanged() < (new \DateTime("- $interval days"))) {
  22.                 $this->addFlash('danger''security-password-expired');
  23.             }
  24.         }
  25.     }
  26.     /**
  27.      * @Route("/sk-hr/edit/{skoda_id}", name="skoda-edit", requirements={"skoda_id"="\d+"})
  28.      */
  29.     public function skodaEditAction(
  30.         Request      $request,
  31.         CiselnikObci $ciselnikObci,
  32.         Ciselniky    $ciselniky,
  33.                      $skoda_id
  34.     ) {
  35.         $skoda $this->getDoctrine()->getManager()->getRepository(Skoda::class)->find($skoda_id);
  36.         $form $this->createForm(SkodaType::class, $skoda, [
  37. //            'ciselniky' => $this->container->get('ciselniky'),
  38. //            'ciselnikObci' => $this->container->get('ciselnikObci'),
  39.             'ciselniky' => $ciselniky,
  40.             'ciselnikObci' => $ciselnikObci
  41.         ]);
  42.         $form->handleRequest($request);
  43.         if ($form->isSubmitted() && $form->isValid()) {
  44.             $em $this->getDoctrine()->getManager();
  45.             $em->persist($skoda);
  46.             $em->flush();
  47.             $this->addFlash('success''skoda-edit');
  48.             return $this->redirectToRoute('skoda-view', ['id' => $skoda->getId()]);
  49.         }
  50.         $this->checkUser();
  51.         return $this->render('skoda/skoda_new.html.twig', [
  52.             'skoda' => $skoda,
  53.             'form' => $form->createView(),
  54.         ]);
  55.     }
  56.     /**
  57.      * @Route("/sk-hr/for/{notice_id}/{skoda_id}", name="skoda-add", requirements={"notice_id"="\d+","skoda_id"="\d+"})
  58.      */
  59.     public function skodaAddAction(Request $request$notice_id$skoda_id) {
  60.         $notice $this->getDoctrine()->getManager()->getRepository(Notice::class)->find($notice_id);
  61.         if (!$notice) {
  62.             return $this->redirectToRoute('homepage');
  63.         }
  64.         //skusi najst report z DB
  65.         if ($skoda_id) {
  66.             $skoda $this->getDoctrine()->getRepository(Skoda::class)->find($skoda_id);
  67.             //pridelenie skody a presmerovanie
  68.             if ($skoda) {
  69.                 $notice->setSkoda($skoda);
  70.                 $em $this->getDoctrine()->getManager();
  71.                 $em->persist($notice);
  72.                 $em->flush();
  73.                 $this->addFlash('success''skoda-add');
  74.                 return $this->redirectToRoute($notice->getType() . '-view', ['id' => $notice->getId()]);
  75.             }
  76.         }
  77.         return $this->redirectToRoute('skoda-new', ['id' => $notice->getId()]);
  78.     }
  79.     /**
  80.      * @Route("/sk-hr/for/{notice_id}", name="skoda-new", requirements={"notice_id"="\d+"})
  81.      */
  82.     public function skodaNewAction(
  83.         Request      $request,
  84.         CiselnikObci $ciselnikObci,
  85.         Ciselniky    $ciselniky,
  86.                      $notice_id
  87.     ) {
  88.         $notice $this->getDoctrine()->getManager()->getRepository(Notice::class)->find($notice_id);
  89.         if (!$notice) {
  90.             return $this->redirectToRoute('homepage');
  91.         }
  92.         //vytvorenie novej skody
  93.         $skoda = new Skoda($notice);
  94.         //naklonovanie pod-entit z notice do skoda
  95.         $this->noticePartsCloneAction($skoda$notice);
  96.         $form $this->createForm(SkodaType::class, $skoda, [
  97. //            'ciselniky' => $this->container->get('ciselniky'),
  98. //            'ciselnikObci' => $this->container->get('ciselnikObci'),
  99.             'ciselniky' => $ciselniky,
  100.             'ciselnikObci' => $ciselnikObci
  101.         ]);
  102.         $form->handleRequest($request);
  103.         if ($form->isSubmitted() && $form->isValid()) {
  104.             $em $this->getDoctrine()->getManager();
  105.             $em->persist($notice);
  106.             $em->persist($skoda);
  107.             $em->flush();
  108.             $this->addFlash('success''skoda-new');
  109.             return $this->redirectToRoute('skoda-view', ['id' => $skoda->getId()]);
  110.         }
  111.         $this->checkUser();
  112.         return $this->render('skoda/skoda_new.html.twig', [
  113.             'skoda' => $skoda,
  114.             'form' => $form->createView(),
  115.         ]);
  116.     }
  117.     private function noticePartsCloneAction(Skoda $skodaNotice $notice) {
  118.         foreach ($notice->getDocs() as $old) {
  119.             $new = clone $old;
  120.             $new->setNotice(null);
  121.             $skoda->addDoc($new);
  122.         }
  123.         foreach ($notice->getLocs() as $old) {
  124.             $new = clone $old;
  125.             $new->setNotice(null);
  126.             $skoda->addLoc($new);
  127.         }
  128.         foreach ($notice->getOperators() as $old) {
  129.             $new = clone $old;
  130.             $new->setNotice(null);
  131.             $new->setType('skoda');
  132.             $skoda->addOperator($new);
  133.         }
  134.         $skoda->setNazov($notice->getNazov());
  135.         $skoda->setWGSE(($notice->getOznamenie()) ? $notice->getOznamenie()->getWGSE() : $notice->getPodnet()->getWGSE());
  136.         $skoda->setWGSN(($notice->getOznamenie()) ? $notice->getOznamenie()->getWGSN() : $notice->getPodnet()->getWGSN());
  137.         $skoda->setVznik(($notice->getOznamenie()) ? $notice->getOznamenie()->getVznik() : $notice->getPodnet()->getVznik());
  138.         $skoda->setZistenie(($notice->getOznamenie()) ? $notice->getOznamenie()->getZistenie() : null);
  139.     }
  140.     /**
  141.      * @Route("/po-oz/resolve", name="notice-resolve")
  142.      */
  143.     public function noticeResolveAction() {
  144.         $this->checkUser();
  145.         $notices $this->getDoctrine()
  146.             ->getRepository(Notice::class)
  147.             ->findBy([], ['id' => 'DESC']);
  148.         $skody $this->getDoctrine()
  149.             ->getRepository(Skoda::class)
  150.             ->findBy([], ['id' => 'DESC']);
  151.         return $this->render('notice/notice_resolve.html.twig', [
  152.             'skody' => $skody,
  153.             'notices' => $notices,
  154.         ]);
  155.     }
  156.     /**
  157.      * @Route("/sk-hr/resolve", name="skoda-resolve")
  158.      */
  159.     public function skodaResolveAction() {
  160.         $this->checkUser();
  161.         $skody $this->getDoctrine()
  162.             ->getRepository(Skoda::class)
  163.             ->findBy([], ['id' => 'DESC']);
  164.         return $this->render('skoda/skoda_resolve.html.twig', [
  165.             'skody' => $skody,
  166.         ]);
  167.     }
  168.     /**
  169.      * @Route("/register/skody", name="register-skody")
  170.      */
  171.     public function registerSkodyShowAction() {
  172.         $this->checkUser();
  173.         $skody $this->getDoctrine()
  174.             ->getRepository(Skoda::class)
  175.             ->findPublicSkody('s');
  176.         return $this->render('skoda/register_es.html.twig', [
  177.             'skody' => $skody,
  178.         ]);
  179.     }
  180.     /**
  181.      * @Route("/register/hrozby", name="register-hrozby")
  182.      */
  183.     public function registerHrozbyShowAction() {
  184.         $this->checkUser();
  185.         $skody $this->getDoctrine()
  186.             ->getRepository(Skoda::class)
  187.             ->findPublicSkody('h');
  188.         return $this->render('skoda/register_bhes.html.twig', [
  189.             'skody' => $skody,
  190.         ]);
  191.     }
  192.     /**
  193.      * @Route("/register/hrozba/{id}", name="register-hrozba", requirements={"id"="\d+"})
  194.      */
  195.     public function registerHrozbaAction(Skoda $skoda) {
  196.         if ($skoda->getDruh() === 's') {
  197.             return $this->redirectToRoute('register-skoda', ['id' => $skoda->getId()]);
  198.         }
  199.         $this->checkUser();
  200.         return $this->skodaViewAction($skoda);
  201.     }
  202.     /**
  203.      * @Route("/register/skoda/{id}", name="register-skoda", requirements={"id"="\d+"})
  204.      */
  205.     public function registerSkodaAction(Skoda $skoda) {
  206.         if ($skoda->getDruh() != 's') {
  207.             return $this->redirectToRoute('register-hrozba', ['id' => $skoda->getId()]);
  208.         }
  209.         $this->checkUser();
  210.         return $this->skodaViewAction($skoda);
  211.     }
  212.     /**
  213.      * @Route("/sk-hr/view/{id}", name="skoda-view")
  214.      */
  215.     public function skodaViewAction(Skoda $skoda) {
  216.         $this->checkUser();
  217.         return $this->render('skoda/skoda_view.html.twig', [
  218.             'skoda' => $skoda,
  219.         ]);
  220.     }
  221. }