src/Controller/UserController.php line 115

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Account;
  4. use App\Entity\Action;
  5. use App\Entity\ActionStd;
  6. use App\Entity\Credit;
  7. use App\Entity\Document;
  8. use App\Entity\DocumentType;
  9. use App\Entity\ExercisingClaimRequest;
  10. use App\Entity\Incident;
  11. use App\Entity\Info;
  12. use App\Entity\Manager;
  13. use App\Entity\Partner;
  14. use App\Entity\Subcontractor;
  15. use App\Entity\SubcontractorGrp;
  16. use App\Entity\SubcontractorStd;
  17. use App\Entity\Subuser;
  18. use App\Entity\System;
  19. use App\Entity\SystemStd;
  20. use App\Entity\Training;
  21. use App\Entity\TrainingCampain;
  22. use App\Entity\TrainingRequest;
  23. use App\Entity\TrainingRequestHistory;
  24. use App\Entity\TrainingTeam;
  25. use App\Entity\Treatment;
  26. use App\Entity\TreatmentState;
  27. use App\Entity\TreatmentStd;
  28. use App\Entity\TreatmentStdCategory;
  29. use App\Entity\User;
  30. use App\Entity\UserDocument;
  31. use App\Form\ActionEditGrpType;
  32. use App\Form\ActionGrpType;
  33. use App\Form\ActionType;
  34. use App\Form\ExercisingClaimRequestType;
  35. use App\Form\IncidentType;
  36. use App\Form\IncidentViewType;
  37. use App\Form\SubcontractorGrpType;
  38. use App\Form\SubcontractorStdType;
  39. use App\Form\SubcontractorType;
  40. use App\Form\SystemType;
  41. use App\Form\TrainingTeamType;
  42. use App\Form\TreatmentStdType;
  43. use App\Form\TreatmentType;
  44. use App\Form\UserType;
  45. use App\Libraries\Pdf_concat;
  46. use App\Pdf\MyPdf;
  47. use App\Services\SendEmailService;
  48. use Doctrine\Common\Collections\ArrayCollection;
  49. use Doctrine\ORM\EntityManagerInterface;
  50. use Doctrine\ORM\EntityRepository;
  51. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  52. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  53. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  54. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  55. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  56. use Symfony\Bundle\FrameworkBundle\Translation\Translator;
  57. use Symfony\Component\Filesystem\Filesystem;
  58. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  59. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  60. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  61. use Symfony\Component\Form\Extension\Core\Type\FileType;
  62. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  63. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  64. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  65. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  66. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  67. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  68. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  69. use Symfony\Component\Form\Extension\Core\Type\TextType;
  70. use Symfony\Component\HttpFoundation\File\UploadedFile;
  71. use Symfony\Component\HttpFoundation\JsonResponse;
  72. use Symfony\Component\HttpFoundation\RedirectResponse;
  73. use Symfony\Component\HttpFoundation\Request;
  74. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  75. use Symfony\Component\HttpFoundation\StreamedResponse;
  76. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  77. use Symfony\Component\Routing\Annotation\Route;
  78. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  79. use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
  80. use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
  81. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  82. use Symfony\Component\Security\Core\Security;
  83. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  84. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  85. use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
  86. use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
  87. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  88. use Symfony\Component\Serializer\Serializer;
  89. use Symfony\Component\Serializer\SerializerInterface;
  90. //use Symfony\Component\Translation\TranslatorInterface;
  91. use Symfony\Contracts\Translation\TranslatorInterface;
  92. use Symfony\Component\Translation\TranslatableMessage;
  93. use Symfony\Component\Validator\Constraints as Assert;
  94. use function Doctrine\ORM\QueryBuilder;
  95. /**
  96.  * @Route("/user", name="user_")
  97.  */
  98. class UserController extends AbstractController
  99. {
  100.     protected $projectDir;
  101.     protected $translator;
  102.     public function __construct(string $projectDirTranslatorInterface $translator)
  103.     {
  104.         $this->projectDir $projectDir;
  105.         $this->translator $translator;
  106.     }
  107.     /**
  108.      * @Route("/", name="homepage")
  109.      */
  110.     public function indexAction(Request $requestSecurity $securityEntityManagerInterface $em)
  111.     {
  112.         $infos $this->getDoctrine()->getRepository(Info::class)->findBy(["enabled" => true], ["date" => "DESC"], 4);
  113.         $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  114.         $treatmentsStats = [
  115.             "total" => 0,
  116.             "inProgress" => 0,
  117.             "toAudit" => 0,
  118.             "valid" => 0,
  119.         ];
  120.         $treatmentsPiaStats = [
  121.             "total" => 0,
  122.             "inProgress" => 0,
  123.             "valid" => 0,
  124.             "reco" => 0
  125.         ];
  126.         foreach ($treatments as $treatment) {
  127.             if ($treatment->getState()) {
  128.                 $treatmentsStats["total"]++;
  129.                 switch ($treatment->getState()->getId()) {
  130.                     case 1:
  131.                         $treatmentsStats["inProgress"]++;
  132.                         break;
  133.                     case 2:
  134.                         $treatmentsStats["toAudit"]++;
  135.                         break;
  136.                     case 3:
  137.                         $treatmentsStats["valid"]++;
  138.                         break;
  139.                 }
  140.             }
  141.             if ($treatment->getPiaFile()) {
  142.                 $treatmentsPiaStats["total"]++;
  143.                 $treatmentsPiaStats["valid"]++;
  144.             } else {
  145.                 if ($treatment->isPiaNeeded() && !$treatment->isPiaExoneration()) {
  146.                     $treatmentsPiaStats["total"]++;
  147.                     if ($treatment->getPiaFile()) {
  148.                         $treatmentsPiaStats["valid"]++;
  149.                     } else {
  150.                         $treatmentsPiaStats["inProgress"]++;
  151.                     }
  152.                 } else {
  153.                     if (!$treatment->isPiaExoneration()) {
  154.                         if ($treatment->isPiaNeeded() || $treatment->isSensitiveData() || count($treatment->getPiaCriteria())) {
  155.                             if (!$treatment->isInsufficientCriteria()) {
  156.                                 $treatmentsPiaStats["total"]++;
  157.                                 $treatmentsPiaStats["reco"]++;
  158.                             }
  159.                         }
  160.                     }
  161.                 }
  162.             }
  163.         }
  164.         $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findBy(["user" => $this->getUser()->getUser()], ["name" => "ASC"]);
  165.         $subcontractors_grp $this->getDoctrine()->getRepository(Subcontractor::class)->findGroupForUser($this->getUser()->getUser());
  166.         $subcontractorsStats = [
  167.             "total" => 0,
  168.             "inProgress" => 0,
  169.             "invalid" => 0,
  170.             "valid" => 0,
  171.         ];
  172.         foreach ($subcontractors as $subcontractor) {
  173.             if ($subcontractor->getConformity()) {
  174.                 $subcontractorsStats["total"]++;
  175.                 switch ($subcontractor->getConformity()->getId()) {
  176.                     case 1:
  177.                         $subcontractorsStats["invalid"]++;
  178.                         break;
  179.                     case 2:
  180.                         $subcontractorsStats["inProgress"]++;
  181.                         break;
  182.                     case 3:
  183.                         $subcontractorsStats["valid"]++;
  184.                         break;
  185.                 }
  186.             }
  187.         }
  188.         foreach ($subcontractors_grp as $subcontractor) {
  189.             if ($subcontractor->getConformity()) {
  190.                 $subcontractorsStats["total"]++;
  191.                 switch ($subcontractor->getConformity()->getId()) {
  192.                     case 1:
  193.                         $subcontractorsStats["invalid"]++;
  194.                         break;
  195.                     case 2:
  196.                         $subcontractorsStats["inProgress"]++;
  197.                         break;
  198.                     case 3:
  199.                         $subcontractorsStats["valid"]++;
  200.                         break;
  201.                 }
  202.             }
  203.         }
  204.         $actions $this->getDoctrine()->getRepository(Action::class)->findForUserWithGroup($this->getUser()->getUser());
  205.         $actionsStats = [
  206.             "total" => 0,
  207.             "invalid" => 0,
  208.             "valid" => 0,
  209.         ];
  210.         foreach ($actions as $action) {
  211.             $actionsStats["total"]++;
  212.             if ($action->isTerminated()) {
  213.                 $actionsStats["valid"]++;
  214.             } else {
  215.                 $actionsStats["invalid"]++;
  216.             }
  217.         }
  218.         $actionsToTreat $this->getDoctrine()->getRepository(Action::class)->findToTreat($this->getUser()->getUser());
  219.         $incidentsToTreat $this->getDoctrine()->getRepository(Incident::class)->findBy(["user" => $this->getUser()->getUser(), "cnilInformed" => false"peopleInformed" => false]);
  220.         $exercisingClaimRequestsToTreat $this->getDoctrine()->getRepository(ExercisingClaimRequest::class)->findBy(["user" => $this->getUser()->getUser(), "answerDate" => null]);
  221.         $trainingsTotal $this->getDoctrine()->getRepository(TrainingRequest::class)->countTotalForUser($this->getUser()->getUser());
  222.         $trainingsSensibilized $this->getDoctrine()->getRepository(TrainingCampain::class)->countTotalSensibilizedForUser($this->getUser()->getUser());
  223.         $trainingsAvgNote $this->getDoctrine()->getRepository(TrainingRequestHistory::class)->avgNoteForUser($this->getUser()->getUser());
  224.         $trainingsAnswered $this->getDoctrine()->getRepository(TrainingRequest::class)->countAnsweredForUser($this->getUser()->getUser());
  225.         $printForm $this->createFormBuilder()
  226.             ->setAction($this->generateUrl('user_dashboard_print'))
  227.             ->setMethod('GET')
  228.             ->add("types"ChoiceType::class, [
  229.                 "choices" => [
  230.                     "Graphiques" => "graphics",
  231.                     "Actions à réaliser" => "actions",
  232.                     "Incidents à traiter" => "incidents",
  233.                     "Demandes d'exercices de droits à traiter" => "exercisingclaims",
  234.                 ],
  235.                 "expanded" => true,
  236.                 "multiple" => true,
  237.                 "label" => "Choix des exports",
  238.                 "data" => ["graphics""actions""incidents""exercisingclaims"]
  239.             ])
  240.             ->getForm();
  241.         $formChildrenUsers null;
  242.         $originalUser $this->getUser()->getUser();
  243.         $originalUserId 0;
  244.         $originalUserSelectedChoice null;
  245.         $token $security->getToken();
  246.         if ($token instanceof SwitchUserToken) {
  247.             $impersonatorUser $token->getOriginalToken()->getUser();
  248.             if ($impersonatorUser) {
  249.                 if ($impersonatorUser->getUser()) {
  250.                     $originalUserId $originalUser->getId();
  251.                     $originalUser $em->getRepository(User::class)->find($impersonatorUser->getUser()->getId());
  252.                 }
  253.             }
  254.         }
  255.         if (count($originalUser->getChildrenUsers())) {
  256.             $mainChoice = (object) [
  257.                 "value" => 0,
  258.                 "label" => ($request->getLocale() == "fr")?"Entité principale":"Main entity"
  259.             ];
  260.             $choices[] = $mainChoice;
  261.             $originalUserSelectedChoice $mainChoice;
  262.             foreach ($originalUser->getChildrenUsers() as $childUser) {
  263.                 $childChoice = (object) [
  264.                     "value" => $childUser->getId(),
  265.                     "label" => $childUser->getCompanyName(),
  266.                 ];
  267.                 $choices[] = $childChoice;
  268.                 if ($childUser->getId() == $originalUserId) {
  269.                     $originalUserSelectedChoice $choices[count($choices)-1];
  270.                 }
  271.             }
  272.             //var_dump($choices);
  273.             $formChildrenUsers $this->createFormBuilder()
  274.                 ->add("comptes"ChoiceType::class, [
  275.                     "choices" => $choices,
  276.                     "required" => true,
  277.                     "choice_label" => function ($entry) {
  278.                         if (is_object($entry)) {
  279.                             return $entry->label;
  280.                         }
  281.                         return "0";
  282.                     },
  283.                     "choice_value" => function ($entry) {
  284.                         if (is_object($entry)) {
  285.                             return $entry->value;
  286.                         }
  287.                         return "0";
  288.                     },
  289.                     "data" => $originalUserSelectedChoice,
  290.                 ])
  291.                 ->getForm();
  292.             $formChildrenUsers->handleRequest($request);
  293.             if ($formChildrenUsers->isSubmitted()) {
  294.             }
  295.         } else {
  296.         }
  297.         return $this->render('user/index.html.twig', [
  298.             "infos" => $infos,
  299.             "treatmentsStats" => $treatmentsStats,
  300.             "treatmentsPiaStats" => $treatmentsPiaStats,
  301.             "subcontractorsStats" => $subcontractorsStats,
  302.             "actionsStats" => $actionsStats,
  303.             "actionsToTreat" => $actionsToTreat,
  304.             "incidentsToTreat" => $incidentsToTreat,
  305.             "exercisingClaimRequestsToTreat" => $exercisingClaimRequestsToTreat,
  306.             "trainingsTotal" => $trainingsTotal,
  307.             "trainingsSensibilized" => $trainingsSensibilized,
  308.             "trainingsAvgNote" => $trainingsAvgNote,
  309.             "trainingsAnswered" => $trainingsAnswered,
  310.             "printForm" => $printForm->createView(),
  311.             "formChildrenUsers" => $formChildrenUsers $formChildrenUsers->createView() : null,
  312.         ]);
  313.     }
  314.     /**
  315.      * @Route("/dashboardprint", name="dashboard_print")
  316.      */
  317.     public function dashboardPrintAction(Request $request)
  318.     {
  319.         $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  320.         $pdf->SetAuthor('myDigitplace');
  321.         $pdf->SetTitle("Tableau de bord");
  322.         $pdf->SetMargins(10,22,10true);
  323.         $pdf->SetAutoPageBreak(TRUE35);
  324.         $pdf->AddPage('L''A4');
  325.         $html $this->renderView('user/pdf/dashboard_top.html.twig', []);
  326.         $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  327.         if (in_array("graphics"$request->get("form")["types"])) {
  328.             $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  329.             $treatmentsStats = [
  330.                 "total" => 0,
  331.                 "inProgress" => 0,
  332.                 "toAudit" => 0,
  333.                 "valid" => 0,
  334.             ];
  335.             $treatmentsPiaStats = [
  336.                 "total" => 0,
  337.                 "inProgress" => 0,
  338.                 "valid" => 0,
  339.                 "reco" => 0
  340.             ];
  341.             foreach ($treatments as $treatment) {
  342.                 if ($treatment->getState()) {
  343.                     $treatmentsStats["total"]++;
  344.                     switch ($treatment->getState()->getId()) {
  345.                         case 1:
  346.                             $treatmentsStats["inProgress"]++;
  347.                             break;
  348.                         case 2:
  349.                             $treatmentsStats["toAudit"]++;
  350.                             break;
  351.                         case 3:
  352.                             $treatmentsStats["valid"]++;
  353.                             break;
  354.                     }
  355.                 }
  356.                 if ($treatment->getPiaFile()) {
  357.                     $treatmentsPiaStats["total"]++;
  358.                     $treatmentsPiaStats["valid"]++;
  359.                 } else {
  360.                     if ($treatment->isPiaNeeded() && !$treatment->isPiaExoneration()) {
  361.                         $treatmentsPiaStats["total"]++;
  362.                         if ($treatment->getPiaFile()) {
  363.                             $treatmentsPiaStats["valid"]++;
  364.                         } else {
  365.                             $treatmentsPiaStats["inProgress"]++;
  366.                         }
  367.                     } else {
  368.                         if (!$treatment->isPiaExoneration()) {
  369.                             if (!$treatment->isPiaNeeded() && $treatment->isSensitiveData()) {
  370.                                 $treatmentsPiaStats["total"]++;
  371.                                 $treatmentsPiaStats["reco"]++;
  372.                             }
  373.                         }
  374.                     }
  375.                 }
  376.             }
  377.             $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findBy(["user" => $this->getUser()->getUser()], ["name" => "ASC"]);
  378.             $subcontractorsStats = [
  379.                 "total" => 0,
  380.                 "inProgress" => 0,
  381.                 "invalid" => 0,
  382.                 "valid" => 0,
  383.             ];
  384.             foreach ($subcontractors as $subcontractor) {
  385.                 if ($subcontractor->getConformity()) {
  386.                     $subcontractorsStats["total"]++;
  387.                     switch ($subcontractor->getConformity()->getId()) {
  388.                         case 1:
  389.                             $subcontractorsStats["invalid"]++;
  390.                             break;
  391.                         case 2:
  392.                             $subcontractorsStats["inProgress"]++;
  393.                             break;
  394.                         case 3:
  395.                             $subcontractorsStats["valid"]++;
  396.                             break;
  397.                     }
  398.                 }
  399.             }
  400.             $actions $this->getDoctrine()->getRepository(Action::class)->findForUserWithGroup($this->getUser()->getUser());
  401.             $actionsStats = [
  402.                 "total" => 0,
  403.                 "invalid" => 0,
  404.                 "valid" => 0,
  405.             ];
  406.             foreach ($actions as $action) {
  407.                 $actionsStats["total"]++;
  408.                 if ($action->isTerminated()) {
  409.                     $actionsStats["valid"]++;
  410.                 } else {
  411.                     $actionsStats["invalid"]++;
  412.                 }
  413.             }
  414.             $html $this->renderView('user/pdf/dashboard_graphics.html.twig', [
  415.                 "treatmentsStats" => $treatmentsStats,
  416.                 "treatmentsPiaStats" => $treatmentsPiaStats,
  417.                 "subcontractorsStats" => $subcontractorsStats,
  418.                 "actionsStats" => $actionsStats,
  419.             ]);
  420.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  421.         }
  422.         if (in_array("actions"$request->get("form")["types"])) {
  423.             $html $this->renderView('user/pdf/dashboard_actions.html.twig', [
  424.                 "actions" => $this->getDoctrine()->getRepository(Action::class)->findToTreat($this->getUser()->getUser())
  425.             ]);
  426.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  427.         }
  428.         if (in_array("incidents"$request->get("form")["types"])) {
  429.             $html $this->renderView('user/pdf/dashboard_incidents.html.twig', [
  430.                 "incidents" => $this->getDoctrine()->getRepository(Incident::class)->findBy(["user" => $this->getUser()->getUser(), "cnilInformed" => false"peopleInformed" => false])
  431.             ]);
  432.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  433.         }
  434.         if (in_array("exercisingclaims"$request->get("form")["types"])) {
  435.             $html $this->renderView('user/pdf/dashboard_exercisingclaims.html.twig', [
  436.                 "exercisingclaims" => $this->getDoctrine()->getRepository(ExercisingClaimRequest::class)->findBy(["user" => $this->getUser()->getUser(), "answerDate" => null])
  437.             ]);
  438.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  439.         }
  440.         $filename 'Tableau_de_bord';
  441.         return $pdf->Output($filename.".pdf",'I');
  442.     }
  443.     /**
  444.      * @Route("/legales", name="legales")
  445.      */
  446.     public function legalesAction(Request $request)
  447.     {
  448.         return $this->render('user/legales.html.twig', [
  449.         ]);
  450.     }
  451.     /**
  452.      * @Route("/privacy", name="privacy")
  453.      */
  454.     public function privacyAction(Request $request)
  455.     {
  456.         return $this->render('user/privacy.html.twig', [
  457.         ]);
  458.     }
  459.     /**
  460.      * @Route("/account", name="account")
  461.      */
  462.     public function accountAction(Request $requestSendEmailService $sendEmailService)
  463.     {
  464.         $em $this->getDoctrine()->getManager();
  465.         $account $this->getUser();
  466.         $r_email $account->getEmail();
  467.         $form $this->createForm(UserType::class, $account->getUser())
  468.             ->add('save'SubmitType::class, [
  469.                 'label' => 'enregistrer',
  470.                 'translation_domain' => 'messages',
  471.             ]);
  472.         $form['email']->setData($account->getEmail());
  473.         $form2 $this->createFormBuilder()
  474.             ->add('password'RepeatedType::class, array(
  475.                 'type' => PasswordType::class,
  476.                 'invalid_message' => 'les_mots_de_passe_ne_sont_pas_identiques',
  477.                 'first_options'  => array(
  478.                     'attr' => array(
  479.                         'placeholder' => 'changer_mot_de_passe'
  480.                     ),
  481.                     'constraints' =>[
  482.                         new Assert\NotBlank([
  483.                             'message' => 'merci_de_saisir_un_mot_de_passe'
  484.                         ]),
  485.                         new Assert\Regex([
  486.                             'pattern' => '/^(?:(?=(\S*?[A-Z]){1})(?=(\S*?[a-z]){1})(?=(\S*?[0-9]){1})(?=\S*?[~!^(){}<>%@#&*+=_\-$`,.\/\\\;:\'"|\[\]]){1}.{12,})$/m',
  487.                             'message' => "votre_mot_de_passe_doit_respecter_les_recommandations_de_l_anssi"
  488.                         ])
  489.                     ],
  490.                     'label' => "nouveau_mot_de_passe"
  491.                 ),
  492.                 'second_options' => array(
  493.                     'attr' => array(
  494.                         'placeholder' => 'confirmation_mot_de_passe'
  495.                     ),
  496.                     'label' => "confirmez_le_mot_de_passe"
  497.                 ),
  498.                 'mapped' => false,
  499.                 'translation_domain' => 'messages',
  500.             ))
  501.             ->add('save'SubmitType::class, [
  502.                 'label' => 'enregistrer',
  503.                 'translation_domain' => 'messages',
  504.             ])
  505.             ->getForm();
  506.         $hasFormSubusers false;
  507.         if ($this->isGranted("ROLE_USER")) {
  508.             $hasFormSubusers true;
  509.             $subusers $em->getRepository(Subuser::class)->findBy(['user' => $this->getUser()->getUser()]);
  510.             $maxUsers count($subusers);
  511.             if ($maxUsers 3) {
  512.                 $maxUsers++;
  513.             }
  514.             $form3 $this->createFormBuilder();
  515.             for ($i 0$i $maxUsers$i++) {
  516.                 $form3->add('email_'.$iEmailType::class, [
  517.                     'attr' => [
  518.                         'placeholder' => 'email_identifiant_de_connexion'
  519.                     ],
  520.                     'label' => new TranslatableMessage('Utilisateur %n%', ['%n%' => ($i+1)]),
  521.                     'data' => isset($subusers[$i]) ? $subusers[$i]->getAccount()->getEmail() : null,
  522.                     'required' => false,
  523.                     'mapped' => false
  524.                 ]);
  525.             }
  526.             $form3 $form3
  527.                 ->add('save'SubmitType::class, [
  528.                     'label' => 'enregistrer',
  529.                     'translation_domain' => 'messages',
  530.                 ])->getForm();
  531.         }
  532.         $form->handleRequest($request);
  533.         $form2->handleRequest($request);
  534.         if ($hasFormSubusers) {
  535.             $form3->handleRequest($request);
  536.         }
  537.         if ($form->isSubmitted() && $form->isValid()) {
  538.             /**
  539.              * @var UploadedFile $file
  540.              */
  541.             $file $form->get('pictureFile')->getData();
  542.             if ($file != NULL) {
  543.                 $fileName $this->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  544.                 $file->move(
  545.                     $this->getParameter('pictures_directory'), $fileName
  546.                 );
  547.                 $account->getUser()->setPicture($fileName);
  548.             }
  549.             $em->flush();
  550.             $this->get('session')->getFlashBag()->add('success''Profil mis à jour');
  551.             if ($r_email != $form['email']->getData()) {
  552.                 if (filter_var($form['email']->getData(), FILTER_VALIDATE_EMAIL)) {
  553.                     $other_account $em->getRepository(Account::class)->findOneBy(['email' => $form['email']->getData()]);
  554.                     if ($other_account && $other_account->getId() != $account->getId()) {
  555.                         $this->get('session')->getFlashBag()->add('danger''Cette adresse mail est déjà utilisée par un autre utilisateur');
  556.                     } else {
  557.                         $account->setEmail($form['email']->getData());
  558.                         $account->getUser()->setEmail($form['email']->getData());
  559.                         $em->flush();
  560.                         $oldToken $this->get('security.token_storage')->getToken();
  561.                         $token = new UsernamePasswordToken(
  562.                             $account//user object with updated username
  563.                             null,
  564.                             $oldToken->getProviderKey(),
  565.                             $oldToken->getRoles());
  566.                         $this->get('security.token_storage')->setToken($token);
  567.                         $this->get('session')->getFlashBag()->add('success''Identifiant de connexion modifié');
  568.                     }
  569.                 } else {
  570.                     $this->get('session')->getFlashBag()->add('danger''Cette adresse mail n\'est pas valide');
  571.                 }
  572.             }
  573.             return $this->redirectToRoute('user_account');
  574.         }
  575.         if ($form2->isSubmitted() && $form2->isValid()) {
  576.             $salt md5(uniqid());
  577.             $pwd $form2['password']->getData();
  578.             $account->setSalt($salt);
  579.             $enc_pwd $this->get('security.password_encoder')->encodePassword($account$pwd);
  580.             $account->setPassword($enc_pwd);
  581.             $em->flush();
  582.             $this->get('session')->getFlashBag()->add('success''Mot de passe mis à jour');
  583.             return $this->redirectToRoute('user_account');
  584.         }
  585.         if ($hasFormSubusers) {
  586.             if ($form3->isSubmitted() && $form3->isValid()) {
  587.                 $now = new \DateTime("now");
  588.                 $error false;
  589.                 for ($key 0$key $maxUsers$key++) {
  590.                     $email $form3['email_'.$key]->getData();
  591.                     if (isset($subusers[$key])) {
  592.                         if ($subusers[$key]->getAccount()->getEmail() != $email) {
  593.                             if (filter_var($emailFILTER_VALIDATE_EMAIL)) {
  594.                                 $other_account $em->getRepository(Account::class)->findOneBy(['email' => $email]);
  595.                                 if ($other_account) {
  596.                                     $this->get('session')->getFlashBag()->add('danger''L\'adresse mail '.$email.' est déjà utilisée par un autre utilisateur');
  597.                                     $error true;
  598.                                 } else {
  599.                                     $newAccount $em->getRepository(Account::class)->find($subusers[$key]->getAccount()->getId());
  600.                                     if ($newAccount) {
  601.                                         $newAccount->setEmail($email);
  602.                                         $newAccount->setEnabled(true);
  603.                                         $newAccount->setRegistrationDate($now);
  604.                                         $newAccount->setRoles(["ROLE_SUBUSER"]);
  605.                                         $salt md5(uniqid());
  606.                                         $pwd "";
  607.                                         $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  608.                                         $charactersLength strlen($characters);
  609.                                         for ($i 0$i 12$i++) {
  610.                                             $pwd .= $characters[rand(0$charactersLength 1)];
  611.                                         }
  612.                                         $newAccount->setSalt($salt);
  613.                                         $enc_pwd $this->get('security.password_encoder')->encodePassword($newAccount$pwd);
  614.                                         $newAccount->setPassword($enc_pwd);
  615.                                         $token hash("sha256"uniqid());
  616.                                         $newAccount->setPasswordRequest($token);
  617.                                         $newAccount->setPasswordRequestDate(new \DateTime('now'));
  618.                                         $em->flush();
  619.                                         $content "<p>Bonjour,<br/>
  620.                                         <br/>
  621.                                         Un accès vous a été créé sur le site myDigitplace et nous vous invitons à définir votre mot de passe.<br/>
  622.                                         <br/>
  623.                                         <br/>
  624.                                         Voici votre lien pour définir un nouveau mot de passe:<br/><a href='".$this->generateUrl("default_reset_password", ["email" => $account->getEmail(), "token" => $token], UrlGeneratorInterface::ABSOLUTE_URL)."'>
  625.                                         ".$this->generateUrl("default_reset_password", ["email" => $account->getEmail(), "token" => $token], UrlGeneratorInterface::ABSOLUTE_URL)."
  626.                                         </a>
  627.                                         <br/>
  628.                                         <br/>
  629.                                         Si le lien n'est pas cliquable, collez le dans la barre d'adresse de votre navigateur.<br/><br/>
  630.                                         <br/>
  631.                                         Bien cordialement,<br/>
  632.                                         <br/>
  633.                                         L’équipe myDigitplace<br/>
  634.                                         <br/>
  635.                                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  636.                                         </p>";
  637.                                         $sendEmailService->send(
  638.                                             "Votre accès myDigiplace",
  639.                                             $newAccount->getEmail(),
  640.                                             'template_emails/left_text.html.twig',
  641.                                             [
  642.                                                 "title" => "Votre accès myDigiplace",
  643.                                                 "content" => $content
  644.                                             ]
  645.                                         );
  646.                                     }
  647.                                 }
  648.                             } else {
  649.                                 $this->get('session')->getFlashBag()->add('danger''L\'adresse mail '.$email.' n\'est pas valide');
  650.                             }
  651.                         }
  652.                     } else {
  653.                         if (filter_var($emailFILTER_VALIDATE_EMAIL)) {
  654.                             $other_account $em->getRepository(Account::class)->findOneBy(['email' => $email]);
  655.                             if ($other_account) {
  656.                                 $this->get('session')->getFlashBag()->add('danger''L\'adresse mail '.$email.' est déjà utilisée par un autre utilisateur');
  657.                                 $error true;
  658.                             } else {
  659.                                 $newSubuser = new Subuser();
  660.                                 $newSubuser->setUser($this->getUser()->getUser());
  661.                                 $em->persist($newSubuser);
  662.                                 $newAccount = new Account();
  663.                                 $newAccount->setEmail($email);
  664.                                 $newAccount->setEnabled(true);
  665.                                 $newAccount->setSubuser($newSubuser);
  666.                                 $newAccount->setRegistrationDate($now);
  667.                                 $newAccount->setRoles(["ROLE_SUBUSER"]);
  668.                                 $salt md5(uniqid());
  669.                                 $pwd "";
  670.                                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  671.                                 $charactersLength strlen($characters);
  672.                                 for ($i 0$i 12$i++) {
  673.                                     $pwd .= $characters[rand(0$charactersLength 1)];
  674.                                 }
  675.                                 $newAccount->setSalt($salt);
  676.                                 $enc_pwd $this->get('security.password_encoder')->encodePassword($newAccount$pwd);
  677.                                 $newAccount->setPassword($enc_pwd);
  678.                                 $token hash("sha256"uniqid());
  679.                                 $newAccount->setPasswordRequest($token);
  680.                                 $newAccount->setPasswordRequestDate(new \DateTime('now'));
  681.                                 $em->persist($newAccount);
  682.                                 $em->flush();
  683.                                 $content "<p>Bonjour,<br/>
  684.                                 <br/>
  685.                                 Un accès vous a été créé sur le site myDigitplace et nous vous invitons à définir votre mot de passe.<br/>
  686.                                 <br/>
  687.                                 <br/>
  688.                                 Voici votre lien pour définir un nouveau mot de passe:<br/><a href='".$this->generateUrl("default_reset_password", ["email" => $account->getEmail(), "token" => $token], UrlGeneratorInterface::ABSOLUTE_URL)."'>
  689.                                 ".$this->generateUrl("default_reset_password", ["email" => $account->getEmail(), "token" => $token], UrlGeneratorInterface::ABSOLUTE_URL)."
  690.                                 </a>
  691.                                 <br/>
  692.                                 <br/>
  693.                                 Si le lien n'est pas cliquable, collez le dans la barre d'adresse de votre navigateur.<br/><br/>
  694.                                 <br/>
  695.                                 Bien cordialement,<br/>
  696.                                 <br/>
  697.                                 L’équipe myDigitplace<br/>
  698.                                 <br/>
  699.                                 <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  700.                                 </p>";
  701.                                 $sendEmailService->send(
  702.                                     "Votre accès myDigiplace",
  703.                                     $account->getEmail(),
  704.                                     'template_emails/left_text.html.twig',
  705.                                     [
  706.                                         "title" => "Votre accès myDigiplace",
  707.                                         "content" => $content
  708.                                     ]
  709.                                 );
  710.                             }
  711.                         } else {
  712.                             $this->get('session')->getFlashBag()->add('danger''L\'adresse mail '.$email.' n\'est pas valide');
  713.                         }
  714.                     }
  715.                 }
  716.                 if ($error) {
  717.                     $this->get('session')->getFlashBag()->add('danger''Impossible de mettre à jour les utilisateurs. Veuillez vérifier les données saisies');
  718.                 } else {
  719.                     $this->get('session')->getFlashBag()->add('success''Utilisateurs mis à jour');
  720.                 }
  721.                 return $this->redirectToRoute('user_account');
  722.             }
  723.         }
  724.         $exportForm $this->createFormBuilder()
  725.             ->setAction($this->generateUrl('user_account_export'))
  726.             ->setMethod('GET')
  727.             ->add("types"ChoiceType::class, [
  728.                 "choices" => [
  729.                     "e_traitements" => "treatments",
  730.                     "e_sous_traitance" => "subcontracting",
  731.                     "e_Cartographie_du_si" => "systems",
  732.                     "e_demandes_d_exercices_de_droits" => "exercisingclaims",
  733.                     "e_incidents" => "incidents",
  734.                     "e_plan_d_actions" => "actions",
  735.                     "e_formations_des_equipes" => "campains",
  736.                     "e_informations_utilisateur" => "user",
  737.                 ],
  738.                 "expanded" => true,
  739.                 "multiple" => true,
  740.                 "label" => "choix_des_exports",
  741.                 "data" => [],
  742.                 'translation_domain' => 'messages',
  743.             ])
  744.             ->getForm();
  745.         return $this->render('user/account.html.twig', [
  746.             'form' => $form->createView(),
  747.             'form2' => $form2->createView(),
  748.             'form3' => $hasFormSubusers $form3->createView() : null,
  749.             'hasFormSubusers' => $hasFormSubusers,
  750.             'maxUsers' => $hasFormSubusers $maxUsers 0,
  751.             'exportForm' => $exportForm->createView()
  752.         ]);
  753.     }
  754.     /**
  755.      * @Route("/account/print", name="account_print")
  756.      */
  757.     public function accountPrintAction(Request $request)
  758.     {
  759.         $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  760.         $pdf->setUser($this->getUser()->getUser());
  761.         $pdf->SetAuthor('myDigitplace');
  762.         $pdf->SetTitle("Fiche société");
  763.         $pdf->SetMargins(10,22,10true);
  764.         $pdf->SetAutoPageBreak(TRUE35);
  765.         $pdf->AddPage('P''A4');
  766.         $html $this->renderView('manager/pdf/user.html.twig', [
  767.             "user" => $this->getUser()->getUser()
  768.         ]);
  769.         $filename 'fiche_societe';
  770.         $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  771.         return $pdf->Output($filename.".pdf",'I');
  772.     }
  773.     /**
  774.      * @Route("/account/export", name="account_export")
  775.      */
  776.     public function accountExportAction(Request $requestSerializerInterface $serializerEntityManagerInterface $em)
  777.     {
  778.         $data = [];
  779.         //treatments
  780.         if (in_array("treatments"$request->get("form")["types"])) {
  781.             $entities $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  782.             $json $serializer->serialize(
  783.                 $entities,
  784.                 JsonEncoder::FORMAT,
  785.                 [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  786.                     AbstractNormalizer::ATTRIBUTES => [
  787.                         "id",
  788.                         "name",
  789.                         "number",
  790.                         "creationDate",
  791.                         "editDate",
  792.                         "mainPurpose",
  793.                         "purpose1",
  794.                         "purpose2",
  795.                         "purpose3",
  796.                         "purpose4",
  797.                         "purpose5",
  798.                         "othersPurpose",
  799.                         "description",
  800.                         "personalData",
  801.                         "peopleData",
  802.                         "transferOutsideUeCountries",
  803.                         "sensitiveData",
  804.                         "consentAsked",
  805.                         "consentHow",
  806.                         "piaCriteria",
  807.                         "piaNeeded",
  808.                         "piaFile",
  809.                         "piaExoneration",
  810.                         "legalBasis",
  811.                         "dataSource",
  812.                         "automatedDecision",
  813.                         "insufficientCriteria",
  814.                         "dataRetentionPeriod",
  815.                         "treatmentAccountant",
  816.                         "dpo",
  817.                         "serviceAccountant",
  818.                         "editor",
  819.                         "group",
  820.                         "subcontractors" => [
  821.                             "id",
  822.                             "name",
  823.                         ],
  824.                         "systems" => [
  825.                             "id",
  826.                             "name",
  827.                         ],
  828.                         "actions" => [
  829.                             "id",
  830.                             "name",
  831.                         ],
  832.                         "state" => [
  833.                             "id",
  834.                             "libelle",
  835.                         ],
  836.                     ]]
  837.             );
  838.             $data["treatments"] = json_decode($json);
  839.             if (count($this->getUser()->getUser()->getGroupTreatments())) {
  840.                 $json $serializer->serialize(
  841.                     $this->getUser()->getUser()->getGroupTreatments(),
  842.                     JsonEncoder::FORMAT,
  843.                     [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  844.                         AbstractNormalizer::ATTRIBUTES => [
  845.                             "id",
  846.                             "name",
  847.                             "number",
  848.                             "creationDate",
  849.                             "editDate",
  850.                             "mainPurpose",
  851.                             "purpose1",
  852.                             "purpose2",
  853.                             "purpose3",
  854.                             "purpose4",
  855.                             "purpose5",
  856.                             "othersPurpose",
  857.                             "description",
  858.                             "personalData",
  859.                             "peopleData",
  860.                             "transferOutsideUeCountries",
  861.                             "sensitiveData",
  862.                             "consentAsked",
  863.                             "consentHow",
  864.                             "piaCriteria",
  865.                             "piaNeeded",
  866.                             "piaFile",
  867.                             "piaExoneration",
  868.                             "legalBasis",
  869.                             "dataSource",
  870.                             "automatedDecision",
  871.                             "insufficientCriteria",
  872.                             "dataRetentionPeriod",
  873.                             "treatmentAccountant",
  874.                             "dpo",
  875.                             "serviceAccountant",
  876.                             "editor",
  877.                             "group",
  878.                             "subcontractors" => [
  879.                                 "id",
  880.                                 "name",
  881.                             ],
  882.                             "systems" => [
  883.                                 "id",
  884.                                 "name",
  885.                             ],
  886.                             "actions" => [
  887.                                 "id",
  888.                                 "name",
  889.                             ],
  890.                             "state" => [
  891.                                 "id",
  892.                                 "libelle",
  893.                             ],
  894.                         ]]
  895.                 );
  896.                 $data["treatmentsGroup"] = json_decode($json);
  897.             }
  898.         }
  899.         //subcontracting
  900.         if (in_array("subcontracting"$request->get("form")["types"])) {
  901.             $entities $em->getRepository(Subcontractor::class)->findBy(["user" => $this->getUser()->getUser(), "group" => false], ["name" => "ASC"]);
  902.             $json $serializer->serialize(
  903.                 $entities,
  904.                 JsonEncoder::FORMAT,
  905.                 [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  906.                     AbstractNormalizer::ATTRIBUTES => [
  907.                         "id",
  908.                         "name",
  909.                         "type",
  910.                         "contactFirstName",
  911.                         "contactLastName",
  912.                         "contactPhone",
  913.                         "contactEmail",
  914.                         "privacyPolicyLink",
  915.                         "date",
  916.                         "editDate",
  917.                         "group",
  918.                         "conformity" => [
  919.                             "id",
  920.                             "libelle"
  921.                         ],
  922.                         "subcontractorType" => [
  923.                             "id",
  924.                             "libelle"
  925.                         ],
  926.                         "documents" => [
  927.                             "id",
  928.                             "name"
  929.                         ],
  930.                         "treatments" => [
  931.                             "id",
  932.                             "name"
  933.                         ],
  934.                     ]]
  935.             );
  936.             $data["subcontracting"] = json_decode($json);
  937.             $entities $em->getRepository(Subcontractor::class)->findGroupForUser($this->getUser()->getUser());
  938.             $json $serializer->serialize(
  939.                 $entities,
  940.                 JsonEncoder::FORMAT,
  941.                 [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  942.                     AbstractNormalizer::ATTRIBUTES => [
  943.                         "id",
  944.                         "name",
  945.                         "type",
  946.                         "contactFirstName",
  947.                         "contactLastName",
  948.                         "contactPhone",
  949.                         "contactEmail",
  950.                         "privacyPolicyLink",
  951.                         "date",
  952.                         "editDate",
  953.                         "group",
  954.                         "conformity" => [
  955.                             "id",
  956.                             "libelle"
  957.                         ],
  958.                         "subcontractorType" => [
  959.                             "id",
  960.                             "libelle"
  961.                         ],
  962.                         "documents" => [
  963.                             "id",
  964.                             "name"
  965.                         ],
  966.                         "treatments" => [
  967.                             "id",
  968.                             "name"
  969.                         ],
  970.                     ]]
  971.             );
  972.             $data["subcontractingGroup"] = json_decode($json);
  973.         }
  974.         //systems
  975.         if (in_array("systems"$request->get("form")["types"])) {
  976.             if ($this->getUser()->getUser()->getParentUser()) {
  977.                 $entities $em->getRepository(System::class)->findForUserWithGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser());
  978.             } else {
  979.                 $entities $em->getRepository(System::class)->findBy(["user" => $this->getUser()->getUser()]);
  980.             }
  981.             $json $serializer->serialize(
  982.                 $entities,
  983.                 JsonEncoder::FORMAT,
  984.                 [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  985.                     AbstractNormalizer::ATTRIBUTES => [
  986.                         "id",
  987.                         "name",
  988.                         "data",
  989.                         "type",
  990.                         "subtype",
  991.                         "group",
  992.                         "treatments" => [
  993.                             "id",
  994.                             "name",
  995.                         ],
  996.                     ]]
  997.             );
  998.             $data["systems"] = json_decode($json);
  999.             if ($this->getUser()->getUser()->isMainGroupAgency()) {
  1000.                 $entities $this->getDoctrine()->getRepository(System::class)->findBy(["user" => $this->getUser()->getUser(), "group" => true]);
  1001.                 $json $serializer->serialize(
  1002.                     $entities,
  1003.                     JsonEncoder::FORMAT,
  1004.                     [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  1005.                         AbstractNormalizer::ATTRIBUTES => [
  1006.                             "id",
  1007.                             "name",
  1008.                             "data",
  1009.                             "type",
  1010.                             "subtype",
  1011.                             "group",
  1012.                             "treatments" => [
  1013.                                 "id",
  1014.                                 "name",
  1015.                             ],
  1016.                         ]]
  1017.                 );
  1018.                 $data["systemsGroup"] = json_decode($json);
  1019.             }
  1020.         }
  1021.         //exercisingclaims
  1022.         if (in_array("exercisingclaims"$request->get("form")["types"])) {
  1023.             $entities $em->getRepository(ExercisingClaimRequest::class)->findBy(["user" => $this->getUser()->getUser()]);
  1024.             $json $serializer->serialize(
  1025.                 $entities,
  1026.                 JsonEncoder::FORMAT,
  1027.                 [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  1028.                     AbstractNormalizer::ATTRIBUTES => [
  1029.                         "id",
  1030.                         "requestDate",
  1031.                         "rights",
  1032.                         "customer",
  1033.                         "answerDate",
  1034.                         "accountantName",
  1035.                         "accountantEmail",
  1036.                         "precisions",
  1037.                         "file",
  1038.                     ]]
  1039.             );
  1040.             $data["exercisingclaims"] = json_decode($json);
  1041.         }
  1042.         //incidents
  1043.         if (in_array("incidents"$request->get("form")["types"])) {
  1044.             if ($this->getUser()->getUser()->getParentUser()) {
  1045.                 $entities $em->getRepository(Incident::class)->findForUserWithGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser());
  1046.             } else {
  1047.                 $entities $em->getRepository(Incident::class)->findBy(["user" => $this->getUser()->getUser()]);
  1048.             }
  1049.             $json $serializer->serialize(
  1050.                 $entities,
  1051.                 JsonEncoder::FORMAT,
  1052.                 [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  1053.                     AbstractNormalizer::ATTRIBUTES => [
  1054.                         "id",
  1055.                         "cnilInformed",
  1056.                         "notice72H",
  1057.                         "type",
  1058.                         "peopleNumber",
  1059.                         "fileType",
  1060.                         "consequences",
  1061.                         "takenMeasures",
  1062.                         "peopleInformed",
  1063.                         "date",
  1064.                         "creationDate",
  1065.                         "editDate",
  1066.                         "group",
  1067.                         "file",
  1068.                     ]]
  1069.             );
  1070.             $data["incidents"] = json_decode($json);
  1071.         }
  1072.         //actions
  1073.         if (in_array("actions"$request->get("form")["types"])) {
  1074.             $entities $em->getRepository(Action::class)->findForUserWithGroup($this->getUser()->getUser());
  1075.             $json $serializer->serialize(
  1076.                 $entities,
  1077.                 JsonEncoder::FORMAT,
  1078.                 [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  1079.                     AbstractNormalizer::ATTRIBUTES => [
  1080.                         "id",
  1081.                         "name",
  1082.                         "budget",
  1083.                         "accountantLastName",
  1084.                         "accountantFirstName",
  1085.                         "accountantEmail",
  1086.                         "accountantPhone",
  1087.                         "goal",
  1088.                         "information",
  1089.                         "usefulLink",
  1090.                         "date",
  1091.                         "editDate",
  1092.                         "setUpDate",
  1093.                         "terminated",
  1094.                         "forDpo",
  1095.                         "treatments" => [
  1096.                             "id",
  1097.                             "name",
  1098.                         ],
  1099.                         "documents" => [
  1100.                             "id",
  1101.                             "name",
  1102.                         ],
  1103.                         "sheets" => [
  1104.                             "id",
  1105.                             "name",
  1106.                         ],
  1107.                     ]]
  1108.             );
  1109.             $data["actions"] = json_decode($json);
  1110.         }
  1111.         //campains
  1112.         if (in_array("campains"$request->get("form")["types"])) {
  1113.             $entities $this->getDoctrine()->getRepository(TrainingCampain::class)->findBy(["user" => $this->getUser()->getUser()], ["creationDate" => "DESC"]);
  1114.             $json $serializer->serialize(
  1115.                 $entities,
  1116.                 JsonEncoder::FORMAT,
  1117.                 [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  1118.                     AbstractNormalizer::ATTRIBUTES => [
  1119.                         "id",
  1120.                         "creationDate",
  1121.                         "title",
  1122.                         "emails",
  1123.                         "emailsCount",
  1124.                         "traineeship",
  1125.                         "traineeshipDate",
  1126.                         "former",
  1127.                     ]]
  1128.             );
  1129.             $data["campains"] = json_decode($json);
  1130.             foreach ($data["campains"] as $key => $value) {
  1131.                 $trainingRequests $this->getDoctrine()->getRepository(TrainingRequest::class)->findBy(["trainingCampain" => $value->id]);
  1132.                 $json $serializer->serialize(
  1133.                     $trainingRequests,
  1134.                     JsonEncoder::FORMAT,
  1135.                     [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  1136.                         AbstractNormalizer::ATTRIBUTES => [
  1137.                             "id",
  1138.                             "email",
  1139.                             "answerDate",
  1140.                             "result",
  1141.                             "firstName",
  1142.                             "lastName",
  1143.                             "position",
  1144.                         ]]
  1145.                 );
  1146.                 $data["campains"][$key]->requests json_decode($json);
  1147.             }
  1148.         }
  1149.         //user
  1150.         if (in_array("user"$request->get("form")["types"])) {
  1151.             $json $serializer->serialize(
  1152.                 $this->getUser()->getUser(),
  1153.                 JsonEncoder::FORMAT,
  1154.                 [AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
  1155.                     AbstractNormalizer::ATTRIBUTES => [
  1156.                         "id",
  1157.                         "companyName",
  1158.                         "siret",
  1159.                         "address",
  1160.                         "address2",
  1161.                         "zipCode",
  1162.                         "city",
  1163.                         "companyPhone",
  1164.                         "phone",
  1165.                         "email",
  1166.                         "contactFirstName",
  1167.                         "contactLastName",
  1168.                         "contactEmail",
  1169.                         "contactPhone",
  1170.                         "contactJob",
  1171.                         "accountantFirstName",
  1172.                         "accountantLastName",
  1173.                         "accountantEmail",
  1174.                         "accountantPhone",
  1175.                         "accountantJob",
  1176.                         "managerDpo",
  1177.                         "employeesNumber",
  1178.                         "language",
  1179.                     ]]
  1180.             );
  1181.             $data["user"] = json_decode($json);
  1182.         }
  1183.         $response = new JsonResponse($data);
  1184.         $response->setEncodingOptions$response->getEncodingOptions() | JSON_PRETTY_PRINT );
  1185.         return $response;
  1186.     }
  1187.     /**
  1188.      * @Route("/intervention", name="intervention")
  1189.      */
  1190.     public function interventionAction(Request $requestSendEmailService $sendEmailService)
  1191.     {
  1192.         $form $this->createFormBuilder()
  1193.             ->add('firstName'TextType::class, [
  1194.                 'attr' => [
  1195.                     'placeholder' => 'Prénom'
  1196.                 ],
  1197.                 'label' => 'Prénom',
  1198.                 'required' => true,
  1199.             ])
  1200.             ->add('lastName'TextType::class, [
  1201.                 'attr' => [
  1202.                     'placeholder' => 'Nom'
  1203.                 ],
  1204.                 'label' => 'Nom',
  1205.                 'required' => true,
  1206.             ])
  1207.             ->add('phone'TextType::class, [
  1208.                 'attr' => [
  1209.                     'placeholder' => 'Téléphone'
  1210.                 ],
  1211.                 'label' => 'Téléphone',
  1212.                 'required' => true,
  1213.             ])
  1214.             ->add('email'TextType::class, [
  1215.                 'attr' => [
  1216.                     'placeholder' => 'Email'
  1217.                 ],
  1218.                 'label' => 'Email',
  1219.                 'required' => true,
  1220.             ])
  1221.             ->add('object'TextType::class, [
  1222.                 'attr' => [
  1223.                     'placeholder' => 'Objet de l’intervention'
  1224.                 ],
  1225.                 'label' => 'Objet de l’intervention',
  1226.                 'required' => true,
  1227.             ])
  1228.             ->add('precision'TextType::class, [
  1229.                 'attr' => [
  1230.                     'placeholder' => 'Précisions'
  1231.                 ],
  1232.                 'label' => 'Précisions',
  1233.                 'required' => false,
  1234.             ])->getForm();
  1235.         $form->handleRequest($request);
  1236.         if ($form->isSubmitted() && $form->isValid()) {
  1237.             $content "<p>Bonjour,<br/>
  1238.                         <br/>
  1239.                         Un nouvelle demande de devis d'intervention a été envoyée.<br/>
  1240.                         <br/>
  1241.                         <br/>
  1242.                         Nom: ".$form['lastName']->getData()."<br/><br/>
  1243.                         Prénom: ".$form['firstName']->getData()."<br/><br/>
  1244.                         Email: ".$form['email']->getData()."<br/><br/>
  1245.                         Téléphone: ".$form['phone']->getData()."<br/><br/>
  1246.                         Objet de l’intervention: ".$form['object']->getData()."<br/><br/>
  1247.                         Précisions: ".$form['precision']->getData()."<br/><br/>
  1248.                         <br/>
  1249.                         <br/>
  1250.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  1251.                         </p>";
  1252.             $sendEmailService->send(
  1253.                 "Demande de devis d'intervention",
  1254.                 "devis@mydigitplace.com",
  1255.                 'template_emails/left_text.html.twig',
  1256.                 [
  1257.                     "title" => "Demande de devis d'intervention",
  1258.                     "content" => $content
  1259.                 ]
  1260.             );
  1261.             $this->get('session')->getFlashBag()->add('success''Demande de devis d\'intervention envoyée');
  1262.             return $this->redirectToRoute("user_intervention");
  1263.         }
  1264.         return $this->render('user/intervention.html.twig', [
  1265.             "form" => $form->createView()
  1266.         ]);
  1267.     }
  1268.     /**
  1269.      * @Route("/partners", name="partners")
  1270.      */
  1271.     public function partnersAction(Request $request)
  1272.     {
  1273.         $partners $this->getDoctrine()->getRepository(Partner::class)->findBy([], ["name" => "ASC"]);
  1274.         return $this->render('user/partners.html.twig', [
  1275.             "partners" => $partners
  1276.         ]);
  1277.     }
  1278.     /**
  1279.      * @Route("/partners/{id}/get", name="partners_get")
  1280.      */
  1281.     public function partnersGetAction(Request $requestPartner $partnerSendEmailService $sendEmailService)
  1282.     {
  1283.         $content "<p>Bonjour,<br/>
  1284.                         <br/>
  1285.                         Un nouvelle demande d'accès à une remise partenaire a été effectuée.<br/>
  1286.                         <br/>
  1287.                         <br/>
  1288.                         Client: ".$this->getUser()->getUser()->getCompanyName()."<br/><br/>
  1289.                         Partenaire: ".$partner->getName()."<br/><br/>
  1290.                         <br/>
  1291.                         <br/>
  1292.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  1293.                         </p>";
  1294.         $sendEmailService->send(
  1295.             "Demande d'accès à une remise partenaire",
  1296.             "partenaires@mydigitplace.com",
  1297.             'template_emails/left_text.html.twig',
  1298.             [
  1299.                 "title" => "Demande d'accès à une remise partenaire",
  1300.                 "content" => $content
  1301.             ]
  1302.         );
  1303.         $this->get('session')->getFlashBag()->add('success''Demande d\'accès à la remise envoyée');
  1304.         return $this->redirectToRoute("user_partners");
  1305.     }
  1306.     /**
  1307.      * @Route("/treatments", name="treatments")
  1308.      */
  1309.     public function treatmentsAction(Request $request)
  1310.     {
  1311.         $hasFilters false;
  1312.         $filter1 null;
  1313.         $filter2 null;
  1314.         if ($request->get("filter")) {
  1315.             $filters explode(","$request->get("filter"));
  1316.             if (count($filters) == 2) {
  1317.                 $filter1 $filters[0];
  1318.                 $filter2 $filters[1];
  1319.                 $hasFilters true;
  1320.             }
  1321.         }
  1322.         $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  1323.         $treatmentsStats = [
  1324.             "total" => 0,
  1325.             "inProgress" => 0,
  1326.             "toAudit" => 0,
  1327.             "valid" => 0,
  1328.         ];
  1329.         $treatmentsPiaStats = [
  1330.             "total" => 0,
  1331.             "inProgress" => 0,
  1332.             "valid" => 0,
  1333.             "reco" => 0,
  1334.         ];
  1335.         //$treatments = new ArrayCollection(array_merge($treatments, $this->getUser()->getUser()->getGroupTreatments()->toArray()));
  1336.         $filteredTreatments = [];
  1337.         foreach ($treatments as $treatment) {
  1338.             $isTreatmentInProgress false;
  1339.             $isTreatmentToAudit false;
  1340.             $isTreatmentValid false;
  1341.             $isPiaInProgress false;
  1342.             $isPiaValid false;
  1343.             $isPiaReco false;
  1344.             if ($treatment->getState()) {
  1345.                 $treatmentsStats["total"]++;
  1346.                 switch ($treatment->getState()->getId()) {
  1347.                     case 1:
  1348.                         $treatmentsStats["inProgress"]++;
  1349.                         $isTreatmentInProgress true;
  1350.                         break;
  1351.                     case 2:
  1352.                         $treatmentsStats["toAudit"]++;
  1353.                         $isTreatmentToAudit true;
  1354.                         break;
  1355.                     case 3:
  1356.                         $treatmentsStats["valid"]++;
  1357.                         $isTreatmentValid true;
  1358.                         break;
  1359.                 }
  1360.             }
  1361.             if ($treatment->getPiaFile()) {
  1362.                 $treatmentsPiaStats["total"]++;
  1363.                 $treatmentsPiaStats["valid"]++;
  1364.                 $isPiaValid true;
  1365.             } else {
  1366.                 if ($treatment->isPiaNeeded() && !$treatment->isPiaExoneration()) {
  1367.                     $treatmentsPiaStats["total"]++;
  1368.                     if ($treatment->getPiaFile()) {
  1369.                         $treatmentsPiaStats["valid"]++;
  1370.                         $isPiaValid true;
  1371.                     } else {
  1372.                         $treatmentsPiaStats["inProgress"]++;
  1373.                         $isPiaInProgress true;
  1374.                     }
  1375.                 } else {
  1376.                     if (!$treatment->isPiaExoneration()) {
  1377.                         if ($treatment->isPiaNeeded() || $treatment->isSensitiveData() || count($treatment->getPiaCriteria())) {
  1378.                             if (!$treatment->isInsufficientCriteria()) {
  1379.                                 $treatmentsPiaStats["total"]++;
  1380.                                 $treatmentsPiaStats["reco"]++;
  1381.                                 $isPiaReco true;
  1382.                             }
  1383.                         }
  1384.                     }
  1385.                 }
  1386.             }
  1387.             if ($hasFilters) {
  1388.                 if ($filter1 == "status") {
  1389.                     if ($filter2 == "inProgress" && $isTreatmentInProgress) {
  1390.                         $filteredTreatments[] = $treatment;
  1391.                     } elseif ($filter2 == "toAudit" && $isTreatmentToAudit) {
  1392.                         $filteredTreatments[] = $treatment;
  1393.                     } elseif ($filter2 == "valid" && $isTreatmentValid) {
  1394.                         $filteredTreatments[] = $treatment;
  1395.                     }
  1396.                 } elseif ($filter1 == "pia") {
  1397.                     if ($filter2 == "inProgress" && $isPiaInProgress) {
  1398.                         $filteredTreatments[] = $treatment;
  1399.                     } elseif ($filter2 == "reco" && $isPiaReco) {
  1400.                         $filteredTreatments[] = $treatment;
  1401.                     } elseif ($filter2 == "valid" && $isPiaValid) {
  1402.                         $filteredTreatments[] = $treatment;
  1403.                     }
  1404.                 }
  1405.             } else {
  1406.                 $filteredTreatments[] = $treatment;
  1407.             }
  1408.         }
  1409.         return $this->render('user/treatments.html.twig', [
  1410.             "treatments" => $filteredTreatments,
  1411.             "treatmentsStats" => $treatmentsStats,
  1412.             "treatmentsPiaStats" => $treatmentsPiaStats,
  1413.             "filter1" => $filter1,
  1414.             "filter2" => $filter2,
  1415.         ]);
  1416.     }
  1417.     /**
  1418.      * @Route("/treatments/standardize/{id}", name="treatments_standardize")
  1419.      */
  1420.     public function treatmentsStandardizeAction(Request $requestSecurity $securityTreatment $treatment)
  1421.     {
  1422.         $form $this->createFormBuilder()
  1423.             ->add('category'EntityType::class, [
  1424.                 'attr' => array(
  1425.                     'placeholder' => 'Catégorie',
  1426.                 ),
  1427.                 'label' => 'Catégorie',
  1428.                 'placeholder' => 'Catégorie',
  1429.                 'required' => true,
  1430.                 'class' => TreatmentStdCategory::class,
  1431.                 'query_builder' => function (EntityRepository $er) {
  1432.                     $qb $er->createQueryBuilder('c');
  1433.                     return $qb
  1434.                         ->addSelect('(CASE WHEN c.id = 17 THEN 1 ELSE 0 END) AS HIDDEN ordCol')
  1435.                         ->addOrderBy('ordCol''ASC')
  1436.                         ->addOrderBy('c.libelle''ASC');
  1437.                 },
  1438.             ])
  1439.             ->getForm();
  1440.         $form->handleRequest($request);
  1441.         if ($form->isSubmitted() && $form->isValid()) {
  1442.             $em $this->getDoctrine()->getManager();
  1443.             $treatmentStd = new TreatmentStd();
  1444.             $treatmentStd->setName($treatment->getName());
  1445.             $treatmentStd->setCreationDate($treatment->getCreationDate());
  1446.             $treatmentStd->setEditDate($treatment->getEditDate());
  1447.             $treatmentStd->setMainPurpose($treatment->getMainPurpose());
  1448.             $treatmentStd->setPurpose1($treatment->getPurpose1());
  1449.             $treatmentStd->setPurpose2($treatment->getPurpose2());
  1450.             $treatmentStd->setPurpose3($treatment->getPurpose3());
  1451.             $treatmentStd->setPurpose4($treatment->getPurpose4());
  1452.             $treatmentStd->setPurpose5($treatment->getPurpose5());
  1453.             $treatmentStd->setOthersPurpose($treatment->getOthersPurpose());
  1454.             $treatmentStd->setDescription($treatment->getDescription());
  1455.             $treatmentStd->setPersonalData($treatment->getPersonalData());
  1456.             $treatmentStd->setPeopleData($treatment->getPeopleData());
  1457.             $treatmentStd->setTransferOutsideUeCountries($treatment->getTransferOutsideUeCountries());
  1458.             $treatmentStd->setSensitiveData($treatment->isSensitiveData());
  1459.             $treatmentStd->setConsentAsked($treatment->isConsentAsked());
  1460.             $treatmentStd->setConsentHow($treatment->getConsentHow());
  1461.             $treatmentStd->setPiaCriteria($treatment->getPiaCriteria());
  1462.             $treatmentStd->setPiaNeeded($treatment->isPiaNeeded());
  1463.             $treatmentStd->setPiaExoneration($treatment->isPiaExoneration());
  1464.             $treatmentStd->setLegalBasis($treatment->getLegalBasis());
  1465.             $treatmentStd->setDataSource($treatment->getDataSource());
  1466.             $treatmentStd->setAutomatedDecision($treatment->isAutomatedDecision());
  1467.             $treatmentStd->setInsufficientCriteria($treatment->isInsufficientCriteria());
  1468.             $treatmentStd->setDataRetentionPeriod($treatment->getDataRetentionPeriod());
  1469.             $treatmentStd->setCategory($form["category"]->getData());
  1470.             $token $security->getToken();
  1471.             if ($token instanceof SwitchUserToken) {
  1472.                 $impersonatorUser $token->getOriginalToken()->getUser();
  1473.                 if ($impersonatorUser) {
  1474.                     if ($impersonatorUser->getManager()) {
  1475.                         $originalManager $em->getRepository(Manager::class)->find($impersonatorUser->getManager()->getId());
  1476.                         if ($originalManager) {
  1477.                             $treatmentStd->setManager($originalManager);
  1478.                         }
  1479.                     }
  1480.                 }
  1481.             }
  1482.             $em->persist($treatmentStd);
  1483.             $em->flush();
  1484.             $this->get('session')->getFlashBag()->add('success''Nouveau traitement standard généré');
  1485.             return $this->redirectToRoute("user_treatments");
  1486.         }
  1487.         return $this->render('user/treatments_standardize.html.twig', [
  1488.             "form" => $form->createView(),
  1489.         ]);
  1490.     }
  1491.     /**
  1492.      * @Route("/treatments/group", name="treatments_group")
  1493.      */
  1494.     public function treatmentsGroupAction(Request $request)
  1495.     {
  1496.         if (!$this->getUser()->getUser()->getParentUser()) {
  1497.             throw new NotFoundHttpException();
  1498.         }
  1499.         $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()->getParentUser(), "group" => true]);
  1500.         $form $this->createFormBuilder();
  1501.         foreach ($treatments as $treatment) {
  1502.             $form->add("t_".$treatment->getId(), CheckboxType::class, [
  1503.                 "label" => " ",
  1504.                 "data" => $this->getUser()->getUser()->getGroupTreatments()->contains($treatment),
  1505.                 "required" => false
  1506.             ]);
  1507.         }
  1508.         $form $form->getForm();
  1509.         $form->handleRequest($request);
  1510.         if ($form->isSubmitted() && $form->isValid()) {
  1511.             $em $this->getDoctrine()->getManager();
  1512.             foreach ($treatments as $treatment) {
  1513.                 if ($form["t_".$treatment->getId()]->getData()) {
  1514.                     if (!$this->getUser()->getUser()->getGroupTreatments()->contains($treatment)) {
  1515.                         $this->getUser()->getUser()->getGroupTreatments()->add($treatment);
  1516.                     }
  1517.                 } else {
  1518.                     if ($this->getUser()->getUser()->getGroupTreatments()->contains($treatment)) {
  1519.                         $this->getUser()->getUser()->getGroupTreatments()->removeElement($treatment);
  1520.                     }
  1521.                 }
  1522.             }
  1523.             $em->flush();
  1524.             $this->get('session')->getFlashBag()->add('success''Vos préférences de traitements de groupes ont été enregistrées');
  1525.             return $this->redirectToRoute("user_treatments_group");
  1526.         }
  1527.         return $this->render('user/treatments_group.html.twig', [
  1528.             "treatments" => $treatments,
  1529.             "form" => $form->createView()
  1530.         ]);
  1531.     }
  1532.     /**
  1533.      * @Route("/treatments/export", name="treatments_export")
  1534.      */
  1535.     public function treatmentsExportAction(Request $request)
  1536.     {
  1537.         if ($this->isPrintingAllowed($this->getUser())) {
  1538.             $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  1539.             //$treatments = new ArrayCollection(array_merge($treatments, $this->getUser()->getUser()->getGroupTreatments()->toArray()));
  1540.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  1541.             $pdf->setUser($this->getUser()->getUser());
  1542.             $pdf->SetAuthor('myDigitplace');
  1543.             $pdf->SetTitle("Registre des traitements");
  1544.             $pdf->SetMargins(10,22,10true);
  1545.             $pdf->SetAutoPageBreak(TRUE35);
  1546.             $pdf->AddPage('L''A4');
  1547.             $html $this->renderView('user/pdf/treatments.html.twig', [
  1548.                 "treatments" => $treatments
  1549.             ]);
  1550.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  1551.             if (count($this->getUser()->getUser()->getGroupTreatments())) {
  1552.                 $pdf->AddPage('L''A4');
  1553.                 $html $this->renderView('user/pdf/treatments.html.twig', [
  1554.                     "treatments" => $this->getUser()->getUser()->getGroupTreatments(),
  1555.                     "group" => true
  1556.                 ]);
  1557.                 $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  1558.             }
  1559.             $filename 'Registre_des_traitements';
  1560.             return $pdf->Output($filename.".pdf",'I');
  1561.         } else {
  1562.             return $this->redirectToRoute("user_treatments");
  1563.         }
  1564.     }
  1565.     /**
  1566.      * @Route("/treatments/exportxlsx", name="treatments_export_xlsx")
  1567.      */
  1568.     public function treatmentsExportXlsxAction(Request $requestEntityManagerInterface $entityManager)
  1569.     {
  1570.         if ($this->isPrintingAllowed($this->getUser())) {
  1571.             $spreadsheet = new Spreadsheet();
  1572.             $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  1573.             $newWorkSheet = new Worksheet($spreadsheet"Traitements");
  1574.             $spreadsheet->addSheet($newWorkSheet1);
  1575.             $spreadsheet->setActiveSheetIndex(1);
  1576.             $sheet $spreadsheet->getActiveSheet();
  1577.             $sheet->setCellValue('A1''Nom du traitement');
  1578.             $sheet->setCellValue('B1''N° du traitement');
  1579.             $sheet->setCellValue('C1''Date création');
  1580.             $sheet->setCellValue('D1''Date mise à jour');
  1581.             $sheet->setCellValue('E1''Finalité');
  1582.             $sheet->setCellValue('F1''PIA');
  1583.             $i 1;
  1584.             foreach ($treatments as $treatment) {
  1585.                 $i++;
  1586.                 $treatmentNumber null;
  1587.                 $str strval($treatment->getNumber());
  1588.                 $strLen strlen($str);
  1589.                 $maxLen 3;
  1590.                 if ($strLen $maxLen) {
  1591.                     for ($k $strLen$k $maxLen$k++) {
  1592.                         $str "0".$str;
  1593.                     }
  1594.                 }
  1595.                 $treatmentNumber "T".$str;
  1596.                 $pia null;
  1597.                 if ($treatment->getPiaFile()) {
  1598.                     $pia "Réalisé";
  1599.                 } else {
  1600.                     if ($treatment->isInsufficientCriteria()) {
  1601.                         $pia "Non concerné";
  1602.                     } else {
  1603.                         if ($treatment->isPiaNeeded()) {
  1604.                             if ($treatment->isPiaExoneration()) {
  1605.                                 $pia "Exonéré";
  1606.                             } else {
  1607.                                 if ($treatment->getPiaFile()) {
  1608.                                     $pia "Réalisé";
  1609.                                 } else {
  1610.                                     $pia "À réaliser";
  1611.                                 }
  1612.                             }
  1613.                         } else {
  1614.                             if ($treatment->isPiaExoneration()) {
  1615.                                 $pia "Exonéré";
  1616.                             } else {
  1617.                                 if ($treatment->isSensitiveData()) {
  1618.                                     $pia "Recommandé";
  1619.                                 } else {
  1620.                                     $pia "Non concerné";
  1621.                                 }
  1622.                             }
  1623.                         }
  1624.                     }
  1625.                 }
  1626.                 $sheet->setCellValue('A' $i$treatment->getName());
  1627.                 $sheet->setCellValue('B' $i$treatmentNumber);
  1628.                 $sheet->setCellValue('C' $i$treatment->getCreationDate()->format("d/m/Y"));
  1629.                 $sheet->setCellValue('D' $i$treatment->getEditDate()->format("d/m/Y"));
  1630.                 $sheet->setCellValue('E' $i$treatment->getMainPurpose());
  1631.                 $sheet->setCellValue('F' $i$pia);
  1632.             }
  1633.             $spreadsheet->removeSheetByIndex(0);
  1634.             $writer = new Xlsx($spreadsheet);
  1635.             $response = new StreamedResponse();
  1636.             $response->setCallback(function () use ($writer) {
  1637.                 $writer->save('php://output');
  1638.             });
  1639.             $response->setStatusCode(200);
  1640.             $response->headers->set('Content-Type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  1641.             $response->headers->set('Content-Disposition''attachment;filename="export_registre_des_traitements.xlsx"');
  1642.             $response->headers->set('Cache-Control','max-age=0');
  1643.             return $response;
  1644.         } else {
  1645.             return $this->redirectToRoute("user_treatments");
  1646.         }
  1647.     }
  1648.     /**
  1649.      * @Route("/treatments/exportfull", name="treatments_export_full")
  1650.      */
  1651.     public function treatmentsExportFullAction(Request $request)
  1652.     {
  1653.         if ($this->isPrintingAllowed($this->getUser())) {
  1654.             $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  1655.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  1656.             $pdf->setUser($this->getUser()->getUser());
  1657.             $pdf->SetAuthor('myDigitplace');
  1658.             $pdf->SetTitle("Registre complet des traitements");
  1659.             $pdf->SetMargins(10,22,10true);
  1660.             $pdf->SetAutoPageBreak(TRUE35);
  1661.             $pdf->AddPage('P''A4');
  1662.             $html $this->renderView('user/pdf/treatments.html.twig', [
  1663.                 "treatments" => $treatments
  1664.             ]);
  1665.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  1666.             if (count($this->getUser()->getUser()->getGroupTreatments())) {
  1667.                 $pdf->AddPage('P''A4');
  1668.                 $html $this->renderView('user/pdf/treatments.html.twig', [
  1669.                     "treatments" => $this->getUser()->getUser()->getGroupTreatments(),
  1670.                     "group" => true
  1671.                 ]);
  1672.                 $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  1673.             }
  1674.             $treatments = new ArrayCollection(array_merge($treatments$this->getUser()->getUser()->getGroupTreatments()->toArray()));
  1675.             foreach ($treatments as $treatment) {
  1676.                 $pdf->AddPage('P''A4');
  1677.                 $html $this->renderView('user/pdf/treatment.html.twig', [
  1678.                     "treatment" => $treatment
  1679.                 ]);
  1680.                 $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  1681.             }
  1682.             $filename 'Registre_des_traitements_complet';
  1683.             return $pdf->Output($filename.".pdf",'I');
  1684.         } else {
  1685.             return $this->redirectToRoute("user_treatments");
  1686.         }
  1687.     }
  1688.     /**
  1689.      * @Route("/treatments/{id}/export", name="treatments_export_one")
  1690.      */
  1691.     public function treatmentsExportOneAction(Request $requestTreatment $treatment)
  1692.     {
  1693.         if ($this->isPrintingAllowed($this->getUser())) {
  1694.             if ($treatment->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  1695.                 if (!$this->getUser()->getUser()->getGroupTreatments()->contains($treatment)) {
  1696.                     if (!$this->getUser()->getUser()->getParentUser() || ($treatment->getUser()->getId() != $this->getUser()->getUser()->getParentUser()->getId())) {
  1697.                         throw new NotFoundHttpException();
  1698.                     }
  1699.                 }
  1700.             }
  1701.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  1702.             $pdf->setUser($this->getUser()->getUser());
  1703.             $pdf->SetAuthor('myDigitplace');
  1704.             $pdf->SetTitle("Registre des traitements");
  1705.             $pdf->SetMargins(10,22,10true);
  1706.             $pdf->SetAutoPageBreak(TRUE35);
  1707.             $pdf->AddPage('P''A4');
  1708.             $html $this->renderView('user/pdf/treatment.html.twig', [
  1709.                 "treatment" => $treatment
  1710.             ]);
  1711.             $filename 'traitement_'.$treatment->getId();
  1712.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  1713.             return $pdf->Output($filename.".pdf",'I');
  1714.         } else {
  1715.             return $this->redirectToRoute("user_treatments");
  1716.         }
  1717.     }
  1718.     /**
  1719.      * @Route("/treatments/add", name="treatments_add")
  1720.      */
  1721.     public function treatmentsAddAction(Request $requestSendEmailService $sendEmailServiceTranslatorInterface $translator)
  1722.     {
  1723.         $em $this->getDoctrine()->getManager();
  1724.         $treatment = new Treatment();
  1725.         /** @var \App\Entity\Account $user */
  1726.         $user $this->getUser()->getUser();
  1727.         $autoAddSystems $this->getDoctrine()->getRepository(System::class)->findBy(["user" => $user"autoApplyToTreatments" => true]);
  1728.         foreach ($autoAddSystems as $autoAddSystem) {
  1729.             $treatment->getSystems()->add($autoAddSystem);
  1730.         }
  1731.         $companyName "la société";
  1732.         if ($user->getCompanyName()) {
  1733.             $companyName $user->getCompanyName();
  1734.         }
  1735.         /*if (!$treatment->getCompanySubcontractorType()) {
  1736.             $defaultCompanySubcontractorType = $em->getRepository(\App\Entity\SubcontractorType::class)->findOneBy(["code" => "RESP_TRAITEMENT"]);
  1737.             if ($defaultCompanySubcontractorType) {
  1738.                 $treatment->setCompanySubcontractorType($defaultCompanySubcontractorType);
  1739.             }
  1740.         }*/
  1741.         $translatableLabel = new TranslatableMessage(
  1742.             'Responsabilité de %company_name% liée à ce traitement'
  1743.             ['%company_name%' => $companyName]
  1744.         );
  1745.         $form $this->createForm(TreatmentType::class, $treatment)
  1746.             ->add('companySubcontractorType'EntityType::class, [
  1747.                 'attr' => array(
  1748.                     'placeholder' => $translatableLabel,
  1749.                 ),
  1750.                 'label' => $translatableLabel,
  1751.                 'required' => true,
  1752.                 'class' => \App\Entity\SubcontractorType::class,
  1753.                 'expanded' => true,
  1754.             ])
  1755.             ->add('subcontractors'EntityType::class, [
  1756.                 'attr' => array(
  1757.                     'placeholder' => 'sous_traitants',
  1758.                 ),
  1759.                 'choice_attr' => function(Subcontractor $subcontractor$key$value) {
  1760.                     return ['data-st' => $subcontractor->getSubcontractorType()->getId()];
  1761.                 },
  1762.                 'placeholder' => 'sous_traitants',
  1763.                 'label' => 'sous_traitants',
  1764.                 'expanded' => true,
  1765.                 'multiple' => true,
  1766.                 'required' => false,
  1767.                 'translation_domain' => 'messages',
  1768.                 'class' => Subcontractor::class,
  1769.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  1770.                     $qb $er->createQueryBuilder('s');
  1771.                     if ($user->getParentUser()) {
  1772.                         $qb->where(
  1773.                             $qb->expr()->andX(
  1774.                                 $qb->expr()->isNotNull("s.user"),
  1775.                                 $qb->expr()->orX(
  1776.                                     "s.user = :user",
  1777.                                     $qb->expr()->andX(
  1778.                                         "s.user = :parentUser",
  1779.                                         "s.group = true"
  1780.                                     )
  1781.                                 )
  1782.                             )
  1783.                         )
  1784.                             ->setParameter("parentUser"$user->getParentUser());
  1785.                     } else {
  1786.                         $qb->where(
  1787.                             $qb->expr()->andX(
  1788.                                 $qb->expr()->isNotNull("s.user"),
  1789.                                 "s.user = :user"
  1790.                             )
  1791.                         );
  1792.                     }
  1793.                     $qb->setParameter("user"$user)
  1794.                         ->addOrderBy("s.subcontractorType""ASC")
  1795.                         ->addOrderBy("s.name""ASC");
  1796.                     return $qb;
  1797.                 },
  1798.                 'choice_label' => function(Subcontractor $subcontractor) {
  1799.                     return $subcontractor->getName();
  1800.                 },
  1801.             ])
  1802.             ->add('systems'EntityType::class, [
  1803.                 'attr' => array(
  1804.                     'placeholder' => 'mesures_techniques',
  1805.                 ),
  1806.                 'placeholder' => 'mesures_techniques',
  1807.                 'label' => 'mesures_techniques',
  1808.                 'expanded' => true,
  1809.                 'multiple' => true,
  1810.                 'required' => false,
  1811.                 'translation_domain' => 'messages',
  1812.                 'class' => System::class,
  1813.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  1814.                     $qb $er->createQueryBuilder('s');
  1815.                     if ($user->getParentUser()) {
  1816.                         $qb->where($qb->expr()->orX(
  1817.                             "s.user = :user"
  1818.                             ,
  1819.                             $qb->expr()->andX(
  1820.                                 "s.user = :parentUser",
  1821.                                 "s.group = true"
  1822.                             )
  1823.                         ));
  1824.                     } else {
  1825.                         $qb->where("s.user = :user");
  1826.                     }
  1827.                     $qb->setParameter("user"$user);
  1828.                     if ($user->getParentUser()) {
  1829.                         $qb->setParameter("parentUser"$user->getParentUser());
  1830.                     }
  1831.                     $qb->addOrderBy("s.name""ASC");
  1832.                     return $qb;
  1833.                 },
  1834.                 'choice_label' => function(System $system) {
  1835.                     return $system->getName();
  1836.                 },
  1837.             ])
  1838.         ;
  1839.         $form->add('piaExoneration'CheckboxType::class, [
  1840.             'label' => "cas_dxonration_de_ralisation_de_pia",
  1841.             'required' => false,
  1842.             'translation_domain' => 'messages',
  1843.         ]);
  1844.         $form->add('insufficientCriteria'CheckboxType::class, [
  1845.             'label' => "abscence_de_critere_suffisant",
  1846.             'required' => false,
  1847.             'translation_domain' => 'messages',
  1848.         ]);
  1849.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  1850.             $form->add('group'CheckboxType::class, [
  1851.                 'label' => "ce_traitement_concerne_le_groupe",
  1852.                 'required' => false,
  1853.             ]);
  1854.         }
  1855.         $form["state"]->setData($this->getDoctrine()->getRepository(TreatmentState::class)->find(1));
  1856.         $fromStd false;
  1857.         if (isset($_GET['std'])) {
  1858.             $treatmentStd $this->getDoctrine()->getRepository(TreatmentStd::class)->find($_GET['std']);
  1859.             if ($treatmentStd) {
  1860.                 if ($treatmentStd->getUser()) {
  1861.                     if ($treatmentStd->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  1862.                         if ($this->getUser()->getUser()->getParentUser()) {
  1863.                             if ($treatmentStd->getUser()->getId() != $this->getUser()->getUser()->getParentUser()->getId()) {
  1864.                                 throw new NotFoundHttpException();
  1865.                             }
  1866.                         } else {
  1867.                             throw new NotFoundHttpException();
  1868.                         }
  1869.                     }
  1870.                 }
  1871.                 $fromStd true;
  1872.                 $form['name']->setData($treatmentStd->getName());
  1873.                 $form['mainPurpose']->setData($treatmentStd->getMainPurpose());
  1874.                 $form['purpose1']->setData($treatmentStd->getPurpose1());
  1875.                 $form['purpose2']->setData($treatmentStd->getPurpose2());
  1876.                 $form['purpose3']->setData($treatmentStd->getPurpose3());
  1877.                 $form['purpose4']->setData($treatmentStd->getPurpose4());
  1878.                 $form['purpose5']->setData($treatmentStd->getPurpose5());
  1879.                 $form['othersPurpose']->setData($treatmentStd->getOthersPurpose());
  1880.                 $form['description']->setData($treatmentStd->getDescription());
  1881.                 $form['peopleData']->setData($treatmentStd->getPeopleData());
  1882.                 $form['transferOutsideUeCountries']->setData($treatmentStd->getTransferOutsideUeCountries());
  1883.                 $form['consentAsked']->setData($treatmentStd->isConsentAsked());
  1884.                 $form['consentHow']->setData($treatmentStd->getConsentHow());
  1885.                 $form['legalBasis']->setData($treatmentStd->getLegalBasis());
  1886.                 $form['dataSource']->setData($treatmentStd->getDataSource());
  1887.                 //$form['automatedDecision']->setData($treatmentStd->isAutomatedDecision());
  1888.                 $form['dataRetentionPeriod']->setData($treatmentStd->getDataRetentionPeriod());
  1889.                 $personalDataFields $treatmentStd->getPersonalData();
  1890.                 foreach ($treatmentStd->getPersonalData() as $key => $field) {
  1891.                     $form->add("field_text_".$keyTextType::class, [
  1892.                         'attr' => [
  1893.                             'placeholder' => 'zone_de_saisie'
  1894.                         ],
  1895.                         'label' => 'zone_de_saisie',
  1896.                         'data' => $field['text'],
  1897.                         'required' => false,
  1898.                         'translation_domain' => 'messages',
  1899.                         'mapped' => false
  1900.                     ]);
  1901.                     /*    ->add("field_duration_".$key, TextType::class, [
  1902.                         'attr' => [
  1903.                             'placeholder' => 'Durée de conservation'
  1904.                         ],
  1905.                         'label' => 'Durée de conservation',
  1906.                         'data' => $field['duration'],
  1907.                         'required' => false,
  1908.                         'mapped' => false
  1909.                     ]);*/
  1910.                 }
  1911.             }
  1912.         }
  1913.         if (!$fromStd) {
  1914.             $personalDataFields = [
  1915.                 [
  1916.                     "title" => $translator->trans('tat_civil_identit_donnes_didentification_images', [], 'messages'),
  1917.                     "level" => 1,
  1918.                 ],
  1919.                 [
  1920.                     "title" => $translator->trans('vie_personnelle_habitudes_de_vie_situation_familia', [], 'messages'),
  1921.                     "level" => 1,
  1922.                 ],
  1923.                 [
  1924.                     "title" => $translator->trans('infos_dordre_conomique_et_financier_revenus_situat', [], 'messages'),
  1925.                     "level" => 1,
  1926.                 ],
  1927.                 [
  1928.                     "title" => $translator->trans('donnes_de_connexion_adress_ip_logs_etc', [], 'messages'),
  1929.                     "level" => 1,
  1930.                 ],
  1931.                 [
  1932.                     "title" => $translator->trans('donnes_de_localisation_dplacements_donnes_gps_gsm', [], 'messages'),
  1933.                     "level" => 1,
  1934.                 ],
  1935.                 [
  1936.                     "title" => $translator->trans('donnes_bancaires_donnes_courantes_non_sensible_mai', [], 'messages'),
  1937.                     "level" => 2,
  1938.                 ],
  1939.                 [
  1940.                     "title" => $translator->trans('numro_de_scurit_sociale_ou_nir', [], 'messages'),
  1941.                     "level" => 2,
  1942.                 ],
  1943.                 [
  1944.                     "title" => $translator->trans('donnes_rvlant_lorigine_raciale_ou_ethnique', [], 'messages'),
  1945.                     "level" => 3,
  1946.                 ],
  1947.                 [
  1948.                     "title" => $translator->trans('donnes_rvlant_les_opinions_politiques', [], 'messages'),
  1949.                     "level" => 3,
  1950.                 ],
  1951.                 [
  1952.                     "title" => $translator->trans('donnes_rvlant_les_convictions_religieuses_ou_philo', [], 'messages'),
  1953.                     "level" => 3,
  1954.                 ],
  1955.                 [
  1956.                     "title" => $translator->trans('donnes_rvlant_lappartenance_syndicale', [], 'messages'),
  1957.                     "level" => 3,
  1958.                 ],
  1959.                 [
  1960.                     "title" => $translator->trans('donnes_gntiques', [], 'messages'),
  1961.                     "level" => 3,
  1962.                 ],
  1963.                 [
  1964.                     "title" => $translator->trans('donnes_biomtriques_aux_fins_didentifier_une_person', [], 'messages'),
  1965.                     "level" => 3,
  1966.                 ],
  1967.                 [
  1968.                     "title" => $translator->trans('donnes_concernant_la_sant', [], 'messages'),
  1969.                     "level" => 3,
  1970.                 ],
  1971.                 [
  1972.                     "title" => $translator->trans('donnes_concernant_la_vie_sexuelle_ou_lorientation', [], 'messages'),
  1973.                     "level" => 3,
  1974.                 ],
  1975.                 [
  1976.                     "title" => $translator->trans('donnes_relatives_des_condamnations_pnales_ou_infra', [], 'messages'),
  1977.                     "level" => 3,
  1978.                 ],
  1979.             ];
  1980.             foreach ($personalDataFields as $key => $field) {
  1981.                 $form->add("field_text_".$keyTextType::class, [
  1982.                     'attr' => [
  1983.                         'placeholder' => 'zone_de_saisie'
  1984.                     ],
  1985.                     'label' => 'zone_de_saisie',
  1986.                     'required' => false,
  1987.                     'mapped' => false,
  1988.                     'translation_domain' => 'messages',
  1989.                 ]);
  1990.                 /*    ->add("field_duration_".$key, TextType::class, [
  1991.                     'attr' => [
  1992.                         'placeholder' => 'Durée de conservation'
  1993.                     ],
  1994.                     'label' => 'Durée de conservation',
  1995.                     'required' => false,
  1996.                     'mapped' => false
  1997.                 ]);*/
  1998.             }
  1999.         }
  2000.         if ($this->getUser()->getUser()->getCompanyName()) {
  2001.             $form['treatmentAccountant']->setData($this->getUser()->getUser()->getCompanyName());
  2002.         } elseif ($this->getUser()->getUser()->getAccountantFirstName() || $this->getUser()->getUser()->getAccountantLastName()) {
  2003.             $form['treatmentAccountant']->setData($this->getUser()->getUser()->getAccountantFirstName().' '.$this->getUser()->getUser()->getAccountantLastName());
  2004.         }
  2005.         if ($this->getUser()->getUser()->getManager() && ($this->getUser()->getUser()->getManager()->getFirstName() || $this->getUser()->getUser()->getManager()->getLastName())) {
  2006.             $form['dpo']->setData($this->getUser()->getUser()->getManager()->getFirstName().' '.$this->getUser()->getUser()->getManager()->getLastName());
  2007.         }
  2008.         if ($this->getUser()->getUser()->getContactFirstName() || $this->getUser()->getUser()->getContactLastName()) {
  2009.             $form['editor']->setData($this->getUser()->getUser()->getContactFirstName().' '.$this->getUser()->getUser()->getContactLastName());
  2010.         }
  2011.         $form->handleRequest($request);
  2012.         if ($form->isSubmitted() && $form->isValid()) {
  2013.             $treatmentsQuery $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()], ['number' => "DESC"], 1);
  2014.             $now = new \DateTime("now");
  2015.             $personalData = [];
  2016.             $sensitiveData false;
  2017.             /*if ($treatment->getTransferOutsideUeCountries()) {
  2018.                 $sensitiveData = true;
  2019.             }*/
  2020.             if ($treatment->isAutomatedDecision()) {
  2021.                 $sensitiveData true;
  2022.             }
  2023.             foreach ($personalDataFields as $key => $field) {
  2024.                 $personalData[] = [
  2025.                     "title" => $field['title'],
  2026.                     "level" => $field['level'],
  2027.                     "text" => $form["field_text_".$key]->getData(),
  2028.                     //"duration" => $form["field_duration_".$key]->getData(),
  2029.                 ];
  2030.                 if (($field['level'] == || $field['level'] == 3) && ($form["field_text_".$key]->getData()/* || $form["field_duration_".$key]->getData()*/)) {
  2031.                     $sensitiveData true;
  2032.                 }
  2033.             }
  2034.             $treatment->setPersonalData($personalData);
  2035.             $treatment->setSensitiveData($sensitiveData);
  2036.             $treatment->setCreationDate($now);
  2037.             $treatment->setEditDate($now);
  2038.             $treatment->setUser($this->getUser()->getUser());
  2039.             if (count($treatmentsQuery)) {
  2040.                 $number $treatmentsQuery[0]->getNumber() + 1;
  2041.             } else {
  2042.                 $number 1;
  2043.             }
  2044.             if ($treatment->isSensitiveData()) {
  2045.                 if (!in_array(1$treatment->getPiaCriteria())) {
  2046.                     $treatment->addPiaCriteria(1);
  2047.                 }
  2048.             }/* else {
  2049.                 $treatment->setInsufficientCriteria(true);
  2050.             }*/
  2051.             $treatment->setNumber($number);
  2052.             if (count($treatment->getPiaCriteria()) >= 2) {
  2053.                 $treatment->setPiaNeeded(true);
  2054.             } else {
  2055.                 $treatment->setPiaNeeded(false);
  2056.             }
  2057.             $em->persist($treatment);
  2058.             $em->flush();
  2059.             if ($treatment->isGroup()) {
  2060.                 foreach ($this->getUser()->getUser()->getChildrenUsers() as $childUser) {
  2061.                     if (!$childUser->getGroupTreatments()->contains($treatment)) {
  2062.                         $childUser->getGroupTreatments()->add($treatment);
  2063.                     }
  2064.                 }
  2065.                 $em->flush();
  2066.             }
  2067.             /**
  2068.              * @var UploadedFile $file
  2069.              */
  2070.             $file $form->get('piaFileFile')->getData();
  2071.             if ($file != NULL) {
  2072.                 $fileName $this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  2073.                 $file->move(
  2074.                     $this->getParameter('documents_directory'), $fileName
  2075.                 );
  2076.                 $treatment->setPiaFile($fileName);
  2077.                 $em->flush();
  2078.             }
  2079.             $content "<p>Bonjour,<br/>
  2080.                         <br/>
  2081.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a créé un nouveau traitement: ".$treatment->getName()."<br/>
  2082.                         <br/>
  2083.                         <br/>
  2084.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  2085.                         </p>";
  2086.             $sendEmailService->send(
  2087.                 "Nouveau traitement client",
  2088.                 $this->getUser()->getUser()->getManager()->getEmail(),
  2089.                 'template_emails/left_text.html.twig',
  2090.                 [
  2091.                     "title" => "Nouveau traitement client",
  2092.                     "content" => $content
  2093.                 ]
  2094.             );
  2095.             $this->get('session')->getFlashBag()->add('success''Nouveau traitement ajouté');
  2096.             return $this->redirectToRoute("user_treatments");
  2097.         }
  2098.         $treatmentsStdGroups = [];
  2099.         $treatmentsStdFromGroup $this->getDoctrine()->getRepository(TreatmentStd::class)->findAllForGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser());
  2100.         if (count($treatmentsStdFromGroup)) {
  2101.             $treatmentsStdGroups["group"] = [
  2102.                 "category" => ["id" => 0"libelle" => "Standards du groupe"],
  2103.                 "treatmentsStd" => $treatmentsStdFromGroup
  2104.             ];
  2105.         }
  2106.         $treatmentsStd $this->getDoctrine()->getRepository(TreatmentStd::class)->findAllOrdered();
  2107.         foreach ($treatmentsStd as $treatmentStd) {
  2108.             if (!isset($treatmentsStdGroups[$treatmentStd->getCategory()->getId()])) {
  2109.                 $treatmentsStdGroups[$treatmentStd->getCategory()->getId()] = [
  2110.                     "category" => $treatmentStd->getCategory(),
  2111.                     "treatmentsStd" => []
  2112.                 ];
  2113.             }
  2114.             $treatmentsStdGroups[$treatmentStd->getCategory()->getId()]["treatmentsStd"][] = $treatmentStd;
  2115.         }
  2116.         $subcontractors = [];
  2117.         $systems = [];
  2118.         $subcontractorsStr = [];
  2119.         $systemsStr = [];
  2120.         foreach ($treatment->getSubcontractors() as $subcontractor) {
  2121.             $subcontractors[] = $subcontractor->getId();
  2122.             $subcontractorsStr[] = $subcontractor->getName();
  2123.         }
  2124.         foreach ($treatment->getSystems() as $system) {
  2125.             $systems[] = $system->getId();
  2126.             $systemsStr[] = $system->getName();
  2127.         }
  2128.         sort($subcontractorsStr);
  2129.         sort($systemsStr);
  2130.         $subcontractorsTypes = [];
  2131.         $stRequest $this->getDoctrine()->getRepository(\App\Entity\SubcontractorType::class)->findAll();
  2132.         foreach ($stRequest as $item) {
  2133.             $subcontractorsTypes[$item->getId()] = $item->getLibelle();
  2134.         }
  2135.         return $this->render('user/treatments_add.html.twig', [
  2136.             "form" => $form->createView(),
  2137.             "treatmentsStdGroups" => $treatmentsStdGroups,
  2138.             "personalDataFields" => $personalDataFields,
  2139.             "subcontractors" => $subcontractors,
  2140.             "systems" => $systems,
  2141.             "subcontractorsStr" => $subcontractorsStr,
  2142.             "systemsStr" => $systemsStr,
  2143.             "subcontractorsTypes" => $subcontractorsTypes
  2144.         ]);
  2145.     }
  2146.     /**
  2147.      * @Route("/treatments/{id}/edit", name="treatments_edit")
  2148.      */
  2149.     public function treatmentsEditAction(Request $requestSendEmailService $sendEmailServiceTreatment $treatment)
  2150.     {
  2151.         if ($treatment->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  2152.             throw new NotFoundHttpException();
  2153.         }
  2154.         $em $this->getDoctrine()->getManager();
  2155.         if (count($treatment->getPiaCriteria()) == 0) {
  2156.             $changesv2 false;
  2157.             $em $this->getDoctrine()->getManager();
  2158.             if ($treatment->isSensitiveData()) {
  2159.                 if (!in_array(1$treatment->getPiaCriteria())) {
  2160.                     $treatment->addPiaCriteria(1);
  2161.                 }
  2162.             }
  2163.             if ($treatment->isAutomatedDecision()) {
  2164.                 $treatment->addPiaCriteria(4);
  2165.                 $treatment->setAutomatedDecision(false);
  2166.             }
  2167.             if ($changesv2) {
  2168.                 $em->flush();
  2169.                 return $this->redirectToRoute("user_treatments_edit", ["id" => $treatment->getId()]);
  2170.             }
  2171.         }
  2172.         $user $this->getUser()->getUser();
  2173.         $currentGroupTreatment = ($treatment->isGroup() == true);
  2174.         $companyName "la société";
  2175.         if ($this->getUser()->getUser()->getCompanyName()) {
  2176.             $companyName $this->getUser()->getUser()->getCompanyName();
  2177.         }
  2178.         /*if (!$treatment->getCompanySubcontractorType()) {
  2179.             $defaultCompanySubcontractorType = $em->getRepository(\App\Entity\SubcontractorType::class)->findOneBy(["code" => "RESP_TRAITEMENT"]);
  2180.             if ($defaultCompanySubcontractorType) {
  2181.                 $treatment->setCompanySubcontractorType($defaultCompanySubcontractorType);
  2182.             }
  2183.         }*/
  2184.         $translatableLabel = new TranslatableMessage(
  2185.             'Responsabilité de %company_name% liée à ce traitement'
  2186.             ['%company_name%' => $companyName]
  2187.         );
  2188.         $form $this->createForm(TreatmentType::class, $treatment)
  2189.             ->add('companySubcontractorType'EntityType::class, [
  2190.                 'attr' => array(
  2191.                     'placeholder' => $translatableLabel,
  2192.                 ),
  2193.                 'label' => $translatableLabel,
  2194.                 'required' => true,
  2195.                 'class' => \App\Entity\SubcontractorType::class,
  2196.                 'expanded' => true,
  2197.             ])
  2198.             ->add('subcontractors'EntityType::class, [
  2199.                 'attr' => array(
  2200.                     'placeholder' => 'sous_traitants',
  2201.                 ),
  2202.                 'choice_attr' => function(Subcontractor $subcontractor$key$value) {
  2203.                     return ['data-st' => $subcontractor->getSubcontractorType()->getId()];
  2204.                 },
  2205.                 'placeholder' => 'sous_traitants',
  2206.                 'label' => 'sous_traitants',
  2207.                 'expanded' => true,
  2208.                 'multiple' => true,
  2209.                 'required' => false,
  2210.                 'translation_domain' => 'messages',
  2211.                 'class' => Subcontractor::class,
  2212.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  2213.                     $qb $er->createQueryBuilder('s');
  2214.                     if ($user->getParentUser()) {
  2215.                         $qb->where(
  2216.                             $qb->expr()->andX(
  2217.                                 $qb->expr()->isNotNull("s.user"),
  2218.                                 $qb->expr()->orX(
  2219.                                     "s.user = :user",
  2220.                                     $qb->expr()->andX(
  2221.                                         "s.user = :parentUser",
  2222.                                         "s.group = true"
  2223.                                     )
  2224.                                 )
  2225.                             )
  2226.                         )
  2227.                             ->setParameter("parentUser"$user->getParentUser());
  2228.                     } else {
  2229.                         $qb->where(
  2230.                             $qb->expr()->andX(
  2231.                                 $qb->expr()->isNotNull("s.user"),
  2232.                                 "s.user = :user"
  2233.                             )
  2234.                         );
  2235.                     }
  2236.                     $qb->setParameter("user"$user)
  2237.                         ->addOrderBy("s.subcontractorType""ASC")
  2238.                         ->addOrderBy("s.name""ASC");
  2239.                     return $qb;
  2240.                 },
  2241.                 'choice_label' => function(Subcontractor $subcontractor) {
  2242.                     return $subcontractor->getName();
  2243.                 },
  2244.             ])
  2245.             ->add('systems'EntityType::class, [
  2246.                 'attr' => array(
  2247.                     'placeholder' => 'mesures_techniques',
  2248.                 ),
  2249.                 'placeholder' => 'mesures_techniques',
  2250.                 'label' => 'mesures_techniques',
  2251.                 'expanded' => true,
  2252.                 'multiple' => true,
  2253.                 'required' => false,
  2254.                 'translation_domain' => 'messages',
  2255.                 'class' => System::class,
  2256.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  2257.                     $qb $er->createQueryBuilder('s');
  2258.                     if ($user->getParentUser()) {
  2259.                         $qb->where($qb->expr()->orX(
  2260.                             "s.user = :user"
  2261.                             ,
  2262.                             $qb->expr()->andX(
  2263.                                 "s.user = :parentUser",
  2264.                                 "s.group = true"
  2265.                             )
  2266.                         ));
  2267.                     } else {
  2268.                         $qb->where("s.user = :user");
  2269.                     }
  2270.                     $qb->setParameter("user"$user);
  2271.                     if ($user->getParentUser()) {
  2272.                         $qb->setParameter("parentUser"$user->getParentUser());
  2273.                     }
  2274.                     $qb->addOrderBy("s.name""ASC");
  2275.                     return $qb;
  2276.                 },
  2277.                 'choice_label' => function(System $system) {
  2278.                     return $system->getName();
  2279.                 },
  2280.             ])
  2281.         ;
  2282.         $form->add('piaExoneration'CheckboxType::class, [
  2283.             'label' => "cas_dxonration_de_ralisation_de_pia",
  2284.             'required' => false,
  2285.             'translation_domain' => 'messages',
  2286.         ]);
  2287.         $form->add('insufficientCriteria'CheckboxType::class, [
  2288.             'label' => "abscence_de_critere_suffisant",
  2289.             'required' => false,
  2290.             'translation_domain' => 'messages',
  2291.         ]);
  2292.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  2293.             $form->add('group'CheckboxType::class, [
  2294.                 'label' => "ce_traitement_concerne_le_groupe",
  2295.                 'required' => false,
  2296.             ]);
  2297.         }
  2298.         if ($treatment->getPiaFile()) {
  2299.             $form->add('deletePiaFile'CheckboxType::class, [
  2300.                 'label' => "supprimer_le_pia",
  2301.                 'required' => false,
  2302.                 'translation_domain' => 'messages',
  2303.                 "mapped" => false
  2304.             ]);
  2305.         }
  2306.         foreach ($treatment->getPersonalData() as $key => $field) {
  2307.             $form->add("field_text_".$keyTextType::class, [
  2308.                 'attr' => [
  2309.                     'placeholder' => 'zone_de_saisie'
  2310.                 ],
  2311.                 'label' => 'zone_de_saisie',
  2312.                 'data' => $field['text'],
  2313.                 'required' => false,
  2314.                 'translation_domain' => 'messages',
  2315.                 'mapped' => false
  2316.             ]);
  2317.             /*->add("field_duration_".$key, TextType::class, [
  2318.                 'attr' => [
  2319.                     'placeholder' => 'Durée de conservation'
  2320.                 ],
  2321.                 'label' => 'Durée de conservation',
  2322.                 'data' => $field['duration'],
  2323.                 'required' => false,
  2324.                 'mapped' => false
  2325.             ]);*/
  2326.         }
  2327.         $form->handleRequest($request);
  2328.         if ($form->isSubmitted() && $form->isValid()) {
  2329.             $treatmentsQuery $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  2330.             $now = new \DateTime("now");
  2331.             $personalData = [];
  2332.             $sensitiveData false;
  2333.             /*if ($treatment->getTransferOutsideUeCountries()) {
  2334.                 $sensitiveData = true;
  2335.             }*/
  2336.             if ($treatment->isAutomatedDecision()) {
  2337.                 $sensitiveData true;
  2338.             }
  2339.             foreach ($treatment->getPersonalData() as $key => $field) {
  2340.                 $personalData[] = [
  2341.                     "title" => $field['title'],
  2342.                     "level" => $field['level'],
  2343.                     "text" => $form["field_text_".$key]->getData(),
  2344.                     //"duration" => $form["field_duration_".$key]->getData(),
  2345.                 ];
  2346.                 if (($field['level'] == || $field['level'] == 3) && ($form["field_text_".$key]->getData()/* || $form["field_duration_".$key]->getData()*/)) {
  2347.                     $sensitiveData true;
  2348.                 }
  2349.             }
  2350.             $treatment->setPersonalData($personalData);
  2351.             $treatment->setSensitiveData($sensitiveData);
  2352.             if ($treatment->isSensitiveData()) {
  2353.                 if (!in_array(1$treatment->getPiaCriteria())) {
  2354.                     $treatment->addPiaCriteria(1);
  2355.                 }
  2356.             }/* else {
  2357.                 $treatment->setInsufficientCriteria(true);
  2358.             }*/
  2359.             $treatment->setEditDate($now);
  2360.             if (count($treatment->getPiaCriteria()) >= 2) {
  2361.                 $treatment->setPiaNeeded(true);
  2362.             } else {
  2363.                 $treatment->setPiaNeeded(false);
  2364.             }
  2365.             if ($treatment->getPiaFile()) {
  2366.                 if ($form["deletePiaFile"]->getData()) {
  2367.                     $treatment->setPiaFile(null);
  2368.                 }
  2369.             }
  2370.             $em->flush();
  2371.             if (!$currentGroupTreatment && $treatment->isGroup()) {
  2372.                 foreach ($this->getUser()->getUser()->getChildrenUsers() as $childUser) {
  2373.                     if (!$childUser->getGroupTreatments()->contains($treatment)) {
  2374.                         $childUser->getGroupTreatments()->add($treatment);
  2375.                     }
  2376.                 }
  2377.                 $em->flush();
  2378.             } elseif ($currentGroupTreatment && !$treatment->isGroup()) {
  2379.                 foreach ($this->getUser()->getUser()->getChildrenUsers() as $childUser) {
  2380.                     if ($childUser->getGroupTreatments()->contains($treatment)) {
  2381.                         $childUser->getGroupTreatments()->removeElement($treatment);
  2382.                     }
  2383.                 }
  2384.                 $em->flush();
  2385.             }
  2386.             /**
  2387.              * @var UploadedFile $file
  2388.              */
  2389.             $file $form->get('piaFileFile')->getData();
  2390.             if ($file != NULL) {
  2391.                 $fileName $this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  2392.                 $file->move(
  2393.                     $this->getParameter('documents_directory'), $fileName
  2394.                 );
  2395.                 $treatment->setPiaFile($fileName);
  2396.                 $em->flush();
  2397.             }
  2398.             $content "<p>Bonjour,<br/>
  2399.                         <br/>
  2400.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a modifié le traitement ".$treatment->getName()."<br/>
  2401.                         <br/>
  2402.                         <br/>
  2403.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  2404.                         </p>";
  2405.             $sendEmailService->send(
  2406.                 "Traitement client modifié",
  2407.                 $this->getUser()->getUser()->getManager()->getEmail(),
  2408.                 'template_emails/left_text.html.twig',
  2409.                 [
  2410.                     "title" => "Traitement client modifié",
  2411.                     "content" => $content
  2412.                 ]
  2413.             );
  2414.             $this->get('session')->getFlashBag()->add('success''Traitement mis à jour');
  2415.             return $this->redirectToRoute("user_treatments");
  2416.         }
  2417.         $subcontractors = [];
  2418.         $systems = [];
  2419.         $subcontractorsStr = [];
  2420.         $systemsStr = [];
  2421.         foreach ($treatment->getSubcontractors() as $subcontractor) {
  2422.             $subcontractors[] = $subcontractor->getId();
  2423.             $subcontractorsStr[] = $subcontractor->getName();
  2424.         }
  2425.         foreach ($treatment->getSystems() as $system) {
  2426.             $systems[] = $system->getId();
  2427.             $systemsStr[] = $system->getName();
  2428.         }
  2429.         sort($subcontractorsStr);
  2430.         sort($systemsStr);
  2431.         $subcontractorsTypes = [];
  2432.         $stRequest $this->getDoctrine()->getRepository(\App\Entity\SubcontractorType::class)->findAll();
  2433.         foreach ($stRequest as $item) {
  2434.             $subcontractorsTypes[$item->getId()] = $item->getLibelle();
  2435.         }
  2436.         return $this->render('user/treatments_edit.html.twig', [
  2437.             "form" => $form->createView(),
  2438.             "treatment" => $treatment,
  2439.             "personalDataFields" => $treatment->getPersonalData(),
  2440.             "subcontractors" => $subcontractors,
  2441.             "systems" => $systems,
  2442.             "subcontractorsStr" => $subcontractorsStr,
  2443.             "systemsStr" => $systemsStr,
  2444.             "subcontractorsTypes" => $subcontractorsTypes
  2445.         ]);
  2446.     }
  2447.     /**
  2448.      * @Route("/treatments/{id}/copy", name="treatments_copy")
  2449.      */
  2450.     public function treatmentsCopyAction(Request $requestSendEmailService $sendEmailServiceTreatment $treatment)
  2451.     {
  2452.         if ($treatment->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  2453.             throw new NotFoundHttpException();
  2454.         }
  2455.         $em $this->getDoctrine()->getManager();
  2456.         if (count($treatment->getPiaCriteria()) == 0) {
  2457.             $changesv2 false;
  2458.             $em $this->getDoctrine()->getManager();
  2459.             if ($treatment->isSensitiveData()) {
  2460.                 if (!in_array(1$treatment->getPiaCriteria())) {
  2461.                     $treatment->addPiaCriteria(1);
  2462.                 }
  2463.             }
  2464.             if ($treatment->isAutomatedDecision()) {
  2465.                 $treatment->addPiaCriteria(4);
  2466.                 $treatment->setAutomatedDecision(false);
  2467.             }
  2468.             if ($changesv2) {
  2469.                 $em->flush();
  2470.                 return $this->redirectToRoute("user_treatments_copy", ["id" => $treatment->getId()]);
  2471.             }
  2472.         }
  2473.         $newTreatment = clone $treatment;
  2474.         $newTreatment->setId(null);
  2475.         $newTreatment->getSubcontractors()->clear();
  2476.         $newTreatment->getSystems()->clear();
  2477.         $user $this->getUser()->getUser();
  2478.         $companyName "la société";
  2479.         if ($this->getUser()->getUser()->getCompanyName()) {
  2480.             $companyName $this->getUser()->getUser()->getCompanyName();
  2481.         }
  2482.         /*if (!$newTreatment->getCompanySubcontractorType()) {
  2483.             $defaultCompanySubcontractorType = $em->getRepository(\App\Entity\SubcontractorType::class)->findOneBy(["code" => "RESP_TRAITEMENT"]);
  2484.             if ($defaultCompanySubcontractorType) {
  2485.                 $newTreatment->setCompanySubcontractorType($defaultCompanySubcontractorType);
  2486.             }
  2487.         }*/
  2488.         $translatableLabel = new TranslatableMessage(
  2489.             'Responsabilité de %company_name% liée à ce traitement'
  2490.             ['%company_name%' => $companyName]
  2491.         );
  2492.         $form $this->createForm(TreatmentType::class, $newTreatment)
  2493.             ->add('companySubcontractorType'EntityType::class, [
  2494.                 'attr' => array(
  2495.                     'placeholder' => $translatableLabel,
  2496.                 ),
  2497.                 'label' => $translatableLabel,
  2498.                 'required' => true,
  2499.                 'class' => \App\Entity\SubcontractorType::class,
  2500.                 'expanded' => true,
  2501.             ])
  2502.             ->add('subcontractors'EntityType::class, [
  2503.                 'attr' => array(
  2504.                     'placeholder' => 'sous_traitants',
  2505.                 ),
  2506.                 'choice_attr' => function(Subcontractor $subcontractor$key$value) {
  2507.                     return ['data-st' => $subcontractor->getSubcontractorType()->getId()];
  2508.                 },
  2509.                 'placeholder' => 'sous_traitants',
  2510.                 'label' => 'sous_traitants',
  2511.                 'expanded' => true,
  2512.                 'multiple' => true,
  2513.                 'required' => false,
  2514.                 'translation_domain' => 'messages',
  2515.                 'class' => Subcontractor::class,
  2516.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  2517.                     $qb $er->createQueryBuilder('s');
  2518.                     if ($user->getParentUser()) {
  2519.                         $qb->where(
  2520.                             $qb->expr()->andX(
  2521.                                 $qb->expr()->isNotNull("s.user"),
  2522.                                 $qb->expr()->orX(
  2523.                                     "s.user = :user",
  2524.                                     $qb->expr()->andX(
  2525.                                         "s.user = :parentUser",
  2526.                                         "s.group = true"
  2527.                                     )
  2528.                                 )
  2529.                             )
  2530.                         )
  2531.                             ->setParameter("parentUser"$user->getParentUser());
  2532.                     } else {
  2533.                         $qb->where(
  2534.                             $qb->expr()->andX(
  2535.                                 $qb->expr()->isNotNull("s.user"),
  2536.                                 "s.user = :user"
  2537.                             )
  2538.                         );
  2539.                     }
  2540.                     $qb->setParameter("user"$user)
  2541.                         ->addOrderBy("s.subcontractorType""ASC")
  2542.                         ->addOrderBy("s.name""ASC");
  2543.                     return $qb;
  2544.                 },
  2545.                 'choice_label' => function(Subcontractor $subcontractor) {
  2546.                     return $subcontractor->getName();
  2547.                 },
  2548.             ])
  2549.             ->add('systems'EntityType::class, [
  2550.                 'attr' => array(
  2551.                     'placeholder' => 'mesures_techniques',
  2552.                 ),
  2553.                 'placeholder' => 'mesures_techniques',
  2554.                 'label' => 'mesures_techniques',
  2555.                 'expanded' => true,
  2556.                 'multiple' => true,
  2557.                 'required' => false,
  2558.                 'translation_domain' => 'messages',
  2559.                 'class' => System::class,
  2560.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  2561.                     $qb $er->createQueryBuilder('s');
  2562.                     if ($user->getParentUser()) {
  2563.                         $qb->where($qb->expr()->orX(
  2564.                             "s.user = :user"
  2565.                             ,
  2566.                             $qb->expr()->andX(
  2567.                                 "s.user = :parentUser",
  2568.                                 "s.group = true"
  2569.                             )
  2570.                         ));
  2571.                     } else {
  2572.                         $qb->where("s.user = :user");
  2573.                     }
  2574.                     $qb->setParameter("user"$user);
  2575.                     if ($user->getParentUser()) {
  2576.                         $qb->setParameter("parentUser"$user->getParentUser());
  2577.                     }
  2578.                     $qb->addOrderBy("s.name""ASC");
  2579.                     return $qb;
  2580.                 },
  2581.                 'choice_label' => function(System $system) {
  2582.                     return $system->getName();
  2583.                 },
  2584.             ])
  2585.         ;
  2586.         $form->add('piaExoneration'CheckboxType::class, [
  2587.             'label' => "cas_dxonration_de_ralisation_de_pia",
  2588.             'required' => false,
  2589.             'translation_domain' => 'messages',
  2590.         ]);
  2591.         $form->add('insufficientCriteria'CheckboxType::class, [
  2592.             'label' => "abscence_de_critere_suffisant",
  2593.             'required' => false,
  2594.             'translation_domain' => 'messages',
  2595.         ]);
  2596.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  2597.             $form->add('group'CheckboxType::class, [
  2598.                 'label' => "ce_traitement_concerne_le_groupe",
  2599.                 'required' => false,
  2600.             ]);
  2601.         }
  2602.         foreach ($newTreatment->getPersonalData() as $key => $field) {
  2603.             $form->add("field_text_".$keyTextType::class, [
  2604.                 'attr' => [
  2605.                     'placeholder' => 'zone_de_saisie'
  2606.                 ],
  2607.                 'label' => 'zone_de_saisie',
  2608.                 'data' => $field['text'],
  2609.                 'required' => false,
  2610.                 'translation_domain' => 'messages',
  2611.                 'mapped' => false
  2612.             ]);
  2613.             /*->add("field_duration_".$key, TextType::class, [
  2614.                 'attr' => [
  2615.                     'placeholder' => 'Durée de conservation'
  2616.                 ],
  2617.                 'label' => 'Durée de conservation',
  2618.                 'data' => $field['duration'],
  2619.                 'required' => false,
  2620.                 'mapped' => false
  2621.             ]);*/
  2622.         }
  2623.         $form->handleRequest($request);
  2624.         if ($form->isSubmitted() && $form->isValid()) {
  2625.             $treatmentsQuery $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()], ['number' => "DESC"], 1);
  2626.             $em $this->getDoctrine()->getManager();
  2627.             $now = new \DateTime("now");
  2628.             $personalData = [];
  2629.             $sensitiveData false;
  2630.             if ($newTreatment->getTransferOutsideUeCountries()) {
  2631.                 $sensitiveData true;
  2632.             }
  2633.             if ($newTreatment->isAutomatedDecision()) {
  2634.                 $sensitiveData true;
  2635.             }
  2636.             foreach ($newTreatment->getPersonalData() as $key => $field) {
  2637.                 $personalData[] = [
  2638.                     "title" => $field['title'],
  2639.                     "level" => $field['level'],
  2640.                     "text" => $form["field_text_".$key]->getData(),
  2641.                     //"duration" => $form["field_duration_".$key]->getData(),
  2642.                 ];
  2643.                 if (($field['level'] == || $field['level'] == 3) && ($form["field_text_".$key]->getData()/* || $form["field_duration_".$key]->getData()*/)) {
  2644.                     $sensitiveData true;
  2645.                 }
  2646.             }
  2647.             $newTreatment->setPersonalData($personalData);
  2648.             $newTreatment->setSensitiveData($sensitiveData);
  2649.             if ($newTreatment->isSensitiveData()) {
  2650.                 if (!in_array(1$treatment->getPiaCriteria())) {
  2651.                     $treatment->addPiaCriteria(1);
  2652.                 }
  2653.             } else {
  2654.                 $treatment->setInsufficientCriteria(true);
  2655.             }
  2656.             $newTreatment->setCreationDate($now);
  2657.             $newTreatment->setEditDate($now);
  2658.             $newTreatment->setUser($this->getUser()->getUser());
  2659.             if (count($treatmentsQuery)) {
  2660.                 $number $treatmentsQuery[0]->getNumber() + 1;
  2661.             } else {
  2662.                 $number 1;
  2663.             }
  2664.             $newTreatment->setNumber($number);
  2665.             if (count($newTreatment->getPiaCriteria()) >= 2) {
  2666.                 $newTreatment->setPiaNeeded(true);
  2667.             } else {
  2668.                 $newTreatment->setPiaNeeded(false);
  2669.             }
  2670.             if (!$newTreatment->isGroup()) {
  2671.                 $newTreatment->getGroupUsers()->clear();
  2672.             }
  2673.             $em->persist($newTreatment);
  2674.             $em->flush();
  2675.             if ($newTreatment->isGroup()) {
  2676.                 foreach ($this->getUser()->getUser()->getChildrenUsers() as $childUser) {
  2677.                     if (!$childUser->getGroupTreatments()->contains($newTreatment)) {
  2678.                         $childUser->getGroupTreatments()->add($newTreatment);
  2679.                     }
  2680.                 }
  2681.                 $em->flush();
  2682.             }
  2683.             /**
  2684.              * @var UploadedFile $file
  2685.              */
  2686.             $file $form->get('piaFileFile')->getData();
  2687.             if ($file != NULL) {
  2688.                 $fileName $this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  2689.                 $file->move(
  2690.                     $this->getParameter('documents_directory'), $fileName
  2691.                 );
  2692.                 $newTreatment->setPiaFile($fileName);
  2693.                 $em->flush();
  2694.             }
  2695.             $content "<p>Bonjour,<br/>
  2696.                         <br/>
  2697.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a créé un nouveau traitement: ".$newTreatment->getName()."<br/>
  2698.                         <br/>
  2699.                         <br/>
  2700.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  2701.                         </p>";
  2702.             $sendEmailService->send(
  2703.                 "Nouveau traitement client",
  2704.                 $this->getUser()->getUser()->getManager()->getEmail(),
  2705.                 'template_emails/left_text.html.twig',
  2706.                 [
  2707.                     "title" => "Nouveau traitement client",
  2708.                     "content" => $content
  2709.                 ]
  2710.             );
  2711.             $this->get('session')->getFlashBag()->add('success''Traitement dupliqué');
  2712.             return $this->redirectToRoute("user_treatments");
  2713.         }
  2714.         $subcontractors = [];
  2715.         $systems = [];
  2716.         $subcontractorsStr = [];
  2717.         $systemsStr = [];
  2718.         foreach ($treatment->getSubcontractors() as $subcontractor) {
  2719.             $subcontractors[] = $subcontractor->getId();
  2720.             $subcontractorsStr[] = $subcontractor->getName();
  2721.         }
  2722.         foreach ($treatment->getSystems() as $system) {
  2723.             $systems[] = $system->getId();
  2724.             $systemsStr[] = $system->getName();
  2725.         }
  2726.         sort($subcontractorsStr);
  2727.         sort($systemsStr);
  2728.         $subcontractorsTypes = [];
  2729.         $stRequest $this->getDoctrine()->getRepository(\App\Entity\SubcontractorType::class)->findAll();
  2730.         foreach ($stRequest as $item) {
  2731.             $subcontractorsTypes[$item->getId()] = $item->getLibelle();
  2732.         }
  2733.         return $this->render('user/treatments_copy.html.twig', [
  2734.             "form" => $form->createView(),
  2735.             "treatment" => $treatment,
  2736.             "personalDataFields" => $treatment->getPersonalData(),
  2737.             "subcontractors" => $subcontractors,
  2738.             "systems" => $systems,
  2739.             "subcontractorsStr" => $subcontractorsStr,
  2740.             "systemsStr" => $systemsStr,
  2741.             "subcontractorsTypes" => $subcontractorsTypes
  2742.         ]);
  2743.     }
  2744.     /**
  2745.      * @Route("/treatments/{id}/show", name="treatments_show")
  2746.      */
  2747.     public function treatmentsShowAction(Request $requestTreatment $treatment)
  2748.     {
  2749.         if ($treatment->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  2750.             if (!$this->getUser()->getUser()->getGroupTreatments()->contains($treatment)) {
  2751.                 if (!$this->getUser()->getUser()->getParentUser() || ($treatment->getUser()->getId() != $this->getUser()->getUser()->getParentUser()->getId())) {
  2752.                     throw new NotFoundHttpException();
  2753.                 }
  2754.             }
  2755.         }
  2756.         return $this->render('user/treatments_show.html.twig', [
  2757.             "treatment" => $treatment,
  2758.         ]);
  2759.     }
  2760.     /**
  2761.      * @Route("/treatments/{id}/delete", name="treatments_delete")
  2762.      */
  2763.     public function treatmentsDeleteAction(Request $requestTreatment $treatment)
  2764.     {
  2765.         if ($treatment->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  2766.             throw new NotFoundHttpException();
  2767.         }
  2768.         $em $this->getDoctrine()->getManager();
  2769.         $em->remove($treatment);
  2770.         $em->flush();
  2771.         $this->get('session')->getFlashBag()->add('success''Traitement supprimé');
  2772.         return $this->redirectToRoute("user_treatments");
  2773.     }
  2774.     /**
  2775.      * @Route("/treatmentsstd", name="treatments_std")
  2776.      */
  2777.     public function treatmentsStdAction(Request $request)
  2778.     {
  2779.         if (!$this->getUser()->getUser()->isMainGroupAgency()) {
  2780.             throw new NotFoundHttpException();
  2781.         }
  2782.         $treatments $this->getDoctrine()->getRepository(TreatmentStd::class)->findBy(["user" => $this->getUser()->getUser()]);
  2783.         return $this->render('user/treatments_std.html.twig', [
  2784.             "treatments" => $treatments
  2785.         ]);
  2786.     }
  2787.     /**
  2788.      * @Route("/treatmentsstd/add", name="treatments_std_add")
  2789.      */
  2790.     public function treatmentsStdAddAction(Request $request)
  2791.     {
  2792.         if (!$this->getUser()->getUser()->isMainGroupAgency()) {
  2793.             throw new NotFoundHttpException();
  2794.         }
  2795.         $treatment = new TreatmentStd();
  2796.         $form $this->createForm(TreatmentStdType::class, $treatment);
  2797.         $personalDataFields = [
  2798.             [
  2799.                 "title" => "État civil, identité, données d'identification, images...",
  2800.                 "level" => 1,
  2801.             ],
  2802.             [
  2803.                 "title" => "Vie personnelle (habitudes de vie, situation familiale, etc.)",
  2804.                 "level" => 1,
  2805.             ],
  2806.             [
  2807.                 "title" => "Infos d'ordre économique et financier (revenus, situation financière, situation fiscale, etc.)",
  2808.                 "level" => 1,
  2809.             ],
  2810.             [
  2811.                 "title" => "Données de connexion (adress IP, logs, etc.)",
  2812.                 "level" => 1,
  2813.             ],
  2814.             [
  2815.                 "title" => "Données de localisation (déplacements, données GPS, GSM, etc.)",
  2816.                 "level" => 1,
  2817.             ],
  2818.             [
  2819.                 "title" => "Données Bancaires (données courantes « non sensible » mais classifié comme tel au vu des risques financiers)",
  2820.                 "level" => 2,
  2821.             ],
  2822.             [
  2823.                 "title" => "Numéro de Sécurité Sociale (ou NIR)",
  2824.                 "level" => 2,
  2825.             ],
  2826.             [
  2827.                 "title" => "Données révélant l'origine raciale ou ethnique",
  2828.                 "level" => 3,
  2829.             ],
  2830.             [
  2831.                 "title" => "Données révélant les opinions politiques",
  2832.                 "level" => 3,
  2833.             ],
  2834.             [
  2835.                 "title" => "Données révélant les convictions religieuses ou philosophiques",
  2836.                 "level" => 3,
  2837.             ],
  2838.             [
  2839.                 "title" => "Données révélant l'appartenance syndicale",
  2840.                 "level" => 3,
  2841.             ],
  2842.             [
  2843.                 "title" => "Données génétiques",
  2844.                 "level" => 3,
  2845.             ],
  2846.             [
  2847.                 "title" => "Données biométriques aux fins d'identifier une personne physique de manière unique",
  2848.                 "level" => 3,
  2849.             ],
  2850.             [
  2851.                 "title" => "Données concernant la santé",
  2852.                 "level" => 3,
  2853.             ],
  2854.             [
  2855.                 "title" => "Données concernant la vie sexuelle ou l'orientation sexuelle",
  2856.                 "level" => 3,
  2857.             ],
  2858.             [
  2859.                 "title" => "Données relatives à des condamnations pénales ou infractions",
  2860.                 "level" => 3,
  2861.             ],
  2862.         ];
  2863.         foreach ($personalDataFields as $key => $field) {
  2864.             $form->add("field_text_".$keyTextType::class, [
  2865.                 'attr' => [
  2866.                     'placeholder' => 'zone_de_saisie'
  2867.                 ],
  2868.                 'label' => 'zone_de_saisie',
  2869.                 'required' => false,
  2870.                 'mapped' => false,
  2871.                 'translation_domain' => 'messages',
  2872.             ]);
  2873.         }
  2874.         $form->handleRequest($request);
  2875.         if ($form->isSubmitted() && $form->isValid()) {
  2876.             $em $this->getDoctrine()->getManager();
  2877.             $now = new \DateTime("now");
  2878.             $personalData = [];
  2879.             $sensitiveData false;
  2880.             foreach ($personalDataFields as $key => $field) {
  2881.                 $personalData[] = [
  2882.                     "title" => $field['title'],
  2883.                     "level" => $field['level'],
  2884.                     "text" => $form["field_text_".$key]->getData(),
  2885.                     //"duration" => $form["field_duration_".$key]->getData(),
  2886.                 ];
  2887.                 if (($field['level'] == || $field['level'] == 3) && ($form["field_text_".$key]->getData()/* || $form["field_duration_".$key]->getData()*/)) {
  2888.                     $sensitiveData true;
  2889.                 }
  2890.             }
  2891.             $treatment->setPersonalData($personalData);
  2892.             $treatment->setSensitiveData($sensitiveData);
  2893.             $treatment->setCreationDate($now);
  2894.             $treatment->setEditDate($now);
  2895.             $treatment->setUser($this->getUser()->getUser());
  2896.             if ($treatment->isSensitiveData()) {
  2897.                 if (!in_array(1$treatment->getPiaCriteria())) {
  2898.                     $treatment->addPiaCriteria(1);
  2899.                 }
  2900.             } else {
  2901.                 $treatment->setInsufficientCriteria(true);
  2902.             }
  2903.             if (count($treatment->getPiaCriteria()) >= 2) {
  2904.                 $treatment->setPiaNeeded(true);
  2905.             } else {
  2906.                 $treatment->setPiaNeeded(false);
  2907.             }
  2908.             $em->persist($treatment);
  2909.             $em->flush();
  2910.             $this->get('session')->getFlashBag()->add('success''Nouveau traitement standard ajouté');
  2911.             return $this->redirectToRoute("user_treatments_std");
  2912.         }
  2913.         return $this->render('user/treatments_std_add.html.twig', [
  2914.             "form" => $form->createView(),
  2915.             "personalDataFields" => $personalDataFields
  2916.         ]);
  2917.     }
  2918.     /**
  2919.      * @Route("/treatmentsstd/{id}/edit", name="treatments_std_edit")
  2920.      */
  2921.     public function treatmentsStdEditAction(Request $requestTreatmentStd $treatment)
  2922.     {
  2923.         if ($treatment->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  2924.             throw new NotFoundHttpException();
  2925.         }
  2926.         if (count($treatment->getPiaCriteria()) == 0) {
  2927.             if ($treatment->isAutomatedDecision()) {
  2928.                 $em $this->getDoctrine()->getManager();
  2929.                 $treatment->setPiaCriteria([4]);
  2930.                 $treatment->setAutomatedDecision(false);
  2931.                 $em->flush();
  2932.                 return $this->redirectToRoute("user_treatments_std_edit", ["id" => $treatment->getId()]);
  2933.             }
  2934.         }
  2935.         $form $this->createForm(TreatmentStdType::class, $treatment);
  2936.         foreach ($treatment->getPersonalData() as $key => $field) {
  2937.             $form->add("field_text_".$keyTextType::class, [
  2938.                 'attr' => [
  2939.                     'placeholder' => 'zone_de_saisie'
  2940.                 ],
  2941.                 'label' => 'zone_de_saisie',
  2942.                 'data' => $field['text'],
  2943.                 'required' => false,
  2944.                 'mapped' => false,
  2945.                 'translation_domain' => 'messages',
  2946.             ]);
  2947.         }
  2948.         $form->handleRequest($request);
  2949.         if ($form->isSubmitted() && $form->isValid()) {
  2950.             $em $this->getDoctrine()->getManager();
  2951.             $now = new \DateTime("now");
  2952.             $personalData = [];
  2953.             $sensitiveData false;
  2954.             foreach ($treatment->getPersonalData() as $key => $field) {
  2955.                 $personalData[] = [
  2956.                     "title" => $field['title'],
  2957.                     "level" => $field['level'],
  2958.                     "text" => $form["field_text_".$key]->getData(),
  2959.                     //"duration" => $form["field_duration_".$key]->getData(),
  2960.                 ];
  2961.                 if (($field['level'] == || $field['level'] == 3) && ($form["field_text_".$key]->getData()/* || $form["field_duration_".$key]->getData()*/)) {
  2962.                     $sensitiveData true;
  2963.                 }
  2964.             }
  2965.             $treatment->setPersonalData($personalData);
  2966.             $treatment->setSensitiveData($sensitiveData);
  2967.             if ($treatment->isSensitiveData()) {
  2968.                 if (!in_array(1$treatment->getPiaCriteria())) {
  2969.                     $treatment->addPiaCriteria(1);
  2970.                 }
  2971.             } else {
  2972.                 $treatment->setInsufficientCriteria(true);
  2973.             }
  2974.             $treatment->setEditDate($now);
  2975.             if (count($treatment->getPiaCriteria()) >= 2) {
  2976.                 $treatment->setPiaNeeded(true);
  2977.             } else {
  2978.                 $treatment->setPiaNeeded(false);
  2979.             }
  2980.             $em->flush();
  2981.             $this->get('session')->getFlashBag()->add('success''Traitement standard mis à jour');
  2982.             return $this->redirectToRoute("user_treatments_std");
  2983.         }
  2984.         return $this->render('user/treatments_std_edit.html.twig', [
  2985.             "form" => $form->createView(),
  2986.             "treatment" => $treatment,
  2987.             "personalDataFields" => $treatment->getPersonalData()
  2988.         ]);
  2989.     }
  2990.     /**
  2991.      * @Route("/treatmentsstd/{id}/delete", name="treatments_std_delete")
  2992.      */
  2993.     public function treatmentsStdDeleteAction(Request $requestTreatmentStd $treatment)
  2994.     {
  2995.         if ($treatment->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  2996.             throw new NotFoundHttpException();
  2997.         }
  2998.         $em $this->getDoctrine()->getManager();
  2999.         $em->remove($treatment);
  3000.         $em->flush();
  3001.         $this->get('session')->getFlashBag()->add('success''Traitement standard supprimé');
  3002.         return $this->redirectToRoute("user_treatments_std");
  3003.     }
  3004.     /**
  3005.      * @Route("/dataprocessing", name="data_processing")
  3006.      */
  3007.     public function dataProcessingAction(Request $request)
  3008.     {
  3009.         return $this->redirectToRoute("user_subcontractors", ["type" => 1]);
  3010.         /*return $this->render('user/data_processing.html.twig', [
  3011.         ]);*/
  3012.     }
  3013.     /**
  3014.      * @Route("/subcontractors/t/{type}", name="subcontractors")
  3015.      */
  3016.     public function subcontractorsAction(Request $request\App\Entity\SubcontractorType $type)
  3017.     {
  3018.         $hasFilters false;
  3019.         $filter null;
  3020.         if ($request->get("filter")) {
  3021.             $filter $request->get("filter");
  3022.             $hasFilters true;
  3023.         }
  3024.         $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findBy(["user" => $this->getUser()->getUser(), "group" => false"subcontractorType" => $type], ["name" => "ASC"]);
  3025.         $subcontractors_grp $this->getDoctrine()->getRepository(Subcontractor::class)->findGroupForUser($this->getUser()->getUser(), $type);
  3026.         $subcontractorsStats = [
  3027.             "total" => 0,
  3028.             "inProgress" => 0,
  3029.             "invalid" => 0,
  3030.             "valid" => 0,
  3031.         ];
  3032.         $filteredSubcontractors = [];
  3033.         $filteredSubcontractorsGrp = [];
  3034.         if (!$hasFilters) {
  3035.             $filteredSubcontractors $subcontractors;
  3036.             $filteredSubcontractorsGrp $subcontractors_grp;
  3037.         }
  3038.         foreach ($subcontractors as $subcontractor) {
  3039.             if ($subcontractor->getConformity()) {
  3040.                 $subcontractorsStats["total"]++;
  3041.                 switch ($subcontractor->getConformity()->getId()) {
  3042.                     case 1:
  3043.                         $subcontractorsStats["invalid"]++;
  3044.                         if ($filter && $filter == "invalid") {
  3045.                             $filteredSubcontractors[] = $subcontractor;
  3046.                         }
  3047.                         break;
  3048.                     case 2:
  3049.                         $subcontractorsStats["inProgress"]++;
  3050.                         if ($filter && $filter == "inprogress") {
  3051.                             $filteredSubcontractors[] = $subcontractor;
  3052.                         }
  3053.                         break;
  3054.                     case 3:
  3055.                         $subcontractorsStats["valid"]++;
  3056.                         if ($filter && $filter == "valid") {
  3057.                             $filteredSubcontractors[] = $subcontractor;
  3058.                         }
  3059.                         break;
  3060.                 }
  3061.             }
  3062.         }
  3063.         foreach ($subcontractors_grp as $subcontractor) {
  3064.             if ($subcontractor->getConformity()) {
  3065.                 $subcontractorsStats["total"]++;
  3066.                 switch ($subcontractor->getConformity()->getId()) {
  3067.                     case 1:
  3068.                         $subcontractorsStats["invalid"]++;
  3069.                         if ($filter && $filter == "invalid") {
  3070.                             $filteredSubcontractorsGrp[] = $subcontractor;
  3071.                         }
  3072.                         break;
  3073.                     case 2:
  3074.                         $subcontractorsStats["inProgress"]++;
  3075.                         if ($filter && $filter == "inprogress") {
  3076.                             $filteredSubcontractorsGrp[] = $subcontractor;
  3077.                         }
  3078.                         break;
  3079.                     case 3:
  3080.                         $subcontractorsStats["valid"]++;
  3081.                         if ($filter && $filter == "valid") {
  3082.                             $filteredSubcontractorsGrp[] = $subcontractor;
  3083.                         }
  3084.                         break;
  3085.                 }
  3086.             }
  3087.         }
  3088.         return $this->render('user/subcontractors.html.twig', [
  3089.             "subcontractors" => $filteredSubcontractors,
  3090.             "subcontractorsGrp" => $filteredSubcontractorsGrp,
  3091.             "subcontractorsStats" => $subcontractorsStats,
  3092.             "filter" => $filter,
  3093.             "type" => $type->getId()
  3094.         ]);
  3095.     }
  3096.     /**
  3097.      * @Route("/subcontractors/standardize/{id}", name="subcontractors_standardize")
  3098.      */
  3099.     public function subcontractorsStandardizeAction(Request $requestSecurity $securitySubcontractor $subcontractor)
  3100.     {
  3101.         $em $this->getDoctrine()->getManager();
  3102.         $subcontractorStd = new SubcontractorStd();
  3103.         $subcontractorStd->setName($subcontractor->getName());
  3104.         $subcontractorStd->setType($subcontractor->getType());
  3105.         $subcontractorStd->setContactFirstName($subcontractor->getContactFirstName());
  3106.         $subcontractorStd->setContactLastName($subcontractor->getContactLastName());
  3107.         $subcontractorStd->setContactPhone($subcontractor->getContactPhone());
  3108.         $subcontractorStd->setContactEmail($subcontractor->getContactEmail());
  3109.         $subcontractorStd->setPrivacyPolicyLink($subcontractor->getPrivacyPolicyLink());
  3110.         $subcontractorStd->setDate($subcontractor->getDate());
  3111.         $subcontractorStd->setEditDate($subcontractor->getEditDate());
  3112.         $subcontractorStd->setConformity($subcontractor->getConformity());
  3113.         $subcontractorStd->setDocuments($subcontractor->getDocuments());
  3114.         $token $security->getToken();
  3115.         if ($token instanceof SwitchUserToken) {
  3116.             $impersonatorUser $token->getOriginalToken()->getUser();
  3117.             if ($impersonatorUser) {
  3118.                 if ($impersonatorUser->getManager()) {
  3119.                     $originalManager $em->getRepository(Manager::class)->find($impersonatorUser->getManager()->getId());
  3120.                     if ($originalManager) {
  3121.                         $subcontractorStd->setManager($originalManager);
  3122.                     }
  3123.                 }
  3124.             }
  3125.         }
  3126.         $em->persist($subcontractorStd);
  3127.         $em->flush();
  3128.         $this->get('session')->getFlashBag()->add('success''Nouveau sous-traitant standard généré');
  3129.         return $this->redirectToRoute("user_data_processing");
  3130.     }
  3131.     /**
  3132.      * @Route("/subcontractors/export", name="subcontractors_export")
  3133.      */
  3134.     public function subcontractorsExportAction(Request $request)
  3135.     {
  3136.         if ($this->isPrintingAllowed($this->getUser())) {
  3137.             $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findBy(["user" => $this->getUser()->getUser(), "group" => false], ["name" => "ASC"]);
  3138.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  3139.             $pdf->setUser($this->getUser()->getUser());
  3140.             $pdf->SetAuthor('myDigitplace');
  3141.             $pdf->SetTitle("Registre des sous-traitants");
  3142.             $pdf->SetMargins(10,22,10true);
  3143.             $pdf->SetAutoPageBreak(TRUE35);
  3144.             $pdf->AddPage('L''A4');
  3145.             $html $this->renderView('user/pdf/subcontractors.html.twig', [
  3146.                 "subcontractors" => $subcontractors
  3147.             ]);
  3148.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  3149.             $subcontractorsGrp $this->getDoctrine()->getRepository(Subcontractor::class)->findGroupForUser($this->getUser()->getUser());
  3150.             if (count($subcontractorsGrp)) {
  3151.                 $pdf->AddPage('L''A4');
  3152.                 $html $this->renderView('user/pdf/subcontractors_grp.html.twig', [
  3153.                     "subcontractors" => $subcontractorsGrp
  3154.                 ]);
  3155.                 $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  3156.             }
  3157.             $filename 'Registre_des_sous_traitants';
  3158.             return $pdf->Output($filename.".pdf",'I');
  3159.         } else {
  3160.             return $this->redirectToRoute("user_subcontractors");
  3161.         }
  3162.     }
  3163.     /**
  3164.      * @Route("/subcontractors/exportxlsx", name="subcontractors_export_xlsx")
  3165.      */
  3166.     public function subcontractorsExportXlsxAction(Request $requestEntityManagerInterface $em)
  3167.     {
  3168.         if ($this->isPrintingAllowed($this->getUser())) {
  3169.             $spreadsheet = new Spreadsheet();
  3170.             $subcontractorsTypes $em->getRepository(\App\Entity\SubcontractorType::class)->findAll();
  3171.             $i 0;
  3172.             foreach ($subcontractorsTypes as $subcontractorsType) {
  3173.                 $i++;
  3174.                 $newWorkSheet = new Worksheet($spreadsheet$subcontractorsType->getLibelle());
  3175.                 $spreadsheet->addSheet($newWorkSheet$i);
  3176.                 $spreadsheet->setActiveSheetIndex($i);
  3177.                 $sheet $spreadsheet->getActiveSheet();
  3178.                 $sheet->setCellValue('A1''Type');
  3179.                 $sheet->setCellValue('B1''Société');
  3180.                 $sheet->setCellValue('C1''Typologie');
  3181.                 $sheet->setCellValue('D1''Traitements');
  3182.                 $sheet->setCellValue('E1''Contact');
  3183.                 $sheet->setCellValue('F1''Tél');
  3184.                 $sheet->setCellValue('G1''Mail');
  3185.                 $sheet->setCellValue('H1''conformité');
  3186.                 $sheet->setCellValue('I1''Doc');
  3187.                 $sheet->setCellValue('J1''Date');
  3188.                 $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findBy(["user" => $this->getUser()->getUser(), "group" => false"subcontractorType" => $subcontractorsType], ["name" => "ASC"]);
  3189.                 $j 1;
  3190.                 foreach ($subcontractors as $subcontractor) {
  3191.                     $j++;
  3192.                     $treatmentsArray = [];
  3193.                     foreach ($subcontractor->getTreatments() as $treatment) {
  3194.                         if ($treatment->getUser()->getId() == $this->getUser()->getUser()->getId()) {
  3195.                             $str strval($treatment->getNumber());
  3196.                             $strLen strlen($str);
  3197.                             $maxLen 3;
  3198.                             if ($strLen $maxLen) {
  3199.                                 for ($k $strLen$k $maxLen$k++) {
  3200.                                     $str "0".$str;
  3201.                                 }
  3202.                             }
  3203.                             $treatmentsArray[] = "T".$str;
  3204.                         }
  3205.                     }
  3206.                     $documentsArray = [];
  3207.                     foreach ($subcontractor->getDocuments() as $document) {
  3208.                         $documentsArray[] = $document->getName();
  3209.                     }
  3210.                     $sheet->setCellValue('A' $j$subcontractor->getSubcontractorType()->getLibelle());
  3211.                     $sheet->setCellValue('B' $j$subcontractor->getName());
  3212.                     $sheet->setCellValue('C' $j$subcontractor->getType());
  3213.                     $sheet->setCellValue('D' $jimplode(" | "$treatmentsArray));
  3214.                     $sheet->setCellValue('E' $j$subcontractor->getContactLastName()." ".$subcontractor->getContactFirstName());
  3215.                     $sheet->setCellValue('F' $j$subcontractor->getContactPhone());
  3216.                     $sheet->setCellValue('G' $j$subcontractor->getContactEmail());
  3217.                     $sheet->setCellValue('H' $j$subcontractor->getConformity()->getLibelle());
  3218.                     $sheet->setCellValue('I' $jimplode(" | "$documentsArray));
  3219.                     $sheet->setCellValue('J' $j$subcontractor->getEditDate()->format("d/m/Y"));
  3220.                 }
  3221.             }
  3222.             $i++;
  3223.             $newWorkSheet = new Worksheet($spreadsheet"Groupe");
  3224.             $spreadsheet->addSheet($newWorkSheet$i);
  3225.             $spreadsheet->setActiveSheetIndex($i);
  3226.             $sheet $spreadsheet->getActiveSheet();
  3227.             $sheet->setCellValue('A1''Type');
  3228.             $sheet->setCellValue('B1''Société');
  3229.             $sheet->setCellValue('C1''Typologie');
  3230.             $sheet->setCellValue('D1''Traitements');
  3231.             $sheet->setCellValue('E1''Contact');
  3232.             $sheet->setCellValue('F1''Tél');
  3233.             $sheet->setCellValue('G1''Mail');
  3234.             $sheet->setCellValue('H1''conformité');
  3235.             $sheet->setCellValue('I1''Doc');
  3236.             $sheet->setCellValue('J1''Date');
  3237.             $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findGroupForUser($this->getUser()->getUser());
  3238.             $j 1;
  3239.             foreach ($subcontractors as $subcontractor) {
  3240.                 $j++;
  3241.                 $treatmentsArray = [];
  3242.                 foreach ($subcontractor->getTreatments() as $treatment) {
  3243.                     if ($treatment->getUser()->getId() == $this->getUser()->getUser()->getId()) {
  3244.                         $str strval($treatment->getNumber());
  3245.                         $strLen strlen($str);
  3246.                         $maxLen 3;
  3247.                         if ($strLen $maxLen) {
  3248.                             for ($i $strLen$i $maxLen$i++) {
  3249.                                 $str "0".$str;
  3250.                             }
  3251.                         }
  3252.                         $treatmentsArray[] = "T".$str;
  3253.                     }
  3254.                 }
  3255.                 $documentsArray = [];
  3256.                 foreach ($subcontractor->getDocuments() as $document) {
  3257.                     $documentsArray[] = $document->getName();
  3258.                 }
  3259.                 $sheet->setCellValue('A' $j$subcontractor->getSubcontractorType()->getLibelle());
  3260.                 $sheet->setCellValue('B' $j$subcontractor->getName());
  3261.                 $sheet->setCellValue('C' $j$subcontractor->getType());
  3262.                 $sheet->setCellValue('D' $jimplode(" | "$treatmentsArray));
  3263.                 $sheet->setCellValue('E' $j$subcontractor->getContactLastName()." ".$subcontractor->getContactFirstName());
  3264.                 $sheet->setCellValue('F' $j$subcontractor->getContactPhone());
  3265.                 $sheet->setCellValue('G' $j$subcontractor->getContactEmail());
  3266.                 $sheet->setCellValue('H' $j$subcontractor->getConformity()->getLibelle());
  3267.                 $sheet->setCellValue('I' $jimplode(" | "$documentsArray));
  3268.                 $sheet->setCellValue('J' $j$subcontractor->getEditDate()->format("d/m/Y"));
  3269.             }
  3270.             $spreadsheet->removeSheetByIndex(0);
  3271.             $writer = new Xlsx($spreadsheet);
  3272.             $response = new StreamedResponse();
  3273.             $response->setCallback(function () use ($writer) {
  3274.                 $writer->save('php://output');
  3275.             });
  3276.             $response->setStatusCode(200);
  3277.             $response->headers->set('Content-Type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  3278.             $response->headers->set('Content-Disposition''attachment;filename="export_sous_traitance.xlsx"');
  3279.             $response->headers->set('Cache-Control','max-age=0');
  3280.             return $response;
  3281.         } else {
  3282.             return $this->redirectToRoute("user_subcontractors", ["type" => 1]);
  3283.         }
  3284.     }
  3285.     /**
  3286.      * @Route("/subcontractors/add", name="subcontractors_add")
  3287.      */
  3288.     public function subcontractorsAddAction(Request $requestSendEmailService $sendEmailService)
  3289.     {
  3290.         $subcontractor = new Subcontractor();
  3291.         $defaultSubcontractorType $this->getDoctrine()->getRepository(\App\Entity\SubcontractorType::class)->findOneBy(["code" => "SOUS_TRAITANT"]);
  3292.         $subcontractor->setSubcontractorType($defaultSubcontractorType);
  3293.         $form $this->createForm(SubcontractorType::class, $subcontractor);
  3294.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  3295.             $form->add('group'CheckboxType::class, [
  3296.                 'label' => 'est_soustraitant_groupe',
  3297.                 'translation_domain' => 'messages',
  3298.                 'required' => false,
  3299.             ]);
  3300.         }
  3301.         $fromStd false;
  3302.         $subcontractorStd null;
  3303.         if (isset($_GET['std'])) {
  3304.             $subcontractorStd $this->getDoctrine()->getRepository(SubcontractorStd::class)->find($_GET['std']);
  3305.             if ($subcontractorStd) {
  3306.                 $fromStd true;
  3307.                 $form['name']->setData($subcontractorStd->getName());
  3308.                 $form['type']->setData($subcontractorStd->getType());
  3309.                 $form['contactFirstName']->setData($subcontractorStd->getContactFirstName());
  3310.                 $form['contactLastName']->setData($subcontractorStd->getContactLastName());
  3311.                 $form['contactPhone']->setData($subcontractorStd->getContactPhone());
  3312.                 $form['contactEmail']->setData($subcontractorStd->getContactEmail());
  3313.                 $form['privacyPolicyLink']->setData($subcontractorStd->getPrivacyPolicyLink());
  3314.                 $form['conformity']->setData($subcontractorStd->getConformity());
  3315.             }
  3316.         }
  3317.         $form->handleRequest($request);
  3318.         if ($form->isSubmitted() && $form->isValid()) {
  3319.             $em $this->getDoctrine()->getManager();
  3320.             $now = new \DateTime("now");
  3321.             $subcontractor->setDate($now);
  3322.             $subcontractor->setEditDate($now);
  3323.             $subcontractor->setUser($this->getUser()->getUser());
  3324.             /*if ($this->getUser()->getUser()->isMainGroupAgency()) {
  3325.                 $subcontractor->setGroup($form["group"]->getData());
  3326.             }*/
  3327.             $em->persist($subcontractor);
  3328.             $em->flush();
  3329.             if ($fromStd) {
  3330.                 if ($subcontractorStd) {
  3331.                     $filesystem = new Filesystem();
  3332.                     foreach ($subcontractorStd->getDocuments() as $document) {
  3333.                         if (isset($_POST["appbundle_subcontractor_documents_".$document->getId()]) && !empty($_POST["appbundle_subcontractor_documents_".$document->getId()])) {
  3334.                             $fileName $document->getFilename();
  3335.                             $childFileName $this->getUser()->getUser()->getId()."_".$fileName;
  3336.                             $filesystem->copy($this->getParameter('documents_directory').$fileName$this->getParameter('documents_directory').$childFileName);
  3337.                             $newDocument = new UserDocument();
  3338.                             $newDocument->setName($document->getName());
  3339.                             $newDocument->setFilename($childFileName);
  3340.                             $newDocument->setUserFilename($document->getUserFilename());
  3341.                             $newDocument->setUser($this->getUser()->getUser());
  3342.                             $newDocument->setSubcontractor($subcontractor);
  3343.                             $em->persist($newDocument);
  3344.                             $em->flush();
  3345.                         }
  3346.                     }
  3347.                 }
  3348.             }
  3349.             if (isset($_FILES['appbundle_subcontractor_documents'])) {
  3350.                 $files $_FILES['appbundle_subcontractor_documents'];
  3351.                 $fileNames $_POST['appbundle_subcontractor_documents_names'];
  3352.                 for ($i=0;$i<count($files['name']);$i++) {
  3353.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  3354.                         $name $files["name"][$i];
  3355.                         $parts explode("."$name);
  3356.                         $extension end($parts);
  3357.                         $fileName $subcontractor->getId()."_".md5(uniqid()) . '.' $extension;
  3358.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  3359.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  3360.                         $document = new UserDocument();
  3361.                         $document->setName($docTitle);
  3362.                         $document->setFilename($fileName);
  3363.                         $document->setUserFilename($files["name"][$i]);
  3364.                         $document->setUser($this->getUser()->getUser());
  3365.                         $document->setSubcontractor($subcontractor);
  3366.                         $em->persist($document);
  3367.                         $em->flush();
  3368.                     }
  3369.                 }
  3370.             }
  3371.             $content "<p>Bonjour,<br/>
  3372.                         <br/>
  3373.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a ajouté un nouveau sous-traitant: ".$subcontractor->getName()."<br/>
  3374.                         <br/>
  3375.                         <br/>
  3376.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  3377.                         </p>";
  3378.             $sendEmailService->send(
  3379.                 "Nouveau sous-traitant client",
  3380.                 $this->getUser()->getUser()->getManager()->getEmail(),
  3381.                 'template_emails/left_text.html.twig',
  3382.                 [
  3383.                     "title" => "Nouveau sous-traitant client",
  3384.                     "content" => $content
  3385.                 ]
  3386.             );
  3387.             $this->get('session')->getFlashBag()->add('success''Nouveau sous-traitant ajouté');
  3388.             return $this->redirectToRoute("user_subcontractors", ["type" => $subcontractor->getSubcontractorType()->getId()]);
  3389.         }
  3390.         $subcontractorsStd $this->getDoctrine()->getRepository(SubcontractorStd::class)->findForUser($this->getUser()->getUser());
  3391.         return $this->render('user/subcontractors_add.html.twig', [
  3392.             "form" => $form->createView(),
  3393.             "subcontractorsStd" => $subcontractorsStd,
  3394.             "fromStd" => $fromStd,
  3395.             "subcontractorStd" => $subcontractorStd
  3396.         ]);
  3397.     }
  3398.     /**
  3399.      * @Route("/subcontractors/{id}/edit", name="subcontractors_edit")
  3400.      */
  3401.     public function subcontractorsEditAction(Request $requestSendEmailService $sendEmailServiceSubcontractor $subcontractor)
  3402.     {
  3403.         if ($subcontractor->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  3404.             throw new NotFoundHttpException();
  3405.         }
  3406.         $form $this->createForm(SubcontractorType::class, $subcontractor);
  3407.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  3408.             $form->add('group'CheckboxType::class, [
  3409.                 'label' => 'est_soustraitant_groupe',
  3410.                 'translation_domain' => 'messages',
  3411.                 'required' => false,
  3412.             ]);
  3413.         }
  3414.         $form->handleRequest($request);
  3415.         if ($form->isSubmitted() && $form->isValid()) {
  3416.             $em $this->getDoctrine()->getManager();
  3417.             $subcontractor->setEditDate(new \DateTime("now"));
  3418.             $em->flush();
  3419.             foreach ($subcontractor->getDocuments() as $document) {
  3420.                 if (isset($_POST["appbundle_subcontractor_documents_".$document->getId()]) && !empty($_POST["appbundle_subcontractor_documents_".$document->getId()])) {
  3421.                     if ($document->getName() != $_POST["appbundle_subcontractor_documents_".$document->getId()]) {
  3422.                         $document->setTitle($_POST["appbundle_subcontractor_documents_".$document->getId()]);
  3423.                         $em->flush();
  3424.                     }
  3425.                 }
  3426.             }
  3427.             if (isset($_FILES['appbundle_subcontractor_documents'])) {
  3428.                 $files $_FILES['appbundle_subcontractor_documents'];
  3429.                 $fileNames $_POST['appbundle_subcontractor_documents_names'];
  3430.                 for ($i=0;$i<count($files['name']);$i++) {
  3431.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  3432.                         $name $files["name"][$i];
  3433.                         $parts explode("."$name);
  3434.                         $extension end($parts);
  3435.                         $fileName $subcontractor->getId()."_".md5(uniqid()) . '.' $extension;
  3436.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  3437.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  3438.                         $document = new UserDocument();
  3439.                         $document->setName($docTitle);
  3440.                         $document->setFilename($fileName);
  3441.                         $document->setUserFilename($files["name"][$i]);
  3442.                         $document->setUser($this->getUser()->getUser());
  3443.                         $document->setSubcontractor($subcontractor);
  3444.                         $em->persist($document);
  3445.                         $em->flush();
  3446.                     }
  3447.                 }
  3448.             }
  3449.             $content "<p>Bonjour,<br/>
  3450.                         <br/>
  3451.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a modifié le sous-traitant ".$subcontractor->getName()."<br/>
  3452.                         <br/>
  3453.                         <br/>
  3454.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  3455.                         </p>";
  3456.             $sendEmailService->send(
  3457.                 "Sous-traitant client modifié",
  3458.                 $this->getUser()->getUser()->getManager()->getEmail(),
  3459.                 'template_emails/left_text.html.twig',
  3460.                 [
  3461.                     "title" => "Sous-traitant client modifié",
  3462.                     "content" => $content
  3463.                 ]
  3464.             );
  3465.             $this->get('session')->getFlashBag()->add('success''Sous-traitant mis à jour');
  3466.             return $this->redirectToRoute("user_subcontractors", ["type" => $subcontractor->getSubcontractorType()->getId()]);
  3467.         }
  3468.         return $this->render('user/subcontractors_edit.html.twig', [
  3469.             "subcontractor" => $subcontractor,
  3470.             "form" => $form->createView()
  3471.         ]);
  3472.     }
  3473.     /**
  3474.      * @Route("/subcontractors/{id}/copy", name="subcontractors_copy")
  3475.      */
  3476.     public function subcontractorsCopyAction(Request $requestSendEmailService $sendEmailServiceSubcontractor $subcontractor)
  3477.     {
  3478.         if ($subcontractor->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  3479.             throw new NotFoundHttpException();
  3480.         }
  3481.         $newSubcontractor = clone $subcontractor;
  3482.         $newSubcontractor->setId(null);
  3483.         $newSubcontractor->getDocuments()->clear();
  3484.         $form $this->createForm(SubcontractorType::class, $newSubcontractor);
  3485.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  3486.             $form->add('group'CheckboxType::class, [
  3487.                 'label' => 'est_soustraitant_groupe',
  3488.                 'translation_domain' => 'messages',
  3489.                 'required' => false,
  3490.             ]);
  3491.         }
  3492.         $form->handleRequest($request);
  3493.         if ($form->isSubmitted() && $form->isValid()) {
  3494.             $em $this->getDoctrine()->getManager();
  3495.             $now = new \DateTime("now");
  3496.             $newSubcontractor->setDate($now);
  3497.             $newSubcontractor->setEditDate($now);
  3498.             $newSubcontractor->setUser($this->getUser()->getUser());
  3499.             $em->persist($newSubcontractor);
  3500.             $em->flush();
  3501.             if (isset($_FILES['appbundle_subcontractor_documents'])) {
  3502.                 $files $_FILES['appbundle_subcontractor_documents'];
  3503.                 $fileNames $_POST['appbundle_subcontractor_documents_names'];
  3504.                 for ($i=0;$i<count($files['name']);$i++) {
  3505.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  3506.                         $name $files["name"][$i];
  3507.                         $parts explode("."$name);
  3508.                         $extension end($parts);
  3509.                         $fileName $newSubcontractor->getId()."_".md5(uniqid()) . '.' $extension;
  3510.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  3511.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  3512.                         $document = new UserDocument();
  3513.                         $document->setName($docTitle);
  3514.                         $document->setFilename($fileName);
  3515.                         $document->setUserFilename($files["name"][$i]);
  3516.                         $document->setUser($this->getUser()->getUser());
  3517.                         $document->setSubcontractor($newSubcontractor);
  3518.                         $em->persist($document);
  3519.                         $em->flush();
  3520.                     }
  3521.                 }
  3522.             }
  3523.             $content "<p>Bonjour,<br/>
  3524.                         <br/>
  3525.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a ajouté un nouveau sous-traitant: ".$newSubcontractor->getName()."<br/>
  3526.                         <br/>
  3527.                         <br/>
  3528.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  3529.                         </p>";
  3530.             $sendEmailService->send(
  3531.                 "Nouveau sous-traitant client",
  3532.                 $this->getUser()->getUser()->getManager()->getEmail(),
  3533.                 'template_emails/left_text.html.twig',
  3534.                 [
  3535.                     "title" => "Nouveau sous-traitant client",
  3536.                     "content" => $content
  3537.                 ]
  3538.             );
  3539.             $this->get('session')->getFlashBag()->add('success''Sous-traitant dupliqué');
  3540.             return $this->redirectToRoute("user_subcontractors", ["type" => $newSubcontractor->getSubcontractorType()->getId()]);
  3541.         }
  3542.         return $this->render('user/subcontractors_copy.html.twig', [
  3543.             "subcontractor" => $subcontractor,
  3544.             "form" => $form->createView()
  3545.         ]);
  3546.     }
  3547.     /**
  3548.      * @Route("/subcontractors/{id}/delete", name="subcontractors_delete")
  3549.      */
  3550.     public function subcontractorsDeleteAction(Request $requestSubcontractor $subcontractor)
  3551.     {
  3552.         if ($subcontractor->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  3553.             throw new NotFoundHttpException();
  3554.         }
  3555.         $typeId $subcontractor->getSubcontractorType()->getId();
  3556.         $em $this->getDoctrine()->getManager();
  3557.         $em->remove($subcontractor);
  3558.         $em->flush();
  3559.         $this->get('session')->getFlashBag()->add('success''Sous-traitant supprimé');
  3560.         return $this->redirectToRoute("user_subcontractors", ["type" => $typeId]);
  3561.     }
  3562.     /**
  3563.      * @Route("/subcontractors/deletedoc/{subcontractor}/{document}", name="subcontractor_deletedoc")
  3564.      */
  3565.     public function subcontractorsDeleteDocAction(Request $requestSubcontractor $subcontractorUserDocument $userDocument)
  3566.     {
  3567.         $em $this->getDoctrine()->getManager();
  3568.         if ($subcontractor->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  3569.             throw new NotFoundHttpException();
  3570.         }
  3571.         if ($userDocument->getSubcontractor() == null || $userDocument->getSubcontractor()->getId() != $subcontractor->getId()) {
  3572.             throw new NotFoundHttpException();
  3573.         }
  3574.         $em->remove($userDocument);
  3575.         $em->flush();
  3576.         $this->get('session')->getFlashBag()->add('success''Document supprimé');
  3577.         return $this->redirectToRoute('user_subcontractors_edit', ['id' => $subcontractor->getId()]);
  3578.     }
  3579.     /**
  3580.      * @Route("/systems", name="systems")
  3581.      */
  3582.     public function systemsAction(Request $request)
  3583.     {
  3584.         if ($this->getUser()->getUser()->getParentUser()) {
  3585.             $systemsQuery $this->getDoctrine()->getRepository(System::class)->findForUserWithGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser());
  3586.         } else {
  3587.             $systemsQuery $this->getDoctrine()->getRepository(System::class)->findBy(["user" => $this->getUser()->getUser()]);
  3588.         }
  3589.         $systems = [
  3590.             "computing" => [
  3591.                 "network" => [],
  3592.                 "security" => [],
  3593.                 "administration" => [],
  3594.                 "device" => [],
  3595.                 "software" => [],
  3596.                 "server" => [],
  3597.             ],
  3598.             "physical" => [
  3599.                 "partitioning" => [],
  3600.                 "information" => [],
  3601.             ],
  3602.             "action" => [
  3603.                 "minimization" => [],
  3604.                 "anonymization" => [],
  3605.                 "pseudonymization" => [],
  3606.                 "sensitization" => [],
  3607.                 "supervision" => [],
  3608.                 "destruction" => [],
  3609.             ],
  3610.             "supplier" => [
  3611.                 "supplier" => []
  3612.             ]
  3613.         ];
  3614.         $systemsJs = [];
  3615.         $encoders = [new JsonEncoder()];
  3616.         $normalizer = new ObjectNormalizer();
  3617.         $normalizers = [$normalizer];
  3618.         $serializer = new Serializer($normalizers$encoders);
  3619.         foreach ($systemsQuery as $system) {
  3620.             $systems[$system->getType()][$system->getSubtype()][] = $system;
  3621.             $systemsJs[$system->getId()] = json_decode($serializer->serialize($system'json', ["attributes" => ['id''name''data''type''subtype']]), true);
  3622.         }
  3623.         $systemsStdQuery $this->getDoctrine()->getRepository(SystemStd::class)->findAll();
  3624.         $systemsStd = [
  3625.             "computing" => [
  3626.                 "network" => [
  3627.                     "label" => "Réseau",
  3628.                     "items" => [],
  3629.                     "icon" => "mdi-ip-network"
  3630.                 ],
  3631.                 "security" => [
  3632.                     "label" => "Sécurité",
  3633.                     "items" => [],
  3634.                     "icon" => "mdi-security"
  3635.                 ],
  3636.                 "administration" => [
  3637.                     "label" => "Administration",
  3638.                     "items" => [],
  3639.                     "icon" => "mdi-account-multiple"
  3640.                 ],
  3641.                 "device" => [
  3642.                     "label" => "Périphérique",
  3643.                     "items" => [],
  3644.                     "icon" => "mdi-responsive"
  3645.                 ],
  3646.                 "software" => [
  3647.                     "label" => "Logiciel",
  3648.                     "items" => [],
  3649.                     "icon" => "mdi-console"
  3650.                 ],
  3651.                 "server" => [
  3652.                     "label" => "Serveur",
  3653.                     "items" => [],
  3654.                     "icon" => "mdi-server"
  3655.                 ],
  3656.             ],
  3657.             "physical" => [
  3658.                 "partitioning" => [
  3659.                     "label" => "Cloisonnement",
  3660.                     "items" => [],
  3661.                     "icon" => "mdi-view-module"
  3662.                 ],
  3663.                 "information" => [
  3664.                     "label" => "Information",
  3665.                     "items" => [],
  3666.                     "icon" => "mdi-lightbulb-on"
  3667.                 ],
  3668.             ],
  3669.             "action" => [
  3670.                 "minimization" => [
  3671.                     "label" => "Minimisation",
  3672.                     "items" => [],
  3673.                     "icon" => "mdi-tab-minus"
  3674.                 ],
  3675.                 "anonymization" => [
  3676.                     "label" => "Anonymisation",
  3677.                     "items" => [],
  3678.                     "icon" => "mdi-incognito"
  3679.                 ],
  3680.                 "pseudonymization" => [
  3681.                     "label" => "Pseudonymisation",
  3682.                     "items" => [],
  3683.                     "icon" => "mdi-account-question"
  3684.                 ],
  3685.                 "sensitization" => [
  3686.                     "label" => "Sensibilisation et formation",
  3687.                     "items" => [],
  3688.                     "icon" => "mdi-account-alert"
  3689.                 ],
  3690.                 "supervision" => [
  3691.                     "label" => "Contrôle",
  3692.                     "items" => [],
  3693.                     "icon" => "mdi-table-search"
  3694.                 ],
  3695.                 "destruction" => [
  3696.                     "label" => "Destruction et suppression",
  3697.                     "items" => [],
  3698.                     "icon" => "mdi-trash-can"
  3699.                 ],
  3700.             ],
  3701.             "supplier" => [
  3702.                 "supplier" => [
  3703.                     "label" => "Prestataires du SI",
  3704.                     "items" => [],
  3705.                     "icon" => "mdi-contacts"
  3706.                 ],
  3707.             ]
  3708.         ];
  3709.         foreach ($systemsStdQuery as $system) {
  3710.             $systemsStd[$system->getType()][$system->getSubtype()]['items'][] = $system;
  3711.         }
  3712.         $mindMapHeight 0;
  3713.         $mindMap = [
  3714.             "id" => "root",
  3715.             "topic" => "<div class='node-level-0'><div class='jmnode-icon'><i class='mdi mdi-sitemap mdi-36px'></i></div><i>Système d'information</i><span class='node-0-actions'><a href=\"".$this->generateUrl("user_systems_export")."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-printer\"></i></a></span></div>",
  3716.             "children" => [
  3717.                 [
  3718.                     "id" => "computing",
  3719.                     "topic" => "<div class='node-level-1'><div class='jmnode-icon'><i class='mdi mdi-desktop-classic mdi-36px'></i></div><i>Informatique</i><span class='node-1-actions'><a href=\"".$this->generateUrl("user_systems_export_excel", ["type" => "computing"])."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-download\"></i></a></span></div>",
  3720.                     "direction" => "right",
  3721.                     "expanded" => (isset($_GET["addedType"]) && $_GET["addedType"] == "computing"),
  3722.                     "attr" => [
  3723.                         "class" => "jmnode-level-1",
  3724.                     ],
  3725.                     "children" => []
  3726.                 ],
  3727.                 [
  3728.                     "id" => "physical",
  3729.                     "topic" => "<div class='node-level-1'><div class='jmnode-icon'><i class='mdi mdi-office-building mdi-36px'></i></div><i>Physique</i><span class='node-1-actions'><a href=\"".$this->generateUrl("user_systems_export_excel", ["type" => "physical"])."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-download\"></i></a></span></div>",
  3730.                     "direction" => "right",
  3731.                     "expanded" => (isset($_GET["addedType"]) && $_GET["addedType"] == "physical"),
  3732.                     "attr" => [
  3733.                         "class" => "jmnode-level-1",
  3734.                     ],
  3735.                     "children" => []
  3736.                 ],
  3737.                 [
  3738.                     "id" => "action",
  3739.                     "topic" => "<div class='node-level-1'><div class='jmnode-icon'><i class='mdi mdi-account-arrow-right mdi-36px'></i></div><i>Action</i><span class='node-1-actions'><a href=\"".$this->generateUrl("user_systems_export_excel", ["type" => "action"])."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-download\"></i></a></span></div>",
  3740.                     "direction" => "right",
  3741.                     "expanded" => (isset($_GET["addedType"]) && $_GET["addedType"] == "action"),
  3742.                     "attr" => [
  3743.                         "class" => "jmnode-level-1",
  3744.                     ],
  3745.                     "children" => []
  3746.                 ],
  3747.                 [
  3748.                     "id" => "supplier",
  3749.                     "topic" => "<div class='node-level-1'><div class='jmnode-icon'><i class='mdi mdi-contacts mdi-36px'></i></div><i>Prestataires du SI</i><span class='node-1-actions'><a href=\"".$this->generateUrl("user_systems_export_excel", ["type" => "supplier"])."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-download\"></i></a></span></div>",
  3750.                     "direction" => "right",
  3751.                     "expanded" => (isset($_GET["addedType"]) && $_GET["addedType"] == "supplier"),
  3752.                     "attr" => [
  3753.                         "class" => "jmnode-level-1",
  3754.                     ],
  3755.                     "children" => []
  3756.                 ],
  3757.             ]
  3758.         ];
  3759.         $key1 0;
  3760.         foreach ($systemsStd as $systemStd) {
  3761.             foreach ($systemStd as $key2 => $value2) {
  3762.                 $data = [
  3763.                     "id" => $mindMap["children"][$key1]["id"]."_".$key2,
  3764.                     "topic" => "<div class='node-level-2'><div class='jmnode-icon'><i class='mdi ".$value2["icon"]." mdi-36px'></i></div><i>".$value2["label"]."</i><span class='node-2-actions'><a href=\"".$this->generateUrl("user_systems_add")."?type=".$mindMap["children"][$key1]["id"]."&subtype=".$key2."\" class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-plus\"></i></a></span></div>",
  3765.                     "direction" => "right",
  3766.                     "expanded" => (isset($_GET["addedSubtype"]) && $_GET["addedSubtype"] == $key2),
  3767.                     "attr" => [
  3768.                         "class" => "jmnode-level-2",
  3769.                     ],
  3770.                     "children" => []
  3771.                 ];
  3772.                 $itemsLenght count($systems[$mindMap["children"][$key1]["id"]][$key2]);
  3773.                 if ($itemsLenght 2) {
  3774.                     $mindMapHeight += $itemsLenght;
  3775.                 } else {
  3776.                     $mindMapHeight += 2;
  3777.                 }
  3778.                 foreach ($systems[$mindMap["children"][$key1]["id"]][$key2] as $item) {
  3779.                     if ($item->getUser()->getId() == $this->getUser()->getUser()->getId()) {
  3780.                         $topic "<div class='node-level-3'><span class='node-topic' onclick='openModalInfo(".$item->getId().")'>".$item->getName()."</span><span class='node-3-actions'><a href=\"".$this->generateUrl("user_systems_edit", ["id" => $item->getId()])."\" class=\"btn btn-light my-1 mr-1\"><i class=\"mdi mdi-circle-edit-outline\"></i></a><a href=\"".$this->generateUrl("user_systems_delete", ["id" => $item->getId()])."\" class=\"btn btn-danger my-1\"  onclick=\"return confirm('Confirmer la suppression de cet élément ?');\"><i class=\"mdi mdi-close\"></i></a></span></div>";
  3781.                     } else {
  3782.                         $topic "<div class='node-level-3'><span class='node-topic' onclick='openModalInfo(".$item->getId().")'>".$item->getName()."</span><span class='node-3-actions'></span></div>";
  3783.                     }
  3784.                     $data["children"][] = [
  3785.                         "id" => $item->getId(),
  3786.                         "topic" => $topic,
  3787.                         "attr" => [
  3788.                             "class" => "jmnode-level-3",
  3789.                             "onclick" => "openModalInfo(".$item->getId().")",
  3790.                         ]
  3791.                     ];
  3792.                 }
  3793.                 $mindMap["children"][$key1]["children"][] = $data;
  3794.             }
  3795.             $key1++;
  3796.         }
  3797.         return $this->render('user/systems.html.twig', [
  3798.             "systems" => $systems,
  3799.             "systemsStd" => $systemsStd,
  3800.             "mindMap" => $mindMap,
  3801.             "mindMapHeight" => 12 * (38 1.5),
  3802.             "systemsJs" => $systemsJs,
  3803.         ]);
  3804.     }
  3805.     /**
  3806.      * @Route("/systems/standardize/{id}", name="systems_standardize")
  3807.      */
  3808.     public function systemsStandardizeAction(Request $requestSecurity $securitySystem $system)
  3809.     {
  3810.         $em $this->getDoctrine()->getManager();
  3811.         $systemStd = new SystemStd();
  3812.         $systemStd->setName($system->getName());
  3813.         $systemStd->setData($system->getData());
  3814.         $systemStd->setType($system->getType());
  3815.         $systemStd->setSubtype($system->getSubtype());
  3816.         $token $security->getToken();
  3817.         if ($token instanceof SwitchUserToken) {
  3818.             $impersonatorUser $token->getOriginalToken()->getUser();
  3819.             if ($impersonatorUser) {
  3820.                 if ($impersonatorUser->getManager()) {
  3821.                     $originalManager $em->getRepository(Manager::class)->find($impersonatorUser->getManager()->getId());
  3822.                     if ($originalManager) {
  3823.                         $systemStd->setManager($originalManager);
  3824.                     }
  3825.                 }
  3826.             }
  3827.         }
  3828.         $em->persist($systemStd);
  3829.         $em->flush();
  3830.         $this->get('session')->getFlashBag()->add('success''Nouvel élément de cartographie standard généré');
  3831.         return $this->redirectToRoute("user_systems");
  3832.     }
  3833.     /**
  3834.      * @Route("/systems/export", name="systems_export")
  3835.      */
  3836.     public function systemsExportAction(Request $request)
  3837.     {
  3838.         if ($this->isPrintingAllowed($this->getUser())) {
  3839.             if ($this->getUser()->getUser()->getParentUser()) {
  3840.                 $systemsQuery $this->getDoctrine()->getRepository(System::class)->findForUserWithGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser());
  3841.             } else {
  3842.                 $systemsQuery $this->getDoctrine()->getRepository(System::class)->findBy(["user" => $this->getUser()->getUser()]);
  3843.             }
  3844.             $systems = [
  3845.                 "computing" => [
  3846.                     "network" => [],
  3847.                     "security" => [],
  3848.                     "administration" => [],
  3849.                     "device" => [],
  3850.                     "software" => [],
  3851.                     "server" => [],
  3852.                 ],
  3853.                 "physical" => [
  3854.                     "partitioning" => [],
  3855.                     "information" => [],
  3856.                 ],
  3857.                 "action" => [
  3858.                     "minimization" => [],
  3859.                     "anonymization" => [],
  3860.                     "pseudonymization" => [],
  3861.                     "sensitization" => [],
  3862.                     "supervision" => [],
  3863.                     "destruction" => [],
  3864.                 ],
  3865.                 "supplier" => [
  3866.                     "supplier" => []
  3867.                 ]
  3868.             ];
  3869.             foreach ($systemsQuery as $system) {
  3870.                 $systems[$system->getType()][$system->getSubtype()][] = $system;
  3871.             }
  3872.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  3873.             $pdf->setUser($this->getUser()->getUser());
  3874.             $pdf->SetAuthor('myDigitplace');
  3875.             $pdf->SetTitle("Cartographie du SI");
  3876.             $pdf->SetMargins(10,22,10true);
  3877.             $pdf->SetAutoPageBreak(TRUE35);
  3878.             $pdf->AddPage('L''A4');
  3879.             $html $this->renderView('user/pdf/systems.html.twig', [
  3880.                 "systems" => $systems
  3881.             ]);
  3882.             $filename 'Cartographie_du_SI';
  3883.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  3884.             return $pdf->Output($filename.".pdf",'I');
  3885.         } else {
  3886.             return $this->redirectToRoute("user_systems");
  3887.         }
  3888.     }
  3889.     /**
  3890.      * @Route("/systems/export/{type}", name="systems_export_excel")
  3891.      */
  3892.     public function systemsExportExcelAction(Request $request$type)
  3893.     {
  3894.         if ($this->isPrintingAllowed($this->getUser())) {
  3895.             if ($this->getUser()->getUser()->getParentUser()) {
  3896.                 $systemsQuery $this->getDoctrine()->getRepository(System::class)->findForUserWithGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser());
  3897.             } else {
  3898.                 $systemsQuery $this->getDoctrine()->getRepository(System::class)->findBy(["user" => $this->getUser()->getUser()]);
  3899.             }
  3900.             $systems = [
  3901.                 "computing" => [
  3902.                     "network" => [],
  3903.                     "security" => [],
  3904.                     "administration" => [],
  3905.                     "device" => [],
  3906.                     "software" => [],
  3907.                     "server" => [],
  3908.                 ],
  3909.                 "physical" => [
  3910.                     "partitioning" => [],
  3911.                     "information" => [],
  3912.                 ],
  3913.                 "action" => [
  3914.                     "minimization" => [],
  3915.                     "anonymization" => [],
  3916.                     "pseudonymization" => [],
  3917.                     "sensitization" => [],
  3918.                     "supervision" => [],
  3919.                     "destruction" => [],
  3920.                 ],
  3921.                 "supplier" => [
  3922.                     "supplier" => []
  3923.                 ]
  3924.             ];
  3925.             foreach ($systemsQuery as $system) {
  3926.                 $systems[$system->getType()][$system->getSubtype()][] = $system;
  3927.             }
  3928.             $spreadsheet = new Spreadsheet();
  3929.             $translateSubtypes = [
  3930.                 "network" => "Réseau",
  3931.                 "security" => "Sécurité",
  3932.                 "administration" => "Administration",
  3933.                 "device" => "Périphérique",
  3934.                 "software" => "Logiciel",
  3935.                 "server" => "Serveur",
  3936.                 "partitioning" => "Cloisonnement",
  3937.                 "minimization" => "Minimisation",
  3938.                 "anonymization" => "Anonymisation",
  3939.                 "pseudonymization" => "Pseudonymisation",
  3940.                 "sensitization" => "Sensibilisation et formation",
  3941.                 "information" => "Information",
  3942.                 "supervision" => "Contrôle",
  3943.                 "destruction" => "Destruction et suppression",
  3944.                 "supplier" => "Prestataires du SI"
  3945.             ];
  3946.             $i 0;
  3947.             foreach ($systems[$type] as $subtype => $systems) {
  3948.                 $i++;
  3949.                 $roomsWorkSheet = new Worksheet($spreadsheet$translateSubtypes[$subtype]);
  3950.                 $spreadsheet->addSheet($roomsWorkSheet$i);
  3951.                 $spreadsheet->setActiveSheetIndex($i);
  3952.                 $sheet $spreadsheet->getActiveSheet();
  3953.                 $sheet->setCellValue('A1''ID');
  3954.                 $sheet->setCellValue('B1''Nom');
  3955.                 switch ($subtype) {
  3956.                     case "network":
  3957.                         $sheet->setCellValue('C1''Type');
  3958.                         $sheet->setCellValue('D1''Informations complémentaires');
  3959.                         $sheet->setCellValue('E1''Type de Wifi');
  3960.                         $sheet->setCellValue('F1''Protocole Wifi');
  3961.                         break;
  3962.                     case "security":
  3963.                     case "administration":
  3964.                     case "device":
  3965.                     case "software":
  3966.                     case "server":
  3967.                         $sheet->setCellValue('C1''Type');
  3968.                         $sheet->setCellValue('D1''Informations complémentaires');
  3969.                         $sheet->setCellValue('E1''Date d\'achat');
  3970.                         $sheet->setCellValue('F1''N° d\'identification');
  3971.                         break;
  3972.                     case "partitioning":
  3973.                     case "minimization":
  3974.                     case "anonymization":
  3975.                     case "pseudonymization":
  3976.                     case "sensitization":
  3977.                     case "information":
  3978.                     case "supervision":
  3979.                     case "destruction":
  3980.                         $sheet->setCellValue('C1''Description');
  3981.                         $sheet->setCellValue('D1''Informations complémentaires');
  3982.                         break;
  3983.                     case "supplier":
  3984.                         $sheet->setCellValue('C1''Type');
  3985.                         break;
  3986.                     default:
  3987.                         throw new NotFoundHttpException();
  3988.                 }
  3989.                 $j 1;
  3990.                 foreach ($systems as $system) {
  3991.                     $j++;
  3992.                     $sheet->setCellValue('A'.$j$system->getId());
  3993.                     $sheet->setCellValue('B'.$j$system->getName());
  3994.                     switch ($subtype) {
  3995.                         case "network":
  3996.                             $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  3997.                             $sheet->setCellValue('D'.$j, isset($system->getData()[1])?$system->getData()[1]["value"]:null);
  3998.                             $sheet->setCellValue('E'.$j, isset($system->getData()[2])?$system->getData()[2]["value"]:null);
  3999.                             $sheet->setCellValue('F'.$j, isset($system->getData()[3])?$system->getData()[3]["value"]:null);
  4000.                             break;
  4001.                         case "security":
  4002.                         case "administration":
  4003.                         case "device":
  4004.                         case "software":
  4005.                         case "server":
  4006.                             $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  4007.                             $sheet->setCellValue('D'.$j, isset($system->getData()[1])?$system->getData()[1]["value"]:null);
  4008.                             $sheet->setCellValue('E'.$j, isset($system->getData()[2])?$system->getData()[2]["value"]:null);
  4009.                             $sheet->setCellValue('F'.$j, isset($system->getData()[3])?$system->getData()[3]["value"]:null);
  4010.                             break;
  4011.                         case "partitioning":
  4012.                         case "minimization":
  4013.                         case "anonymization":
  4014.                         case "pseudonymization":
  4015.                         case "sensitization":
  4016.                         case "information":
  4017.                         case "supervision":
  4018.                         case "destruction":
  4019.                             $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  4020.                             $sheet->setCellValue('D'.$j, isset($system->getData()[1])?$system->getData()[1]["value"]:null);
  4021.                             break;
  4022.                         case "supplier":
  4023.                             $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  4024.                             break;
  4025.                         default:
  4026.                             throw new NotFoundHttpException();
  4027.                     }
  4028.                 }
  4029.             }
  4030.             $spreadsheet->removeSheetByIndex(0);
  4031.             $writer = new Xlsx($spreadsheet);
  4032.             $response = new StreamedResponse();
  4033.             $response->setCallback(function () use ($writer) {
  4034.                 $writer->save('php://output');
  4035.             });
  4036.             $response->setStatusCode(200);
  4037.             $response->headers->set('Content-Type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  4038.             $response->headers->set('Content-Disposition''attachment;filename="export_cartographie.xlsx"');
  4039.             $response->headers->set('Cache-Control','max-age=0');
  4040.             return $response;
  4041.         } else {
  4042.             return $this->redirectToRoute("user_systems");
  4043.         }
  4044.     }
  4045.     /**
  4046.      * @Route("/systems/add", name="systems_add")
  4047.      */
  4048.     public function systemsAddAction(Request $requestSendEmailService $sendEmailService)
  4049.     {
  4050.         $types = [
  4051.             "computing" => [
  4052.                 "network" => 4,
  4053.                 "security" => 4,
  4054.                 "administration" => 4,
  4055.                 "device" => 4,
  4056.                 "software" => 4,
  4057.                 "server" => 4,
  4058.             ],
  4059.             "physical" => [
  4060.                 "partitioning" => 2,
  4061.                 "information" => 2,
  4062.             ],
  4063.             "action" => [
  4064.                 "minimization" => 2,
  4065.                 "anonymization" => 2,
  4066.                 "pseudonymization" => 2,
  4067.                 "sensitization" => 2,
  4068.                 "supervision" => 2,
  4069.                 "destruction" => 2,
  4070.             ],
  4071.             "supplier" => [
  4072.                 "supplier" => 1
  4073.             ]
  4074.         ];
  4075.         $type null;
  4076.         $subtype null;
  4077.         $fromStd false;
  4078.         $systemsStd = [];
  4079.         if (isset($_GET['std'])) {
  4080.             $systemStd $this->getDoctrine()->getRepository(SystemStd::class)->find($_GET['std']);
  4081.             if ($systemStd) {
  4082.                 $type $systemStd->getType();
  4083.                 $subtype $systemStd->getSubtype();
  4084.                 $fromStd true;
  4085.             }
  4086.         } else {
  4087.             if (!$_GET['type'] || !$_GET['subtype']) {
  4088.                 throw new NotFoundHttpException();
  4089.             }
  4090.             if (!key_exists($_GET['type'], $types)) {
  4091.                 throw new NotFoundHttpException();
  4092.             }
  4093.             if (!key_exists($_GET['subtype'], $types[$_GET['type']])) {
  4094.                 throw new NotFoundHttpException();
  4095.             }
  4096.             $type $_GET['type'];
  4097.             $subtype $_GET['subtype'];
  4098.             $systemsStd $this->getDoctrine()->getRepository(SystemStd::class)->findBy(["type" => $type"subtype" => $subtype], ["name" => "ASC"]);
  4099.         }
  4100.         $system = new System();
  4101.         $form $this->createForm(SystemType::class, $system);
  4102.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  4103.             $form->add('group'CheckboxType::class, [
  4104.                 'label' => "Cet élément de cartographie appartient au groupe",
  4105.                 'required' => false,
  4106.             ]);
  4107.             if ($request->get("group")) {
  4108.                 $form["group"]->setData(true);
  4109.             }
  4110.         }
  4111.         $defaultValues = [];
  4112.         for ($i=0$i $types[$type][$subtype]; $i++) {
  4113.             $defaultValues[$i] = null;
  4114.         }
  4115.         if ($fromStd) {
  4116.             $form['name']->setData($systemStd->getName());
  4117.             for ($i=0$i $types[$type][$subtype]; $i++) {
  4118.                 $defaultValues[$i] = isset($systemStd->getData()[$i])?$systemStd->getData()[$i]['value']:null;
  4119.             }
  4120.         }
  4121.         switch ($subtype) {
  4122.             case "network":
  4123.                 $form->add('field1'ChoiceType::class, [
  4124.                         'attr' => [
  4125.                             'placeholder' => 'Type'
  4126.                         ],
  4127.                         'placeholder' => 'Type',
  4128.                         'label' => 'Type',
  4129.                         'data' => $defaultValues[0],
  4130.                         'choices' => [
  4131.                             "Filaire" => "Filaire",
  4132.                             "Sans-fil" => "Sans-fil",
  4133.                         ],
  4134.                         'required' => false,
  4135.                         'mapped' => false
  4136.                     ])
  4137.                     ->add('field2'TextareaType::class, [
  4138.                         'attr' => [
  4139.                             'placeholder' => 'Informations complémentaires'
  4140.                         ],
  4141.                         'label' => 'Informations complémentaires',
  4142.                         'data' => $defaultValues[1],
  4143.                         'required' => false,
  4144.                         'mapped' => false
  4145.                     ])
  4146.                     ->add('field3'ChoiceType::class, [
  4147.                         'attr' => [
  4148.                             'placeholder' => 'Type'
  4149.                         ],
  4150.                         'placeholder' => 'Type',
  4151.                         'label' => 'Si Wifi, sélectionnez le type',
  4152.                         'data' => $defaultValues[2],
  4153.                         'choices' => [
  4154.                             "Privé" => "Privé",
  4155.                             "Public" => "Public",
  4156.                         ],
  4157.                         'required' => false,
  4158.                         'mapped' => false
  4159.                     ])
  4160.                     ->add('field4'TextType::class, [
  4161.                         'attr' => [
  4162.                             'placeholder' => 'Protocole'
  4163.                         ],
  4164.                         'label' => 'Si Wifi, quel protocole ?',
  4165.                         'data' => $defaultValues[3],
  4166.                         'required' => false,
  4167.                         'mapped' => false
  4168.                     ])
  4169.                 ;
  4170.                 break;
  4171.             case "security":
  4172.             case "administration":
  4173.             case "device":
  4174.             case "software":
  4175.             case "server":
  4176.                 $form->add('field1'TextType::class, [
  4177.                         'attr' => [
  4178.                             'placeholder' => 'Type'
  4179.                         ],
  4180.                         'label' => 'Type',
  4181.                         'data' => $defaultValues[0],
  4182.                         'required' => false,
  4183.                         'mapped' => false
  4184.                     ])
  4185.                     ->add('field2'TextareaType::class, [
  4186.                         'attr' => [
  4187.                             'placeholder' => 'Informations complémentaires'
  4188.                         ],
  4189.                         'label' => 'Informations complémentaires',
  4190.                         'data' => $defaultValues[1],
  4191.                         'required' => false,
  4192.                         'mapped' => false
  4193.                     ])
  4194.                     ->add('field3'TextType::class, [
  4195.                         'attr' => [
  4196.                             'placeholder' => '__/__/____',
  4197.                             'data-mask' => '00/00/0000',
  4198.                             'data-mask-clearifnotmatch' => 'true'
  4199.                         ],
  4200.                         'label' => 'Date d\'achat',
  4201.                         'data' => $defaultValues[2],
  4202.                         'required' => false,
  4203.                         'mapped' => false
  4204.                     ])
  4205.                     ->add('field4'TextType::class, [
  4206.                         'attr' => [
  4207.                             'placeholder' => 'N° d’identification'
  4208.                         ],
  4209.                         'label' => 'N° d’identification',
  4210.                         'data' => $defaultValues[3],
  4211.                         'required' => false,
  4212.                         'mapped' => false
  4213.                     ]);
  4214.                 break;
  4215.             case "partitioning":
  4216.             case "minimization":
  4217.             case "anonymization":
  4218.             case "pseudonymization":
  4219.             case "sensitization":
  4220.             case "information":
  4221.             case "supervision":
  4222.             case "destruction":
  4223.                 $form->add('field1'TextareaType::class, [
  4224.                         'attr' => [
  4225.                             'placeholder' => 'Description'
  4226.                         ],
  4227.                         'label' => 'Description',
  4228.                         'data' => $defaultValues[0],
  4229.                         'required' => false,
  4230.                         'mapped' => false
  4231.                     ])
  4232.                     ->add('field2'TextareaType::class, [
  4233.                         'attr' => [
  4234.                             'placeholder' => 'Informations complémentaires'
  4235.                         ],
  4236.                         'label' => 'Informations complémentaires',
  4237.                         'data' => $defaultValues[1],
  4238.                         'required' => false,
  4239.                         'mapped' => false
  4240.                     ]);
  4241.                 break;
  4242.             case "supplier":
  4243.                 $form->add('field1'TextType::class, [
  4244.                     'attr' => [
  4245.                         'placeholder' => 'Type'
  4246.                     ],
  4247.                     'label' => 'Type',
  4248.                     'data' => $defaultValues[0],
  4249.                     'required' => false,
  4250.                     'mapped' => false
  4251.                 ]);
  4252.                 break;
  4253.             default:
  4254.                 throw new NotFoundHttpException();
  4255.         }
  4256.         $form->handleRequest($request);
  4257.         if ($form->isSubmitted() && $form->isValid()) {
  4258.             $em $this->getDoctrine()->getManager();
  4259.             $data = [];
  4260.             switch ($subtype) {
  4261.                 case "network":
  4262.                     $data[] = [
  4263.                         "title" => 'Type',
  4264.                         "value" => $form['field1']->getData()
  4265.                     ];
  4266.                     $data[] = [
  4267.                         "title" => 'Informations complémentaires',
  4268.                         "value" => $form['field2']->getData()
  4269.                     ];
  4270.                     $data[] = [
  4271.                         "title" => 'Type de Wifi',
  4272.                         "value" => $form['field3']->getData()
  4273.                     ];
  4274.                     $data[] = [
  4275.                         "title" => 'Protocole Wifi',
  4276.                         "value" => $form['field4']->getData()
  4277.                     ];
  4278.                     ;
  4279.                     break;
  4280.                 case "security":
  4281.                 case "administration":
  4282.                 case "device":
  4283.                 case "software":
  4284.                 case "server":
  4285.                     $data[] = [
  4286.                         "title" => 'Type',
  4287.                         "value" => $form['field1']->getData()
  4288.                     ];
  4289.                     $data[] = [
  4290.                         "title" => 'Informations complémentaires',
  4291.                         "value" => $form['field2']->getData()
  4292.                     ];
  4293.                     $data[] = [
  4294.                         "title" => 'Date d\'achat',
  4295.                         "value" => $form['field3']->getData()
  4296.                     ];
  4297.                     $data[] = [
  4298.                         "title" => 'N° d’identification',
  4299.                         "value" => $form['field4']->getData()
  4300.                     ];
  4301.                     break;
  4302.                 case "partitioning":
  4303.                 case "minimization":
  4304.                 case "anonymization":
  4305.                 case "pseudonymization":
  4306.                 case "sensitization":
  4307.                 case "information":
  4308.                 case "supervision":
  4309.                 case "destruction":
  4310.                     $data[] = [
  4311.                         "title" => 'Description',
  4312.                         "value" => $form['field1']->getData()
  4313.                     ];
  4314.                     $data[] = [
  4315.                         "title" => 'Informations complémentaires',
  4316.                         "value" => $form['field2']->getData()
  4317.                     ];
  4318.                     break;
  4319.                 case "supplier":
  4320.                     $data[] = [
  4321.                         "title" => 'Type',
  4322.                         "value" => $form['field1']->getData()
  4323.                     ];
  4324.                     break;
  4325.                 default:
  4326.                     throw new NotFoundHttpException();
  4327.             }
  4328.             $system->setData($data);
  4329.             $system->setType($type);
  4330.             $system->setSubtype($subtype);
  4331.             $system->setUser($this->getUser()->getUser());
  4332.             $em->persist($system);
  4333.             $em->flush();
  4334.             if ($system->isAutoApplyToTreatments()) {
  4335.                 $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  4336.                 foreach ($treatments as $treatment) {
  4337.                     $treatment->getSystems()->add($system);
  4338.                     $em->flush();
  4339.                 }
  4340.             }
  4341.             $content "<p>Bonjour,<br/>
  4342.                         <br/>
  4343.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a ajouté un nouvel élément de cartographie du SI: ".$system->getName()."<br/>
  4344.                         <br/>
  4345.                         <br/>
  4346.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  4347.                         </p>";
  4348.             $sendEmailService->send(
  4349.                 "Nouvel élément de cartographie du SI client",
  4350.                 $this->getUser()->getUser()->getManager()->getEmail(),
  4351.                 'template_emails/left_text.html.twig',
  4352.                 [
  4353.                     "title" => "Nouvel élément de cartographie du SI client",
  4354.                     "content" => $content
  4355.                 ]
  4356.             );
  4357.             $this->get('session')->getFlashBag()->add('success''Mise à jour de la cartographie du système');
  4358.             $url null;
  4359.             if ($system->isGroup()) {
  4360.                 $url $this->generateUrl("user_systems_group");
  4361.             } else {
  4362.                 $url $this->generateUrl("user_systems");
  4363.             }
  4364.             if ($system->getType() && $system->getSubtype()) {
  4365.                 $url .= "?addedType=".$system->getType()."&addedSubtype=".$system->getSubtype();
  4366.             }
  4367.             return $this->redirect($url);
  4368.         }
  4369.         return $this->render('user/systems_add.html.twig', [
  4370.             "form" => $form->createView(),
  4371.             "fields" => $types[$type][$subtype],
  4372.             "systemsStd" => $systemsStd
  4373.         ]);
  4374.     }
  4375.     /**
  4376.      * @Route("/systems/{id}/edit", name="systems_edit")
  4377.      */
  4378.     public function systemsEditAction(Request $requestSendEmailService $sendEmailServiceSystem $system)
  4379.     {
  4380.         if ($system->getUser()->getId() != $this->getUser()->getUser()->getId()){
  4381.             throw new NotFoundHttpException();
  4382.         }
  4383.         $current_isAutoApplyToTreatments $system->isAutoApplyToTreatments();
  4384.         $types = [
  4385.             "computing" => [
  4386.                 "network" => 4,
  4387.                 "security" => 4,
  4388.                 "administration" => 4,
  4389.                 "device" => 4,
  4390.                 "software" => 4,
  4391.                 "server" => 4,
  4392.             ],
  4393.             "physical" => [
  4394.                 "partitioning" => 2,
  4395.                 "information" => 2,
  4396.             ],
  4397.             "action" => [
  4398.                 "minimization" => 2,
  4399.                 "anonymization" => 2,
  4400.                 "pseudonymization" => 2,
  4401.                 "sensitization" => 2,
  4402.                 "supervision" => 2,
  4403.                 "destruction" => 2,
  4404.             ],
  4405.             "supplier" => [
  4406.                 "supplier" => 1
  4407.             ]
  4408.         ];
  4409.         $form $this->createForm(SystemType::class, $system);
  4410.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  4411.             $form->add('group'CheckboxType::class, [
  4412.                 'label' => "Cet élément de cartographie appartient au groupe",
  4413.                 'required' => false,
  4414.             ]);
  4415.         }
  4416.         switch ($system->getSubtype()) {
  4417.             case "network":
  4418.                 $form->add('field1'ChoiceType::class, [
  4419.                     'attr' => [
  4420.                         'placeholder' => 'Type'
  4421.                     ],
  4422.                     'placeholder' => 'Type',
  4423.                     'label' => 'Type',
  4424.                     'choices' => [
  4425.                         "Filaire" => "Filaire",
  4426.                         "Sans-fil" => "Sans-fil",
  4427.                     ],
  4428.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  4429.                     'required' => false,
  4430.                     'mapped' => false
  4431.                 ])
  4432.                     ->add('field2'TextareaType::class, [
  4433.                         'attr' => [
  4434.                             'placeholder' => 'Informations complémentaires'
  4435.                         ],
  4436.                         'label' => 'Informations complémentaires',
  4437.                         'data' => isset($system->getData()[1])?$system->getData()[1]["value"]:null,
  4438.                         'required' => false,
  4439.                         'mapped' => false
  4440.                     ])
  4441.                     ->add('field3'ChoiceType::class, [
  4442.                         'attr' => [
  4443.                             'placeholder' => 'Type'
  4444.                         ],
  4445.                         'placeholder' => 'Type',
  4446.                         'label' => 'Si Wifi, sélectionnez le type',
  4447.                         'choices' => [
  4448.                             "Privé" => "Privé",
  4449.                             "Public" => "Public",
  4450.                         ],
  4451.                         'data' => isset($system->getData()[2])?$system->getData()[2]["value"]:null,
  4452.                         'required' => false,
  4453.                         'mapped' => false
  4454.                     ])
  4455.                     ->add('field4'TextType::class, [
  4456.                         'attr' => [
  4457.                             'placeholder' => 'Protocole'
  4458.                         ],
  4459.                         'label' => 'Si Wifi, quel protocole ?',
  4460.                         'data' => isset($system->getData()[3])?$system->getData()[3]["value"]:null,
  4461.                         'required' => false,
  4462.                         'mapped' => false
  4463.                     ])
  4464.                 ;
  4465.                 break;
  4466.             case "security":
  4467.             case "administration":
  4468.             case "device":
  4469.             case "software":
  4470.             case "server":
  4471.                 $form->add('field1'TextType::class, [
  4472.                     'attr' => [
  4473.                         'placeholder' => 'Type'
  4474.                     ],
  4475.                     'label' => 'Type',
  4476.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  4477.                     'required' => false,
  4478.                     'mapped' => false
  4479.                 ])
  4480.                     ->add('field2'TextareaType::class, [
  4481.                         'attr' => [
  4482.                             'placeholder' => 'Informations complémentaires'
  4483.                         ],
  4484.                         'label' => 'Informations complémentaires',
  4485.                         'data' => isset($system->getData()[1])?$system->getData()[1]["value"]:null,
  4486.                         'required' => false,
  4487.                         'mapped' => false
  4488.                     ])
  4489.                     ->add('field3'TextType::class, [
  4490.                         'attr' => [
  4491.                             'placeholder' => '__/__/____',
  4492.                             'data-mask' => '00/00/0000',
  4493.                             'data-mask-clearifnotmatch' => 'true'
  4494.                         ],
  4495.                         'label' => 'Date d\'achat',
  4496.                         'data' => isset($system->getData()[2])?$system->getData()[2]["value"]:null,
  4497.                         'required' => false,
  4498.                         'mapped' => false
  4499.                     ])
  4500.                     ->add('field4'TextType::class, [
  4501.                         'attr' => [
  4502.                             'placeholder' => 'N° d’identification'
  4503.                         ],
  4504.                         'label' => 'N° d’identification',
  4505.                         'data' => isset($system->getData()[3])?$system->getData()[3]["value"]:null,
  4506.                         'required' => false,
  4507.                         'mapped' => false
  4508.                     ]);
  4509.                 break;
  4510.             case "partitioning":
  4511.             case "minimization":
  4512.             case "anonymization":
  4513.             case "pseudonymization":
  4514.             case "sensitization":
  4515.             case "information":
  4516.             case "supervision":
  4517.             case "destruction":
  4518.                 $form->add('field1'TextareaType::class, [
  4519.                     'attr' => [
  4520.                         'placeholder' => 'Description'
  4521.                     ],
  4522.                     'label' => 'Description',
  4523.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  4524.                     'required' => false,
  4525.                     'mapped' => false
  4526.                 ])
  4527.                     ->add('field2'TextareaType::class, [
  4528.                         'attr' => [
  4529.                             'placeholder' => 'Informations complémentaires'
  4530.                         ],
  4531.                         'label' => 'Informations complémentaires',
  4532.                         'data' => isset($system->getData()[1])?$system->getData()[1]["value"]:null,
  4533.                         'required' => false,
  4534.                         'mapped' => false
  4535.                     ]);
  4536.                 break;
  4537.             case "supplier":
  4538.                 $form->add('field1'TextType::class, [
  4539.                     'attr' => [
  4540.                         'placeholder' => 'Type'
  4541.                     ],
  4542.                     'label' => 'Type',
  4543.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  4544.                     'required' => false,
  4545.                     'mapped' => false
  4546.                 ]);
  4547.                 break;
  4548.             default:
  4549.                 throw new NotFoundHttpException();
  4550.         }
  4551.         $form->handleRequest($request);
  4552.         if ($form->isSubmitted() && $form->isValid()) {
  4553.             $em $this->getDoctrine()->getManager();
  4554.             $data = [];
  4555.             switch ($system->getSubtype()) {
  4556.                 case "network":
  4557.                     $data[] = [
  4558.                         "title" => 'Type',
  4559.                         "value" => $form['field1']->getData()
  4560.                     ];
  4561.                     $data[] = [
  4562.                         "title" => 'Informations complémentaires',
  4563.                         "value" => $form['field2']->getData()
  4564.                     ];
  4565.                     $data[] = [
  4566.                         "title" => 'Type de Wifi',
  4567.                         "value" => $form['field3']->getData()
  4568.                     ];
  4569.                     $data[] = [
  4570.                         "title" => 'Protocole Wifi',
  4571.                         "value" => $form['field4']->getData()
  4572.                     ];
  4573.                     ;
  4574.                     break;
  4575.                 case "security":
  4576.                 case "administration":
  4577.                 case "device":
  4578.                 case "software":
  4579.                 case "server":
  4580.                     $data[] = [
  4581.                         "title" => 'Type',
  4582.                         "value" => $form['field1']->getData()
  4583.                     ];
  4584.                     $data[] = [
  4585.                         "title" => 'Informations complémentaires',
  4586.                         "value" => $form['field2']->getData()
  4587.                     ];
  4588.                     $data[] = [
  4589.                         "title" => 'Date d\'achat',
  4590.                         "value" => $form['field3']->getData()
  4591.                     ];
  4592.                     $data[] = [
  4593.                         "title" => 'N° d’identification',
  4594.                         "value" => $form['field4']->getData()
  4595.                     ];
  4596.                     break;
  4597.                 case "partitioning":
  4598.                 case "minimization":
  4599.                 case "anonymization":
  4600.                 case "pseudonymization":
  4601.                 case "sensitization":
  4602.                 case "information":
  4603.                 case "supervision":
  4604.                 case "destruction":
  4605.                     $data[] = [
  4606.                         "title" => 'Description',
  4607.                         "value" => $form['field1']->getData()
  4608.                     ];
  4609.                     $data[] = [
  4610.                         "title" => 'Informations complémentaires',
  4611.                         "value" => $form['field2']->getData()
  4612.                     ];
  4613.                     break;
  4614.                 case "supplier":
  4615.                     $data[] = [
  4616.                         "title" => 'Type',
  4617.                         "value" => $form['field1']->getData()
  4618.                     ];
  4619.                     break;
  4620.                 default:
  4621.                     throw new NotFoundHttpException();
  4622.             }
  4623.             $system->setData($data);
  4624.             $em->flush();
  4625.             if (!$current_isAutoApplyToTreatments && $system->isAutoApplyToTreatments()) {
  4626.                 $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  4627.                 foreach ($treatments as $treatment) {
  4628.                     if (!$treatment->getSystems()->contains($system)) {
  4629.                         $treatment->getSystems()->add($system);
  4630.                         $em->flush();
  4631.                     }
  4632.                 }
  4633.             }
  4634.             $content "<p>Bonjour,<br/>
  4635.                         <br/>
  4636.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a modifié l'élément de cartographie du SI ".$system->getName()."<br/>
  4637.                         <br/>
  4638.                         <br/>
  4639.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  4640.                         </p>";
  4641.             $sendEmailService->send(
  4642.                 "Élément de cartographie du SI client modifié",
  4643.                 $this->getUser()->getUser()->getManager()->getEmail(),
  4644.                 'template_emails/left_text.html.twig',
  4645.                 [
  4646.                     "title" => "Élément de cartographie du SI client modifié",
  4647.                     "content" => $content
  4648.                 ]
  4649.             );
  4650.             $this->get('session')->getFlashBag()->add('success''Mise à jour de la cartographie du système');
  4651.             $url null;
  4652.             if ($system->isGroup()) {
  4653.                 $url $this->generateUrl("user_systems_group");
  4654.             } else {
  4655.                 $url $this->generateUrl("user_systems");
  4656.             }
  4657.             if ($system->getType() && $system->getSubtype()) {
  4658.                 $url .= "?addedType=".$system->getType()."&addedSubtype=".$system->getSubtype();
  4659.             }
  4660.             return $this->redirect($url);
  4661.         }
  4662.         return $this->render('user/systems_edit.html.twig', [
  4663.             "form" => $form->createView(),
  4664.             "fields" => $types[$system->getType()][$system->getSubtype()]
  4665.         ]);
  4666.     }
  4667.     /**
  4668.      * @Route("/systems/{id}/delete", name="systems_delete")
  4669.      */
  4670.     public function systemsDeleteAction(Request $requestSystem $system)
  4671.     {
  4672.         if ($system->getUser()->getId() != $this->getUser()->getUser()->getId()){
  4673.             throw new NotFoundHttpException();
  4674.         }
  4675.         $em $this->getDoctrine()->getManager();
  4676.         $em->remove($system);
  4677.         $em->flush();
  4678.         $this->get('session')->getFlashBag()->add('success''Mise à jour de la cartographie du système');
  4679.         return $this->redirectToRoute("user_systems");
  4680.     }
  4681.     /**
  4682.      * @Route("/systemsgroup", name="systems_group")
  4683.      */
  4684.     public function systemsGroupAction(Request $request)
  4685.     {
  4686.         if (!$this->getUser()->getUser()->isMainGroupAgency()) {
  4687.             throw new NotFoundHttpException();
  4688.         }
  4689.         $systemsQuery $this->getDoctrine()->getRepository(System::class)->findBy(["user" => $this->getUser()->getUser(), "group" => true]);
  4690.         $systems = [
  4691.             "computing" => [
  4692.                 "network" => [],
  4693.                 "security" => [],
  4694.                 "administration" => [],
  4695.                 "device" => [],
  4696.                 "software" => [],
  4697.                 "server" => [],
  4698.             ],
  4699.             "physical" => [
  4700.                 "partitioning" => [],
  4701.                 "information" => [],
  4702.             ],
  4703.             "action" => [
  4704.                 "minimization" => [],
  4705.                 "anonymization" => [],
  4706.                 "pseudonymization" => [],
  4707.                 "sensitization" => [],
  4708.                 "supervision" => [],
  4709.                 "destruction" => [],
  4710.             ],
  4711.             "supplier" => [
  4712.                 "supplier" => []
  4713.             ]
  4714.         ];
  4715.         $systemsJs = [];
  4716.         $encoders = [new JsonEncoder()];
  4717.         $normalizer = new ObjectNormalizer();
  4718.         $normalizer->setCircularReferenceLimit(1);
  4719.         $normalizer->setCircularReferenceHandler(function ($object) {
  4720.             return $object->getId();
  4721.         });
  4722.         $normalizers = [$normalizer];
  4723.         $serializer = new Serializer($normalizers$encoders);
  4724.         foreach ($systemsQuery as $system) {
  4725.             $systems[$system->getType()][$system->getSubtype()][] = $system;
  4726.             $systemsJs[$system->getId()] = json_decode($serializer->serialize($system'json', ["attributes" => ['id''name''data''type''subtype']]), true);
  4727.         }
  4728.         $systemsStdQuery $this->getDoctrine()->getRepository(SystemStd::class)->findAll();
  4729.         $systemsStd = [
  4730.             "computing" => [
  4731.                 "network" => [
  4732.                     "label" => "Réseau",
  4733.                     "items" => [],
  4734.                     "icon" => "mdi-ip-network"
  4735.                 ],
  4736.                 "security" => [
  4737.                     "label" => "Sécurité",
  4738.                     "items" => [],
  4739.                     "icon" => "mdi-security"
  4740.                 ],
  4741.                 "administration" => [
  4742.                     "label" => "Administration",
  4743.                     "items" => [],
  4744.                     "icon" => "mdi-account-multiple"
  4745.                 ],
  4746.                 "device" => [
  4747.                     "label" => "Périphérique",
  4748.                     "items" => [],
  4749.                     "icon" => "mdi-responsive"
  4750.                 ],
  4751.                 "software" => [
  4752.                     "label" => "Logiciel",
  4753.                     "items" => [],
  4754.                     "icon" => "mdi-console"
  4755.                 ],
  4756.                 "server" => [
  4757.                     "label" => "Serveur",
  4758.                     "items" => [],
  4759.                     "icon" => "mdi-server"
  4760.                 ],
  4761.             ],
  4762.             "physical" => [
  4763.                 "partitioning" => [
  4764.                     "label" => "Cloisonnement",
  4765.                     "items" => [],
  4766.                     "icon" => "mdi-view-module"
  4767.                 ],
  4768.                 "information" => [
  4769.                     "label" => "Information",
  4770.                     "items" => [],
  4771.                     "icon" => "mdi-lightbulb-on"
  4772.                 ],
  4773.             ],
  4774.             "action" => [
  4775.                 "minimization" => [
  4776.                     "label" => "Minimisation",
  4777.                     "items" => [],
  4778.                     "icon" => "mdi-tab-minus"
  4779.                 ],
  4780.                 "anonymization" => [
  4781.                     "label" => "Anonymisation",
  4782.                     "items" => [],
  4783.                     "icon" => "mdi-incognito"
  4784.                 ],
  4785.                 "pseudonymization" => [
  4786.                     "label" => "Pseudonymisation",
  4787.                     "items" => [],
  4788.                     "icon" => "mdi-account-question"
  4789.                 ],
  4790.                 "sensitization" => [
  4791.                     "label" => "Sensibilisation et formation",
  4792.                     "items" => [],
  4793.                     "icon" => "mdi-account-alert"
  4794.                 ],
  4795.                 "supervision" => [
  4796.                     "label" => "Contrôle",
  4797.                     "items" => [],
  4798.                     "icon" => "mdi-table-search"
  4799.                 ],
  4800.                 "destruction" => [
  4801.                     "label" => "Destruction et suppression",
  4802.                     "items" => [],
  4803.                     "icon" => "mdi-trash-can"
  4804.                 ],
  4805.             ],
  4806.             "supplier" => [
  4807.                 "supplier" => [
  4808.                     "label" => "Prestataires du SI",
  4809.                     "items" => [],
  4810.                     "icon" => "mdi-contacts"
  4811.                 ],
  4812.             ]
  4813.         ];
  4814.         foreach ($systemsStdQuery as $system) {
  4815.             $systemsStd[$system->getType()][$system->getSubtype()]['items'][] = $system;
  4816.         }
  4817.         $mindMapHeight 0;
  4818.         $mindMap = [
  4819.             "id" => "root",
  4820.             "topic" => "<div class='node-level-0'><div class='jmnode-icon'><i class='mdi mdi-sitemap mdi-36px'></i></div><i>Système d'information</i><span class='node-0-actions'><a href=\"".$this->generateUrl("user_systems_group_export")."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-printer\"></i></a></span></div>",
  4821.             "children" => [
  4822.                 [
  4823.                     "id" => "computing",
  4824.                     "topic" => "<div class='node-level-1'><div class='jmnode-icon'><i class='mdi mdi-desktop-classic mdi-36px'></i></div><i>Informatique</i><span class='node-1-actions'><a href=\"".$this->generateUrl("user_systems_group_export_excel", ["type" => "computing"])."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-download\"></i></a></span></div>",
  4825.                     "direction" => "right",
  4826.                     "expanded" => (isset($_GET["addedType"]) && $_GET["addedType"] == "computing"),
  4827.                     "attr" => [
  4828.                         "class" => "jmnode-level-1",
  4829.                     ],
  4830.                     "children" => []
  4831.                 ],
  4832.                 [
  4833.                     "id" => "physical",
  4834.                     "topic" => "<div class='node-level-1'><div class='jmnode-icon'><i class='mdi mdi-office-building mdi-36px'></i></div><i>Physique</i><span class='node-1-actions'><a href=\"".$this->generateUrl("user_systems_group_export_excel", ["type" => "physical"])."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-download\"></i></a></span></div>",
  4835.                     "direction" => "right",
  4836.                     "expanded" => (isset($_GET["addedType"]) && $_GET["addedType"] == "physical"),
  4837.                     "attr" => [
  4838.                         "class" => "jmnode-level-1",
  4839.                     ],
  4840.                     "children" => []
  4841.                 ],
  4842.                 [
  4843.                     "id" => "action",
  4844.                     "topic" => "<div class='node-level-1'><div class='jmnode-icon'><i class='mdi mdi-account-arrow-right mdi-36px'></i></div><i>Action</i><span class='node-1-actions'><a href=\"".$this->generateUrl("user_systems_group_export_excel", ["type" => "action"])."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-download\"></i></a></span></div>",
  4845.                     "direction" => "right",
  4846.                     "expanded" => (isset($_GET["addedType"]) && $_GET["addedType"] == "action"),
  4847.                     "attr" => [
  4848.                         "class" => "jmnode-level-1",
  4849.                     ],
  4850.                     "children" => []
  4851.                 ],
  4852.                 [
  4853.                     "id" => "supplier",
  4854.                     "topic" => "<div class='node-level-1'><div class='jmnode-icon'><i class='mdi mdi-contacts mdi-36px'></i></div><i>Prestataires du SI</i><span class='node-1-actions'><a href=\"".$this->generateUrl("user_systems_group_export_excel", ["type" => "supplier"])."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-download\"></i></a></span></div>",
  4855.                     "direction" => "right",
  4856.                     "expanded" => (isset($_GET["addedType"]) && $_GET["addedType"] == "supplier"),
  4857.                     "attr" => [
  4858.                         "class" => "jmnode-level-1",
  4859.                     ],
  4860.                     "children" => []
  4861.                 ],
  4862.             ]
  4863.         ];
  4864.         $key1 0;
  4865.         foreach ($systemsStd as $systemStd) {
  4866.             foreach ($systemStd as $key2 => $value2) {
  4867.                 $data = [
  4868.                     "id" => $mindMap["children"][$key1]["id"]."_".$key2,
  4869.                     "topic" => "<div class='node-level-2'><div class='jmnode-icon'><i class='mdi ".$value2["icon"]." mdi-36px'></i></div><i>".$value2["label"]."</i><span class='node-2-actions'><a href=\"".$this->generateUrl("user_systems_add")."?type=".$mindMap["children"][$key1]["id"]."&subtype=".$key2."&group=1\" class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-plus\"></i></a></span></div>",
  4870.                     "direction" => "right",
  4871.                     "expanded" => (isset($_GET["addedSubtype"]) && $_GET["addedSubtype"] == $key2),
  4872.                     "attr" => [
  4873.                         "class" => "jmnode-level-2",
  4874.                     ],
  4875.                     "children" => []
  4876.                 ];
  4877.                 $itemsLenght count($systems[$mindMap["children"][$key1]["id"]][$key2]);
  4878.                 if ($itemsLenght 2) {
  4879.                     $mindMapHeight += $itemsLenght;
  4880.                 } else {
  4881.                     $mindMapHeight += 2;
  4882.                 }
  4883.                 foreach ($systems[$mindMap["children"][$key1]["id"]][$key2] as $item) {
  4884.                     $data["children"][] = [
  4885.                         "id" => $item->getId(),
  4886.                         "topic" => "<div class='node-level-3'><span class='node-topic' onclick='openModalInfo(".$item->getId().")'>".$item->getName()."</span><span class='node-3-actions'><a href=\"".$this->generateUrl("user_systems_edit", ["id" => $item->getId()])."\" class=\"btn btn-light my-1 mr-1\"><i class=\"mdi mdi-circle-edit-outline\"></i></a><a href=\"".$this->generateUrl("user_systems_delete", ["id" => $item->getId()])."\" class=\"btn btn-danger my-1\"  onclick=\"return confirm('Confirmer la suppression de cet élément ?');\"><i class=\"mdi mdi-close\"></i></a></span></div>",
  4887.                         "attr" => [
  4888.                             "class" => "jmnode-level-3",
  4889.                             "onclick" => "openModalInfo(".$item->getId().")",
  4890.                         ]
  4891.                     ];
  4892.                 }
  4893.                 $mindMap["children"][$key1]["children"][] = $data;
  4894.             }
  4895.             $key1++;
  4896.         }
  4897.         return $this->render('user/systemsgroup.html.twig', [
  4898.             "systems" => $systems,
  4899.             "systemsStd" => $systemsStd,
  4900.             "mindMap" => $mindMap,
  4901.             "mindMapHeight" => 12 * (38 1.5),
  4902.             "systemsJs" => $systemsJs,
  4903.         ]);
  4904.     }
  4905.     /**
  4906.      * @Route("/systemsgroup/export", name="systems_group_export")
  4907.      */
  4908.     public function systemsGroupExportAction(Request $request)
  4909.     {
  4910.         if (!$this->getUser()->getUser()->isMainGroupAgency()) {
  4911.             throw new NotFoundHttpException();
  4912.         }
  4913.         if ($this->isPrintingAllowed($this->getUser())) {
  4914.             $systemsQuery $this->getDoctrine()->getRepository(System::class)->findBy(["user" => $this->getUser()->getUser(), "group" => true]);
  4915.             $systems = [
  4916.                 "computing" => [
  4917.                     "network" => [],
  4918.                     "security" => [],
  4919.                     "administration" => [],
  4920.                     "device" => [],
  4921.                     "software" => [],
  4922.                     "server" => [],
  4923.                 ],
  4924.                 "physical" => [
  4925.                     "partitioning" => [],
  4926.                     "information" => [],
  4927.                 ],
  4928.                 "action" => [
  4929.                     "minimization" => [],
  4930.                     "anonymization" => [],
  4931.                     "pseudonymization" => [],
  4932.                     "sensitization" => [],
  4933.                     "supervision" => [],
  4934.                     "destruction" => [],
  4935.                 ],
  4936.                 "supplier" => [
  4937.                     "supplier" => []
  4938.                 ]
  4939.             ];
  4940.             foreach ($systemsQuery as $system) {
  4941.                 $systems[$system->getType()][$system->getSubtype()][] = $system;
  4942.             }
  4943.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  4944.             $pdf->setUser($this->getUser()->getUser());
  4945.             $pdf->SetAuthor('myDigitplace');
  4946.             $pdf->SetTitle("Cartographie du SI");
  4947.             $pdf->SetMargins(10,22,10true);
  4948.             $pdf->SetAutoPageBreak(TRUE35);
  4949.             $pdf->AddPage('L''A4');
  4950.             $html $this->renderView('user/pdf/systems.html.twig', [
  4951.                 "systems" => $systems,
  4952.                 "group" => true
  4953.             ]);
  4954.             $filename 'Cartographie_du_SI';
  4955.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  4956.             return $pdf->Output($filename.".pdf",'I');
  4957.         } else {
  4958.             return $this->redirectToRoute("user_systems");
  4959.         }
  4960.     }
  4961.     /**
  4962.      * @Route("/systemsgroup/export/{type}", name="systems_group_export_excel")
  4963.      */
  4964.     public function systemsGroupExportExcelAction(Request $request$type)
  4965.     {
  4966.         if (!$this->getUser()->getUser()->isMainGroupAgency()) {
  4967.             throw new NotFoundHttpException();
  4968.         }
  4969.         if ($this->isPrintingAllowed($this->getUser())) {
  4970.             $systemsQuery $this->getDoctrine()->getRepository(System::class)->findBy(["user" => $this->getUser()->getUser(), "group" => true]);
  4971.             $systems = [
  4972.                 "computing" => [
  4973.                     "network" => [],
  4974.                     "security" => [],
  4975.                     "administration" => [],
  4976.                     "device" => [],
  4977.                     "software" => [],
  4978.                     "server" => [],
  4979.                 ],
  4980.                 "physical" => [
  4981.                     "partitioning" => [],
  4982.                     "information" => [],
  4983.                 ],
  4984.                 "action" => [
  4985.                     "minimization" => [],
  4986.                     "anonymization" => [],
  4987.                     "pseudonymization" => [],
  4988.                     "sensitization" => [],
  4989.                     "supervision" => [],
  4990.                     "destruction" => [],
  4991.                 ],
  4992.                 "supplier" => [
  4993.                     "supplier" => []
  4994.                 ]
  4995.             ];
  4996.             foreach ($systemsQuery as $system) {
  4997.                 $systems[$system->getType()][$system->getSubtype()][] = $system;
  4998.             }
  4999.             $spreadsheet = new Spreadsheet();
  5000.             $translateSubtypes = [
  5001.                 "network" => "Réseau",
  5002.                 "security" => "Sécurité",
  5003.                 "administration" => "Administration",
  5004.                 "device" => "Périphérique",
  5005.                 "software" => "Logiciel",
  5006.                 "server" => "Serveur",
  5007.                 "partitioning" => "Cloisonnement",
  5008.                 "minimization" => "Minimisation",
  5009.                 "anonymization" => "Anonymisation",
  5010.                 "pseudonymization" => "Pseudonymisation",
  5011.                 "sensitization" => "Sensibilisation et formation",
  5012.                 "information" => "Information",
  5013.                 "supervision" => "Contrôle",
  5014.                 "destruction" => "Destruction et suppression",
  5015.                 "supplier" => "Prestataires du SI"
  5016.             ];
  5017.             $i 0;
  5018.             foreach ($systems[$type] as $subtype => $systems) {
  5019.                 $i++;
  5020.                 $roomsWorkSheet = new Worksheet($spreadsheet$translateSubtypes[$subtype]);
  5021.                 $spreadsheet->addSheet($roomsWorkSheet$i);
  5022.                 $spreadsheet->setActiveSheetIndex($i);
  5023.                 $sheet $spreadsheet->getActiveSheet();
  5024.                 $sheet->setCellValue('A1''ID');
  5025.                 $sheet->setCellValue('B1''Nom');
  5026.                 switch ($subtype) {
  5027.                     case "network":
  5028.                         $sheet->setCellValue('C1''Type');
  5029.                         $sheet->setCellValue('D1''Informations complémentaires');
  5030.                         $sheet->setCellValue('E1''Type de Wifi');
  5031.                         $sheet->setCellValue('F1''Protocole Wifi');
  5032.                         break;
  5033.                     case "security":
  5034.                     case "administration":
  5035.                     case "device":
  5036.                     case "software":
  5037.                     case "server":
  5038.                         $sheet->setCellValue('C1''Type');
  5039.                         $sheet->setCellValue('D1''Informations complémentaires');
  5040.                         $sheet->setCellValue('E1''Date d\'achat');
  5041.                         $sheet->setCellValue('F1''N° d\'identification');
  5042.                         break;
  5043.                     case "partitioning":
  5044.                     case "minimization":
  5045.                     case "anonymization":
  5046.                     case "pseudonymization":
  5047.                     case "sensitization":
  5048.                     case "information":
  5049.                     case "supervision":
  5050.                     case "destruction":
  5051.                         $sheet->setCellValue('C1''Description');
  5052.                         $sheet->setCellValue('D1''Informations complémentaires');
  5053.                         break;
  5054.                     case "supplier":
  5055.                         $sheet->setCellValue('C1''Type');
  5056.                         break;
  5057.                     default:
  5058.                         throw new NotFoundHttpException();
  5059.                 }
  5060.                 $j 1;
  5061.                 foreach ($systems as $system) {
  5062.                     $j++;
  5063.                     $sheet->setCellValue('A'.$j$system->getId());
  5064.                     $sheet->setCellValue('B'.$j$system->getName());
  5065.                     switch ($subtype) {
  5066.                         case "network":
  5067.                             $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  5068.                             $sheet->setCellValue('D'.$j, isset($system->getData()[1])?$system->getData()[1]["value"]:null);
  5069.                             $sheet->setCellValue('E'.$j, isset($system->getData()[2])?$system->getData()[2]["value"]:null);
  5070.                             $sheet->setCellValue('F'.$j, isset($system->getData()[3])?$system->getData()[3]["value"]:null);
  5071.                             break;
  5072.                         case "security":
  5073.                         case "administration":
  5074.                         case "device":
  5075.                         case "software":
  5076.                         case "server":
  5077.                             $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  5078.                             $sheet->setCellValue('D'.$j, isset($system->getData()[1])?$system->getData()[1]["value"]:null);
  5079.                             $sheet->setCellValue('E'.$j, isset($system->getData()[2])?$system->getData()[2]["value"]:null);
  5080.                             $sheet->setCellValue('F'.$j, isset($system->getData()[3])?$system->getData()[3]["value"]:null);
  5081.                             break;
  5082.                         case "partitioning":
  5083.                         case "minimization":
  5084.                         case "anonymization":
  5085.                         case "pseudonymization":
  5086.                         case "sensitization":
  5087.                         case "information":
  5088.                         case "supervision":
  5089.                         case "destruction":
  5090.                             $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  5091.                             $sheet->setCellValue('D'.$j, isset($system->getData()[1])?$system->getData()[1]["value"]:null);
  5092.                             break;
  5093.                         case "supplier":
  5094.                             $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  5095.                             break;
  5096.                         default:
  5097.                             throw new NotFoundHttpException();
  5098.                     }
  5099.                 }
  5100.             }
  5101.             $spreadsheet->removeSheetByIndex(0);
  5102.             $writer = new Xlsx($spreadsheet);
  5103.             $response = new StreamedResponse();
  5104.             $response->setCallback(function () use ($writer) {
  5105.                 $writer->save('php://output');
  5106.             });
  5107.             $response->setStatusCode(200);
  5108.             $response->headers->set('Content-Type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  5109.             $response->headers->set('Content-Disposition''attachment;filename="export_cartographie.xlsx"');
  5110.             $response->headers->set('Cache-Control','max-age=0');
  5111.             return $response;
  5112.         } else {
  5113.             return $this->redirectToRoute("user_systems");
  5114.         }
  5115.     }
  5116.     /**
  5117.      * @Route("/incidents", name="incidents")
  5118.      */
  5119.     public function incidentsAction(Request $request)
  5120.     {
  5121.         if ($this->getUser()->getUser()->getParentUser()) {
  5122.             $incidents $this->getDoctrine()->getRepository(Incident::class)->findForUserWithGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser());
  5123.         } else {
  5124.             $incidents $this->getDoctrine()->getRepository(Incident::class)->findBy(["user" => $this->getUser()->getUser()]);
  5125.         }
  5126.         return $this->render('user/incidents.html.twig', [
  5127.             "incidents" => $incidents
  5128.         ]);
  5129.     }
  5130.     /**
  5131.      * @Route("/incidents/export", name="incidents_export")
  5132.      */
  5133.     public function incidentsExportAction(Request $request)
  5134.     {
  5135.         if ($this->isPrintingAllowed($this->getUser())) {
  5136.             if ($this->getUser()->getUser()->getParentUser()) {
  5137.                 $incidents $this->getDoctrine()->getRepository(Incident::class)->findForUserWithGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser());
  5138.             } else {
  5139.                 $incidents $this->getDoctrine()->getRepository(Incident::class)->findBy(["user" => $this->getUser()->getUser()]);
  5140.             }
  5141.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  5142.             $pdf->setUser($this->getUser()->getUser());
  5143.             $pdf->SetAuthor('myDigitplace');
  5144.             $pdf->SetTitle("Registre des incidents");
  5145.             $pdf->SetMargins(10,22,10true);
  5146.             $pdf->SetAutoPageBreak(TRUE35);
  5147.             $pdf->AddPage('L''A4');
  5148.             $html $this->renderView('user/pdf/incidents.html.twig', [
  5149.                 "incidents" => $incidents
  5150.             ]);
  5151.             $filename 'Registre_des_incidents';
  5152.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  5153.             return $pdf->Output($filename.".pdf",'I');
  5154.         } else {
  5155.             return $this->redirectToRoute("user_incidents");
  5156.         }
  5157.     }
  5158.     /**
  5159.      * @Route("/incidents/add", name="incidents_add")
  5160.      */
  5161.     public function incidentsAddAction(Request $requestSendEmailService $sendEmailService)
  5162.     {
  5163.         $incident = new Incident();
  5164.         $form $this->createForm(IncidentType::class, $incident);
  5165.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  5166.             $form->add('group'CheckboxType::class, [
  5167.                 'label' => "cet_incident_touche_le_groupe",
  5168.                 'required' => false,
  5169.                 'translation_domain' => 'messages',
  5170.             ]);
  5171.         }
  5172.         $form->handleRequest($request);
  5173.         if ($form->isSubmitted() && $form->isValid()) {
  5174.             $em $this->getDoctrine()->getManager();
  5175.             $now = new \DateTime("now");
  5176.             $incident->setCreationDate($now);
  5177.             $incident->setEditDate($now);
  5178.             $incident->setUser($this->getUser()->getUser());
  5179.             $em->persist($incident);
  5180.             $em->flush();
  5181.             /**
  5182.              * @var UploadedFile $file
  5183.              */
  5184.             $file $form->get('documentFile')->getData();
  5185.             if ($file != NULL) {
  5186.                 $fileName $this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  5187.                 $file->move(
  5188.                     $this->getParameter('documents_directory'), $fileName
  5189.                 );
  5190.                 $incident->setFile($fileName);
  5191.                 $em->flush();
  5192.             }
  5193.             $content "<p>Bonjour,<br/>
  5194.                         <br/>
  5195.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a ajouté un nouvel incident<br/>
  5196.                         <br/>
  5197.                         <br/>
  5198.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  5199.                         </p>";
  5200.             $sendEmailService->send(
  5201.                 "Nouvel incident client",
  5202.                 $this->getUser()->getUser()->getManager()->getEmail(),
  5203.                 'template_emails/left_text.html.twig',
  5204.                 [
  5205.                     "title" => "Nouvel incident client",
  5206.                     "content" => $content
  5207.                 ]
  5208.             );
  5209.             $this->get('session')->getFlashBag()->add('success''Nouvel incident ajouté');
  5210.             return $this->redirectToRoute("user_incidents");
  5211.         }
  5212.         return $this->render('user/incidents_add.html.twig', [
  5213.             "form" => $form->createView(),
  5214.         ]);
  5215.     }
  5216.     /**
  5217.      * @Route("/incidents/{id}/edit", name="incidents_edit")
  5218.      */
  5219.     public function incidentsEditAction(Request $requestSendEmailService $sendEmailServiceIncident $incident)
  5220.     {
  5221.         if ($incident->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  5222.             throw new NotFoundHttpException();
  5223.         }
  5224.         $form $this->createForm(IncidentType::class, $incident);
  5225.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  5226.             $form->add('group'CheckboxType::class, [
  5227.                 'label' => "cet_incident_touche_le_groupe",
  5228.                 'required' => false,
  5229.                 'translation_domain' => 'messages',
  5230.             ]);
  5231.         }
  5232.         $form->handleRequest($request);
  5233.         if ($form->isSubmitted() && $form->isValid()) {
  5234.             $em $this->getDoctrine()->getManager();
  5235.             $now = new \DateTime("now");
  5236.             $incident->setEditDate($now);
  5237.             $em->flush();
  5238.             /**
  5239.              * @var UploadedFile $file
  5240.              */
  5241.             $file $form->get('documentFile')->getData();
  5242.             if ($file != NULL) {
  5243.                 $fileName $this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  5244.                 $file->move(
  5245.                     $this->getParameter('documents_directory'), $fileName
  5246.                 );
  5247.                 $incident->setFile($fileName);
  5248.                 $em->flush();
  5249.             }
  5250.             $content "<p>Bonjour,<br/>
  5251.                         <br/>
  5252.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a modifié un incident<br/>
  5253.                         <br/>
  5254.                         <br/>
  5255.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  5256.                         </p>";
  5257.             $sendEmailService->send(
  5258.                 "Incident client modifié",
  5259.                 $this->getUser()->getUser()->getManager()->getEmail(),
  5260.                 'template_emails/left_text.html.twig',
  5261.                 [
  5262.                     "title" => "Incident client modifié",
  5263.                     "content" => $content
  5264.                 ]
  5265.             );
  5266.             $this->get('session')->getFlashBag()->add('success''Incident mis à jour');
  5267.             return $this->redirectToRoute("user_incidents");
  5268.         }
  5269.         return $this->render('user/incidents_edit.html.twig', [
  5270.             "incident" => $incident,
  5271.             "form" => $form->createView(),
  5272.         ]);
  5273.     }
  5274.     /**
  5275.      * @Route("/incidents/{id}/copy", name="incidents_copy")
  5276.      */
  5277.     public function incidentsCopyAction(Request $requestSendEmailService $sendEmailServiceIncident $incident)
  5278.     {
  5279.         if ($incident->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  5280.             throw new NotFoundHttpException();
  5281.         }
  5282.         $newIncident = clone $incident;
  5283.         $newIncident->setId(null);
  5284.         $form $this->createForm(IncidentType::class, $newIncident);
  5285.         $form->handleRequest($request);
  5286.         if ($form->isSubmitted() && $form->isValid()) {
  5287.             $em $this->getDoctrine()->getManager();
  5288.             $now = new \DateTime("now");
  5289.             $newIncident->setCreationDate($now);
  5290.             $newIncident->setEditDate($now);
  5291.             $newIncident->setUser($this->getUser()->getUser());
  5292.             $em->persist($newIncident);
  5293.             $em->flush();
  5294.             /**
  5295.              * @var UploadedFile $file
  5296.              */
  5297.             $file $form->get('documentFile')->getData();
  5298.             if ($file != NULL) {
  5299.                 $fileName $this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  5300.                 $file->move(
  5301.                     $this->getParameter('documents_directory'), $fileName
  5302.                 );
  5303.                 $newIncident->setFile($fileName);
  5304.                 $em->flush();
  5305.             }
  5306.             $content "<p>Bonjour,<br/>
  5307.                         <br/>
  5308.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a ajouté un nouvel incident<br/>
  5309.                         <br/>
  5310.                         <br/>
  5311.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  5312.                         </p>";
  5313.             $sendEmailService->send(
  5314.                 "Nouvel incident client",
  5315.                 $this->getUser()->getUser()->getManager()->getEmail(),
  5316.                 'template_emails/left_text.html.twig',
  5317.                 [
  5318.                     "title" => "Nouvel incident client",
  5319.                     "content" => $content
  5320.                 ]
  5321.             );
  5322.             $this->get('session')->getFlashBag()->add('success''Incident dupliqué');
  5323.             return $this->redirectToRoute("user_incidents");
  5324.         }
  5325.         return $this->render('user/incidents_add.html.twig', [
  5326.             "form" => $form->createView(),
  5327.         ]);
  5328.     }
  5329.     /**
  5330.      * @Route("/incidents/{id}/delete", name="incidents_delete")
  5331.      */
  5332.     public function incidentsDeleteAction(Request $requestIncident $incident)
  5333.     {
  5334.         if ($incident->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  5335.             throw new NotFoundHttpException();
  5336.         }
  5337.         $em $this->getDoctrine()->getManager();
  5338.         $em->remove($incident);
  5339.         $em->flush();
  5340.         $this->get('session')->getFlashBag()->add('success''Incident supprimé');
  5341.         return $this->redirectToRoute("user_incidents");
  5342.     }
  5343.     /**
  5344.      * @Route("/incidents/{id}/view", name="incidents_view")
  5345.      */
  5346.     public function incidentsViewAction(Request $requestIncident $incident)
  5347.     {
  5348.         if ($incident->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  5349.             if (!$incident->isGroup() || !$this->getUser()->getUser()->getParentUser() || ($this->getUser()->getUser()->getParentUser() && $incident->getUser()->getId() != $this->getUser()->getUser()->getParentUser()->getId())) {
  5350.                 throw new NotFoundHttpException();
  5351.             }
  5352.         }
  5353.         $form $this->createForm(IncidentViewType::class, $incident);
  5354.         return $this->render('user/incidents_view.html.twig', [
  5355.             "form" => $form->createView(),
  5356.             "incident" => $incident
  5357.         ]);
  5358.     }
  5359.     /**
  5360.      * @Route("/actions", name="actions")
  5361.      */
  5362.     public function actionsAction(Request $request)
  5363.     {
  5364.         $actions $this->getDoctrine()->getRepository(Action::class)->findForUserWithGroup($this->getUser()->getUser());
  5365.         $actionsStats = [
  5366.             "total" => 0,
  5367.             "invalid" => 0,
  5368.             "valid" => 0,
  5369.         ];
  5370.         foreach ($actions as $action) {
  5371.             $actionsStats["total"]++;
  5372.             if ($action->isTerminated()) {
  5373.                 $actionsStats["valid"]++;
  5374.             } else {
  5375.                 $actionsStats["invalid"]++;
  5376.             }
  5377.         }
  5378.         $filteredActions $this->getDoctrine()->getRepository(Action::class)->findForUserWithGroupNotTerminated($this->getUser()->getUser());
  5379.         $groupActions $this->getDoctrine()->getRepository(Action::class)->findGroupsForUser($this->getUser()->getUser());
  5380.         return $this->render('user/actions.html.twig', [
  5381.             "actions" => $filteredActions,
  5382.             "groupActions" => $groupActions,
  5383.             "actionsStats" => $actionsStats,
  5384.             "filter" => null,
  5385.         ]);
  5386.     }
  5387.     /**
  5388.      * @Route("/actions/terminated", name="actions_terminated")
  5389.      */
  5390.     public function actionsTerminatedAction(Request $request)
  5391.     {
  5392.         $actions $this->getDoctrine()->getRepository(Action::class)->findForUserWithGroup($this->getUser()->getUser());
  5393.         $actionsStats = [
  5394.             "total" => 0,
  5395.             "invalid" => 0,
  5396.             "valid" => 0,
  5397.         ];
  5398.         foreach ($actions as $action) {
  5399.             $actionsStats["total"]++;
  5400.             if ($action->isTerminated()) {
  5401.                 $actionsStats["valid"]++;
  5402.             } else {
  5403.                 $actionsStats["invalid"]++;
  5404.             }
  5405.         }
  5406.         $filteredActions $this->getDoctrine()->getRepository(Action::class)->findForUserWithGroupTerminated($this->getUser()->getUser());
  5407.         return $this->render('user/actions_terminated.html.twig', [
  5408.             "actions" => $filteredActions,
  5409.             "actionsStats" => $actionsStats,
  5410.             "filter" => null,
  5411.         ]);
  5412.     }
  5413.     /**
  5414.      * @Route("/actions/standardize/{id}", name="actions_standardize")
  5415.      */
  5416.     public function actionsStandardizeAction(Request $requestSecurity $securityAction $action)
  5417.     {
  5418.         $em $this->getDoctrine()->getManager();
  5419.         $actionStd = new ActionStd();
  5420.         $actionStd->setName($action->getName());
  5421.         $actionStd->setBudget($action->getBudget());
  5422.         $actionStd->setGoal($action->getGoal());
  5423.         $actionStd->setInformation($action->getInformation());
  5424.         $actionStd->setUsefulLink($action->getUsefulLink());
  5425.         $actionStd->setDate($action->getDate());
  5426.         $actionStd->setEditDate($action->getEditDate());
  5427.         $actionStd->setDocuments($action->getDocuments());
  5428.         $actionStd->setSheets($action->getSheets());
  5429.         $token $security->getToken();
  5430.         if ($token instanceof SwitchUserToken) {
  5431.             $impersonatorUser $token->getOriginalToken()->getUser();
  5432.             if ($impersonatorUser) {
  5433.                 if ($impersonatorUser->getManager()) {
  5434.                     $originalManager $em->getRepository(Manager::class)->find($impersonatorUser->getManager()->getId());
  5435.                     if ($originalManager) {
  5436.                         $actionStd->setManager($originalManager);
  5437.                     }
  5438.                 }
  5439.             }
  5440.         }
  5441.         $em->persist($actionStd);
  5442.         $em->flush();
  5443.         $this->get('session')->getFlashBag()->add('success''Nouvelle action standard générée');
  5444.         return $this->redirectToRoute("user_actions");
  5445.     }
  5446.     /**
  5447.      * @Route("/actions/export", name="actions_export")
  5448.      */
  5449.     public function actionsExportAction(Request $request)
  5450.     {
  5451.         if ($this->isPrintingAllowed($this->getUser())) {
  5452.             $actions $this->getDoctrine()->getRepository(Action::class)->findForUserWithGroup($this->getUser()->getUser());
  5453.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  5454.             $pdf->setUser($this->getUser()->getUser());
  5455.             $pdf->SetAuthor('myDigitplace');
  5456.             $pdf->SetTitle("Plan d'actions");
  5457.             $pdf->SetMargins(10,22,10true);
  5458.             $pdf->SetAutoPageBreak(TRUE35);
  5459.             $pdf->AddPage('L''A4');
  5460.             $html $this->renderView('user/pdf/actions.html.twig', [
  5461.                 "actions" => $actions
  5462.             ]);
  5463.             $filename 'plan_d_actions';
  5464.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  5465.             return $pdf->Output($filename.".pdf",'I');
  5466.         } else {
  5467.             return $this->redirectToRoute("user_actions");
  5468.         }
  5469.     }
  5470.     /**
  5471.      * @Route("/actions/add", name="actions_add")
  5472.      */
  5473.     public function actionsAddAction(Request $requestSendEmailService $sendEmailService)
  5474.     {
  5475.         $action = new Action();
  5476.         $user $this->getUser()->getUser();
  5477.         $form $this->createForm(ActionType::class, $action)
  5478.             ->add('treatments'EntityType::class, [
  5479.                 'attr' => array(
  5480.                     'placeholder' => 'traitements_lis',
  5481.                 ),
  5482.                 'placeholder' => 'traitements_lis',
  5483.                 'label' => 'selectionnez_les_traitements_lies',
  5484.                 'expanded' => false,
  5485.                 'multiple' => true,
  5486.                 'required' => false,
  5487.                 'translation_domain' => 'messages',
  5488.                 'class' => Treatment::class,
  5489.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  5490.                     return $er->createQueryBuilder('t')
  5491.                         ->where('t.user = :user')
  5492.                         ->setParameters(["user" => $user]);
  5493.                 },
  5494.                 'choice_label' => function(Treatment $treatment) {
  5495.                     return $treatment->getName();
  5496.                 },
  5497.             ])
  5498.             ->add('sheets'EntityType::class, [
  5499.                 'attr' => array(
  5500.                     'placeholder' => 'annexer_des_fiches_pratiques',
  5501.                 ),
  5502.                 'placeholder' => 'annexer_des_fiches_pratiques',
  5503.                 'label' => 'annexer_des_fiches_pratiques',
  5504.                 'expanded' => false,
  5505.                 'multiple' => true,
  5506.                 'required' => false,
  5507.                 'translation_domain' => 'messages',
  5508.                 'class' => Document::class,
  5509.                 'query_builder' => function (EntityRepository $er) {
  5510.                     return $er->createQueryBuilder('d')
  5511.                         ->leftJoin("d.type""t")
  5512.                         ->leftJoin("t.parent""pt")
  5513.                         ->where('t.id = 2')
  5514.                         ->orWhere('pt.id = 2')
  5515.                         ->addOrderBy("d.name""ASC")
  5516.                         ->addOrderBy("d.filename""ASC");
  5517.                 }
  5518.             ]);
  5519.         if ($this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  5520.             $form->add('forDpo'CheckboxType::class, [
  5521.                 'label' => "action_a_realiser_par_mdp",
  5522.                 'required' => false,
  5523.                 'translation_domain' => 'messages',
  5524.             ])
  5525.                 ->add('estimationTime'NumberType::class, [
  5526.                     'attr' => [
  5527.                         'placeholder' => 'temps_de_realisation_facture_en_heures'
  5528.                     ],
  5529.                     'label' => 'temps_de_realisation_facture_en_heures',
  5530.                     'required' => false,
  5531.                     'translation_domain' => 'messages',
  5532.                 ])
  5533.                 ->add('realTime'NumberType::class, [
  5534.                     'attr' => [
  5535.                         'placeholder' => 'temps_de_realisation_en_heures'
  5536.                     ],
  5537.                     'label' => 'temps_de_realisation_en_heures',
  5538.                     'required' => false,
  5539.                     'translation_domain' => 'messages',
  5540.                 ]);
  5541.         } else {
  5542.             $form->add('estimationTime'NumberType::class, [
  5543.                     'attr' => [
  5544.                         'placeholder' => 'temps_de_realisation_estime_en_heures'
  5545.                     ],
  5546.                     'label' => 'temps_de_realisation_estime_en_heures',
  5547.                     'required' => false,
  5548.                     'translation_domain' => 'messages',
  5549.                 ])
  5550.                 ->add('realTime'NumberType::class, [
  5551.                     'attr' => [
  5552.                         'placeholder' => 'temps_de_realisation_en_heures'
  5553.                     ],
  5554.                     'label' => 'temps_de_realisation_en_heures',
  5555.                     'required' => false,
  5556.                     'translation_domain' => 'messages',
  5557.                 ]);
  5558.         }
  5559.         $fromStd false;
  5560.         $actionStd null;
  5561.         if (isset($_GET['std'])) {
  5562.             $actionStd $this->getDoctrine()->getRepository(ActionStd::class)->find($_GET['std']);
  5563.             if ($actionStd) {
  5564.                 $fromStd true;
  5565.                 $form['name']->setData($actionStd->getName());
  5566.                 $form['budget']->setData($actionStd->getBudget());
  5567.                 $form['goal']->setData($actionStd->getGoal());
  5568.                 $form['information']->setData($actionStd->getInformation());
  5569.                 $form['usefulLink']->setData($actionStd->getUsefulLink());
  5570.                 $form['sheets']->setData($actionStd->getSheets());
  5571.             }
  5572.         }
  5573.         $form->handleRequest($request);
  5574.         if ($form->isSubmitted() && $form->isValid()) {
  5575.             $em $this->getDoctrine()->getManager();
  5576.             $now = new \DateTime("now");
  5577.             $action->setDate($now);
  5578.             $action->setEditDate($now);
  5579.             $action->setUser($this->getUser()->getUser());
  5580.             if ($this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  5581.                 $action->setByManager(true);
  5582.             }
  5583.             $em->persist($action);
  5584.             $em->flush();
  5585.             if ($this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  5586.                 if ($action->isForDpo()) {
  5587.                     if ($action->getEstimationTime()) {
  5588.                         $credit = new Credit();
  5589.                         $credit->setCreationDate($now);
  5590.                         $credit->setUser($user);
  5591.                         $credit->setTitle("Action : ".$action->getName());
  5592.                         $credit->setStock(-$action->getEstimationTime());
  5593.                         $credit->convertToDecimal(true);
  5594.                         $em->persist($credit);
  5595.                         $em->flush();
  5596.                         $user->setCredit($user->getCredit() + $credit->getStock());
  5597.                         $em->flush();
  5598.                     }
  5599.                 }
  5600.             }
  5601.             if ($fromStd) {
  5602.                 if ($actionStd) {
  5603.                     $filesystem = new Filesystem();
  5604.                     foreach ($actionStd->getDocuments() as $document) {
  5605.                         if (isset($_POST["appbundle_action_documents_".$document->getId()]) && !empty($_POST["appbundle_action_documents_".$document->getId()])) {
  5606.                             $fileName $document->getFilename();
  5607.                             $childFileName $this->getUser()->getUser()->getId()."_".$fileName;
  5608.                             $filesystem->copy($this->getParameter('documents_directory').$fileName$this->getParameter('documents_directory').$childFileName);
  5609.                             $newDocument = new UserDocument();
  5610.                             $newDocument->setName($document->getName());
  5611.                             $newDocument->setFilename($childFileName);
  5612.                             $newDocument->setUserFilename($document->getUserFilename());
  5613.                             $newDocument->setUser($this->getUser()->getUser());
  5614.                             $newDocument->setAction($action);
  5615.                             $em->persist($newDocument);
  5616.                             $em->flush();
  5617.                         }
  5618.                     }
  5619.                 }
  5620.             }
  5621.             if (isset($_FILES['appbundle_action_documents'])) {
  5622.                 $files $_FILES['appbundle_action_documents'];
  5623.                 $fileNames $_POST['appbundle_action_documents_names'];
  5624.                 for ($i=0;$i<count($files['name']);$i++) {
  5625.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  5626.                         $name $files["name"][$i];
  5627.                         $parts explode("."$name);
  5628.                         $extension end($parts);
  5629.                         $fileName $action->getId()."_".md5(uniqid()) . '.' $extension;
  5630.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  5631.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  5632.                         $document = new UserDocument();
  5633.                         $document->setName($docTitle);
  5634.                         $document->setFilename($fileName);
  5635.                         $document->setUserFilename($files["name"][$i]);
  5636.                         $document->setUser($this->getUser()->getUser());
  5637.                         $document->setAction($action);
  5638.                         $em->persist($document);
  5639.                         $em->flush();
  5640.                     }
  5641.                 }
  5642.             }
  5643.             $content "<p>Bonjour,<br/>
  5644.                         <br/>
  5645.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a ajouté une nouvelle action: ".$action->getName()."<br/>
  5646.                         <br/>
  5647.                         <br/>
  5648.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  5649.                         </p>";
  5650.             $sendEmailService->send(
  5651.                 "Nouvelle action client",
  5652.                 $this->getUser()->getUser()->getManager()->getEmail(),
  5653.                 'template_emails/left_text.html.twig',
  5654.                 [
  5655.                     "title" => "Nouvelle action client",
  5656.                     "content" => $content
  5657.                 ]
  5658.             );
  5659.             $this->get('session')->getFlashBag()->add('success''Nouvelle action ajoutée');
  5660.             if ($action->getAccountantEmail()) {
  5661.                 if (filter_var($action->getAccountantEmail(), FILTER_VALIDATE_EMAIL)) {
  5662.                     $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  5663.                     $pdf->setUser($this->getUser()->getUser());
  5664.                     $pdf->SetAuthor('myDigitplace');
  5665.                     $pdf->SetTitle("Fiche action");
  5666.                     $pdf->SetMargins(10,22,10true);
  5667.                     $pdf->SetAutoPageBreak(TRUE35);
  5668.                     $pdf->AddPage('P''A4');
  5669.                     $filename 'fiche_action';
  5670.                     $html $this->renderView('user/pdf/action.html.twig', [
  5671.                         "action" => $action
  5672.                     ]);
  5673.                     $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  5674.                     $filePath1 tempnam(sys_get_temp_dir(), 'FicheAction');
  5675.                     $file1 fopen($filePath1"w");
  5676.                     fwrite($file1$pdf->Output($filePath1'F'));
  5677.                     $meta_data1 stream_get_meta_data($file1);
  5678.                     $path1 $meta_data1['uri'];
  5679.                     fclose($file1);
  5680.                     if (count($action->getDocuments()) || count($action->getSheets())) {
  5681.                         $filesToAdd = [];
  5682.                         foreach ($action->getDocuments() as $document) {
  5683.                             if ($document->getFilename()) {
  5684.                                 if (substr($document->getFilename(), -3) == "pdf") {
  5685.                                     $path2 $this->projectDir '/../web/uploads/documents/'.$document->getFilename();
  5686.                                     if (file_exists($path2)) {
  5687.                                         $filepdf fopen($path2,"r");
  5688.                                         if ($filepdf) {
  5689.                                             $line_first fgets($filepdf);
  5690.                                             preg_match_all('!\d+!'$line_first$matches);
  5691.                                             $pdfversion implode('.'$matches[0]);
  5692.                                             if($pdfversion <= "1.4"){
  5693.                                                 $filesToAdd[] = $path2;
  5694.                                             }
  5695.                                             fclose($filepdf);
  5696.                                         }
  5697.                                     }
  5698.                                 }
  5699.                             }
  5700.                         }
  5701.                         foreach ($action->getSheets() as $sheet) {
  5702.                             if ($sheet->getFilename()) {
  5703.                                 if (substr($sheet->getFilename(), -3) == "pdf") {
  5704.                                     $path2 $this->projectDir '/../web/uploads/documents/'.$sheet->getFilename();
  5705.                                     if (file_exists($path2)) {
  5706.                                         $filepdf fopen($path2,"r");
  5707.                                         if ($filepdf) {
  5708.                                             $line_first fgets($filepdf);
  5709.                                             preg_match_all('!\d+!'$line_first$matches);
  5710.                                             $pdfversion implode('.'$matches[0]);
  5711.                                             if($pdfversion <= "1.4"){
  5712.                                                 $filesToAdd[] = $path2;
  5713.                                             }
  5714.                                             fclose($filepdf);
  5715.                                         }
  5716.                                     }
  5717.                                 }
  5718.                             }
  5719.                         }
  5720.                         $nbFiles count($filesToAdd);
  5721.                         if ($nbFiles) {
  5722.                             $i 1;
  5723.                             foreach ($filesToAdd as $path2) {
  5724.                                 $file2merge = [$path1$path2];
  5725.                                 $pdfConcat = new Pdf_concat();
  5726.                                 $pdfConcat->setFiles($file2merge);
  5727.                                 $pdfConcat->concat();
  5728.                                 $pdfConcat->SetAuthor('myDigitplace');
  5729.                                 $pdfConcat->SetTitle("Fiche action");
  5730.                                 $filePath1 tempnam(sys_get_temp_dir(), 'FicheAction');
  5731.                                 $file1 fopen($filePath1"w");
  5732.                                 fwrite($file1$pdfConcat->Output('F'$filePath1));
  5733.                                 $meta_data1 stream_get_meta_data($file1);
  5734.                                 $path1 $meta_data1['uri'];
  5735.                                 fclose($file1);
  5736.                                 $i++;
  5737.                             }
  5738.                         }
  5739.                     }
  5740.                     $content "<p>Bonjour,<br/>
  5741.                     <br/>
  5742.                     Vous avez été assigné comme responsable d'une nouvelle action.<br/>
  5743.                     Pour plus de détails sur cette action, vous pouvez consulter le document en pièce jointe.<br/>
  5744.                     <br/>
  5745.                     <br/>
  5746.                     <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  5747.                     </p>";
  5748.                     $sendEmailService->send(
  5749.                         "Nouvelle action",
  5750.                         $action->getAccountantEmail(),
  5751.                         'template_emails/left_text.html.twig',
  5752.                         [
  5753.                             "title" => "Nouvelle action",
  5754.                             "content" => $content
  5755.                         ],
  5756.                         [
  5757.                             [
  5758.                                 'path' => $path1,
  5759.                                 'fileName' => "fiche_action.pdf",
  5760.                             ]
  5761.                         ]
  5762.                     );
  5763.                 }
  5764.             }
  5765.             return $this->redirectToRoute("user_actions");
  5766.         }
  5767.         $actionsStd $this->getDoctrine()->getRepository(ActionStd::class)->findBy([], ["name" => "ASC"]);
  5768.         return $this->render('user/actions_add.html.twig', [
  5769.             "form" => $form->createView(),
  5770.             "actionsStd" => $actionsStd,
  5771.             "fromStd" => $fromStd,
  5772.             "actionStd" => $actionStd,
  5773.             "isAdmin" => $this->isGranted("ROLE_PREVIOUS_ADMIN")
  5774.         ]);
  5775.     }
  5776.     /**
  5777.      * @Route("/actions/{id}/edit", name="actions_edit")
  5778.      */
  5779.     public function actionsEditAction(Request $requestSendEmailService $sendEmailServiceAction $action)
  5780.     {
  5781.         if ($action->getUser()->getId() != $this->getUser()->getUser()->getId() && !$action->getGroupUser() && $action->getGroupUser()->getId() != $this->getUser()->getUser()->getId()) {
  5782.             throw new NotFoundHttpException();
  5783.         }
  5784.         $currentEstimatedTime $action->getEstimationTime();
  5785.         $user $this->getUser()->getUser();
  5786.         if ($action->isByGroup()) {
  5787.             $form $this->createForm(ActionEditGrpType::class, $action);
  5788.         } else {
  5789.             $form $this->createForm(ActionType::class, $action);
  5790.         }
  5791.         $form->add('treatments'EntityType::class, [
  5792.                 'attr' => array(
  5793.                     'placeholder' => 'traitements_lis',
  5794.                 ),
  5795.                 'placeholder' => 'traitements_lis',
  5796.                 'label' => 'selectionnez_les_traitements_lies',
  5797.                 'expanded' => false,
  5798.                 'multiple' => true,
  5799.                 'required' => false,
  5800.                 'translation_domain' => 'messages',
  5801.                 'class' => Treatment::class,
  5802.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  5803.                     return $er->createQueryBuilder('t')
  5804.                         ->where('t.user = :user')
  5805.                         ->setParameters(["user" => $user]);
  5806.                 },
  5807.                 'choice_label' => function(Treatment $treatment) {
  5808.                     return $treatment->getName();
  5809.                 },
  5810.             'disabled' => $action->isByGroup()?true:false,
  5811.             ])
  5812.             ->add('sheets'EntityType::class, [
  5813.                 'attr' => array(
  5814.                     'placeholder' => 'annexer_des_fiches_pratiques',
  5815.                 ),
  5816.                 'placeholder' => 'annexer_des_fiches_pratiques',
  5817.                 'label' => 'annexer_des_fiches_pratiques',
  5818.                 'expanded' => false,
  5819.                 'multiple' => true,
  5820.                 'required' => false,
  5821.                 'translation_domain' => 'messages',
  5822.                 'class' => Document::class,
  5823.                 'query_builder' => function (EntityRepository $er) {
  5824.                     return $er->createQueryBuilder('d')
  5825.                         ->leftJoin("d.type""t")
  5826.                         ->leftJoin("t.parent""pt")
  5827.                         ->where('t.id = 2')
  5828.                         ->orWhere('pt.id = 2')
  5829.                         ->addOrderBy("d.name""ASC")
  5830.                         ->addOrderBy("d.filename""ASC");
  5831.                 },
  5832.                 'disabled' => $action->isByGroup()?true:false,
  5833.             ]);
  5834.         if (!$action->isByGroup() && $this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  5835.             $form->add('forDpo'CheckboxType::class, [
  5836.                 'label' => "action_a_realiser_par_mdp",
  5837.                 'required' => false,
  5838.                 'translation_domain' => 'messages',
  5839.             ])
  5840.                 ->add('estimationTime'NumberType::class, [
  5841.                     'attr' => [
  5842.                         'placeholder' => 'temps_de_realisation_facture_en_heures'
  5843.                     ],
  5844.                     'label' => 'temps_de_realisation_facture_en_heures',
  5845.                     'required' => false,
  5846.                     'translation_domain' => 'messages',
  5847.                 ])
  5848.                 ->add('realTime'NumberType::class, [
  5849.                     'attr' => [
  5850.                         'placeholder' => 'temps_de_realisation_en_heures'
  5851.                     ],
  5852.                     'label' => 'temps_de_realisation_en_heures',
  5853.                     'required' => false,
  5854.                     'translation_domain' => 'messages',
  5855.                 ]);
  5856.         } else {
  5857.             $form->add('estimationTime'NumberType::class, [
  5858.                 'attr' => [
  5859.                     'placeholder' => 'temps_de_realisation_estime_en_heures'
  5860.                 ],
  5861.                 'label' => 'temps_de_realisation_estime_en_heures',
  5862.                 'required' => false,
  5863.                 'translation_domain' => 'messages',
  5864.             ])
  5865.                 ->add('realTime'NumberType::class, [
  5866.                     'attr' => [
  5867.                         'placeholder' => 'temps_de_realisation_en_heures'
  5868.                     ],
  5869.                     'label' => 'temps_de_realisation_en_heures',
  5870.                     'required' => false,
  5871.                     'translation_domain' => 'messages',
  5872.                 ]);
  5873.         }
  5874.         $form->handleRequest($request);
  5875.         if ($form->isSubmitted() && $form->isValid()) {
  5876.             $em $this->getDoctrine()->getManager();
  5877.             $now = new \DateTime("now");
  5878.             $action->setEditDate($now);
  5879.             $em->flush();
  5880.             if (!$action->isByGroup() && $this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  5881.                 if ($action->isForDpo()) {
  5882.                     if ($currentEstimatedTime == && $action->getEstimationTime()) {
  5883.                         $credit = new Credit();
  5884.                         $credit->setCreationDate($now);
  5885.                         $credit->setUser($user);
  5886.                         $credit->setTitle("Action : ".$action->getName());
  5887.                         $credit->setStock(-$action->getEstimationTime());
  5888.                         $credit->convertToDecimal(true);
  5889.                         $em->persist($credit);
  5890.                         $em->flush();
  5891.                         $user->setCredit($user->getCredit() + $credit->getStock());
  5892.                         $em->flush();
  5893.                     }
  5894.                 }
  5895.             }
  5896.             foreach ($action->getDocuments() as $document) {
  5897.                 if (isset($_POST["appbundle_action_documents_".$document->getId()]) && !empty($_POST["appbundle_action_documents_".$document->getId()])) {
  5898.                     if ($document->getName() != $_POST["appbundle_action_documents_".$document->getId()]) {
  5899.                         $document->setTitle($_POST["appbundle_action_documents_".$document->getId()]);
  5900.                         $em->flush();
  5901.                     }
  5902.                 }
  5903.             }
  5904.             if (isset($_FILES['appbundle_action_documents'])) {
  5905.                 $files $_FILES['appbundle_action_documents'];
  5906.                 $fileNames $_POST['appbundle_action_documents_names'];
  5907.                 for ($i=0;$i<count($files['name']);$i++) {
  5908.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  5909.                         $name $files["name"][$i];
  5910.                         $parts explode("."$name);
  5911.                         $extension end($parts);
  5912.                         $fileName $action->getId()."_".md5(uniqid()) . '.' $extension;
  5913.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  5914.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  5915.                         $document = new UserDocument();
  5916.                         $document->setName($docTitle);
  5917.                         $document->setFilename($fileName);
  5918.                         $document->setUserFilename($files["name"][$i]);
  5919.                         $document->setUser($this->getUser()->getUser());
  5920.                         $document->setAction($action);
  5921.                         $em->persist($document);
  5922.                         $em->flush();
  5923.                     }
  5924.                 }
  5925.             }
  5926.             $content "<p>Bonjour,<br/>
  5927.                         <br/>
  5928.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a modifié l'action ".$action->getName()."<br/>
  5929.                         <br/>
  5930.                         <br/>
  5931.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  5932.                         </p>";
  5933.             $sendEmailService->send(
  5934.                 "Action client modifiée",
  5935.                 $this->getUser()->getUser()->getManager()->getEmail(),
  5936.                 'template_emails/left_text.html.twig',
  5937.                 [
  5938.                     "title" => "Action client modifiée",
  5939.                     "content" => $content
  5940.                 ]
  5941.             );
  5942.             $this->get('session')->getFlashBag()->add('success''Action mise à jour');
  5943.             return $this->redirectToRoute("user_actions");
  5944.         }
  5945.         return $this->render($action->isByGroup() ? 'user/actions_grp_edit.html.twig' 'user/actions_edit.html.twig', [
  5946.             "action" => $action,
  5947.             "form" => $form->createView(),
  5948.             "isAdmin" => $this->isGranted("ROLE_PREVIOUS_ADMIN")
  5949.         ]);
  5950.     }
  5951.     /**
  5952.      * @Route("/actions/{id}/copy", name="actions_copy")
  5953.      */
  5954.     public function actionsCopyAction(Request $requestSendEmailService $sendEmailServiceAction $action)
  5955.     {
  5956.         if ($action->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  5957.             throw new NotFoundHttpException();
  5958.         }
  5959.         $newAction = clone $action;
  5960.         $newAction->setId(null);
  5961.         $newAction->getDocuments()->clear();
  5962.         $newAction->getTreatments()->clear();
  5963.         $user $this->getUser()->getUser();
  5964.         $form $this->createForm(ActionType::class, $newAction)
  5965.             ->add('treatments'EntityType::class, [
  5966.                 'attr' => array(
  5967.                     'placeholder' => 'traitements_lis',
  5968.                 ),
  5969.                 'placeholder' => 'traitements_lis',
  5970.                 'label' => 'selectionnez_les_traitements_lies',
  5971.                 'expanded' => false,
  5972.                 'multiple' => true,
  5973.                 'required' => false,
  5974.                 'translation_domain' => 'messages',
  5975.                 'class' => Treatment::class,
  5976.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  5977.                     return $er->createQueryBuilder('t')
  5978.                         ->where('t.user = :user')
  5979.                         ->setParameters(["user" => $user]);
  5980.                 },
  5981.                 'choice_label' => function(Treatment $treatment) {
  5982.                     return $treatment->getName();
  5983.                 },
  5984.             ])
  5985.             ->add('sheets'EntityType::class, [
  5986.                 'attr' => array(
  5987.                     'placeholder' => 'annexer_des_fiches_pratiques',
  5988.                 ),
  5989.                 'placeholder' => 'annexer_des_fiches_pratiques',
  5990.                 'label' => 'annexer_des_fiches_pratiques',
  5991.                 'expanded' => false,
  5992.                 'multiple' => true,
  5993.                 'required' => false,
  5994.                 'translation_domain' => 'messages',
  5995.                 'class' => Document::class,
  5996.                 'query_builder' => function (EntityRepository $er) {
  5997.                     return $er->createQueryBuilder('d')
  5998.                         ->leftJoin("d.type""t")
  5999.                         ->leftJoin("t.parent""pt")
  6000.                         ->where('t.id = 2')
  6001.                         ->orWhere('pt.id = 2')
  6002.                         ->addOrderBy("d.name""ASC")
  6003.                         ->addOrderBy("d.filename""ASC");
  6004.                 }
  6005.             ]);
  6006.         if ($this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  6007.             $form->add('forDpo'CheckboxType::class, [
  6008.                 'label' => "action_a_realiser_par_mdp",
  6009.                 'required' => false,
  6010.                 'translation_domain' => 'messages',
  6011.             ])
  6012.                 ->add('estimationTime'NumberType::class, [
  6013.                     'attr' => [
  6014.                         'placeholder' => 'temps_de_realisation_facture_en_heures'
  6015.                     ],
  6016.                     'label' => 'temps_de_realisation_facture_en_heures',
  6017.                     'required' => false,
  6018.                     'translation_domain' => 'messages',
  6019.                 ])
  6020.                 ->add('realTime'NumberType::class, [
  6021.                     'attr' => [
  6022.                         'placeholder' => 'temps_de_realisation_en_heures'
  6023.                     ],
  6024.                     'label' => 'temps_de_realisation_en_heures',
  6025.                     'required' => false,
  6026.                     'translation_domain' => 'messages',
  6027.                 ]);
  6028.         } else {
  6029.             $form->add('estimationTime'NumberType::class, [
  6030.                 'attr' => [
  6031.                     'placeholder' => 'temps_de_realisation_estime_en_heures'
  6032.                 ],
  6033.                 'label' => 'temps_de_realisation_estime_en_heures',
  6034.                 'required' => false,
  6035.                 'translation_domain' => 'messages',
  6036.             ])
  6037.                 ->add('realTime'NumberType::class, [
  6038.                     'attr' => [
  6039.                         'placeholder' => 'temps_de_realisation_en_heures'
  6040.                     ],
  6041.                     'label' => 'temps_de_realisation_en_heures',
  6042.                     'required' => false,
  6043.                     'translation_domain' => 'messages',
  6044.                 ]);
  6045.         }
  6046.         $form->handleRequest($request);
  6047.         if ($form->isSubmitted() && $form->isValid()) {
  6048.             $em $this->getDoctrine()->getManager();
  6049.             $now = new \DateTime("now");
  6050.             $newAction->setDate($now);
  6051.             $newAction->setEditDate($now);
  6052.             $newAction->setUser($this->getUser()->getUser());
  6053.             if ($this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  6054.                 $newAction->setByManager(true);
  6055.             }
  6056.             $em->persist($newAction);
  6057.             $em->flush();
  6058.             if (isset($_FILES['appbundle_action_documents'])) {
  6059.                 $files $_FILES['appbundle_action_documents'];
  6060.                 $fileNames $_POST['appbundle_action_documents_names'];
  6061.                 for ($i=0;$i<count($files['name']);$i++) {
  6062.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  6063.                         $name $files["name"][$i];
  6064.                         $parts explode("."$name);
  6065.                         $extension end($parts);
  6066.                         $fileName $newAction->getId()."_".md5(uniqid()) . '.' $extension;
  6067.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  6068.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  6069.                         $document = new UserDocument();
  6070.                         $document->setName($docTitle);
  6071.                         $document->setFilename($fileName);
  6072.                         $document->setUserFilename($files["name"][$i]);
  6073.                         $document->setUser($this->getUser()->getUser());
  6074.                         $document->setAction($newAction);
  6075.                         $em->persist($document);
  6076.                         $em->flush();
  6077.                     }
  6078.                 }
  6079.             }
  6080.             $content "<p>Bonjour,<br/>
  6081.                         <br/>
  6082.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a ajouté une nouvelle action: ".$newAction->getName()."<br/>
  6083.                         <br/>
  6084.                         <br/>
  6085.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  6086.                         </p>";
  6087.             $sendEmailService->send(
  6088.                 "Nouvelle action client",
  6089.                 $this->getUser()->getUser()->getManager()->getEmail(),
  6090.                 'template_emails/left_text.html.twig',
  6091.                 [
  6092.                     "title" => "Nouvelle action client",
  6093.                     "content" => $content
  6094.                 ]
  6095.             );
  6096.             $this->get('session')->getFlashBag()->add('success''Action dupliquée');
  6097.             return $this->redirectToRoute("user_actions");
  6098.         }
  6099.         $actionsStd $this->getDoctrine()->getRepository(ActionStd::class)->findBy([], ["name" => "ASC"]);
  6100.         return $this->render('user/actions_add.html.twig', [
  6101.             "action"        => $action,
  6102.             "actionsStd"    => $actionsStd,
  6103.             "form"          => $form->createView()
  6104.         ]);
  6105.     }
  6106.     /**
  6107.      * @Route("/actions/{id}/delete", name="actions_delete")
  6108.      */
  6109.     public function actionsDeleteAction(Request $requestAction $action)
  6110.     {
  6111.         if ($action->getUser()->getId() != $this->getUser()->getUser()->getId() && !$action->getGroupUser() && $action->getGroupUser()->getId() != $this->getUser()->getUser()->getId()) {
  6112.             throw new NotFoundHttpException();
  6113.         }
  6114.         $em $this->getDoctrine()->getManager();
  6115.         $em->remove($action);
  6116.         $em->flush();
  6117.         $this->get('session')->getFlashBag()->add('success''Action supprimée');
  6118.         return $this->redirectToRoute("user_actions");
  6119.     }
  6120.     /**
  6121.      * @Route("/actions/{id}/print", name="actions_print")
  6122.      */
  6123.     public function actionsPrintAction(Request $requestAction $action)
  6124.     {
  6125.         if ($this->isPrintingAllowed($this->getUser())) {
  6126.             if ($action->getUser()->getId() != $this->getUser()->getUser()->getId() && !$action->getGroupUser() && $action->getGroupUser()->getId() != $this->getUser()->getUser()->getId()) {
  6127.                 throw new NotFoundHttpException();
  6128.             }
  6129.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  6130.             $pdf->setUser($this->getUser()->getUser());
  6131.             $pdf->SetAuthor('myDigitplace');
  6132.             $pdf->SetTitle("Fiche action");
  6133.             $pdf->SetMargins(10,22,10true);
  6134.             $pdf->SetAutoPageBreak(TRUE35);
  6135.             $pdf->AddPage('P''A4');
  6136.             $filename 'fiche_action';
  6137.             $html $this->renderView('user/pdf/action.html.twig', [
  6138.                 "action" => $action
  6139.             ]);
  6140.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  6141.             if (count($action->getDocuments()) || count($action->getSheets())) {
  6142.                 $filePath1 tempnam(sys_get_temp_dir(), 'UploadedFile');
  6143.                 $file1 fopen($filePath1"w");
  6144.                 fwrite($file1$pdf->Output($filePath1'F'));
  6145.                 $meta_data1 stream_get_meta_data($file1);
  6146.                 $path1 $meta_data1['uri'];
  6147.                 fclose($file1);
  6148.                 $filesToAdd = [];
  6149.                 foreach ($action->getDocuments() as $document) {
  6150.                     if ($document->getFilename()) {
  6151.                         if (substr($document->getFilename(), -3) == "pdf") {
  6152.                             $path2 $this->projectDir '/../web/uploads/documents/'.$document->getFilename();
  6153.                             if (file_exists($path2)) {
  6154.                                 $filepdf fopen($path2,"r");
  6155.                                 if ($filepdf) {
  6156.                                     $line_first fgets($filepdf);
  6157.                                     preg_match_all('!\d+!'$line_first$matches);
  6158.                                     $pdfversion implode('.'$matches[0]);
  6159.                                     if($pdfversion <= "1.4"){
  6160.                                         $filesToAdd[] = $path2;
  6161.                                     }
  6162.                                     fclose($filepdf);
  6163.                                 }
  6164.                             }
  6165.                         }
  6166.                     }
  6167.                 }
  6168.                 foreach ($action->getSheets() as $sheet) {
  6169.                     if ($sheet->getFilename()) {
  6170.                         if (substr($sheet->getFilename(), -3) == "pdf") {
  6171.                             $path2 $this->projectDir '/../web/uploads/documents/'.$sheet->getFilename();
  6172.                             if (file_exists($path2)) {
  6173.                                 $filepdf fopen($path2,"r");
  6174.                                 if ($filepdf) {
  6175.                                     $line_first fgets($filepdf);
  6176.                                     preg_match_all('!\d+!'$line_first$matches);
  6177.                                     $pdfversion implode('.'$matches[0]);
  6178.                                     if($pdfversion <= "1.4"){
  6179.                                         $filesToAdd[] = $path2;
  6180.                                     }
  6181.                                     fclose($filepdf);
  6182.                                 }
  6183.                             }
  6184.                         }
  6185.                     }
  6186.                 }
  6187.                 $nbFiles count($filesToAdd);
  6188.                 if ($nbFiles) {
  6189.                     $i 1;
  6190.                     foreach ($filesToAdd as $path2) {
  6191.                         $file2merge = [$path1$path2];
  6192.                         $pdfConcat = new Pdf_concat();
  6193.                         $pdfConcat->setFiles($file2merge);
  6194.                         $pdfConcat->concat();
  6195.                         if ($i == $nbFiles) {
  6196.                             $pdfConcat->SetAuthor('myDigitplace');
  6197.                             $pdfConcat->SetTitle("Fiche action");
  6198.                             return $pdfConcat->Output('I'$filename.".pdf");
  6199.                         }
  6200.                         $filePath1 tempnam(sys_get_temp_dir(), 'UploadedFile');
  6201.                         $file1 fopen($filePath1"w");
  6202.                         fwrite($file1$pdfConcat->Output('F'$filePath1));
  6203.                         $meta_data1 stream_get_meta_data($file1);
  6204.                         $path1 $meta_data1['uri'];
  6205.                         fclose($file1);
  6206.                         $i++;
  6207.                     }
  6208.                 }
  6209.             }
  6210.             return $pdf->Output($filename.".pdf",'I');
  6211.         } else {
  6212.             return $this->redirectToRoute("user_actions");
  6213.         }
  6214.     }
  6215.     /**
  6216.      * @Route("/actions/deletedoc/{action}/{document}", name="actions_deletedoc")
  6217.      */
  6218.     public function actionsDeleteDocAction(Request $requestAction $actionUserDocument $userDocument)
  6219.     {
  6220.         $em $this->getDoctrine()->getManager();
  6221.         if ($action->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  6222.             throw new NotFoundHttpException();
  6223.         }
  6224.         if ($userDocument->getSubcontractor() == null || $userDocument->getAction()->getId() != $action->getId()) {
  6225.             throw new NotFoundHttpException();
  6226.         }
  6227.         $em->remove($userDocument);
  6228.         $em->flush();
  6229.         $this->get('session')->getFlashBag()->add('success''Document supprimé');
  6230.         return $this->redirectToRoute('user_actions_edit', ['id' => $action->getId()]);
  6231.     }
  6232.     /**
  6233.      * @Route("/actionsgrp/add", name="actions_grp_add")
  6234.      */
  6235.     public function actionsGrpAddAction(Request $requestSendEmailService $sendEmailService)
  6236.     {
  6237.         if (!$this->getUser()->getUser()->isMainGroupAgency()) {
  6238.             throw new NotFoundHttpException();
  6239.         }
  6240.         $action = new Action();
  6241.         $user $this->getUser()->getUser();
  6242.         $form $this->createForm(ActionGrpType::class, $action)
  6243.             ->add('treatments'EntityType::class, [
  6244.                 'attr' => array(
  6245.                     'placeholder' => 'traitements_lis',
  6246.                 ),
  6247.                 'placeholder' => 'traitements_lis',
  6248.                 'label' => 'selectionnez_les_traitements_lies',
  6249.                 'expanded' => false,
  6250.                 'multiple' => true,
  6251.                 'required' => false,
  6252.                 'translation_domain' => 'messages',
  6253.                 'class' => Treatment::class,
  6254.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  6255.                     return $er->createQueryBuilder('t')
  6256.                         ->where('t.user = :user')
  6257.                         ->andWhere("t.group = true")
  6258.                         ->setParameters(["user" => $user]);
  6259.                 },
  6260.                 'choice_label' => function(Treatment $treatment) {
  6261.                     return $treatment->getName();
  6262.                 },
  6263.             ])
  6264.             ->add('sheets'EntityType::class, [
  6265.                 'attr' => array(
  6266.                     'placeholder' => 'annexer_des_fiches_pratiques',
  6267.                 ),
  6268.                 'placeholder' => 'annexer_des_fiches_pratiques',
  6269.                 'label' => 'annexer_des_fiches_pratiques',
  6270.                 'expanded' => false,
  6271.                 'multiple' => true,
  6272.                 'required' => false,
  6273.                 'translation_domain' => 'messages',
  6274.                 'class' => Document::class,
  6275.                 'query_builder' => function (EntityRepository $er) {
  6276.                     return $er->createQueryBuilder('d')
  6277.                         ->leftJoin("d.type""t")
  6278.                         ->leftJoin("t.parent""pt")
  6279.                         ->where('t.id = 2')
  6280.                         ->orWhere('pt.id = 2')
  6281.                         ->addOrderBy("d.name""ASC")
  6282.                         ->addOrderBy("d.filename""ASC");
  6283.                 }
  6284.             ])
  6285.             ->add('estimationTime'NumberType::class, [
  6286.             'attr' => [
  6287.                 'placeholder' => 'temps_de_realisation_estime_en_heures'
  6288.             ],
  6289.             'label' => 'temps_de_realisation_estime_en_heures',
  6290.             'required' => false,
  6291.             'translation_domain' => 'messages',
  6292.         ])
  6293.             ->add('realTime'NumberType::class, [
  6294.                 'attr' => [
  6295.                     'placeholder' => 'temps_de_realisation_en_heures'
  6296.                 ],
  6297.                 'label' => 'temps_de_realisation_en_heures',
  6298.                 'required' => false,
  6299.                 'translation_domain' => 'messages',
  6300.             ])
  6301.             ->add('users'EntityType::class, [
  6302.                 'label' => 'Entités concernées',
  6303.                 'expanded' => true,
  6304.                 'multiple' => true,
  6305.                 'required' => false,
  6306.                 'mapped' => false,
  6307.                 //'data' => $user->getChildrenUsers(),
  6308.                 'class' => User::class,
  6309.                 'query_builder' => function (EntityRepository $er) use ( $user ) {
  6310.                     return $er->createQueryBuilder('u')
  6311.                         ->where('u.parentUser = :user')
  6312.                         ->orWhere("u.id = :userId")
  6313.                         ->setParameters(["user" => $user"userId" => $user->getId()]);
  6314.                 },
  6315.                 'choice_label' => function(User $user) {
  6316.                     return $user->getCompanyName();
  6317.                 },
  6318.             ]);
  6319.         $fromStd false;
  6320.         $actionStd null;
  6321.         if (isset($_GET['std'])) {
  6322.             $actionStd $this->getDoctrine()->getRepository(ActionStd::class)->find($_GET['std']);
  6323.             if ($actionStd) {
  6324.                 $fromStd true;
  6325.                 $form['name']->setData($actionStd->getName());
  6326.                 $form['budget']->setData($actionStd->getBudget());
  6327.                 $form['goal']->setData($actionStd->getGoal());
  6328.                 $form['information']->setData($actionStd->getInformation());
  6329.                 $form['usefulLink']->setData($actionStd->getUsefulLink());
  6330.                 $form['sheets']->setData($actionStd->getSheets());
  6331.             }
  6332.         }
  6333.         $form->handleRequest($request);
  6334.         if ($form->isSubmitted() && $form->isValid()) {
  6335.             if ($form["users"]->getData() && count($form["users"]->getData())) {
  6336.                 $actions = [];
  6337.                 $em $this->getDoctrine()->getManager();
  6338.                 $now = new \DateTime("now");
  6339.                 $group_user_concerned false;
  6340.                 $usersToAdd = [];
  6341.                 foreach ($form["users"]->getData() as $userToAdd) {
  6342.                     if ($userToAdd->getId() == $this->getUser()->getUser()->getId()) {
  6343.                         $group_user_concerned true;
  6344.                     } else {
  6345.                         $usersToAdd[] = $userToAdd;
  6346.                     }
  6347.                 }
  6348.                 array_unshift($usersToAdd$this->getUser()->getUser());
  6349.                 foreach ($usersToAdd as $userToAdd) {
  6350.                     $newAction = new Action();
  6351.                     $newAction->setUser($userToAdd);
  6352.                     $newAction->setByGroup(true);
  6353.                     $newAction->setGroupUser($this->getUser()->getUser());
  6354.                     if ($userToAdd->getId() == $this->getUser()->getUser()->getId()) {
  6355.                         $newAction->setGroupUserConcerned($group_user_concerned);
  6356.                     } else {
  6357.                         $newAction->setGroupUserConcerned(false);
  6358.                     }
  6359.                     $newAction->setDate($now);
  6360.                     $newAction->setEditDate($now);
  6361.                     $newAction->setName($action->getName());
  6362.                     $newAction->setBudget($action->getBudget());
  6363.                     $newAction->setGoal($action->getGoal());
  6364.                     $newAction->setInformation($action->getInformation());
  6365.                     $newAction->setUsefulLink($action->getUsefulLink());
  6366.                     $newAction->setSetUpDate($action->getSetUpDate());
  6367.                     $newAction->setTerminated($action->isTerminated());
  6368.                     $newAction->setEstimationTime($action->getEstimationTime());
  6369.                     $newAction->setRealTime($action->getRealTime());
  6370.                     $newAction->setPriority($action->getPriority());
  6371.                     $newAction->setTreatments($action->getTreatments());
  6372.                     $newAction->setSheets($action->getSheets());
  6373.                     $newAction->setAccountantLastName($userToAdd->getContactLastName());
  6374.                     $newAction->setAccountantFirstName($userToAdd->getContactFirstName());
  6375.                     $newAction->setAccountantEmail($userToAdd->getContactEmail());
  6376.                     $newAction->setAccountantPhone($userToAdd->getContactPhone());
  6377.                     if (count($actions)) {
  6378.                         $newAction->setGroupAction($actions[0]);
  6379.                     }
  6380.                     $em->persist($newAction);
  6381.                     $em->flush();
  6382.                     $actions[] = $newAction;
  6383.                 }
  6384.                 if ($fromStd) {
  6385.                     if ($actionStd) {
  6386.                         $filesystem = new Filesystem();
  6387.                         foreach ($actionStd->getDocuments() as $document) {
  6388.                             if (isset($_POST["appbundle_action_documents_".$document->getId()]) && !empty($_POST["appbundle_action_documents_".$document->getId()])) {
  6389.                                 $fileName $document->getFilename();
  6390.                                 $childFileName $this->getUser()->getUser()->getId()."_".$fileName;
  6391.                                 $filesystem->copy($this->getParameter('documents_directory').$fileName$this->getParameter('documents_directory').$childFileName);
  6392.                                 foreach ($actions as $actionToAdd) {
  6393.                                     $newDocument = new UserDocument();
  6394.                                     $newDocument->setName($document->getName());
  6395.                                     $newDocument->setFilename($childFileName);
  6396.                                     $newDocument->setUserFilename($document->getUserFilename());
  6397.                                     $newDocument->setUser($actionToAdd->getUser());
  6398.                                     $newDocument->setAction($actionToAdd);
  6399.                                     $em->persist($newDocument);
  6400.                                     $em->flush();
  6401.                                 }
  6402.                             }
  6403.                         }
  6404.                     }
  6405.                 }
  6406.                 if (isset($_FILES['appbundle_action_documents'])) {
  6407.                     $files $_FILES['appbundle_action_documents'];
  6408.                     $fileNames $_POST['appbundle_action_documents_names'];
  6409.                     for ($i=0;$i<count($files['name']);$i++) {
  6410.                         if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  6411.                             $name $files["name"][$i];
  6412.                             $parts explode("."$name);
  6413.                             $extension end($parts);
  6414.                             $fileName $action->getId()."_".md5(uniqid()) . '.' $extension;
  6415.                             move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  6416.                             $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  6417.                             foreach ($actions as $actionToAdd) {
  6418.                                 $document = new UserDocument();
  6419.                                 $document->setName($docTitle);
  6420.                                 $document->setFilename($fileName);
  6421.                                 $document->setUserFilename($files["name"][$i]);
  6422.                                 $document->setUser($actionToAdd->getUser());
  6423.                                 $document->setAction($actionToAdd);
  6424.                                 $em->persist($document);
  6425.                                 $em->flush();
  6426.                             }
  6427.                         }
  6428.                     }
  6429.                 }
  6430.                 $this->get('session')->getFlashBag()->add('success''Nouvelle action ajoutée');
  6431.                 foreach ($actions as $actionToAdd) {
  6432.                     if ($actionToAdd->getAccountantEmail()) {
  6433.                         if (filter_var($actionToAdd->getAccountantEmail(), FILTER_VALIDATE_EMAIL)) {
  6434.                             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  6435.                             $pdf->setUser($actionToAdd->getUser());
  6436.                             $pdf->SetAuthor('myDigitplace');
  6437.                             $pdf->SetTitle("Fiche action");
  6438.                             $pdf->SetMargins(102210true);
  6439.                             $pdf->SetAutoPageBreak(TRUE35);
  6440.                             $pdf->AddPage('P''A4');
  6441.                             $filename 'fiche_action';
  6442.                             $html $this->renderView('user/pdf/action.html.twig', [
  6443.                                 "action" => $actionToAdd
  6444.                             ]);
  6445.                             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  6446.                             $filePath1 tempnam(sys_get_temp_dir(), 'FicheAction');
  6447.                             $file1 fopen($filePath1"w");
  6448.                             fwrite($file1$pdf->Output($filePath1'F'));
  6449.                             $meta_data1 stream_get_meta_data($file1);
  6450.                             $path1 $meta_data1['uri'];
  6451.                             fclose($file1);
  6452.                             if (count($actionToAdd->getDocuments()) || count($actionToAdd->getSheets())) {
  6453.                                 $filesToAdd = [];
  6454.                                 foreach ($actionToAdd->getDocuments() as $document) {
  6455.                                     if ($document->getFilename()) {
  6456.                                         if (substr($document->getFilename(), -3) == "pdf") {
  6457.                                             $path2 $this->projectDir '/../web/uploads/documents/' $document->getFilename();
  6458.                                             if (file_exists($path2)) {
  6459.                                                 $filepdf fopen($path2"r");
  6460.                                                 if ($filepdf) {
  6461.                                                     $line_first fgets($filepdf);
  6462.                                                     preg_match_all('!\d+!'$line_first$matches);
  6463.                                                     $pdfversion implode('.'$matches[0]);
  6464.                                                     if ($pdfversion <= "1.4") {
  6465.                                                         $filesToAdd[] = $path2;
  6466.                                                     }
  6467.                                                     fclose($filepdf);
  6468.                                                 }
  6469.                                             }
  6470.                                         }
  6471.                                     }
  6472.                                 }
  6473.                                 foreach ($actionToAdd->getSheets() as $sheet) {
  6474.                                     if ($sheet->getFilename()) {
  6475.                                         if (substr($sheet->getFilename(), -3) == "pdf") {
  6476.                                             $path2 $this->projectDir '/../web/uploads/documents/' $sheet->getFilename();
  6477.                                             if (file_exists($path2)) {
  6478.                                                 $filepdf fopen($path2"r");
  6479.                                                 if ($filepdf) {
  6480.                                                     $line_first fgets($filepdf);
  6481.                                                     preg_match_all('!\d+!'$line_first$matches);
  6482.                                                     $pdfversion implode('.'$matches[0]);
  6483.                                                     if ($pdfversion <= "1.4") {
  6484.                                                         $filesToAdd[] = $path2;
  6485.                                                     }
  6486.                                                     fclose($filepdf);
  6487.                                                 }
  6488.                                             }
  6489.                                         }
  6490.                                     }
  6491.                                 }
  6492.                                 $nbFiles count($filesToAdd);
  6493.                                 if ($nbFiles) {
  6494.                                     $i 1;
  6495.                                     foreach ($filesToAdd as $path2) {
  6496.                                         $file2merge = [$path1$path2];
  6497.                                         $pdfConcat = new Pdf_concat();
  6498.                                         $pdfConcat->setFiles($file2merge);
  6499.                                         $pdfConcat->concat();
  6500.                                         $pdfConcat->SetAuthor('myDigitplace');
  6501.                                         $pdfConcat->SetTitle("Fiche action");
  6502.                                         $filePath1 tempnam(sys_get_temp_dir(), 'FicheAction');
  6503.                                         $file1 fopen($filePath1"w");
  6504.                                         fwrite($file1$pdfConcat->Output('F'$filePath1));
  6505.                                         $meta_data1 stream_get_meta_data($file1);
  6506.                                         $path1 $meta_data1['uri'];
  6507.                                         fclose($file1);
  6508.                                         $i++;
  6509.                                     }
  6510.                                 }
  6511.                             }
  6512.                             $content "<p>Bonjour,<br/>
  6513.                         <br/>
  6514.                         Vous avez été assigné comme responsable d'une nouvelle action.<br/>
  6515.                         Pour plus de détails sur cette action, vous pouvez consulter le document en pièce jointe.<br/>
  6516.                         <br/>
  6517.                         <br/>
  6518.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  6519.                         </p>";
  6520.                             $sendEmailService->send(
  6521.                                 "Nouvelle action",
  6522.                                 $actionToAdd->getAccountantEmail(),
  6523.                                 'template_emails/left_text.html.twig',
  6524.                                 [
  6525.                                     "title" => "Nouvelle action",
  6526.                                     "content" => $content
  6527.                                 ],
  6528.                                 [
  6529.                                     [
  6530.                                         'path' => $path1,
  6531.                                         'fileName' => "fiche_action.pdf",
  6532.                                     ]
  6533.                                 ]
  6534.                             );
  6535.                         }
  6536.                     }
  6537.                 }
  6538.                 return $this->redirectToRoute("user_actions");
  6539.             } else {
  6540.                 $this->get('session')->getFlashBag()->add('danger''Veuillez sélectionner au minimum 1 entité en cliquant sur le bouton [ Sélectionner les entités concernées ] en bas de page');
  6541.             }
  6542.         }
  6543.         $actionsStd $this->getDoctrine()->getRepository(ActionStd::class)->findBy([], ["name" => "ASC"]);
  6544.         $users = [];
  6545.         $usersStr = [];
  6546.         $usersStrAssoc = [];
  6547.         foreach ($form["users"]->getData()??[] as $userToFetch) {
  6548.             $users[] = $userToFetch->getId();
  6549.             $usersStr[] = $userToFetch->getCompanyName();
  6550.         }
  6551.         $usersStrAssoc[$user->getId()] = $user->getCompanyName();
  6552.         foreach ($user->getChildrenUsers()??[] as $userToFetch) {
  6553.             $usersStrAssoc[$userToFetch->getId()] = $userToFetch->getCompanyName();
  6554.         }
  6555.         sort($usersStr);
  6556.         return $this->render('user/actions_grp_add.html.twig', [
  6557.             "form" => $form->createView(),
  6558.             "actionsStd" => $actionsStd,
  6559.             "fromStd" => $fromStd,
  6560.             "actionStd" => $actionStd,
  6561.             "isAdmin" => $this->isGranted("ROLE_PREVIOUS_ADMIN"),
  6562.             "users" => $users,
  6563.             "usersStr" => $usersStr,
  6564.             "usersStrAssoc" => $usersStrAssoc,
  6565.         ]);
  6566.     }
  6567.     /**
  6568.      * @Route("/actionsgrp/{id}/list", name="actions_grp_list")
  6569.      */
  6570.     public function actionsGrpListAction(Request $requestAction $action)
  6571.     {
  6572.         if (!$action->isByGroup() || $action->getGroupUser()->getId() != $this->getUser()->getUser()->getId()) {
  6573.             throw new NotFoundHttpException();
  6574.         }
  6575.         $actions $this->getDoctrine()->getRepository(Action::class)->findGroupsForAction($action);
  6576.         return $this->render('user/actions_grp_list.html.twig', [
  6577.             "mainAction" => $action,
  6578.             "actions" => $actions,
  6579.         ]);
  6580.     }
  6581.     /**
  6582.      * @Route("/actionsgrp/{id}/deleteall", name="actions_grp_delete_all")
  6583.      */
  6584.     public function actionsGrpDeleteAllAction(Request $requestEntityManagerInterface $emAction $action)
  6585.     {
  6586.         if (!$action->isByGroup() || $action->getGroupUser()->getId() != $this->getUser()->getUser()->getId()) {
  6587.             throw new NotFoundHttpException();
  6588.         }
  6589.         $actions $this->getDoctrine()->getRepository(Action::class)->findGroupsForAction($action);
  6590.         foreach ($actions as $actionToDelete) {
  6591.             $em->remove($actionToDelete);
  6592.             $em->flush();
  6593.         }
  6594.         $em->remove($action);
  6595.         $em->flush();
  6596.         return $this->redirectToRoute("user_actions");
  6597.     }
  6598.     /**
  6599.      * @Route("/exercisingclaims", name="exercisingclaims")
  6600.      */
  6601.     public function exercisingclaimsAction(Request $request)
  6602.     {
  6603.         $exercisingclaims $this->getDoctrine()->getRepository(ExercisingClaimRequest::class)->findBy(["user" => $this->getUser()->getUser()]);
  6604.         return $this->render('user/exercisingclaims.html.twig', [
  6605.             "exercisingclaims" => $exercisingclaims
  6606.         ]);
  6607.     }
  6608.     /**
  6609.      * @Route("/exercisingclaims/add", name="exercisingclaims_add")
  6610.      */
  6611.     public function exercisingclaimsAddAction(Request $requestSendEmailService $sendEmailService)
  6612.     {
  6613.         $exercisingclaim = new ExercisingClaimRequest();
  6614.         $form $this->createForm(ExercisingClaimRequestType::class, $exercisingclaim);
  6615.         $form->handleRequest($request);
  6616.         if ($form->isSubmitted() && $form->isValid()) {
  6617.             $em $this->getDoctrine()->getManager();
  6618.             $exercisingclaim->setUser($this->getUser()->getUser());
  6619.             $requestDate \DateTime::createFromFormat("d/m/Y H:i:s"$form['requestDate']->getData()." 00:00:00");
  6620.             if ($requestDate) {
  6621.                 $exercisingclaim->setRequestDate($requestDate);
  6622.             }
  6623.             $answerDate \DateTime::createFromFormat("d/m/Y"$form['answerDate']->getData());
  6624.             if ($answerDate) {
  6625.                 $exercisingclaim->setAnswerDate($answerDate);
  6626.             }
  6627.             $em->persist($exercisingclaim);
  6628.             $em->flush();
  6629.             /**
  6630.              * @var UploadedFile $file
  6631.              */
  6632.             $file $form->get('documentFile')->getData();
  6633.             if ($file != NULL) {
  6634.                 $fileName $this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  6635.                 $file->move(
  6636.                     $this->getParameter('documents_directory'), $fileName
  6637.                 );
  6638.                 $exercisingclaim->setFile($fileName);
  6639.                 $em->flush();
  6640.             }
  6641.             $this->get('session')->getFlashBag()->add('success''Nouvelle demande d’exercice des droits ajoutée');
  6642.             if ($exercisingclaim->getRequestDate() && !$exercisingclaim->getAnswerDate()) {
  6643.                 if ($exercisingclaim->getAccountantEmail()) {
  6644.                     if (filter_var($exercisingclaim->getAccountantEmail(), FILTER_VALIDATE_EMAIL)) {
  6645.                         $content "<p>Bonjour,<br/>
  6646.                         <br/>
  6647.                         Vous avez été assigné comme responsable d'une nouvelle demande d’exercice de droits<br/>
  6648.                         <br/>
  6649.                         Personne concernée: ".$exercisingclaim->getCustomer()."<br/>
  6650.                         Date de la demande: ".$exercisingclaim->getRequestDate()->format("d/m/Y")."<br/>
  6651.                         Droit: ".$exercisingclaim->getRights()."<br/>
  6652.                         Précisions sur la demande: ".nl2br($exercisingclaim->getPrecisions())."<br/>
  6653.                         <br/>
  6654.                         <br/>
  6655.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  6656.                         </p>";
  6657.                         $sendEmailService->send(
  6658.                             "Nouvelle demande d’exercice de droits",
  6659.                             $exercisingclaim->getAccountantEmail(),
  6660.                             'template_emails/left_text.html.twig',
  6661.                             [
  6662.                                 "title" => "Nouvelle demande d’exercice de droits",
  6663.                                 "content" => $content
  6664.                             ]
  6665.                         );
  6666.                     }
  6667.                 }
  6668.             }
  6669.             return $this->redirectToRoute("user_exercisingclaims");
  6670.         }
  6671.         return $this->render('user/exercisingclaims_add.html.twig', [
  6672.             "form" => $form->createView()
  6673.         ]);
  6674.     }
  6675.     /**
  6676.      * @Route("/exercisingclaims/{id}/edit", name="exercisingclaims_edit")
  6677.      */
  6678.     public function exercisingclaimsEditAction(Request $requestExercisingClaimRequest $exercisingclaim)
  6679.     {
  6680.         if ($exercisingclaim->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  6681.             throw new NotFoundHttpException();
  6682.         }
  6683.         $form $this->createForm(ExercisingClaimRequestType::class, $exercisingclaim);
  6684.         if ($exercisingclaim->getRequestDate()) {
  6685.             $form['requestDate']->setData($exercisingclaim->getRequestDate()->format("d/m/Y"));
  6686.         }
  6687.         if ($exercisingclaim->getAnswerDate()) {
  6688.             $form['answerDate']->setData($exercisingclaim->getAnswerDate()->format("d/m/Y"));
  6689.         }
  6690.         $form->handleRequest($request);
  6691.         if ($form->isSubmitted() && $form->isValid()) {
  6692.             $em $this->getDoctrine()->getManager();
  6693.             $exercisingclaim->setUser($this->getUser()->getUser());
  6694.             $requestDate \DateTime::createFromFormat("d/m/Y H:i:s"$form['requestDate']->getData()." 00:00:00");
  6695.             if ($requestDate) {
  6696.                 $exercisingclaim->setRequestDate($requestDate);
  6697.             } else {
  6698.                 $exercisingclaim->setRequestDate(null);
  6699.             }
  6700.             $answerDate \DateTime::createFromFormat("d/m/Y"$form['answerDate']->getData());
  6701.             if ($answerDate) {
  6702.                 $exercisingclaim->setAnswerDate($answerDate);
  6703.             } else {
  6704.                 $exercisingclaim->setAnswerDate(null);
  6705.             }
  6706.             $em->persist($exercisingclaim);
  6707.             $em->flush();
  6708.             /**
  6709.              * @var UploadedFile $file
  6710.              */
  6711.             $file $form->get('documentFile')->getData();
  6712.             if ($file != NULL) {
  6713.                 $fileName $this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  6714.                 $file->move(
  6715.                     $this->getParameter('documents_directory'), $fileName
  6716.                 );
  6717.                 $exercisingclaim->setFile($fileName);
  6718.                 $em->flush();
  6719.             }
  6720.             $this->get('session')->getFlashBag()->add('success''Demande d’exercice des droits mise à jour');
  6721.             return $this->redirectToRoute("user_exercisingclaims");
  6722.         }
  6723.         return $this->render('user/exercisingclaims_edit.html.twig', [
  6724.             "exercisingclaim" => $exercisingclaim,
  6725.             "form" => $form->createView()
  6726.         ]);
  6727.     }
  6728.     /**
  6729.      * @Route("/exercisingclaims/{id}/delete", name="exercisingclaims_delete")
  6730.      */
  6731.     public function exercisingclaimsDeleteAction(Request $requestExercisingClaimRequest $exercisingclaim)
  6732.     {
  6733.         if ($exercisingclaim->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  6734.             throw new NotFoundHttpException();
  6735.         }
  6736.         $em $this->getDoctrine()->getManager();
  6737.         $em->remove($exercisingclaim);
  6738.         $em->flush();
  6739.         $this->get('session')->getFlashBag()->add('success''Demande d’exercice des droits supprimée');
  6740.         return $this->redirectToRoute("user_exercisingclaims");
  6741.     }
  6742.     /**
  6743.      * @Route("/documents", name="documents")
  6744.      */
  6745.     public function documentsAction(Request $requestTranslatorInterface $translator)
  6746.     {
  6747.         $documentsTypes $this->getDoctrine()->getRepository(DocumentType::class)->findBy(["parent" => null]);
  6748.         $userDocuments $this->getDoctrine()->getRepository(UserDocument::class)->findBy(["user" => $this->getUser()->getUser(), "subcontractor" => null"action" => null], ['name' => "ASC""filename" => "ASC"]);
  6749.         $actions $this->getDoctrine()->getRepository(Action::class)->findForUserWithGroup($this->getUser()->getUser());
  6750.         $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findBy(["user" => $this->getUser()->getUser(), "group" => false], ["name" => "ASC"]);
  6751.         $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()]);
  6752.         $piaFiles = [];
  6753.         foreach ($treatments as $treatment) {
  6754.             if ($treatment->getPiaFile()) {
  6755.                 $piaFiles[] = $treatment;
  6756.             }
  6757.         }
  6758.         $form $this->createFormBuilder()
  6759.             ->add('file'FileType::class, [
  6760.                 'attr' => [
  6761.                     'placeholder' => 'Fichier'
  6762.                 ],
  6763.                 'label' => 'Fichier',
  6764.                 'required' => true,
  6765.                 'mapped' => false
  6766.             ])
  6767.             ->add('name'TextType::class, [
  6768.                 'attr' => [
  6769.                     'placeholder' => 'Nom'
  6770.                 ],
  6771.                 'label' => 'Nom',
  6772.                 'required' => false,
  6773.                 'mapped' => false
  6774.             ])
  6775.             ->add('children'CheckboxType::class, [
  6776.                 'label' => "Fichier disponible pour les comptes rattachés",
  6777.                 'required' => false,
  6778.                 'mapped' => false
  6779.             ])->getForm();
  6780.         $form->handleRequest($request);
  6781.         if ($form->isSubmitted() && $form->isValid()) {
  6782.             $em $this->getDoctrine()->getManager();
  6783.             /**
  6784.              * @var UploadedFile $file
  6785.              */
  6786.             $file $form->get('file')->getData();
  6787.             if ($file != NULL) {
  6788.                 $fileName $this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  6789.                 $fileExtension $file->guessExtension();
  6790.                 $clientOriginalName $file->getClientOriginalName();
  6791.                 $file->move(
  6792.                     $this->getParameter('documents_directory'), $fileName
  6793.                 );
  6794.                 $docTitle $form['name']->getData()??$clientOriginalName;
  6795.                 $document = new UserDocument();
  6796.                 $document->setName($docTitle);
  6797.                 $document->setFilename($fileName);
  6798.                 $document->setUserFilename($clientOriginalName);
  6799.                 $document->setUser($this->getUser()->getUser());
  6800.                 $em->persist($document);
  6801.                 $em->flush();
  6802.                 if ($form['children']->getData()) {
  6803.                     $filesystem = new Filesystem();
  6804.                     foreach ($this->getUser()->getUser()->getChildrenUsers() as $childUser) {
  6805.                         $childFileName $childUser->getId()."_".$this->getUser()->getUser()->getId()."_".md5(uniqid()) . '.' $fileExtension;
  6806.                         $filesystem->copy($this->getParameter('documents_directory').$fileName$this->getParameter('documents_directory').$childFileName);
  6807.                         /*$file->move(
  6808.                             $this->getParameter('documents_directory'), $fileName
  6809.                         );*/
  6810.                         $childUserDocument = new UserDocument();
  6811.                         $childUserDocument->setName($docTitle);
  6812.                         $childUserDocument->setFilename($childFileName);
  6813.                         $childUserDocument->setUserFilename($clientOriginalName);
  6814.                         $childUserDocument->setUser($childUser);
  6815.                         $em->persist($childUserDocument);
  6816.                         $em->flush();
  6817.                     }
  6818.                 }
  6819.                 $this->get('session')->getFlashBag()->add('success''Nouveau document téléversé');
  6820.             }
  6821.             return $this->redirectToRoute("user_documents");
  6822.         }
  6823.         $isMdpReadDocAllowed $this->isMdpReadDocAllowed($this->getUser());
  6824.         $conformityJson = [
  6825.             [
  6826.                 "id" => 0,
  6827.                 "label" => $translator->trans("ma_conformit"),
  6828.                 "type" => "d",
  6829.                 "children" => [
  6830.                     [
  6831.                         "id" => 0,
  6832.                         "label" => $translator->trans("mon_registre"),
  6833.                         "type" => "d",
  6834.                         "children" => [],
  6835.                     ],
  6836.                     [
  6837.                         "id" => 1,
  6838.                         "label" => $translator->trans("mes_pia"),
  6839.                         "type" => "d",
  6840.                         "children" => [],
  6841.                     ],
  6842.                     [
  6843.                         "id" => 2,
  6844.                         "label" => $translator->trans("documentation_rgpd"),
  6845.                         "type" => "d",
  6846.                         "children" => [],
  6847.                     ],
  6848.                 ],
  6849.             ],
  6850.             [
  6851.                 "id" => 1,
  6852.                 "label" => $translator->trans("mes_sous_traitants"),
  6853.                 "type" => "d",
  6854.                 "children" => [],
  6855.             ],
  6856.             [
  6857.                 "id" => 2,
  6858.                 "label" => $translator->trans("mes_cotraitant"),
  6859.                 "type" => "d",
  6860.                 "children" => [],
  6861.             ],
  6862.             [
  6863.                 "id" => 3,
  6864.                 "label" => $translator->trans("mes_responsable_de_traitement"),
  6865.                 "type" => "d",
  6866.                 "children" => [],
  6867.             ],
  6868.             [
  6869.                 "id" => 4,
  6870.                 "label" => $translator->trans("mes_actions"),
  6871.                 "type" => "d",
  6872.                 "children" => [],
  6873.             ]
  6874.         ];
  6875.         $conformityJson[0]["children"][0]["children"][] = [
  6876.             "id" => 0,
  6877.             "label" => $translator->trans("registre_complet"),
  6878.             "type" => "f",
  6879.             "url" => $this->generateUrl("user_treatments_export_full"),
  6880.             "deleteUrl" => null,
  6881.             "children" => [],
  6882.         ];
  6883.         foreach ($treatments as $treatment) {
  6884.             $conformityJson[0]["children"][0]["children"][] = [
  6885.                 "id" => $treatment->getId(),
  6886.                 "label" => $treatment->getName()." ".$this->formatTreatmentNumber($treatment->getNumber()),
  6887.                 "type" => "f",
  6888.                 "url" => $this->generateUrl("user_treatments_export_one", ["id" => $treatment->getId()]),
  6889.                 "deleteUrl" => null,
  6890.                 "children" => [],
  6891.             ];
  6892.         }
  6893.         foreach ($piaFiles as $treatment) {
  6894.             $conformityJson[0]["children"][1]["children"][] = [
  6895.                 "id" => $treatment->getId(),
  6896.                 "label" => $treatment->getName()." ".$this->formatTreatmentNumber($treatment->getNumber()),
  6897.                 "type" => "f",
  6898.                 "url" => "/uploads/documents/".$treatment->getPiaFile(),
  6899.                 "deleteUrl" => null,
  6900.                 "children" => [],
  6901.             ];
  6902.         }
  6903.         foreach ($userDocuments as $userDocument) {
  6904.             $conformityJson[0]["children"][2]["children"][] = [
  6905.                 "id" => $userDocument->getId(),
  6906.                 "label" => $userDocument->getName(),
  6907.                 "type" => "f",
  6908.                 "url" => $this->generateUrl("user_read_user_documents", ["id" => $userDocument->getId()]),
  6909.                 "deleteUrl" => $this->generateUrl("user_user_documents_delete", ["id" => $userDocument->getId()]),
  6910.                 "children" => [],
  6911.             ];
  6912.         }
  6913.         foreach ($subcontractors as $subcontractor) {
  6914.             $subData = [
  6915.                 "id" => $subcontractor->getId(),
  6916.                 "label" => $subcontractor->getName(),
  6917.                 "type" => "d",
  6918.                 "children" => [],
  6919.             ];
  6920.             foreach ($subcontractor->getDocuments() as $userDocument) {
  6921.                 $subData["children"][] = [
  6922.                     "id" => $userDocument->getId(),
  6923.                     "label" => $userDocument->getName(),
  6924.                     "type" => "f",
  6925.                     "url" => $this->generateUrl("user_read_user_documents", ["id" => $userDocument->getId()]),
  6926.                     "deleteUrl" => null,
  6927.                     "children" => [],
  6928.                 ];
  6929.             }
  6930.             if ($subcontractor->getSubcontractorType()) {
  6931.                 switch ($subcontractor->getSubcontractorType()->getCode()) {
  6932.                     case "SOUS_TRAITANT":
  6933.                         $conformityJson[1]["children"][] = $subData;
  6934.                         break;
  6935.                     case "CO_TRAITANT":
  6936.                         $conformityJson[2]["children"][] = $subData;
  6937.                         break;
  6938.                     case "RESP_TRAITEMENT":
  6939.                         $conformityJson[3]["children"][] = $subData;
  6940.                         break;
  6941.                     default:
  6942.                         $conformityJson[1]["children"][] = $subData;
  6943.                         break;
  6944.                 }
  6945.             } else {
  6946.                 $conformityJson[1]["children"][] = $subData;
  6947.             }
  6948.         }
  6949.         foreach ($actions as $action) {
  6950.             $subData = [
  6951.                 "id" => $action->getId(),
  6952.                 "label" => $action->getName(),
  6953.                 "type" => "d",
  6954.                 "children" => [],
  6955.             ];
  6956.             foreach ($action->getDocuments() as $userDocument) {
  6957.                 $subData["children"][] = [
  6958.                     "id" => $userDocument->getId(),
  6959.                     "label" => $userDocument->getName(),
  6960.                     "type" => "f",
  6961.                     "url" => $this->generateUrl("user_read_user_documents", ["id" => $userDocument->getId()]),
  6962.                     "deleteUrl" => null,
  6963.                     "children" => [],
  6964.                 ];
  6965.             }
  6966.             $conformityJson[4]["children"][] = $subData;
  6967.         }
  6968.         $documentsTypesJson = [];
  6969.         $i 0;
  6970.         foreach ($documentsTypes as $type) {
  6971.             $documentsTypesJson[$i] = [
  6972.                 "id" => $type->getId(),
  6973.                 "label" => $type->getLibelle(),
  6974.                 "type" => "d",
  6975.                 "children" => [],
  6976.             ];
  6977.             $j 0;
  6978.             foreach ($type->getChildren() as $childType) {
  6979.                 $documentsTypesJson[$i]["children"][] = [
  6980.                     "id" => $childType->getId(),
  6981.                     "label" => $childType->getLibelle(),
  6982.                     "type" => "d",
  6983.                     "children" => [],
  6984.                 ];
  6985.                 $k 0;
  6986.                 foreach ($childType->getDocuments() as $document) {
  6987.                     $documentsTypesJson[$i]["children"][$j]["children"][] = [
  6988.                         "id" => $isMdpReadDocAllowed $document->getId() : null,
  6989.                         "label" => $document->getName(),
  6990.                         "type" => "f",
  6991.                         "root" => $childType->getId(),
  6992.                         "read" => $isMdpReadDocAllowed,
  6993.                         "children" => [],
  6994.                     ];
  6995.                     $k++;
  6996.                 }
  6997.                 $j++;
  6998.             }
  6999.             foreach ($type->getDocuments() as $document) {
  7000.                 $documentsTypesJson[$i]["children"][] = [
  7001.                     "id" => $isMdpReadDocAllowed $document->getId() : null,
  7002.                     "label" => $document->getName(),
  7003.                     "type" => "f",
  7004.                     "root" => $type->getId(),
  7005.                     "read" => $isMdpReadDocAllowed,
  7006.                     "children" => [],
  7007.                 ];
  7008.                 $j++;
  7009.             }
  7010.             $i++;
  7011.         }
  7012.         return $this->render('user/documents.html.twig', [
  7013.             "documentsTypes" => $documentsTypes,
  7014.             "documentsTypesJson" => $documentsTypesJson,
  7015.             "userDocuments" => $userDocuments,
  7016.             "actions" => $actions,
  7017.             "subcontractors" => $subcontractors,
  7018.             "treatments" => $treatments,
  7019.             "piaFiles" => $piaFiles,
  7020.             "conformityJson" => $conformityJson,
  7021.             "form" => $form->createView(),
  7022.         ]);
  7023.     }
  7024.     /**
  7025.      * @Route("/users", name="users")
  7026.      */
  7027.     public function usersAction(Request $request)
  7028.     {
  7029.         return $this->render('user/users.html.twig', [
  7030.             "users" => $this->getUser()->getUser()->getChildrenUsers()
  7031.         ]);
  7032.     }
  7033.     /**
  7034.      * @Route("/subcontractorsgrp", name="subcontractors_grp")
  7035.      */
  7036.     public function subcontractorsGrpAction(Request $request)
  7037.     {
  7038.         $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findGroupForUser($this->getUser()->getUser());
  7039.         return $this->render('user/subcontractors_grp.html.twig', [
  7040.             "subcontractors" => $subcontractors
  7041.         ]);
  7042.     }
  7043.     /**
  7044.      * @Route("/subcontractorsgrp/export", name="subcontractors_grp_export")
  7045.      */
  7046.     public function subcontractorsGrpExportAction(Request $request)
  7047.     {
  7048.         if ($this->isPrintingAllowed($this->getUser())) {
  7049.             $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findGroupForUser($this->getUser()->getUser());
  7050.             $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  7051.             $pdf->setUser($this->getUser()->getUser());
  7052.             $pdf->SetAuthor('myDigitplace');
  7053.             $pdf->SetTitle("Sous-traitants groupe");
  7054.             $pdf->SetMargins(10,22,10true);
  7055.             $pdf->SetAutoPageBreak(TRUE35);
  7056.             $pdf->AddPage('L''A4');
  7057.             $html $this->renderView('user/pdf/subcontractors.html.twig', [
  7058.                 "subcontractors" => $subcontractors
  7059.             ]);
  7060.             $filename 'Sous_traitants_groupe';
  7061.             $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  7062.             return $pdf->Output($filename.".pdf",'I');
  7063.         } else {
  7064.             return $this->redirectToRoute("user_subcontractors_grp");
  7065.         }
  7066.     }
  7067.     /**
  7068.      * @Route("/subcontractorsgrp/add", name="subcontractors_grp_add")
  7069.      */
  7070.     public function subcontractorsGrpAddAction(Request $requestSendEmailService $sendEmailService)
  7071.     {
  7072.         $subcontractor = new Subcontractor();
  7073.         $defaultSubcontractorType $this->getDoctrine()->getRepository(\App\Entity\SubcontractorType::class)->findOneBy(["code" => "SOUS_TRAITANT"]);
  7074.         $subcontractor->setSubcontractorType($defaultSubcontractorType);
  7075.         $subcontractor->setGroup(true);
  7076.         $form $this->createForm(SubcontractorType::class, $subcontractor);
  7077.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  7078.             $form->add('group'CheckboxType::class, [
  7079.                 'label' => 'est_soustraitant_groupe',
  7080.                 'translation_domain' => 'messages',
  7081.                 'required' => false,
  7082.             ]);
  7083.         }
  7084.         $fromStd false;
  7085.         $subcontractorStd null;
  7086.         if (isset($_GET['std'])) {
  7087.             $subcontractorStd $this->getDoctrine()->getRepository(SubcontractorStd::class)->find($_GET['std']);
  7088.             if ($subcontractorStd) {
  7089.                 $fromStd true;
  7090.                 $form['name']->setData($subcontractorStd->getName());
  7091.                 $form['type']->setData($subcontractorStd->getType());
  7092.                 $form['contactFirstName']->setData($subcontractorStd->getContactFirstName());
  7093.                 $form['contactLastName']->setData($subcontractorStd->getContactLastName());
  7094.                 $form['contactPhone']->setData($subcontractorStd->getContactPhone());
  7095.                 $form['contactEmail']->setData($subcontractorStd->getContactEmail());
  7096.                 $form['privacyPolicyLink']->setData($subcontractorStd->getPrivacyPolicyLink());
  7097.                 $form['conformity']->setData($subcontractorStd->getConformity());
  7098.             }
  7099.         }
  7100.         $form->handleRequest($request);
  7101.         if ($form->isSubmitted() && $form->isValid()) {
  7102.             $em $this->getDoctrine()->getManager();
  7103.             $now = new \DateTime("now");
  7104.             $subcontractor->setDate($now);
  7105.             $subcontractor->setEditDate($now);
  7106.             $subcontractor->setUser($this->getUser()->getUser());
  7107.             $em->persist($subcontractor);
  7108.             $em->flush();
  7109.             if ($fromStd) {
  7110.                 if ($subcontractorStd) {
  7111.                     $filesystem = new Filesystem();
  7112.                     foreach ($subcontractorStd->getDocuments() as $document) {
  7113.                         if (isset($_POST["appbundle_subcontractor_documents_".$document->getId()]) && !empty($_POST["appbundle_subcontractor_documents_".$document->getId()])) {
  7114.                             $fileName $document->getFilename();
  7115.                             $childFileName $this->getUser()->getUser()->getId()."_".$fileName;
  7116.                             $filesystem->copy($this->getParameter('documents_directory').$fileName$this->getParameter('documents_directory').$childFileName);
  7117.                             $newDocument = new UserDocument();
  7118.                             $newDocument->setName($document->getName());
  7119.                             $newDocument->setFilename($childFileName);
  7120.                             $newDocument->setUserFilename($document->getUserFilename());
  7121.                             $newDocument->setUser($this->getUser()->getUser());
  7122.                             $newDocument->setSubcontractor($subcontractor);
  7123.                             $em->persist($newDocument);
  7124.                             $em->flush();
  7125.                         }
  7126.                     }
  7127.                 }
  7128.             }
  7129.             if (isset($_FILES['appbundle_subcontractor_documents'])) {
  7130.                 $files $_FILES['appbundle_subcontractor_documents'];
  7131.                 $fileNames $_POST['appbundle_subcontractor_documents_names'];
  7132.                 for ($i=0;$i<count($files['name']);$i++) {
  7133.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  7134.                         $name $files["name"][$i];
  7135.                         $parts explode("."$name);
  7136.                         $extension end($parts);
  7137.                         $fileName $subcontractor->getId()."_".md5(uniqid()) . '.' $extension;
  7138.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  7139.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  7140.                         $document = new UserDocument();
  7141.                         $document->setName($docTitle);
  7142.                         $document->setFilename($fileName);
  7143.                         $document->setUserFilename($files["name"][$i]);
  7144.                         $document->setUser($this->getUser()->getUser());
  7145.                         $document->setSubcontractor($subcontractor);
  7146.                         $em->persist($document);
  7147.                         $em->flush();
  7148.                     }
  7149.                 }
  7150.             }
  7151.             $content "<p>Bonjour,<br/>
  7152.                         <br/>
  7153.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a ajouté un nouveau sous-traitant groupe: ".$subcontractor->getName()."<br/>
  7154.                         <br/>
  7155.                         <br/>
  7156.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  7157.                         </p>";
  7158.             $sendEmailService->send(
  7159.                 "Nouveau sous-traitant groupe",
  7160.                 $this->getUser()->getUser()->getManager()->getEmail(),
  7161.                 'template_emails/left_text.html.twig',
  7162.                 [
  7163.                     "title" => "Nouveau sous-traitant groupe",
  7164.                     "content" => $content
  7165.                 ]
  7166.             );
  7167.             $this->get('session')->getFlashBag()->add('success''Nouveau sous-traitant groupe ajouté');
  7168.             return $this->redirectToRoute("user_subcontractors_grp");
  7169.         }
  7170.         $subcontractorsStd $this->getDoctrine()->getRepository(SubcontractorStd::class)->findForUser($this->getUser()->getUser());
  7171.         return $this->render('user/subcontractors_grp_add.html.twig', [
  7172.             "form" => $form->createView(),
  7173.             "subcontractorsStd" => $subcontractorsStd,
  7174.             "fromStd" => $fromStd,
  7175.             "subcontractorStd" => $subcontractorStd
  7176.         ]);
  7177.     }
  7178.     /**
  7179.      * @Route("/subcontractorsgrp/{id}/edit", name="subcontractors_grp_edit")
  7180.      */
  7181.     public function subcontractorsGrpEditAction(Request $requestSendEmailService $sendEmailServiceSubcontractor $subcontractor)
  7182.     {
  7183.         if ($subcontractor->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  7184.             throw new NotFoundHttpException();
  7185.         }
  7186.         $form $this->createForm(SubcontractorType::class, $subcontractor);
  7187.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  7188.             $form->add('group'CheckboxType::class, [
  7189.                 'label' => 'est_soustraitant_groupe',
  7190.                 'translation_domain' => 'messages',
  7191.                 'required' => false,
  7192.             ]);
  7193.         }
  7194.         $form->handleRequest($request);
  7195.         if ($form->isSubmitted() && $form->isValid()) {
  7196.             $em $this->getDoctrine()->getManager();
  7197.             $subcontractor->setEditDate(new \DateTime("now"));
  7198.             $em->flush();
  7199.             foreach ($subcontractor->getDocuments() as $document) {
  7200.                 if (isset($_POST["appbundle_subcontractor_documents_".$document->getId()]) && !empty($_POST["appbundle_subcontractor_documents_".$document->getId()])) {
  7201.                     if ($document->getName() != $_POST["appbundle_subcontractor_documents_".$document->getId()]) {
  7202.                         $document->setTitle($_POST["appbundle_subcontractor_documents_".$document->getId()]);
  7203.                         $em->flush();
  7204.                     }
  7205.                 }
  7206.             }
  7207.             if (isset($_FILES['appbundle_subcontractor_documents'])) {
  7208.                 $files $_FILES['appbundle_subcontractor_documents'];
  7209.                 $fileNames $_POST['appbundle_subcontractor_documents_names'];
  7210.                 for ($i=0;$i<count($files['name']);$i++) {
  7211.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  7212.                         $name $files["name"][$i];
  7213.                         $parts explode("."$name);
  7214.                         $extension end($parts);
  7215.                         $fileName $subcontractor->getId()."_".md5(uniqid()) . '.' $extension;
  7216.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  7217.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  7218.                         $document = new UserDocument();
  7219.                         $document->setName($docTitle);
  7220.                         $document->setFilename($fileName);
  7221.                         $document->setUserFilename($files["name"][$i]);
  7222.                         $document->setUser($this->getUser()->getUser());
  7223.                         $document->setSubcontractor($subcontractor);
  7224.                         $em->persist($document);
  7225.                         $em->flush();
  7226.                     }
  7227.                 }
  7228.             }
  7229.             $content "<p>Bonjour,<br/>
  7230.                         <br/>
  7231.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a modifié le sous-traitant groupe ".$subcontractor->getName()."<br/>
  7232.                         <br/>
  7233.                         <br/>
  7234.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  7235.                         </p>";
  7236.             $sendEmailService->send(
  7237.                 "Sous-traitant groupe modifié",
  7238.                 $this->getUser()->getUser()->getManager()->getEmail(),
  7239.                 'template_emails/left_text.html.twig',
  7240.                 [
  7241.                     "title" => "Sous-traitant groupe modifié",
  7242.                     "content" => $content
  7243.                 ]
  7244.             );
  7245.             $this->get('session')->getFlashBag()->add('success''Sous-traitant groupe mis à jour');
  7246.             return $this->redirectToRoute("user_subcontractors_grp");
  7247.         }
  7248.         return $this->render('user/subcontractors_grp_edit.html.twig', [
  7249.             "subcontractor" => $subcontractor,
  7250.             "form" => $form->createView()
  7251.         ]);
  7252.     }
  7253.     /**
  7254.      * @Route("/subcontractorsgrp/{id}/copy", name="subcontractors_grp_copy")
  7255.      */
  7256.     public function subcontractorsGrpCopyAction(Request $requestSendEmailService $sendEmailServiceSubcontractor $subcontractor)
  7257.     {
  7258.         if ($subcontractor->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  7259.             throw new NotFoundHttpException();
  7260.         }
  7261.         $newSubcontractor = clone $subcontractor;
  7262.         $newSubcontractor->setId(null);
  7263.         $newSubcontractor->getDocuments()->clear();
  7264.         $form $this->createForm(SubcontractorType::class, $newSubcontractor);
  7265.         if ($this->getUser()->getUser()->isMainGroupAgency()) {
  7266.             $form->add('group'CheckboxType::class, [
  7267.                 'label' => 'est_soustraitant_groupe',
  7268.                 'translation_domain' => 'messages',
  7269.                 'required' => false,
  7270.             ]);
  7271.         }
  7272.         $form->handleRequest($request);
  7273.         if ($form->isSubmitted() && $form->isValid()) {
  7274.             $em $this->getDoctrine()->getManager();
  7275.             $now = new \DateTime("now");
  7276.             $newSubcontractor->setDate($now);
  7277.             $newSubcontractor->setEditDate($now);
  7278.             $newSubcontractor->setUser($this->getUser()->getUser());
  7279.             $newSubcontractor->setGroup(true);
  7280.             $em->persist($newSubcontractor);
  7281.             $em->flush();
  7282.             if (isset($_FILES['appbundle_subcontractor_documents'])) {
  7283.                 $files $_FILES['appbundle_subcontractor_documents'];
  7284.                 $fileNames $_POST['appbundle_subcontractor_documents_names'];
  7285.                 for ($i=0;$i<count($files['name']);$i++) {
  7286.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  7287.                         $name $files["name"][$i];
  7288.                         $parts explode("."$name);
  7289.                         $extension end($parts);
  7290.                         $fileName $newSubcontractor->getId()."_".md5(uniqid()) . '.' $extension;
  7291.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  7292.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  7293.                         $document = new UserDocument();
  7294.                         $document->setName($docTitle);
  7295.                         $document->setFilename($fileName);
  7296.                         $document->setUserFilename($files["name"][$i]);
  7297.                         $document->setUser($this->getUser()->getUser());
  7298.                         $document->setSubcontractor($newSubcontractor);
  7299.                         $em->persist($document);
  7300.                         $em->flush();
  7301.                     }
  7302.                 }
  7303.             }
  7304.             $content "<p>Bonjour,<br/>
  7305.                         <br/>
  7306.                         Le client ".$this->getUser()->getUser()->getCompanyName()." a ajouté un nouveau sous-traitant groupe: ".$newSubcontractor->getName()."<br/>
  7307.                         <br/>
  7308.                         <br/>
  7309.                         <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  7310.                         </p>";
  7311.             $sendEmailService->send(
  7312.                 "Nouveau sous-traitant groupe",
  7313.                 $this->getUser()->getUser()->getManager()->getEmail(),
  7314.                 'template_emails/left_text.html.twig',
  7315.                 [
  7316.                     "title" => "Nouveau sous-traitant groupe",
  7317.                     "content" => $content
  7318.                 ]
  7319.             );
  7320.             $this->get('session')->getFlashBag()->add('success''Sous-traitant groupe dupliqué');
  7321.             return $this->redirectToRoute("user_subcontractors_grp");
  7322.         }
  7323.         return $this->render('user/subcontractors_grp_copy.html.twig', [
  7324.             "subcontractor" => $subcontractor,
  7325.             "form" => $form->createView()
  7326.         ]);
  7327.     }
  7328.     /**
  7329.      * @Route("/subcontractorsgrp/{id}/delete", name="subcontractors_grp_delete")
  7330.      */
  7331.     public function subcontractorsGrpDeleteAction(Request $requestSubcontractor $subcontractor)
  7332.     {
  7333.         if ($subcontractor->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  7334.             throw new NotFoundHttpException();
  7335.         }
  7336.         $em $this->getDoctrine()->getManager();
  7337.         $em->remove($subcontractor);
  7338.         $em->flush();
  7339.         $this->get('session')->getFlashBag()->add('success''Sous-traitant groupe supprimé');
  7340.         return $this->redirectToRoute("user_subcontractors_grp");
  7341.     }
  7342.     /**
  7343.      * @Route("/subcontractorsgrp/deletedoc/{subcontractor}/{document}", name="subcontractor_grp_deletedoc")
  7344.      */
  7345.     public function subcontractorsGrpDeleteDocAction(Request $requestSubcontractor $subcontractorUserDocument $userDocument)
  7346.     {
  7347.         $em $this->getDoctrine()->getManager();
  7348.         if ($subcontractor->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  7349.             throw new NotFoundHttpException();
  7350.         }
  7351.         if ($userDocument->getSubcontractor() == null || $userDocument->getSubcontractor()->getId() != $subcontractor->getId()) {
  7352.             throw new NotFoundHttpException();
  7353.         }
  7354.         $em->remove($userDocument);
  7355.         $em->flush();
  7356.         $this->get('session')->getFlashBag()->add('success''Document supprimé');
  7357.         return $this->redirectToRoute('user_subcontractors_grp_edit', ['id' => $subcontractor->getId()]);
  7358.     }
  7359.     /**
  7360.      * @Route("/trainings", name="trainings")
  7361.      */
  7362.     public function trainingsAction(Request $requestSendEmailService $sendEmailService)
  7363.     {
  7364.         $campains $this->getDoctrine()->getRepository(TrainingCampain::class)->findBy(["user" => $this->getUser()->getUser()], ["creationDate" => "DESC"]);
  7365.         $user $this->getUser()->getUser();
  7366.         $form $this->createFormBuilder()
  7367.             //->add("training", HiddenType::class, [])
  7368.             ->add('campain_type'ChoiceType::class, [
  7369.                 'attr' => [
  7370.                     'placeholder' => 'Type de campagne'
  7371.                 ],
  7372.                 'label' => 'Type de campagne',
  7373.                 'choices' => [
  7374.                     "campagne_interne" => "0",
  7375.                     "campagne_externe" => "1",
  7376.                 ],
  7377.                 'data' => '0',
  7378.                 'expanded' => true,
  7379.                 'multiple' => false,
  7380.                 'translation_domain' => 'messages',
  7381.             ])
  7382.             ->add("title"TextType::class, [
  7383.                 "attr" => [
  7384.                     "placeholder" => "titre_de_la_campagne"
  7385.                 ],
  7386.                 "label" => "titre_de_la_campagne",
  7387.                 "required" => true,
  7388.                 'translation_domain' => 'messages',
  7389.             ])
  7390.             ->add('traineeship'ChoiceType::class, [
  7391.                 'attr' => [
  7392.                     'placeholder' => 'Formation réalisée au préalable ?'
  7393.                 ],
  7394.                 'label' => 'Formation réalisée au préalable ?',
  7395.                 'choices' => [
  7396.                     "Oui" => "1",
  7397.                     "Non" => "0",
  7398.                 ],
  7399.                 'data' => '0',
  7400.                 'expanded' => true,
  7401.                 'multiple' => false,
  7402.             ])
  7403.             ->add("former"TextType::class, [
  7404.                 "attr" => [
  7405.                     "placeholder" => "nom_et_prenom_du_formateur"
  7406.                 ],
  7407.                 "label" => "nom_et_prenom_du_formateur",
  7408.                 "required" => false,
  7409.                 'translation_domain' => 'messages',
  7410.             ])
  7411.             ->add('traineeshipDate'TextType::class, [
  7412.                 'attr' => [
  7413.                     'placeholder' => '__/__/____',
  7414.                     'data-mask' => '00/00/0000',
  7415.                     'data-mask-clearifnotmatch' => 'true'
  7416.                 ],
  7417.                 'label' => "date_de_la_formation",
  7418.                 'required' => false,
  7419.                 'mapped' => false,
  7420.                 'translation_domain' => 'messages',
  7421.             ])
  7422.             ->add("emails"TextType::class, [
  7423.                 "label" => "ou_saisissez_les_adresses_mail",
  7424.                 "required" => false,
  7425.                 'translation_domain' => 'messages',
  7426.             ])
  7427.             ->add('teams'EntityType::class, [
  7428.                 'attr' => array(
  7429.                     'placeholder' => 'equipes_sensibilisees_ou_a_interroger',
  7430.                 ),
  7431.                 'label' => 'equipes_sensibilisees_ou_a_interroger',
  7432.                 'translation_domain' => 'messages',
  7433.                 "required" => false,
  7434.                 'expanded' => false,
  7435.                 'multiple' => true,
  7436.                 'class' => TrainingTeam::class,
  7437.                 'placeholder' => "Equipes",
  7438.                 'query_builder' => function (EntityRepository $er) use ($user) {
  7439.                     $qb $er->createQueryBuilder('tt');
  7440.                     return $qb->where('tt.user = :user')
  7441.                         ->setParameter("user"$user)
  7442.                         ->addOrderBy("tt.name""ASC");
  7443.                 },
  7444.                 'choice_label' => function(TrainingTeam $trainingTeam) {
  7445.                     return $trainingTeam->getName();
  7446.                 },
  7447.             ])
  7448.             ->add('training'EntityType::class, [
  7449.                 'attr' => array(
  7450.                     'placeholder' => 'Envoyer un questionnaire aux personnes',
  7451.                 ),
  7452.                 'label' => 'Envoyer un questionnaire aux personnes',
  7453.                 'expanded' => true,
  7454.                 'multiple' => false,
  7455.                 'class' => Training::class,
  7456.                 'placeholder' => "Aucun questionnaire",
  7457.                 'query_builder' => function (EntityRepository $er) use ($user) {
  7458.                     $qb $er->createQueryBuilder('t');
  7459.                     return $qb->where('t.active = true')
  7460.                         ->andWhere("t.answered = true")
  7461.                         ->leftJoin("t.users""u")
  7462.                         ->andWhere($qb->expr()->orX(
  7463.                             "t.availableForAll = true",
  7464.                             "u.id = :userId"
  7465.                         ))
  7466.                         ->setParameter("userId"$user->getId())
  7467.                         ->addOrderBy("t.title""ASC");
  7468.                 },
  7469.                 'choice_label' => function(Training $training) {
  7470.                     return $training->getTitle();
  7471.                 },
  7472.             ])
  7473.             ->getForm();
  7474.         $form->handleRequest($request);
  7475.         if ($form->isSubmitted() && $form->isValid()) {
  7476.             $emails json_decode($form['emails']->getData(), true);
  7477.             $emailsArray = [];
  7478. if ($emails) {
  7479.             foreach ($emails as $value) {
  7480.                 $emailAddress trim($value['value']);
  7481.                 if (filter_var($emailAddressFILTER_VALIDATE_EMAIL)) {
  7482.                     $emailsArray[] = $emailAddress;
  7483.                 }
  7484.             }
  7485. }
  7486. if ($form['teams']->getData()) {
  7487.             foreach ($form['teams']->getData() as $team) {
  7488.                 $addresses explode("\n"$team->getEmailAddresses());
  7489.                 foreach ($addresses as $address) {
  7490.                     $emailAddress trim($address);
  7491.                     if (filter_var($emailAddressFILTER_VALIDATE_EMAIL)) {
  7492.                         $emailsArray[] = $emailAddress;
  7493.                     }
  7494.                 }
  7495.             }
  7496. }
  7497.             $emailsArray array_unique($emailsArray);
  7498.             if (count($emailsArray)) {
  7499.                 $now = new \DateTime("now");
  7500.                 $em $this->getDoctrine()->getManager();
  7501.                 $campain = new TrainingCampain();
  7502.                 $campain->setUser($this->getUser()->getUser());
  7503.                 $campain->setCreationDate($now);
  7504.                 $traineeshipDate \DateTime::createFromFormat("d/m/Y"$form['traineeshipDate']->getData());
  7505.                 if ($traineeshipDate) {
  7506.                     $campain->setTraineeshipDate($traineeshipDate);
  7507.                 }
  7508.                 $campain->setTitle($form["title"]->getData());
  7509.                 $campain->setTraineeship($form["traineeship"]->getData());
  7510.                 $campain->setFormer($form["former"]->getData());
  7511.                 $campain->setExternal($form["campain_type"]->getData());
  7512.                 $campain->setEmails($emailsArray);
  7513.                 $campain->setEmailsCount(count($emailsArray));
  7514.                 $campain->setTeams($form['teams']->getData());
  7515.                 $em->persist($campain);
  7516.                 $em->flush();
  7517.                 $this->get('session')->getFlashBag()->add('success''Campagne de sensibilisation créée');
  7518.                 if ($campain->getTraineeship()) {
  7519.                     $system = new System();
  7520.                     $system->setData([
  7521.                         [
  7522.                             "title" => 'Description',
  7523.                             "value" => $campain->getTitle()
  7524.                         ],
  7525.                         [
  7526.                             "title" => 'Informations complémentaires',
  7527.                             "value" => "Nombre de personnes formées : ".$campain->getEmailsCount()
  7528.                         ]
  7529.                     ]);
  7530.                     $system->setName("Sensibilisation des personnels");
  7531.                     $system->setType("physical");
  7532.                     $system->setSubtype("sensitization");
  7533.                     $system->setUser($this->getUser()->getUser());
  7534.                     $em->persist($system);
  7535.                     $em->flush();
  7536.                 }
  7537.                 $training $form["training"]->getData();
  7538.                 if ($training) {
  7539.                     $campain->setQuestions($training->getQuestions());
  7540.                     $campain->setAnswers($training->getAnswers());
  7541.                     $campain->setTraining($training);
  7542.                     $em->flush();
  7543.                     $count 0;
  7544.                     foreach ($emailsArray as $email) {
  7545.                         $trainingRequest = new TrainingRequest();
  7546.                         $trainingRequest->setTrainingCampain($campain);
  7547.                         $trainingRequest->setEmail($email);
  7548.                         $trainingRequest->setToken(hash("sha256"uniqid($email)));
  7549.                         $em->persist($trainingRequest);
  7550.                         $em->flush();
  7551.                         $content "<p>Bonjour,<br/>
  7552.                             <br/>
  7553.                             Nous vous invitons à répondre au questionnaire de formation des équipes en cliquant sur le lien suivant: <br/>
  7554.                             <br/>
  7555.                             <br/>
  7556.                             <a href='".$this->generateUrl("default_training", ["email" => $trainingRequest->getEmail(), "token" => $trainingRequest->getToken()], UrlGeneratorInterface::ABSOLUTE_URL)."'>
  7557.                             ".$this->generateUrl("default_training", ["email" => $trainingRequest->getEmail(), "token" => $trainingRequest->getToken()], UrlGeneratorInterface::ABSOLUTE_URL)."
  7558.                             </a>
  7559.                             <br/>
  7560.                             <br/>
  7561.                             Si le lien n'est pas cliquable, collez le dans la barre d'adresse de votre navigateur.<br/><br/>
  7562.                             <br/>
  7563.                             Bien cordialement,<br/>
  7564.                             <br/>
  7565.                             <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  7566.                             </p>";
  7567.                         $sendEmailService->send(
  7568.                             "Questionnaire de formation des équipes",
  7569.                             $trainingRequest->getEmail(),
  7570.                             'template_emails/left_text.html.twig',
  7571.                             [
  7572.                                 "title" => $campain->getTraining()->getTitle(),
  7573.                                 "content" => $content
  7574.                             ]
  7575.                         );
  7576.                         $count++;
  7577.                     }
  7578.                     $this->get('session')->getFlashBag()->add('success'$count.' questionnaire(s) envoyé(s)');
  7579.                     return $this->redirectToRoute('user_trainings');
  7580.                 }
  7581.             }
  7582.         }
  7583.         return $this->render('user/trainings.html.twig', [
  7584.             "campains" => $campains,
  7585.             "form" => $form->createView(),
  7586.         ]);
  7587.     }
  7588.     /**
  7589.      * @Route("/trainings/teams", name="trainings_teams")
  7590.      */
  7591.     public function trainingsTeamsAction(Request $request)
  7592.     {
  7593.         $user $this->getUser()->getUser();
  7594.         $teams $this->getDoctrine()->getRepository(TrainingTeam::class)->findBy(["user" => $user], ["name" => "ASC"]);
  7595.         return $this->render('user/trainings_teams.html.twig', [
  7596.             "teams" => $teams,
  7597.         ]);
  7598.     }
  7599.     /**
  7600.      * @Route("/trainings/teams/add", name="trainings_teams_add")
  7601.      */
  7602.     public function trainingsTeamsAddAction(Request $request)
  7603.     {
  7604.         $user $this->getUser()->getUser();
  7605.         $team = new TrainingTeam();
  7606.         $form $this->createForm(TrainingTeamType::class, $team);
  7607.         $form->handleRequest($request);
  7608.         if ($form->isSubmitted() && $form->isValid()) {
  7609.             $em $this->getDoctrine()->getManager();
  7610.             $team->setUser($user);
  7611.             $em->persist($team);
  7612.             $em->flush();
  7613.             return $this->redirectToRoute("user_trainings_teams");
  7614.         }
  7615.         return $this->render('user/trainings_teams_add.html.twig', [
  7616.             "form" => $form->createView(),
  7617.         ]);
  7618.     }
  7619.     /**
  7620.      * @Route("/trainings/teams/{id}/edit", name="trainings_teams_edit")
  7621.      */
  7622.     public function trainingsTeamsEditAction(Request $requestTrainingTeam $team)
  7623.     {
  7624.         $user $this->getUser()->getUser();
  7625.         if ($team->getUser()->getId() != $user->getId()) {
  7626.             throw new NotFoundHttpException();
  7627.         }
  7628.         $form $this->createForm(TrainingTeamType::class, $team);
  7629.         $form->handleRequest($request);
  7630.         if ($form->isSubmitted() && $form->isValid()) {
  7631.             $em $this->getDoctrine()->getManager();
  7632.             $em->flush();
  7633.             return $this->redirectToRoute("user_trainings_teams");
  7634.         }
  7635.         return $this->render('user/trainings_teams_edit.html.twig', [
  7636.             "team" => $team,
  7637.             "form" => $form->createView(),
  7638.         ]);
  7639.     }
  7640.     /**
  7641.      * @Route("/trainings/teams/{id}/delete", name="trainings_teams_delete")
  7642.      */
  7643.     public function trainingsTeamsDeleteAction(Request $requestTrainingTeam $team)
  7644.     {
  7645.         $user $this->getUser()->getUser();
  7646.         if ($team->getUser()->getId() != $user->getId()) {
  7647.             throw new NotFoundHttpException();
  7648.         }
  7649.         $em $this->getDoctrine()->getManager();
  7650.         $em->remove($team);
  7651.         $em->flush();
  7652.         return $this->redirectToRoute("user_trainings_teams");
  7653.     }
  7654.     /**
  7655.      * @Route("/trainings/{id}/requests", name="trainings_requests")
  7656.      */
  7657.     public function trainingsRequestsAction(Request $request)
  7658.     {
  7659.         $trainingCampain $this->getDoctrine()->getRepository(TrainingCampain::class)->findOneBy(["id" => $request->get("id"), "user" => $this->getUser()->getUser()]);
  7660.         if (!$trainingCampain) {
  7661.             throw new NotFoundHttpException();
  7662.         }
  7663.         $trainingRequests $this->getDoctrine()->getRepository(TrainingRequest::class)->findBy(["trainingCampain" => $trainingCampain]);
  7664.         return $this->render('user/trainings_requests.html.twig', [
  7665.             "trainingCampain" => $trainingCampain,
  7666.             "trainingRequests" => $trainingRequests,
  7667.         ]);
  7668.     }
  7669.     /**
  7670.      * @Route("/trainings/{trainingCampain}/requests/all/revive", name="trainings_requests_revive_all")
  7671.      */
  7672.     public function trainingsRequestsReviveAllAction(Request $requestSendEmailService $sendEmailServiceTrainingCampain $trainingCampain)
  7673.     {
  7674.         if ($trainingCampain->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  7675.             throw new NotFoundHttpException();
  7676.         }
  7677.         $now = new \DateTime("now");
  7678.         $em $this->getDoctrine()->getManager();
  7679.         $trainingRequests $em->getRepository(TrainingRequest::class)->findBy(["trainingCampain" => $trainingCampain]);
  7680.         foreach ($trainingRequests as $trainingRequest) {
  7681.             if ($trainingRequest->getResendDate() && $now->getTimestamp() - $trainingRequest->getResendDate()->getTimestamp() < 172800) {
  7682.             } else {
  7683.                 $content "<p>Bonjour,<br/>
  7684.                             <br/>
  7685.                             Nous vous invitons à répondre au questionnaire de formation des équipes en cliquant sur le lien suivant: <br/>
  7686.                             <br/>
  7687.                             <br/>
  7688.                             <a href='".$this->generateUrl("default_training", ["email" => $trainingRequest->getEmail(), "token" => $trainingRequest->getToken()], UrlGeneratorInterface::ABSOLUTE_URL)."'>
  7689.                             ".$this->generateUrl("default_training", ["email" => $trainingRequest->getEmail(), "token" => $trainingRequest->getToken()], UrlGeneratorInterface::ABSOLUTE_URL)."
  7690.                             </a>
  7691.                             <br/>
  7692.                             <br/>
  7693.                             Si le lien n'est pas cliquable, collez le dans la barre d'adresse de votre navigateur.<br/><br/>
  7694.                             <br/>
  7695.                             Bien cordialement,<br/>
  7696.                             <br/>
  7697.                             <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  7698.                             </p>";
  7699.                 $sendEmailService->send(
  7700.                     "Questionnaire de formation des équipes",
  7701.                     $trainingRequest->getEmail(),
  7702.                     'template_emails/left_text.html.twig',
  7703.                     [
  7704.                         "title" => $trainingRequest->getTrainingCampain()->getTraining()->getTitle(),
  7705.                         "content" => $content
  7706.                     ]
  7707.                 );
  7708.             }
  7709.         }
  7710.         $this->get('session')->getFlashBag()->add("success""Les relances ont été envoyées.");
  7711.         return $this->redirectToRoute("user_trainings_requests", ["id" => $trainingCampain->getId()]);
  7712.     }
  7713.     /**
  7714.      * @Route("/trainings/{trainingCampain}/requests/{trainingRequest}/revive", name="trainings_requests_revive")
  7715.      */
  7716.     public function trainingsRequestsReviveAction(Request $requestSendEmailService $sendEmailServiceTrainingCampain $trainingCampainTrainingRequest $trainingRequest)
  7717.     {
  7718.         if ($trainingCampain->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  7719.             throw new NotFoundHttpException();
  7720.         }
  7721.         if ($trainingCampain->getId() != $trainingRequest->getTrainingCampain()->getId()) {
  7722.             throw new NotFoundHttpException();
  7723.         }
  7724.         $now = new \DateTime("now");
  7725.         if ($trainingRequest->getResendDate() && $now->getTimestamp() - $trainingRequest->getResendDate()->getTimestamp() < 172800) {
  7726.             $this->get('session')->getFlashBag()->add("danger""Vous ne pouvez envoyer des relances que toutes les 48h.");
  7727.         } else {
  7728.             $content "<p>Bonjour,<br/>
  7729.                             <br/>
  7730.                             Nous vous invitons à répondre au questionnaire de formation des équipes en cliquant sur le lien suivant: <br/>
  7731.                             <br/>
  7732.                             <br/>
  7733.                             <a href='".$this->generateUrl("default_training", ["email" => $trainingRequest->getEmail(), "token" => $trainingRequest->getToken()], UrlGeneratorInterface::ABSOLUTE_URL)."'>
  7734.                             ".$this->generateUrl("default_training", ["email" => $trainingRequest->getEmail(), "token" => $trainingRequest->getToken()], UrlGeneratorInterface::ABSOLUTE_URL)."
  7735.                             </a>
  7736.                             <br/>
  7737.                             <br/>
  7738.                             Si le lien n'est pas cliquable, collez le dans la barre d'adresse de votre navigateur.<br/><br/>
  7739.                             <br/>
  7740.                             Bien cordialement,<br/>
  7741.                             <br/>
  7742.                             <i>Cet e-mail a été envoyé depuis le site myDigitplace. NE PAS répondre à ce message automatique.</i><br/>
  7743.                             </p>";
  7744.             $sendEmailService->send(
  7745.                 "Questionnaire de formation des équipes",
  7746.                 $trainingRequest->getEmail(),
  7747.                 'template_emails/left_text.html.twig',
  7748.                 [
  7749.                     "title" => $trainingRequest->getTrainingCampain()->getTraining()->getTitle(),
  7750.                     "content" => $content
  7751.                 ]
  7752.             );
  7753.             $this->get('session')->getFlashBag()->add("success""La relance a été envoyée.");
  7754.         }
  7755.         return $this->redirectToRoute("user_trainings_requests", ["id" => $trainingCampain->getId()]);
  7756.     }
  7757.     /**
  7758.      * @Route("/trainings/{training}/answers", name="trainings_requests_answers")
  7759.      */
  7760.     public function trainingsRequestsAnswersAction(Request $request)
  7761.     {
  7762.         $trainingCampain $this->getDoctrine()->getRepository(TrainingCampain::class)->findOneBy(["id" => $request->get("training"), "user" => $this->getUser()->getUser()]);
  7763.         if (!$trainingCampain) {
  7764.             return new JsonResponse([
  7765.                 "success" => false
  7766.             ]);
  7767.         }
  7768.         $trainingRequest $this->getDoctrine()->getRepository(TrainingRequest::class)->findOneBy(["trainingCampain" => $trainingCampain"id" => $request->get("request")]);
  7769.         if (!$trainingRequest) {
  7770.             return new JsonResponse([
  7771.                 "success" => false
  7772.             ]);
  7773.         }
  7774.         return new JsonResponse([
  7775.             "success" => true,
  7776.             "html" => $this->renderView('user/includes/training_answers.html.twig', [
  7777.                 "trainingRequest" => $trainingRequest
  7778.             ])
  7779.         ]);
  7780.     }
  7781.     /**
  7782.      * @Route("/trainings/{training}/stats", name="trainings_requests_stats")
  7783.      */
  7784.     public function trainingsRequestsStatsAction(Request $request)
  7785.     {
  7786.         $trainingCampain $this->getDoctrine()->getRepository(TrainingCampain::class)->findOneBy(["id" => $request->get("training"), "user" => $this->getUser()->getUser()]);
  7787.         if (!$trainingCampain) {
  7788.             return new JsonResponse([
  7789.                 "success" => false
  7790.             ]);
  7791.         }
  7792.         $questionsChoices = [];
  7793.         $questionsChoicesTotal = [];
  7794.         $questionsCount = [];
  7795.         foreach ($trainingCampain->getQuestions() as $questionKey => $question) {
  7796.             $questionsChoices[$questionKey] = $question["choices"];
  7797.             $questionsCount[$questionKey] = 0;
  7798.             
  7799.             $questionsChoicesTotal[$questionKey] = [];
  7800.             foreach ($question["choices"] as $choiceKey => $choice) {
  7801.                 $questionsChoicesTotal[$questionKey][$choiceKey] = 0;
  7802.             }
  7803.         }
  7804.         $trainingRequests $this->getDoctrine()->getRepository(TrainingRequest::class)->findBy(["trainingCampain" => $trainingCampain]);
  7805.         foreach ($trainingRequests as $trainingRequest) {
  7806.             if ($trainingRequest->getAnswerDate()) {
  7807.                 foreach ($trainingCampain->getQuestions() as $key => $item) {
  7808.                     if (isset($questionsChoices[$key])) {
  7809.                         if ($item["choices"] == $questionsChoices[$key]) {
  7810.                             $questionsCount[$key] = $questionsCount[$key]+1;
  7811.                             foreach ($item["choices"] as $choiceKey => $choice) {
  7812.                                 if ($item["multiple"]) {
  7813.                                     if (in_array($choiceKey$trainingRequest->getUserAnswers()[$key])) {
  7814.                                         $questionsChoicesTotal[$key][$choiceKey] = $questionsChoicesTotal[$key][$choiceKey]+1;
  7815.                                     }
  7816.                                 } else {
  7817.                                     if ($choiceKey == $trainingRequest->getUserAnswers()[$key]) {
  7818.                                         $questionsChoicesTotal[$key][$choiceKey] = $questionsChoicesTotal[$key][$choiceKey]+1;
  7819.                                     }
  7820.                                 }
  7821.                             }
  7822.                         }
  7823.                     }
  7824.                 }
  7825.             }
  7826.         }
  7827.         return new JsonResponse([
  7828.             "success" => true,
  7829.             "html" => $this->renderView('user/includes/training_stats.html.twig', [
  7830.                 "trainingCampain" => $trainingCampain,
  7831.                 "questionsChoices" => $questionsChoices,
  7832.                 "questionsChoicesTotal" => $questionsChoicesTotal,
  7833.                 "questionsCount" => $questionsCount,
  7834.             ])
  7835.         ]);
  7836.     }
  7837.     /**
  7838.      * @Route("/userdocuments/{id}/delete", name="user_documents_delete")
  7839.      */
  7840.     public function userDocumentsDeleteAction(Request $requestUserDocument $userDocument)
  7841.     {
  7842.         if ($userDocument->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  7843.             throw new NotFoundHttpException();
  7844.         }
  7845.         $filePath $this->getParameter('documents_directory') . $userDocument->getFilename();
  7846.         $em $this->getDoctrine()->getManager();
  7847.         $em->remove($userDocument);
  7848.         $em->flush();
  7849.         unlink($filePath);
  7850.         $this->get('session')->getFlashBag()->add('success''Document supprimé');
  7851.         return $this->redirectToRoute("user_documents");
  7852.     }
  7853.     /**
  7854.      * @Route("/userdocuments/{id}", name="read_user_documents")
  7855.      */
  7856.     public function readUserDocumentsAction(Request $requestUserDocument $userDocument)
  7857.     {
  7858.         if ($userDocument->getUser()->getId() != $this->getUser()->getUser()->getId()) {
  7859.             if ($userDocument->getSubcontractor()) {
  7860.                 if (!$userDocument->getSubcontractor()->isGroup() || !$this->getUser()->getUser()->getParentUser() || $userDocument->getUser()->getId() != $this->getUser()->getUser()->getParentUser()->getId()) {
  7861.                     throw new NotFoundHttpException();
  7862.                 }
  7863.             } else {
  7864.                 throw new NotFoundHttpException();
  7865.             }
  7866.         }
  7867.         $filePath $this->getParameter('documents_directory') . $userDocument->getFilename();
  7868.         return $this->file($filePath$userDocument->getUserFilename(), ResponseHeaderBag::DISPOSITION_INLINE);
  7869.     }
  7870.     /**
  7871.      * @Route("/mdpdocuments/{type}/{document}", name="read_mdp_documents")
  7872.      */
  7873.     public function readMdpDocumentsAction(Request $requestDocumentType $typeDocument $document)
  7874.     {
  7875.         /*if ($this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  7876.             return true;
  7877.         }*/
  7878.         $noSubscription false;
  7879.         if (!$this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  7880.             if (!$this->getUser()->getUser()->getCurrentSubscription()) {
  7881.                 $noSubscription true;
  7882.             } else {
  7883.                 if (!$this->getUser()->getUser()->getCurrentSubscription()->isActive()) {
  7884.                     $noSubscription true;
  7885.                 } else {
  7886.                     if (!$this->getUser()->getUser()->getCurrentSubscription()->getEndDate()) {
  7887.                         $noSubscription true;
  7888.                     } else {
  7889.                         $now = new \DateTime("now");
  7890.                         if ($now >= $this->getUser()->getUser()->getCurrentSubscription()->getEndDate()) {
  7891.                             $noSubscription true;
  7892.                         } else {
  7893.                             $allowedSubscriptions = ["ABOPLS""ABOSTD""ABOLIB""PARTEN"];
  7894.                             if (!$this->getUser()->getUser()->getCurrentSubscription()->getType() || !in_array($this->getUser()->getUser()->getCurrentSubscription()->getType()->getCode(), $allowedSubscriptions)) {
  7895.                                 $noSubscription true;
  7896.                             }
  7897.                         }
  7898.                     }
  7899.                 }
  7900.             }
  7901.         }
  7902.         if ($noSubscription) {
  7903.             $this->get('session')->getFlashBag()->add('danger''Votre abonnement ne vous permet pas d\'accéder à cette fonctionnalité');
  7904.             throw new NotFoundHttpException();
  7905.         }
  7906.         $filePath $this->getParameter('documents_directory') . $document->getFilename();
  7907.         return $this->file($filePath$document->getFilename(), ResponseHeaderBag::DISPOSITION_INLINE);
  7908.     }
  7909.     /**
  7910.      * @Route("/json/treatments", name="json_treatments")
  7911.      */
  7912.     public function jsonTreatmentsAction(Request $request)
  7913.     {
  7914.         $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser()], ["name" => "ASC"]);
  7915.         $returnResponse = [];
  7916.         foreach ($treatments as $treatment) {
  7917.             $returnResponse[] = [
  7918.                 "id" => $treatment->getId(),
  7919.                 "text" => $treatment->getName(),
  7920.             ];
  7921.         }
  7922.         return new JsonResponse($returnResponse);
  7923.     }
  7924.     /**
  7925.      * @Route("/json/treatmentsgrp", name="json_treatments_grp")
  7926.      */
  7927.     public function jsonTreatmentsGrpAction(Request $request)
  7928.     {
  7929.         $treatments $this->getDoctrine()->getRepository(Treatment::class)->findBy(["user" => $this->getUser()->getUser(), "group" => true], ["name" => "ASC"]);
  7930.         $returnResponse = [];
  7931.         foreach ($treatments as $treatment) {
  7932.             $returnResponse[] = [
  7933.                 "id" => $treatment->getId(),
  7934.                 "text" => $treatment->getName(),
  7935.             ];
  7936.         }
  7937.         return new JsonResponse($returnResponse);
  7938.     }
  7939.     /**
  7940.      * @Route("/json/subcontractors", name="json_subcontractors")
  7941.      */
  7942.     public function jsonSubcontractorsAction(Request $request)
  7943.     {
  7944.         if (isset($_POST['name']) && !empty($_POST['name'])) {
  7945.             $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->searchAllForUser($this->getUser()->getUser(), $_POST['name']);
  7946.         } else {
  7947.             $subcontractors $this->getDoctrine()->getRepository(Subcontractor::class)->findAllForUser($this->getUser()->getUser());
  7948.         }
  7949.         $returnResponse = [];
  7950.         foreach ($subcontractors as $subcontractor) {
  7951.             $returnResponse[] = [
  7952.                 "id" => $subcontractor->getId(),
  7953.                 "text" => $subcontractor->getName(),
  7954.                 "st" => $subcontractor->getSubcontractorType()->getId(),
  7955.             ];
  7956.         }
  7957.         return new JsonResponse($returnResponse);
  7958.     }
  7959.     /**
  7960.      * @Route("/json/systems", name="json_systems")
  7961.      */
  7962.     public function jsonSystemsAction(Request $request)
  7963.     {
  7964.         if (isset($_POST['name']) && !empty($_POST['name'])) {
  7965.             $systems $this->getDoctrine()->getRepository(System::class)->searchAllForUserWithGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser(), $_POST['name']);
  7966.         } else {
  7967.             $systems $this->getDoctrine()->getRepository(System::class)->findForUserWithGroup($this->getUser()->getUser(), $this->getUser()->getUser()->getParentUser());
  7968.         }
  7969.         $returnResponse = [];
  7970.         foreach ($systems as $system) {
  7971.             $returnResponse[] = [
  7972.                 "id" => $system->getId(),
  7973.                 "text" => $system->getName(),
  7974.             ];
  7975.         }
  7976.         return new JsonResponse($returnResponse);
  7977.     }
  7978.     /**
  7979.      * @Route("/update/treatmentdata", name="update_treatmentdata")
  7980.      */
  7981.     public function updatetreatmentdataAction(Request $request)
  7982.     {
  7983.         throw new NotFoundHttpException();
  7984.         $em $this->getDoctrine()->getManager();
  7985.         $treatments $em->getRepository(Treatment::class)->findAll();
  7986.         // UPDATE 1
  7987.         /*foreach ($treatments as $treatment) {
  7988.             if ($treatment->getPersonalData()[5]["title"] == "Données Bancaires") {
  7989.                 $personnalData = $treatment->getPersonalData();
  7990.                 $personnalData[5]["title"] = "Données Bancaires (données courantes « non sensible » mais classifié comme tel au vu des risques financiers)";
  7991.                 $treatment->setPersonalData($personnalData);
  7992.                 $em->flush();
  7993.             }
  7994.         }*/
  7995.         return new JsonResponse("OK");
  7996.     }
  7997.     /**
  7998.      * @Route("/switch/{id}", name="user_switch")
  7999.      */
  8000.     public function userSwitchAction(Request $requestUser $user)
  8001.     {
  8002.         if (!$user->getParentUser() || $user->getParentUser()->getId() != $this->getUser()->getUser()->getId()) {
  8003.             throw new NotFoundHttpException();
  8004.         }
  8005.         return $this->redirectToRoute("default_homepage", ['_switch_user' =>  $user->getAccount()->getEmail()]);
  8006.     }
  8007.     /**
  8008.      * @Route("/json/toggleaction", name="json_toggle_action")
  8009.      */
  8010.     public function getJsonToggleActionAction(Request $request)
  8011.     {
  8012.         if (isset($_POST['id'])) {
  8013.             $em $this->getDoctrine()->getManager();
  8014.             $action $em->getRepository(Action::class)->find($_POST['id']);
  8015.             if ($action) {
  8016.                 if ($action->getUser()->getId() == $this->getUser()->getUser()->getId() || ($action->getGroupUser() && $action->getGroupUser()->getId() == $this->getUser()->getUser()->getId())) {
  8017.                    $action->setTerminated(!$action->isTerminated());
  8018.                    $em->flush();
  8019.                     return new JsonResponse([
  8020.                         "success" => true,
  8021.                         "state" => $action->isTerminated()
  8022.                     ]);
  8023.                 }
  8024.             }
  8025.         }
  8026.         return new JsonResponse([
  8027.             "success" => false
  8028.         ]);
  8029.     }
  8030.     /**
  8031.      * @Route("/json/existingsubcontractorgrp", name="json_existing_subcontractor_grp")
  8032.      */
  8033.     public function getexistingSubcontractorGrpAction(Request $request)
  8034.     {
  8035.         if (isset($_POST['terms'])) {
  8036.             $subcontractorGrp $this->getDoctrine()->getRepository(Subcontractor::class)->findExistingGroupForUserAndTerms($this->getUser()->getUser(), $_POST['terms']);
  8037.             if ($subcontractorGrp) {
  8038.                 return new JsonResponse([
  8039.                     "existing" => true,
  8040.                     "data" => $subcontractorGrp->getName()
  8041.                 ]);
  8042.             }
  8043.         }
  8044.         return new JsonResponse([
  8045.             "existing" => false,
  8046.             "data" => null
  8047.         ]);
  8048.     }
  8049.     /**
  8050.      * @Route("/json/info", name="json_info")
  8051.      */
  8052.     public function jsonInfoAction(Request $request)
  8053.     {
  8054.         if (isset($_GET['id'])) {
  8055.             $em $this->getDoctrine()->getManager();
  8056.             $info $em->getRepository(Info::class)->findOneBy(["id" => $_GET['id'], "enabled" => true]);
  8057.             if ($info) {
  8058.                 return new JsonResponse([
  8059.                     'title' => $info->getTitle(),
  8060.                     'content' => nl2br($info->getContent())
  8061.                 ]);
  8062.             }
  8063.         }
  8064.         return new JsonResponse([
  8065.             'title' => "",
  8066.             'content' => ""
  8067.         ]);
  8068.     }
  8069.     private function formatTreatmentNumber($number) {
  8070.         $str strval($number);
  8071.         $strLen strlen($str);
  8072.         $maxLen 3;
  8073.         if ($strLen $maxLen) {
  8074.             for ($i $strLen$i $maxLen$i++) {
  8075.                 $str "0".$str;
  8076.             }
  8077.         }
  8078.         return "T".$str;
  8079.     }
  8080.     private function isPrintingAllowed(Account $account) {
  8081.         if ($this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  8082.             return true;
  8083.         }
  8084.         $noSubscription false;
  8085.         if (!$account->getUser()->getCurrentSubscription()) {
  8086.             $noSubscription true;
  8087.         } else {
  8088.             if (!$account->getUser()->getCurrentSubscription()->isActive()) {
  8089.                 $noSubscription true;
  8090.             } else {
  8091.                 if (!$account->getUser()->getCurrentSubscription()->getEndDate()) {
  8092.                     $noSubscription true;
  8093.                 } else {
  8094.                     $now = new \DateTime("now");
  8095.                     if ($now >= $account->getUser()->getCurrentSubscription()->getEndDate()) {
  8096.                         $noSubscription true;
  8097.                     } else {
  8098.                         $allowedSubscriptions = ["ABOPLS""ABOSTD""ABOLIB""PARTEN""FREE30D"];
  8099.                         if (!$account->getUser()->getCurrentSubscription()->getType() || !in_array($account->getUser()->getCurrentSubscription()->getType()->getCode(), $allowedSubscriptions)) {
  8100.                             $noSubscription true;
  8101.                         }
  8102.                     }
  8103.                 }
  8104.             }
  8105.         }
  8106.         if ($noSubscription) {
  8107.             $this->get('session')->getFlashBag()->add('danger''Votre abonnement ne vous permet pas d\'accéder à cette fonctionnalité');
  8108.             return false;
  8109.         }
  8110.         return true;
  8111.     }
  8112.     private function isMdpReadDocAllowed(Account $account)
  8113.     {
  8114.         if ($this->isGranted("ROLE_PREVIOUS_ADMIN")) {
  8115.             return true;
  8116.         }
  8117.         $noSubscription false;
  8118.         if (!$account->getUser()->getCurrentSubscription()) {
  8119.             $noSubscription true;
  8120.         } else {
  8121.             if (!$account->getUser()->getCurrentSubscription()->isActive()) {
  8122.                 $noSubscription true;
  8123.             } else {
  8124.                 if (!$account->getUser()->getCurrentSubscription()->getEndDate()) {
  8125.                     $noSubscription true;
  8126.                 } else {
  8127.                     $now = new \DateTime("now");
  8128.                     if ($now >= $account->getUser()->getCurrentSubscription()->getEndDate()) {
  8129.                         $noSubscription true;
  8130.                     } else {
  8131.                         $allowedSubscriptions = ["ABOPLS""ABOSTD""ABOLIB""PARTEN"];
  8132.                         if (!$account->getUser()->getCurrentSubscription()->getType() || !in_array($account->getUser()->getCurrentSubscription()->getType()->getCode(), $allowedSubscriptions)) {
  8133.                             $noSubscription true;
  8134.                         }
  8135.                     }
  8136.                 }
  8137.             }
  8138.         }
  8139.         if ($noSubscription) {
  8140.             $this->get('session')->getFlashBag()->add('danger''Votre abonnement ne vous permet pas d\'accéder à cette fonctionnalité');
  8141.             return false;
  8142.         }
  8143.         return true;
  8144.     }
  8145. }