src/Controller/Kernel/ContactController.php line 104

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Kernel;
  3. use App\Entity\Kernel\Contact;
  4. use App\Form\Kernel\ContactType;
  5. use App\Form\Kernel\ContactMailType;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use App\Service\Kernel\KernelService;
  11. use App\Service\Kernel\MailService;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use App\Service\Kernel\DMSService;
  14. /**
  15.  * @Route("/{_locale}/contact")
  16.  */
  17. class ContactController extends AbstractController
  18. {
  19.     /**
  20.      * @Route("/", name="contact_index", methods={"GET"})
  21.      */
  22.     public function index(): Response
  23.     {
  24.         $classname =  explode("\\", get_class($this));
  25.         $arraysize = count($classname);
  26.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  27.         $this->denyAccessUnlessGranted($attribute);
  28.     
  29.         /*$contacts = $this->getDoctrine()
  30.             ->getRepository(Contact::class)
  31.             ->findBy(array('state' => 0));*/
  32.         return $this->render('kernel/contact/index.html.twig', [
  33.             //'contacts' => $contacts,
  34.         ]);
  35.     }
  36.     
  37.     /**
  38.      * @Route("/table/{state}/{type}/{entityid}", name="contact_table", methods={"GET"})
  39.      */
  40.     public function table(int $state, int $type = 0, int $entityid = 0): Response
  41.     {
  42.         $classname =  explode("\\", get_class($this));
  43.         $arraysize = count($classname);
  44.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  45.         $this->denyAccessUnlessGranted($attribute);
  46.     
  47.         $em = $this->getDoctrine()->getManager();
  48.         if ($type == 0)
  49.         {
  50.             if ($this->getUser()->getOrganization() == null)
  51.             {
  52.                 $query = $em->createQuery("SELECT s FROM App\Entity\Kernel\Contact s WHERE (s.state = ?1)");
  53.                 $query = $query->setParameter(1, $state);
  54.                 $contacts = $query->getResult();
  55.             }
  56.             else
  57.             {
  58.                 $query = $em->createQuery("SELECT s FROM App\Entity\Kernel\Contact s WHERE ((s.state = ?1) AND ((s.organization = ?2) or (s.organization is null)))");
  59.                 $query = $query->setParameter(1, $state);
  60.                 $query = $query->setParameter(2, $this->getUser()->getOrganization()->getId());
  61.                 $contacts = $query->getResult();
  62.             }
  63.         }
  64.         elseif ($type == 1) {
  65.             
  66.             $query = $em->createQuery("SELECT s FROM App\Entity\Kernel\Contact s LEFT JOIN s.employees t WHERE (s.state = ?1) AND (t.id = ?2)");
  67.             $query = $query->setParameter(1, $state);
  68.             $query = $query->setParameter(2, $entityid);
  69.             $contacts = $query->getResult();
  70.         }elseif ($type == 2) {
  71.             
  72.             $query = $em->createQuery("SELECT s FROM App\Entity\Kernel\Contact s WHERE (s.state = ?1) AND (s.invoice = ?2)");
  73.             $query = $query->setParameter(1, $state);
  74.             $query = $query->setParameter(2, $entityid);
  75.             $contacts = $query->getResult();
  76.         }elseif ($type == 3) {
  77.             
  78.             $query = $em->createQuery("SELECT s FROM App\Entity\Kernel\Contact s WHERE (s.state = ?1) AND (s.creditnote = ?2)");
  79.             $query = $query->setParameter(1, $state);
  80.             $query = $query->setParameter(2, $entityid);
  81.             $contacts = $query->getResult();
  82.         }else
  83.         {
  84.             $contacts = array();
  85.         }
  86.         return $this->render('kernel/contact/table.html.twig', [
  87.             'contacts' => $contacts,
  88.             'state' => $state,
  89.             'type' => $type,
  90.             'entityid' => $entityid,
  91.         ]);
  92.     }
  93.     
  94.     
  95.     /**
  96.      * @Route("/new/{type?0}/{entityid?0}/{contacttype?0}", name="contact_new", methods={"GET","POST"})
  97.      */
  98.     public function new(Request $request, int $type = 0, int $entityid = 0,int $contacttype = 0, KernelService $kernel_service, TranslatorInterface $translator, MailService $mailService, DMSService $dmsservice): Response
  99.     {
  100.         $classname =  explode("\\", get_class($this));
  101.         $arraysize = count($classname);
  102.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  103.         $this->denyAccessUnlessGranted($attribute);
  104.         
  105.         $entity = null;
  106.         $entityManager = $this->getDoctrine()->getManager();
  107.         if($type == 1)
  108.         {
  109.             $entity = $entityManager->getRepository(\App\Entity\HR\Employee::class)->findOneById($entityid);
  110.         }
  111.         if($type == 2)
  112.         {
  113.             $entity = $entityManager->getRepository(\App\Entity\Finance\Invoice::class)->findOneById($entityid);
  114.         }
  115.         if($type == 3)
  116.         {
  117.             $entity = $entityManager->getRepository(\App\Entity\Finance\CreditNote::class)->findOneById($entityid);
  118.         }
  119.     
  120.         $contact = new Contact();
  121.         $contact->setContactDate(new \DateTime());
  122.         if ($contacttype == 1)
  123.         {
  124.             $fromarray = array();
  125.             $from = $kernel_service->getApplicationInfoValue("Kernel.Fromemail", $entity->getOrganization());
  126.             $fromarray[$from] = $from;
  127.             if (!filter_var($this->getUser()->getEmail(), FILTER_VALIDATE_EMAIL) === false) {
  128.                 $fromarray[$this->getUser()->getFirstname() . " " . $this->getUser()->getLastname() . " <" . $this->getUser()->getEmail() . ">"] = $this->getUser()->getEmail();
  129.             }
  130.             
  131.             $toarray = array();
  132.             $to = array();
  133.             $ccarray = array();
  134.             $cc = array();
  135.             $attachmentarray = array();
  136.             $attachment = array();
  137.             $functionalArea = "";
  138.             if($type == 1)
  139.             {    
  140.                 if (!filter_var($entity->getEmail(), FILTER_VALIDATE_EMAIL) === false) {
  141.                     $toarray = array($entity . " (" . $entity->getEmail() . ") - ". $translator->trans("Employee") => "EM".$entity->getId());
  142.                     $to[] = "EM".$entity->getId();
  143.                 }
  144.                 $functionalArea = "Employee";
  145.             }
  146.             if($type == 2)
  147.             {    
  148.                 if (!filter_var($entity->getClient()->getEmail(), FILTER_VALIDATE_EMAIL) === false) {
  149.                     $toarray = array($entity->getClient() . " (" . $entity->getClient()->getEmail() . ") - ". $translator->trans("Client") => "CL".$entity->getClient()->getId());
  150.                     $to[] = "CL".$entity->getClient()->getId();
  151.                 }
  152.                 
  153.                 $ccemail = $kernel_service->getApplicationInfoValue("Finance.AdditionalCCEmailForInvoices", $entity->getOrganization());
  154.                 if (!filter_var($ccemail, FILTER_VALIDATE_EMAIL) === false) {
  155.                     $ccarray = array($ccemail => "MA".$ccemail);
  156.                     $cc[] = "MA".$ccemail;
  157.                 }
  158.                 
  159.                 $functionalArea = "Invoice";
  160.                 
  161.                 $attachmentarray["".$entity->getPdf()] = $entity->getPdf()->getId();
  162.                 $attachment[] = $entity->getPdf()->getId();
  163.                 
  164.                 if ($entity->getUbl() != null)
  165.                 {
  166.                     $attachmentarray["".$entity->getUbl()] = $entity->getUbl()->getId();
  167.                     
  168.                     $includeUBLInInvoiceMail = $kernel_service->getApplicationInfoValue("Finance.IncludeUBLInInvoiceMail", $entity->getOrganization());
  169.                     if ($includeUBLInInvoiceMail == true)
  170.                     {
  171.                         $attachment[] = $entity->getUbl()->getId();
  172.                     }
  173.                 }
  174.                 
  175.                 
  176.                 $applicationfolder = $dmsservice->createFolderIfNeeded("System");
  177.                 $invoicefolder = $dmsservice->createFolderIfNeeded("Invoice", $applicationfolder);
  178.                 $folder = $dmsservice->createFolderIfNeeded("".$entity->getId(), $invoicefolder);
  179.                 
  180.                 foreach($folder->getKernelfiles() as $kernelfile)
  181.                 {
  182.                     if ($kernelfile->getState() == 0)
  183.                     {
  184.                         $attachmentarray["".$kernelfile] = $kernelfile->getId();
  185.                     }
  186.                 }
  187.             }
  188.             if($type == 3)
  189.             {    
  190.                 if (!filter_var($entity->getClient()->getEmail(), FILTER_VALIDATE_EMAIL) === false) {
  191.                     $toarray = array($entity->getClient() . " (" . $entity->getClient()->getEmail() . ") - ". $translator->trans("Client") => "CL".$entity->getClient()->getId());
  192.                     $to[] = "CL".$entity->getClient()->getId();
  193.                 }
  194.                 
  195.                 $ccemail = $kernel_service->getApplicationInfoValue("Finance.AdditionalCCEmailForInvoices", $entity->getOrganization());
  196.                 if (!filter_var($ccemail, FILTER_VALIDATE_EMAIL) === false) {
  197.                     $ccarray = array($ccemail => "MA".$ccemail);
  198.                     $cc[] = "MA".$ccemail;
  199.                 }
  200.                 
  201.                 $functionalArea = "CreditNote";
  202.                 
  203.                 $attachmentarray["".$entity->getPdf()] = $entity->getPdf()->getId();
  204.                 $attachment[] = $entity->getPdf()->getId();
  205.                 
  206.                 if ($entity->getUbl() != null)
  207.                 {
  208.                     $attachmentarray["".$entity->getUbl()] = $entity->getUbl()->getId();
  209.                     
  210.                     $includeUBLInInvoiceMail = $kernel_service->getApplicationInfoValue("Finance.IncludeUBLInInvoiceMail", $entity->getOrganization());
  211.                     if ($includeUBLInInvoiceMail == true)
  212.                     {
  213.                         $attachment[] = $entity->getUbl()->getId();
  214.                     }
  215.                 }
  216.                 
  217.                              
  218.                 $applicationfolder = $dmsservice->createFolderIfNeeded("System");
  219.                 $invoicefolder = $dmsservice->createFolderIfNeeded("Invoice", $applicationfolder);
  220.                 $folder = $dmsservice->createFolderIfNeeded("".$entity->getId(), $invoicefolder);
  221.                 
  222.                 foreach($folder->getKernelfiles() as $kernelfile)
  223.                 {
  224.                     if ($kernelfile->getState() == 0)
  225.                     {
  226.                         $attachmentarray["".$kernelfile] = $kernelfile->getId();
  227.                     }
  228.                 }
  229.             }
  230.             
  231.             $form = $this->createForm(ContactMailType::class, $contact, 
  232.                 ['from' => $fromarray, 'toarray' => $toarray, 'to' => $to,'ccarray' => $ccarray, 'cc' => $cc,'functionalArea' => $functionalArea,
  233.                     'attachmentarray' => $attachmentarray, 'attachment' => $attachment,
  234.                     'action' => $this->generateUrl('contact_new', 
  235.                         array('type' => $type, 'entityid' => $entityid, 'contacttype'=>$contacttype )),
  236.                         'attr' => ['id' => $this->generateUrl('contact_new',
  237.                         array('type' => $type, 'entityid' => $entityid, 'contacttype'=>$contacttype))]]);
  238.         } else
  239.         {
  240.             $form = $this->createForm(ContactType::class, $contact, 
  241.                 ['action' => $this->generateUrl('contact_new', 
  242.                         array('type' => $type, 'entityid' => $entityid, 'contacttype'=>$contacttype)),
  243.                         'attr' => ['id' => $this->generateUrl('contact_new',
  244.                         array('type' => $type, 'entityid' => $entityid, 'contacttype'=>$contacttype))]]);
  245.         }
  246.         $form->handleRequest($request);
  247.         
  248.         
  249.         if ($form->isSubmitted()) { // && $form->isValid()) {
  250.             $entityManager = $this->getDoctrine()->getManager();
  251.             
  252.             $organization = null;
  253.             if ($this->getUser()->getOrganization() != null) {
  254.                 $organization = $this->getUser()->getOrganization();
  255.             }
  256.             
  257.             if ($contacttype == 0)
  258.             {
  259.                 $contact->setState(0);
  260.                 $entityManager->persist($contact);
  261.                 $entityManager->flush();
  262.                 $this->denyAccessUnlessGranted($attribute, $contact);
  263.                 if ($type == 1)
  264.                 {
  265.                     $organization = $entity->getOrganization();
  266.                     $contact->addEmployee($entity);
  267.                     $entityManager->persist($contact);
  268.                     $entityManager->flush();
  269.                     return $this->redirectToRoute('employee_show', array('id' => $entityid));
  270.                 }
  271.                 
  272.                 if ($type == 2)
  273.                 {
  274.                     $organization = $entity->getOrganization();
  275.                     $contact->setInvoice($entity);
  276.                     $entityManager->persist($contact);
  277.                     $entityManager->flush();
  278.                     
  279.                     return $this->redirectToRoute('invoice_show', array('id' => $entityid));
  280.                 }
  281.                 
  282.                 if ($type == 3)
  283.                 {
  284.                     $organization = $entity->getOrganization();
  285.                     $contact->setCreditnote($entity);
  286.                     $entityManager->persist($contact);
  287.                     $entityManager->flush();
  288.                     
  289.                     return $this->redirectToRoute('app_credit_note_show', array('id' => $entityid));
  290.                 }
  291.                 
  292.             } elseif ($contacttype == 1) {
  293.                 $tomail = array();
  294.                 $ccmail = array();
  295.                 $attachments = array();
  296.                 $requestdata = $request->request->all("contact_mail");
  297.                 if (isset($requestdata['to']) == true)
  298.                 {
  299.                     foreach ($requestdata['to'] as $to)
  300.                     {
  301.                         $type2 = substr($to, 0, 2);
  302.                         $toid = substr($to, 2);
  303.                         if ($type2 == "EM")
  304.                         {
  305.                             $item  = $entityManager->getRepository(\App\Entity\HR\Employee::class)->findOneById($toid);
  306.                             $tomail[] = $item;
  307.                         } else if ($type2 == "US")
  308.                         {
  309.                             $item  = $entityManager->getRepository(\App\Entity\Kernel\User::class)->findOneById($toid);
  310.                             $tomail[] = $item;
  311.                         } else if ($type2 == "CL")
  312.                         {
  313.                             $item  = $entityManager->getRepository(\App\Entity\CRM\Client::class)->findOneById($toid);
  314.                             $tomail[] = $item;
  315.                         }else if ($type2 == "MA")
  316.                         {
  317.                             $tomail[] = $toid;
  318.                         }
  319.                     }
  320.                     
  321.                     if (isset($requestdata['cc']) == true)
  322.                     {
  323.                         foreach ($requestdata['cc'] as $cc)
  324.                         {
  325.                             $type2 = substr($cc, 0, 2);
  326.                             $ccid = substr($cc, 2);
  327.                             if ($type2 == "EM")
  328.                             {
  329.                                 $item  = $entityManager->getRepository(\App\Entity\HR\Employee::class)->findOneById($ccid);
  330.                                 $ccmail[] = $item;
  331.                             } else if ($type2 == "US")
  332.                             {
  333.                                 $item  = $entityManager->getRepository(\App\Entity\Kernel\User::class)->findOneById($ccid);
  334.                                 $ccmail[] = $item;
  335.                             } else if ($type2 == "CL")
  336.                             {
  337.                                 $item  = $entityManager->getRepository(\App\Entity\CRM\Client::class)->findOneById($ccid);
  338.                                 $ccmail[] = $item;
  339.                             } else if ($type2 == "MA")
  340.                             {
  341.                                 $ccmail[] = $ccid;
  342.                             }
  343.                         }
  344.                     }
  345.                     
  346.                     if (isset($requestdata['attachments']) == true)
  347.                     {
  348.                         foreach ($requestdata['attachments'] as $attachment)
  349.                         {
  350.                             $attachmententity  = $entityManager->getRepository(\App\Entity\Kernel\KernelFile::class)->findOneById($attachment);
  351.                             if ($attachmententity)
  352.                             {
  353.                                 $attachments[] = $attachmententity;
  354.                             }
  355.                         }
  356.                     }
  357.                     
  358.                     $from = $requestdata['from'];
  359.                     
  360.                     $contact = $mailService->createMail($tomail, $contact->getSubject(), $contact->getDetails(), $attachments, $ccmail, $from, $organization) ;
  361.                 }
  362.                 
  363.                 if ($type == 1)
  364.                 {
  365.                     return $this->redirectToRoute('employee_show', array('id' => $entityid));
  366.                 }
  367.                 
  368.                 if ($type == 2)
  369.                 {
  370.                     $contact->setInvoice($entity);
  371.                     $entityManager->persist($contact);
  372.                     $entityManager->flush();
  373.                     
  374.                     if ($entity->getProcessState() < 1)
  375.                     {
  376.                         $entity->setProcessState(1);
  377.                         $entityManager->persist($entity);
  378.                         $entityManager->flush();
  379.                     }
  380.                     
  381.                     return $this->redirectToRoute('invoice_show', array('id' => $entityid));
  382.                 }
  383.                 
  384.                 if ($type == 3)
  385.                 {
  386.                     $contact->setCreditnote($entity);
  387.                     $entityManager->persist($contact);
  388.                     $entityManager->flush();
  389.                     
  390.                     return $this->redirectToRoute('app_credit_note_show', array('id' => $entityid));
  391.                 }
  392.                 
  393.             }
  394.             
  395.             return $this->redirectToRoute('contact_index');
  396.         }
  397.         
  398.         
  399.         return $this->render('kernel/contact/new.html.twig', [
  400.             'contact' => $contact,
  401.             'form' => $form->createView(),
  402.             'type' => $type,
  403.             'entityid' => $entityid,
  404.             'entity' => $entity,
  405.             'contacttype' => $contacttype
  406.         ]);
  407.     }
  408.     /**
  409.      * @Route("/{id}/{type}/{entityid}", name="contact_show", methods={"GET"})
  410.      */
  411.     public function show(Contact $contact, int $type = 0, int $entityid = 0, DMSService $dmsservice): Response
  412.     {
  413.         $classname =  explode("\\", get_class($this));
  414.         $arraysize = count($classname);
  415.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  416.         $this->denyAccessUnlessGranted($attribute, $contact);  
  417.         
  418.         $entity = null;
  419.         $entityManager = $this->getDoctrine()->getManager();
  420.         if($type == 1)
  421.         {
  422.             $entity = $entityManager->getRepository(\App\Entity\HR\Employee::class)->findOneById($entityid);
  423.         }
  424.         if($type == 2)
  425.         {
  426.             $entity = $entityManager->getRepository(\App\Entity\Finance\Invoice::class)->findOneById($entityid);
  427.         }
  428.         if($type == 3)
  429.         {
  430.             $entity = $entityManager->getRepository(\App\Entity\Finance\CreditNote::class)->findOneById($entityid);
  431.         }
  432.         
  433.         $folder = null;
  434.         if ($contact->getMail())
  435.         {
  436.             $applicationfolder = $dmsservice->createFolderIfNeeded("System");
  437.             $mailfolder = $dmsservice->createFolderIfNeeded("Mail", $applicationfolder);
  438.             $folder = $dmsservice->createFolderIfNeeded("".$contact->getMail()->getId(), $mailfolder);
  439.         }
  440.         
  441.         return $this->render('kernel/contact/show.html.twig', [
  442.             'contact' => $contact,
  443.             'type' => $type,
  444.             'entityid' => $entityid,
  445.             'entity' => $entity,
  446.             'folder' => $folder
  447.         ]);
  448.     }
  449.     
  450.     /**
  451.      * @Route("/{id}/audit/{type}/{entityid}", name="contact_showaudit", methods={"GET"})
  452.      */
  453.     public function showaudit(Contact $contact, int $type = 0, int $entityid = 0): Response
  454.     {
  455.         $classname =  explode("\\", get_class($this));
  456.         $arraysize = count($classname);
  457.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  458.         $this->denyAccessUnlessGranted($attribute, $contact);  
  459.         
  460.         return $this->render('kernel/contact/showaudit.html.twig', [
  461.             'contact' => $contact,
  462.             'type' => $type,
  463.             'entityid' => $entityid
  464.         ]);
  465.     }
  466.     
  467.     /**
  468.      * @Route("/{id}/archive/{type}/{entityid}", name="contact_archive", methods={"GET"})
  469.      */
  470.     public function archive(Contact $contact, int $type = 0, int $entityid = 0): Response
  471.     {
  472.         $classname =  explode("\\", get_class($this));
  473.         $arraysize = count($classname);
  474.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  475.         $this->denyAccessUnlessGranted($attribute, $contact); 
  476.         
  477.                 
  478.         $entityManager = $this->getDoctrine()->getManager();
  479.         $contact->setState(1);
  480.         $entityManager->persist($contact);
  481.         $entityManager->flush();
  482.         return $this->redirectToRoute('contact_show', array('id' => $contact->getId(), 'type' => $type, 'entityid' => $entityid));
  483.     }
  484.     
  485.     /**
  486.      * @Route("/{id}/restore/{type}/{entityid}", name="contact_restore", methods={"GET"})
  487.      */
  488.     public function restore(Contact $contact, int $type = 0, int $entityid = 0): Response
  489.     {
  490.         $classname =  explode("\\", get_class($this));
  491.         $arraysize = count($classname);
  492.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  493.         $this->denyAccessUnlessGranted($attribute, $contact); 
  494.         
  495.                 
  496.         $entityManager = $this->getDoctrine()->getManager();
  497.         $contact->setState(0);
  498.         $entityManager->persist($contact);
  499.         $entityManager->flush();
  500.         
  501.         return $this->redirectToRoute('contact_show', array('id' => $contact->getId(), 'type' => $type, 'entityid' => $entityid));
  502.     }
  503.     
  504.     /**
  505.      * @Route("/{id}/delete/{type}/{entityid}", name="contact_logicaldelete", methods={"GET"})
  506.      */
  507.     public function logicaldelete(Contact $contact, int $type = 0, int $entityid = 0): Response
  508.     {
  509.         $classname =  explode("\\", get_class($this));
  510.         $arraysize = count($classname);
  511.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  512.         $this->denyAccessUnlessGranted($attribute, $contact); 
  513.         
  514.                 
  515.         $entityManager = $this->getDoctrine()->getManager();
  516.         $contact->setState(2);
  517.         $entityManager->persist($contact);
  518.         $entityManager->flush();
  519.         
  520.         
  521.         if ($type == 1)
  522.         {
  523.             return $this->redirectToRoute('employee_show', array('id' => $entityid));
  524.         }
  525.         if ($type == 2)
  526.         {
  527.             return $this->redirectToRoute('invoice_show', array('id' => $entityid));
  528.         }
  529.         if ($type == 3)
  530.         {
  531.             return $this->redirectToRoute('app_credit_note_show', array('id' => $entityid));
  532.         }
  533.         
  534.         return $this->redirectToRoute('contact_index');
  535.     }
  536.     /**
  537.      * @Route("/{id}/edit/{type}/{entityid}", name="contact_edit", methods={"GET","POST"})
  538.      */
  539.     public function edit(Request $request, Contact $contact, int $type = 0, int $entityid = 0): Response
  540.     {
  541.         $classname =  explode("\\", get_class($this));
  542.         $arraysize = count($classname);
  543.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  544.         $this->denyAccessUnlessGranted($attribute, $contact); 
  545.     
  546.         $form = $this->createForm(ContactType::class, $contact, 
  547.                 ['action' => $this->generateUrl('contact_edit', array('id' => $contact->getId(), 'type' => $type, 'entityid' => $entityid)),
  548.                     'attr' => ['id' => $this->generateUrl('contact_edit', array('id' => $contact->getId(), 'type' => $type, 'entityid' => $entityid))]]);
  549.         
  550.         
  551.         
  552.         $form->handleRequest($request);
  553.         if ($form->isSubmitted() && $form->isValid()) {
  554.             $this->getDoctrine()->getManager()->flush();
  555.             return $this->redirectToRoute('contact_show', array('id' => $contact->getId(), 'type' => $type, 'entityid' => $entityid));
  556.         }
  557.         
  558.         $entity = null;
  559.         $entityManager = $this->getDoctrine()->getManager();
  560.         if($type == 1)
  561.         {
  562.             $entity = $entityManager->getRepository(\App\Entity\HR\Employee::class)->findOneById($entityid);
  563.         }
  564.         if($type == 2)
  565.         {
  566.             $entity = $entityManager->getRepository(\App\Entity\Finance\Invoice::class)->findOneById($entityid);
  567.         }
  568.         if($type == 3)
  569.         {
  570.             $entity = $entityManager->getRepository(\App\Entity\Finance\CreditNote::class)->findOneById($entityid);
  571.         }
  572.         return $this->render('kernel/contact/edit.html.twig', [
  573.             'contact' => $contact,
  574.             'form' => $form->createView(),
  575.             'type' => $type,
  576.             'entityid' => $entityid,
  577.             'entity' => $entity
  578.         ]);
  579.     }
  580.     /**
  581.      * @Route("/{id}", name="contact_delete", methods={"DELETE"})
  582.      */
  583.     public function delete(Request $request, Contact $contact): Response
  584.     {
  585.         $classname =  explode("\\", get_class($this));
  586.         $arraysize = count($classname);
  587.         $attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
  588.         $this->denyAccessUnlessGranted($attribute, $contact); 
  589.     
  590.         if ($this->isCsrfTokenValid('delete'.$contact->getId(), $request->request->get('_token'))) {
  591.             $entityManager = $this->getDoctrine()->getManager();
  592.             $entityManager->remove($contact);
  593.             $entityManager->flush();
  594.         }
  595.         return $this->redirectToRoute('contact_index');
  596.     }
  597. }