src/Controller/Kernel/KernelFileController.php line 141

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Kernel;
  3. use App\Entity\Kernel\KernelFile;
  4. use App\Entity\Kernel\Folder;
  5. use App\Entity\Kernel\Mail;
  6. use App\Entity\CRM\Client;
  7. use App\Entity\Finance\Product;
  8. use App\Entity\Finance\Invoice;
  9. use App\Entity\Finance\CreditNote;
  10. use App\Entity\HR\Employee;
  11. use App\Entity\CMS\Website;
  12. use App\Form\Kernel\KernelFileType;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use App\Service\Kernel\DMSService;
  18. /**
  19.  * @Route("/{_locale}/kernelfile")
  20.  */
  21. class KernelFileController extends AbstractController
  22. {
  23.     /**
  24.      * @Route("/", name="kernel_file_index", methods={"GET"})
  25.      */
  26.     public function index(): Response
  27.     {
  28.         $classname =  explode("\\", get_class($this));
  29.         $arraysize = count($classname);
  30.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  31.         $this->denyAccessUnlessGranted($attribute);
  32.     
  33.         $kernelFiles = $this->getDoctrine()
  34.             ->getRepository(KernelFile::class)
  35.             ->findBy(array('state' => 0));
  36.         return $this->render('kernel/kernel_file/index.html.twig', [
  37.             'kernel_files' => $kernelFiles,
  38.         ]);
  39.     }
  40.     
  41.     /**
  42.      * @Route("/showarchived", name="kernel_file_showarchived", methods={"GET"})
  43.      */
  44.     public function showarchived(): Response
  45.     {
  46.         $classname =  explode("\\", get_class($this));
  47.         $arraysize = count($classname);
  48.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  49.         $this->denyAccessUnlessGranted($attribute);
  50.     
  51.         $kernelFiles = $this->getDoctrine()
  52.             ->getRepository(KernelFile::class)
  53.             ->findBy(array('state' => 1));
  54.         return $this->render('kernel/kernel_file/archived.html.twig', [
  55.             'kernel_files' => $kernelFiles,
  56.         ]);
  57.     }
  58.     
  59.     /**
  60.      * @Route("/showdeleted", name="kernel_file_showdeleted", methods={"GET"})
  61.      */
  62.     public function showdeleted(): Response
  63.     {
  64.         $classname =  explode("\\", get_class($this));
  65.         $arraysize = count($classname);
  66.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  67.         $this->denyAccessUnlessGranted($attribute);
  68.     
  69.         $kernelFiles = $this->getDoctrine()
  70.             ->getRepository(KernelFile::class)
  71.             ->findBy(array('state' => 2));
  72.         return $this->render('kernel/kernel_file/deleted.html.twig', [
  73.             'kernel_files' => $kernelFiles,
  74.         ]);
  75.     }
  76.     /**
  77.      * @Route("/{folder}/new/{type}/{entityid}", name="kernel_file_new", methods={"POST"})
  78.      */
  79.     public function new($folder, int $type = 0, int $entityid = 0, Request $request, DMSService $dmsservice): Response
  80.     {
  81.         $classname =  explode("\\", get_class($this));
  82.         $arraysize = count($classname);
  83.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  84.         $this->denyAccessUnlessGranted($attribute);
  85.     
  86.         $folder =  $this->getDoctrine()->getRepository(Folder::class)->find($folder);
  87.         $content = $request->files->get('file');
  88.         if (!empty($content))
  89.         {
  90.             $file = $dmsservice->uploadfile($content,$folder);
  91.         }
  92.         
  93.         if ($type == 1)
  94.         {
  95.             return $this->redirect($this->generateUrl('client_show' , array('id'=>$entityid)));
  96.         }
  97.         
  98.         if ($type == 2)
  99.         {
  100.             return $this->redirect($this->generateUrl('product_show' , array('id'=>$entityid)));
  101.         }
  102.         if($type == 3)
  103.         {
  104.             return $this->redirect($this->generateUrl('invoice_show', array('id'=>$entityid)));
  105.         }
  106.         if($type == 4)
  107.         {
  108.             return $this->redirect($this->generateUrl('employee_showdocuments', array('id'=>$entityid)));
  109.         }
  110.         if($type == 5)
  111.         {
  112.             //no option
  113.         }
  114.         if($type == 6)
  115.         {
  116.             return $this->redirect($this->generateUrl('website_show', array('id'=>$entityid)));
  117.         }
  118.         if($type == 7)
  119.         {
  120.             return $this->redirect($this->generateUrl('employee_sharedfiles'));
  121.         }
  122.         if($type == 8)
  123.         {
  124.             return $this->redirect($this->generateUrl('app_credit_note_show', array('id'=>$entityid)));
  125.         }
  126.         
  127.         return $this->redirect($this->generateUrl('folder_show' , array('id'=>$folder->getId(), 'type'=>$type, 'entityid' => $entityid)));
  128.     }
  129.     /**
  130.      * @Route("/{id}/show/{type}/{entityid}", name="kernel_file_show", methods={"GET"})
  131.      */
  132.     public function show(KernelFile $kernelFile, int $type = 0, int $entityid = 0, DMSService $dmsservice): Response
  133.     {
  134.         $classname =  explode("\\", get_class($this));
  135.         $arraysize = count($classname);
  136.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  137.         $this->denyAccessUnlessGranted($attribute, $kernelFile);  
  138.         
  139.         //$dmsservice->testExcel("test", $kernelFile->getFolder());
  140.         //$dmsservice->readExcel($kernelFile);
  141.         
  142.         $entityManager = $this->getDoctrine()->getManager();
  143.         $entity = null;
  144.         if ($type == 1)
  145.         {
  146.             $entity = $entityManager->getRepository(Client::class)->findOneById($entityid);
  147.         }
  148.         if ($type == 2)
  149.         {
  150.             $entity = $entityManager->getRepository(Product::class)->findOneById($entityid);
  151.         }
  152.         if($type == 3){
  153.             $entity = $entityManager->getRepository(Invoice::class)->findOneById($entityid);
  154.         }
  155.         if($type == 4)
  156.         {
  157.             $entity = $entityManager->getRepository(Employee::class)->findOneById($entityid);
  158.         }
  159.         if($type == 5)
  160.         {
  161.             $entity = $entityManager->getRepository(Mail::class)->findOneById($entityid);
  162.         }
  163.         if($type == 6)
  164.         {
  165.             $entity = $entityManager->getRepository(Website::class)->findOneById($entityid);
  166.         }
  167.         if($type == 8)
  168.         {
  169.             $entity = $entityManager->getRepository(CreditNote::class)->findOneById($entityid);
  170.         }
  171.         
  172.         
  173.         return $this->render('kernel/kernel_file/show.html.twig', [
  174.             'kernel_file' => $kernelFile,
  175.             'type' => $type,
  176.             'entityid' => $entityid,
  177.             'entity' => $entity
  178.         ]);
  179.     }
  180.     
  181.     /**
  182.      * @Route("/{id}/audit", name="kernel_file_showaudit", methods={"GET"})
  183.      */
  184.     public function showaudit(KernelFile $kernelFile): Response
  185.     {
  186.         $classname =  explode("\\", get_class($this));
  187.         $arraysize = count($classname);
  188.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  189.         $this->denyAccessUnlessGranted($attribute, $kernelFile);  
  190.         
  191.         return $this->render('kernel/kernel_file/showaudit.html.twig', [
  192.             'kernel_file' => $kernelFile,
  193.         ]);
  194.     }
  195.     
  196.     /**
  197.      * @Route("/{id}/archive/{type}/{entityid}", name="kernel_file_archive", methods={"GET"})
  198.      */
  199.     public function archive(KernelFile $kernelFile, int $type = 0, int $entityid = 0): Response
  200.     {
  201.         $classname =  explode("\\", get_class($this));
  202.         $arraysize = count($classname);
  203.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  204.         $this->denyAccessUnlessGranted($attribute, $kernelFile); 
  205.         
  206.                 
  207.         $entityManager = $this->getDoctrine()->getManager();
  208.         $kernelFile->setState(1);
  209.         $entityManager->persist($kernelFile);
  210.         $entityManager->flush();
  211.         
  212.         return $this->redirectToRoute('kernel_file_show', array('id' => $kernelFile->getId(), 'type'=>$type, 'entityid' => $entityid));
  213.     }
  214.     
  215.     /**
  216.      * @Route("/{id}/restore/{type}/{entityid}", name="kernel_file_restore", methods={"GET"})
  217.      */
  218.     public function restore(KernelFile $kernelFile, int $type = 0, int $entityid = 0): Response
  219.     {
  220.         $classname =  explode("\\", get_class($this));
  221.         $arraysize = count($classname);
  222.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  223.         $this->denyAccessUnlessGranted($attribute, $kernelFile); 
  224.         
  225.                 
  226.         $entityManager = $this->getDoctrine()->getManager();
  227.         $kernelFile->setState(0);
  228.         $entityManager->persist($kernelFile);
  229.         $entityManager->flush();
  230.         
  231.         return $this->redirectToRoute('kernel_file_show', array('id' => $kernelFile->getId(), 'type'=>$type, 'entityid' => $entityid));
  232.     }
  233.     
  234.     /**
  235.      * @Route("/{id}/delete/{type}/{entityid}", name="kernel_file_logicaldelete", methods={"GET"})
  236.      */
  237.     public function logicaldelete(KernelFile $kernelFile, int $type = 0, int $entityid = 0): Response
  238.     {
  239.         $classname =  explode("\\", get_class($this));
  240.         $arraysize = count($classname);
  241.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  242.         $this->denyAccessUnlessGranted($attribute, $kernelFile); 
  243.         
  244.                 
  245.         $entityManager = $this->getDoctrine()->getManager();
  246.         $kernelFile->setState(2);
  247.         $entityManager->persist($kernelFile);
  248.         $entityManager->flush();
  249.         
  250.         if ($type == 1)
  251.         {
  252.             return $this->redirect($this->generateUrl('client_show' , array('id'=>$entityid)));
  253.         }
  254.         if ($type == 2)
  255.         {
  256.             return $this->redirect($this->generateUrl('product_show' , array('id'=>$entityid)));
  257.         }
  258.         if ($type == 3)
  259.         {
  260.             return $this->redirect($this->generateUrl('invoice_show', array('id'=>$entityid)));
  261.         }
  262.         if ($type == 5)
  263.         {
  264.             return $this->redirect($this->generateUrl('employee_showdocuments', array('id'=>$entityid)));
  265.         }
  266.         if($type == 6)
  267.         {
  268.             return $this->redirect($this->generateUrl('website_show', array('id'=>$entityid)));
  269.         }
  270.         if($type == 7)
  271.         {
  272.             return $this->redirect($this->generateUrl('employee_sharedfiles'));
  273.         }
  274.         if($type == 8)
  275.         {
  276.             return $this->redirect($this->generateUrl('app_credit_note_show', array('id'=>$entityid)));
  277.         }
  278.         
  279.         
  280.         return $this->redirect($this->generateUrl('folder_show' , array('id'=>$folder->getId(), 'type'=>$type, 'entityid' => $entityid)));
  281.     }
  282.     /**
  283.      * @Route("/{id}/edit/{type}/{entityid}", name="kernel_file_edit", methods={"GET","POST"})
  284.      */
  285.     public function edit(Request $request, KernelFile $kernelFile, int $type = 0, int $entityid = 0): Response
  286.     {
  287.         $classname =  explode("\\", get_class($this));
  288.         $arraysize = count($classname);
  289.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  290.         $this->denyAccessUnlessGranted($attribute, $kernelFile); 
  291.     
  292.         $form = $this->createForm(KernelFileType::class, $kernelFile, 
  293.                 ['action' => $this->generateUrl('kernel_file_edit', array('id' => $kernelFile->getId(), 'type' => $type, 'entityid' => $entityid)), 
  294.                     'attr' => ['id' => $this->generateUrl('kernel_file_edit', array('id' => $kernelFile->getId(), 'type' => $type, 'entityid' => $entityid))]]);
  295.         $form->handleRequest($request);
  296.         if ($form->isSubmitted() && $form->isValid()) {
  297.             $this->getDoctrine()->getManager()->flush();
  298.             return $this->redirectToRoute('kernel_file_show', array('id' => $kernelFile->getId(), 'type'=>$type, 'entityid' => $entityid));
  299.         }
  300.         
  301.         $entityManager = $this->getDoctrine()->getManager();
  302.         $entity = null;
  303.         if ($type == 1)
  304.         {
  305.             $entity = $entityManager->getRepository(Client::class)->findOneById($entityid);
  306.         }
  307.         if ($type == 2)
  308.         {
  309.             $entity = $entityManager->getRepository(Product::class)->findOneById($entityid);
  310.         }
  311.         if($type == 3)
  312.         {
  313.             $entity = $entityManager->getRepository(Invoice::class)->findOneById($entityid);
  314.         }
  315.         if($type == 4)
  316.         {
  317.             $entity = $entityManager->getRepository(Employee::class)->findOneById($entityid);
  318.         }
  319.         if($type == 6)
  320.         {
  321.             $entity = $entityManager->getRepository(Website::class)->findOneById($entityid);
  322.         }
  323.         if($type == 8)
  324.         {
  325.             $entity = $entityManager->getRepository(CreditNote::class)->findOneById($entityid);
  326.         }
  327.         return $this->render('kernel/kernel_file/edit.html.twig', [
  328.             'kernel_file' => $kernelFile,
  329.             'form' => $form->createView(),
  330.             'type' => $type,
  331.             'entityid' => $entityid,
  332.             'entity' => $entity
  333.         ]);
  334.     }
  335.     /**
  336.      * @Route("/{id}", name="kernel_file_delete", methods={"DELETE"})
  337.      */
  338.     public function delete(Request $request, KernelFile $kernelFile): Response
  339.     {
  340.         $classname =  explode("\\", get_class($this));
  341.         $arraysize = count($classname);
  342.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  343.         $this->denyAccessUnlessGranted($attribute, $kernelFile); 
  344.     
  345.         if ($this->isCsrfTokenValid('delete'.$kernelFile->getId(), $request->request->get('_token'))) {
  346.             $entityManager = $this->getDoctrine()->getManager();
  347.             $entityManager->remove($kernelFile);
  348.             $entityManager->flush();
  349.         }
  350.         return $this->redirectToRoute('kernel_file_index');
  351.     }
  352. }