src/Controller/ManagerController.php line 1555

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Account;
  4. use App\Entity\ActionStd;
  5. use App\Entity\ActionStdDocument;
  6. use App\Entity\Credit;
  7. use App\Entity\Document;
  8. use App\Entity\DocumentType;
  9. use App\Entity\Info;
  10. use App\Entity\LoginLog;
  11. use App\Entity\Manager;
  12. use App\Entity\Partner;
  13. use App\Entity\Subcontractor;
  14. use App\Entity\SubcontractorStd;
  15. use App\Entity\SubcontractorStdDocument;
  16. use App\Entity\Subscription;
  17. use App\Entity\System;
  18. use App\Entity\SystemStd;
  19. use App\Entity\Training;
  20. use App\Entity\TrainingRequest;
  21. use App\Entity\TrainingRequestHistory;
  22. use App\Entity\Treatment;
  23. use App\Entity\TreatmentStd;
  24. use App\Entity\User;
  25. use App\Entity\UserDocument;
  26. use App\Form\ActionStdTranslateType;
  27. use App\Form\ActionStdType;
  28. use App\Form\InfoType;
  29. use App\Form\ManagerType;
  30. use App\Form\PartnerType;
  31. use App\Form\SubcontractorStdTranslateType;
  32. use App\Form\SubcontractorStdType;
  33. use App\Form\SubcontractorType;
  34. use App\Form\SubscriptionType;
  35. use App\Form\SubscriptionUserType;
  36. use App\Form\SystemStdTranslateType;
  37. use App\Form\SystemStdType;
  38. use App\Form\SystemType;
  39. use App\Form\TrainingTranslateType;
  40. use App\Form\TrainingType;
  41. use App\Form\TreatmentStdTranslateType;
  42. use App\Form\TreatmentStdType;
  43. use App\Form\TreatmentType;
  44. use App\Form\UserType;
  45. use App\Pdf\MyPdf;
  46. use Doctrine\ORM\EntityRepository;
  47. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  48. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  49. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  50. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  51. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  52. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  53. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  54. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  55. use Symfony\Component\Form\Extension\Core\Type\FileType;
  56. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  57. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  58. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  59. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  60. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  61. use Symfony\Component\Form\Extension\Core\Type\TextType;
  62. use Symfony\Component\HttpFoundation\File\UploadedFile;
  63. use Symfony\Component\HttpFoundation\JsonResponse;
  64. use Symfony\Component\HttpFoundation\Request;
  65. use Symfony\Component\HttpFoundation\StreamedResponse;
  66. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  67. use Symfony\Component\Routing\Annotation\Route;
  68. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  69. use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
  70. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  71. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  72. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  73. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  74. use Symfony\Component\Serializer\Serializer;
  75. use App\Security\PasswordEncoder;
  76. use Symfony\Component\Validator\Constraints as Assert;
  77. use function Doctrine\ORM\QueryBuilder;
  78. use Qipsius\TCPDFBundle\Controller\TCPDFController;
  79. /**
  80.  * @Route("/manager", name="manager_")
  81.  */
  82. class ManagerController extends AbstractController
  83. {
  84.     /**
  85.      * @Route("/", name="homepage")
  86.      */
  87.     public function indexAction(Request $request)
  88.     {
  89.         return $this->redirectToRoute("manager_users");
  90.     }
  91.     /**
  92.      * @Route("/account", name="account")
  93.      */
  94.     public function accountAction(Request $request)
  95.     {
  96.         $em $this->getDoctrine()->getManager();
  97.         $account $this->getUser();
  98.         $r_email $account->getEmail();
  99.         $form $this->createForm(ManagerType::class, $account->getManager());
  100.         $form['email']->setData($account->getEmail());
  101.         $form2 $this->createFormBuilder()
  102.             ->add('password'RepeatedType::class, array(
  103.                 'type' => PasswordType::class,
  104.                 'invalid_message' => 'Les mot de passe ne sont pas identiques',
  105.                 'first_options'  => array(
  106.                     'attr' => array(
  107.                         'placeholder' => 'Changer mot de passe'
  108.                     ),
  109.                     'constraints' =>[
  110.                         new Assert\NotBlank([
  111.                             'message' => 'Merci de saisir un mot de passe'
  112.                         ]),
  113.                         new Assert\Regex([
  114.                             'pattern' => '/^(?:(?=(\S*?[A-Z]){1})(?=(\S*?[a-z]){1})(?=(\S*?[0-9]){1})(?=\S*?[~!^(){}<>%@#&*+=_\-$`,.\/\\\;:\'"|\[\]]){1}.{12,})$/m',
  115.                             'message' => "Votre mot de passe doit respecter les recommandations de l'ANSSI : au moins 12 caractères de types différents (majuscules, minuscules, chiffres, caractères spéciaux)"
  116.                         ])
  117.                     ],
  118.                     'label' => "Nouveau mot de passe"
  119.                 ),
  120.                 'second_options' => array(
  121.                     'attr' => array(
  122.                         'placeholder' => 'Confirmation mot de passe'
  123.                     ),
  124.                     'label' => "Confirmez le mot de passe"
  125.                 ),
  126.                 'mapped' => false
  127.             ))->getForm();
  128.         $form->handleRequest($request);
  129.         $form2->handleRequest($request);
  130.         if ($form->isSubmitted() && $form->isValid()) {
  131.             $em->flush();
  132.             $this->get('session')->getFlashBag()->add('success''Profil mis à jour');
  133.             if ($r_email != $form['email']->getData()) {
  134.                 if (filter_var($form['email']->getData(), FILTER_VALIDATE_EMAIL)) {
  135.                     $other_account $em->getRepository(Account::class)->findOneBy(['email' => $form['email']->getData()]);
  136.                     if ($other_account && $other_account->getId() != $account->getId()) {
  137.                         $this->get('session')->getFlashBag()->add('danger''Cette adresse mail est déjà utilisée par un autre utilisateur');
  138.                     } else {
  139.                         $account->setEmail($form['email']->getData());
  140.                         $account->getManager()->setEmail($form['email']->getData());
  141.                         $em->flush();
  142.                         $oldToken $this->get('security.token_storage')->getToken();
  143.                         $token = new UsernamePasswordToken(
  144.                             $account//user object with updated username
  145.                             $oldToken->getFirewallName());
  146.                         $this->get('security.token_storage')->setToken($token);
  147.                         $this->get('session')->getFlashBag()->add('success''Identifiant de connexion modifié');
  148.                     }
  149.                 } else {
  150.                     $this->get('session')->getFlashBag()->add('danger''Cette adresse mail n\'est pas valide');
  151.                 }
  152.             }
  153.             return $this->redirectToRoute('manager_account');
  154.         }
  155.         if ($form2->isSubmitted() && $form2->isValid()) {
  156.             $salt md5(uniqid());
  157.             $pwd $form2['password']->getData();
  158.             $account->setSalt($salt);
  159.             $PasswordEncoder = new PasswordEncoder;
  160.             $enc_pwd $PasswordEncoder->encodePassword($pwd$salt);
  161.             $account->setPassword($enc_pwd);
  162.             $em->flush();
  163.             $this->get('session')->getFlashBag()->add('success''Mot de passe mis à jour');
  164.             return $this->redirectToRoute('manager_account');
  165.         }
  166.         return $this->render('manager/account.html.twig', [
  167.             'form' => $form->createView(),
  168.             'form2' => $form2->createView(),
  169.         ]);
  170.     }
  171.     /**
  172.      * @Route("/managers", name="managers")
  173.      */
  174.     public function managersAction(Request $request)
  175.     {
  176.         if (!$this->isGranted("ROLE_DPO")) {
  177.             throw new NotFoundHttpException();
  178.         }
  179.         $managers $this->getDoctrine()->getRepository(Manager::class)->findAll();
  180.         return $this->render('manager/managers.html.twig', [
  181.             "managers" => $managers
  182.         ]);
  183.     }
  184.     /**
  185.      * @Route("/managers/add", name="managers_add")
  186.      */
  187.     public function managersAddAction(Request $request)
  188.     {
  189.         if (!$this->isGranted("ROLE_DPO")) {
  190.             throw new NotFoundHttpException();
  191.         }
  192.         $manager = new Manager();
  193.         $form $this->createForm(ManagerType::class, $manager)
  194.             ->add('role'ChoiceType::class, [
  195.                 'attr' => [
  196.                     'placeholder' => 'Type de compte'
  197.                 ],
  198.                 'label' => 'Type de compte',
  199.                 'choices' => [
  200.                     "A définir" => "ROLE_MANAGER",
  201.                     "Administrateur" => "ROLE_ADMIN",
  202.                     "DPO" => "ROLE_DPO",
  203.                     "Juriste" => "ROLE_JURISTE",
  204.                     "Commerce" => "ROLE_COMMERCE",
  205.                 ],
  206.                 'required' => true,
  207.                 'mapped' => false
  208.             ])
  209.         ;
  210.         $form->handleRequest($request);
  211.         if ($form->isSubmitted() && $form->isValid()) {
  212.             $em $this->getDoctrine()->getManager();
  213.             if ($form['email']->getData()) {
  214.                 if (filter_var($form['email']->getData(), FILTER_VALIDATE_EMAIL)) {
  215.                     $other_account $em->getRepository(Account::class)->findOneBy(['email' => $form['email']->getData()]);
  216.                     if ($other_account) {
  217.                         $this->get('session')->getFlashBag()->add('danger''Cette adresse mail est déjà utilisée par un autre utilisateur');
  218.                     } else {
  219.                         $manager->setEmail($form['email']->getData());
  220.                     }
  221.                 } else {
  222.                     $this->get('session')->getFlashBag()->add('danger''Cette adresse mail n\'est pas valide');
  223.                 }
  224.             }
  225.             if ($manager->getEmail()) {
  226.                 $now = new \DateTime("now");
  227.                 $em->persist($manager);
  228.                 $account = new Account();
  229.                 $account->setEmail($manager->getEmail());
  230.                 $account->setEnabled(true);
  231.                 $account->setManager($manager);
  232.                 $account->setRegistrationDate($now);
  233.                 $account->setRoles([$form['role']->getData()]);
  234.                 $salt md5(uniqid());
  235.                 $pwd "";
  236.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  237.                 $charactersLength strlen($characters);
  238.                 for ($i 0$i 12$i++) {
  239.                     $pwd .= $characters[rand(0$charactersLength 1)];
  240.                 }
  241.                 $account->setSalt($salt);
  242.                 $PasswordEncoder = new PasswordEncoder;
  243.                 $enc_pwd $PasswordEncoder->encodePassword($pwd$salt);
  244.                 $account->setPassword($enc_pwd);
  245.                 $em->persist($account);
  246.                 $em->flush();
  247.                 $this->get('session')->getFlashBag()->add('success''Nouveau délégué ajouté');
  248.                 return $this->redirectToRoute("manager_managers");
  249.             }
  250.         }
  251.         return $this->render('manager/managers_add.html.twig', [
  252.             "form" => $form->createView(),
  253.         ]);
  254.     }
  255.     /**
  256.      * @Route("/managers/{id}/edit", name="managers_edit")
  257.      */
  258.     public function managersEditAction(Request $requestManager $manager)
  259.     {
  260.         if (!$this->isGranted("ROLE_DPO")) {
  261.             throw new NotFoundHttpException();
  262.         }
  263.         if ($manager->getAccount()->getId() == $this->getUser()->getId()) {
  264.             return $this->redirectToRoute("manager_account");
  265.         }
  266.         $r_email $manager->getEmail();
  267.         $form $this->createForm(ManagerType::class, $manager)
  268.             ->add('role'ChoiceType::class, [
  269.                 'attr' => [
  270.                     'placeholder' => 'Type de compte'
  271.                 ],
  272.                 'label' => 'Type de compte',
  273.                 'choices' => [
  274.                     "A définir" => "ROLE_MANAGER",
  275.                     "Administrateur" => "ROLE_ADMIN",
  276.                     "DPO" => "ROLE_DPO",
  277.                     "Juriste" => "ROLE_JURISTE",
  278.                     "Commerce" => "ROLE_COMMERCE",
  279.                 ],
  280.                 'required' => true,
  281.                 'mapped' => false
  282.             ])
  283.             ->add('enabled'CheckboxType::class, [
  284.                 'label' => "Compte actif",
  285.                 'required' => false,
  286.                 'mapped' => false
  287.             ])
  288.         ;
  289.         $form['email']->setData($manager->getEmail());
  290.         $form['enabled']->setData($manager->getAccount()->isEnabled());
  291.         $form['role']->setData($manager->getAccount()->getRoles()[0]);
  292.         $form->handleRequest($request);
  293.         if ($form->isSubmitted() && $form->isValid()) {
  294.             $em $this->getDoctrine()->getManager();
  295.             $manager->getAccount()->setEnabled($form['enabled']->getData());
  296.             $manager->getAccount()->setRoles([$form['role']->getData()]);
  297.             $this->get('session')->getFlashBag()->add('success''Compte mis à jour');
  298.             $em->flush();
  299.             if ($r_email != $form['email']->getData()) {
  300.                 if (filter_var($form['email']->getData(), FILTER_VALIDATE_EMAIL)) {
  301.                     $other_account $em->getRepository(Account::class)->findOneBy(['email' => $form['email']->getData()]);
  302.                     if ($other_account && $other_account->getId() != $manager->getAccount()->getId()) {
  303.                         $this->get('session')->getFlashBag()->add('danger''Cette adresse mail est déjà utilisée par un autre utilisateur');
  304.                     } else {
  305.                         $manager->getAccount()->setEmail($form['email']->getData());
  306.                         $manager->setEmail($form['email']->getData());
  307.                         $em->flush();
  308.                         $this->get('session')->getFlashBag()->add('success''Identifiant de connexion modifié');
  309.                     }
  310.                 } else {
  311.                     $this->get('session')->getFlashBag()->add('danger''Cette adresse mail n\'est pas valide');
  312.                 }
  313.             }
  314.             return $this->redirectToRoute("manager_managers");
  315.         }
  316.         return $this->render('manager/managers_edit.html.twig', [
  317.             "form" => $form->createView(),
  318.         ]);
  319.     }
  320.     /**
  321.      * @Route("/managers/{id}/delete", name="managers_delete")
  322.      */
  323.     public function managersDeleteAction(Request $requestManager $manager)
  324.     {
  325.         if (!$this->isGranted("ROLE_DPO")) {
  326.             throw new NotFoundHttpException();
  327.         }
  328.         $em $this->getDoctrine()->getManager();
  329.         $users $em->getRepository(User::class)->findBy(['manager' => $manager]);
  330.         $documents $em->getRepository(Document::class)->findBy(['manager' => $manager]);
  331.         if (count($users) == && count($documents) == 0) {
  332.             $em->remove($manager);
  333.             $em->flush();
  334.             $this->get('session')->getFlashBag()->add('success''Compte délégué supprimé');
  335.         } else {
  336.             $form $this->createFormBuilder()
  337.                 ->add('changeUsers'ChoiceType::class, [
  338.                     'choices' => [
  339.                         "Supprimer les clients" => "0",
  340.                         "Associer à un autre délégué" => "1",
  341.                     ],
  342.                     'data' => '1',
  343.                     'expanded' => true,
  344.                     'multiple' => false,
  345.                 ])
  346.                 ->add('managerUsers'EntityType::class, [
  347.                     'attr' => array(
  348.                         'placeholder' => 'Délégué à la Protection des Données',
  349.                     ),
  350.                     'label' => 'Délégué à la Protection des Données',
  351.                     'expanded' => false,
  352.                     'multiple' => false,
  353.                     'required' => true,
  354.                     'class' => Manager::class,
  355.                     'query_builder' => function (EntityRepository $er) use ( $manager ) {
  356.                         $qb $er->createQueryBuilder('m');
  357.                         return $qb->where('m.id != :managerId')
  358.                             ->setParameter("managerId"$manager->getId())
  359.                             ->orderBy('m.lastName''ASC');
  360.                     },
  361.                     'choice_label' => function(Manager $manager) {
  362.                         return $manager->getFirstName().' '.$manager->getLastName().' ('.$manager->getCompanyName().')';
  363.                     },
  364.                 ])
  365.                 ->add('changeDocuments'ChoiceType::class, [
  366.                     'choices' => [
  367.                         "Supprimer les documents" => "0",
  368.                         "Associer à un autre délégué" => "1",
  369.                     ],
  370.                     'data' => '1',
  371.                     'expanded' => true,
  372.                     'multiple' => false,
  373.                 ])
  374.                 ->add('managerDocuments'EntityType::class, [
  375.                     'attr' => array(
  376.                         'placeholder' => 'Délégué à la Protection des Données',
  377.                     ),
  378.                     'label' => 'Délégué à la Protection des Données',
  379.                     'expanded' => false,
  380.                     'multiple' => false,
  381.                     'required' => true,
  382.                     'class' => Manager::class,
  383.                     'query_builder' => function (EntityRepository $er) use ( $manager ) {
  384.                         $qb $er->createQueryBuilder('m');
  385.                         return $qb->where('m.id != :managerId')
  386.                             ->setParameter("managerId"$manager->getId())
  387.                             ->orderBy('m.lastName''ASC');
  388.                     },
  389.                     'choice_label' => function(Manager $manager) {
  390.                         return $manager->getFirstName().' '.$manager->getLastName().' ('.$manager->getCompanyName().')';
  391.                     },
  392.                 ])
  393.                 ->getForm();
  394.             $form->handleRequest($request);
  395.             if ($form->isSubmitted() && $form->isValid()) {
  396.                 $error false;
  397.                 if ($form['changeDocuments']->getData() && $form['changeDocuments']->getData() == "1") {
  398.                     if (!$form['managerDocuments']->getData()) {
  399.                         $error true;
  400.                     }
  401.                 }
  402.                 if ($form['changeUsers']->getData() && $form['changeUsers']->getData() == "1") {
  403.                     if (!$form['managerUsers']->getData()) {
  404.                         $error true;
  405.                     }
  406.                 }
  407.                 if (!$error) {
  408.                     if ($form['changeDocuments']->getData() && $form['changeDocuments']->getData() == "1") {
  409.                         foreach ($documents as $document) {
  410.                             $document->setManager($form['managerDocuments']->getData());
  411.                             $em->flush();
  412.                         }
  413.                     } else {
  414.                         foreach ($documents as $document) {
  415.                             $em->remove($document);
  416.                             $em->flush();
  417.                         }
  418.                     }
  419.                     if ($form['changeUsers']->getData() && $form['changeUsers']->getData() == "1") {
  420.                         foreach ($users as $user) {
  421.                             $user->setManager($form['managerUsers']->getData());
  422.                         }
  423.                     } else {
  424.                         foreach ($users as $user) {
  425.                             $em->remove($user);
  426.                             $em->flush();
  427.                         }
  428.                     }
  429.                     $em->remove($manager);
  430.                     $em->flush();
  431.                     $this->get('session')->getFlashBag()->add('success''Compte délégué supprimé');
  432.                     return $this->redirectToRoute("manager_managers");
  433.                 }
  434.             }
  435.             return $this->render('manager/managers_delete.html.twig', [
  436.                 "form" => $form->createView(),
  437.             ]);
  438.         }
  439.         return $this->redirectToRoute("manager_managers");
  440.     }
  441.     /**
  442.      * @Route("/currentsubscriptions", name="current_subscriptions")
  443.      */
  444.     public function currentSubscriptionsAction(Request $request)
  445.     {
  446.         if ($this->isGranted("ROLE_DPO")) {
  447.             $users $this->getDoctrine()->getRepository(User::class)->findAll();
  448.         } elseif ($this->isGranted("ROLE_JURISTE")) {
  449.             $users $this->getDoctrine()->getRepository(User::class)->findForManager($this->getUser()->getManager());
  450.         } else {
  451.             $users $this->getDoctrine()->getRepository(User::class)->findBy(['demo' => true]);
  452.         }
  453.         return $this->render('manager/current_subscriptions.html.twig', [
  454.             "users" => $users,
  455.             "now" => new \DateTime("now"),
  456.         ]);
  457.     }
  458.     /**
  459.      * @Route("/users", name="users")
  460.      */
  461.     public function usersAction(Request $request)
  462.     {
  463.         if ($this->isGranted("ROLE_DPO")) {
  464.             $users $this->getDoctrine()->getRepository(User::class)->findAll();
  465.         } elseif ($this->isGranted("ROLE_JURISTE")) {
  466.             $users $this->getDoctrine()->getRepository(User::class)->findForManager($this->getUser()->getManager());
  467.         } else {
  468.             $users $this->getDoctrine()->getRepository(User::class)->findBy(['demo' => true]);
  469.         }
  470.         return $this->render('manager/users.html.twig', [
  471.             "users" => $users
  472.         ]);
  473.     }
  474.     /**
  475.      * @Route("/users/add", name="users_add")
  476.      */
  477.     public function usersAddAction(Request $request)
  478.     {
  479.         $user = new User();
  480.         $form $this->createForm(UserType::class, $user);
  481.         if ($this->isGranted("ROLE_DPO")) {
  482.             $isAdmin true;
  483.         } else {
  484.             $isAdmin false;
  485.         }
  486.         $manager $this->getUser()->getManager();
  487.         $form->add('parentUser'EntityType::class, [
  488.                 'attr' => array(
  489.                     'placeholder' => 'Compte client principal',
  490.                 ),
  491.                 'label' => 'Compte client principal',
  492.                 'placeholder' => 'Compte client principal',
  493.                 'expanded' => false,
  494.                 'multiple' => false,
  495.                 'required' => false,
  496.                 'class' => User::class,
  497.                 'query_builder' => function (EntityRepository $er) use ( $user$manager$isAdmin ) {
  498.                     $qb $er->createQueryBuilder('u');
  499.                     if (!$isAdmin) {
  500.                         $qb->andWhere("u.manager = :manager")
  501.                         ->setParameter("manager"$manager);
  502.                     }
  503.                     return $qb->orderBy('u.companyName''ASC');
  504.                 },
  505.                 'choice_label' => function(User $queryUser) {
  506.                     return $queryUser->getCompanyName();
  507.                 },
  508.             ])
  509.             ->add('childrenUsers'EntityType::class, [
  510.                 'attr' => array(
  511.                     'placeholder' => 'Comptes clients rattachés',
  512.                 ),
  513.                 'label' => 'Comptes clients rattachés',
  514.                 'placeholder' => 'Comptes clients rattachés',
  515.                 'expanded' => false,
  516.                 'multiple' => true,
  517.                 'required' => false,
  518.                 'class' => User::class,
  519.                 'query_builder' => function (EntityRepository $er) use ( $user$manager$isAdmin ) {
  520.                     $qb $er->createQueryBuilder('u');
  521.                     if (!$isAdmin) {
  522.                         $qb->andWhere("u.manager = :manager")
  523.                             ->setParameter("manager"$manager);
  524.                     }
  525.                     return $qb->orderBy('u.companyName''ASC');
  526.                 },
  527.                 'choice_label' => function(User $queryUser) {
  528.                     return $queryUser->getCompanyName();
  529.                 },
  530.             ])
  531.             ;
  532.         if ($this->isGranted("ROLE_DPO")) {
  533.             $form->add('manager'EntityType::class, [
  534.                 'attr' => array(
  535.                     'placeholder' => 'Délégué à la Protection des Données',
  536.                 ),
  537.                 'label' => 'Délégué à la Protection des Données',
  538.                 'expanded' => false,
  539.                 'multiple' => false,
  540.                 'required' => true,
  541.                 'data' => $this->getUser()->getManager(),
  542.                 'class' => Manager::class,
  543.                 'choice_label' => function(Manager $manager) {
  544.                     return $manager->getFirstName().' '.$manager->getLastName().' ('.$manager->getCompanyName().')';
  545.                 },
  546.             ])
  547.                 ->add('managerDpo'CheckboxType::class, [
  548.                 'label' => "Délégué à la Protection des Données",
  549.                 'required' => false
  550.             ])
  551.                 ->add('lawyer'EntityType::class, [
  552.                     'attr' => array(
  553.                         'placeholder' => 'Juriste',
  554.                     ),
  555.                     'label' => 'Juriste',
  556.                     'expanded' => false,
  557.                     'multiple' => false,
  558.                     'required' => false,
  559.                     'class' => Manager::class,
  560.                     'choice_label' => function(Manager $manager) {
  561.                         return $manager->getFirstName().' '.$manager->getLastName().' ('.$manager->getCompanyName().')';
  562.                     },
  563.                 ]);
  564.         } else {
  565.             $form->add('managerDpo'CheckboxType::class, [
  566.                 'label' => "Vous êtes DPO pour ce client",
  567.                 'required' => false
  568.             ]);
  569.         }
  570.         $form->add('demo'CheckboxType::class, [
  571.             'label' => "Compte de démo pour les commerciaux",
  572.             'required' => false
  573.         ]);
  574.         $form->handleRequest($request);
  575.         if ($form->isSubmitted() && $form->isValid()) {
  576.             $em $this->getDoctrine()->getManager();
  577.             if ($form['email']->getData()) {
  578.                 if (filter_var($form['email']->getData(), FILTER_VALIDATE_EMAIL)) {
  579.                     $other_account $em->getRepository(Account::class)->findOneBy(['email' => $form['email']->getData()]);
  580.                     if ($other_account) {
  581.                         $this->get('session')->getFlashBag()->add('danger''Cette adresse mail est déjà utilisée par un autre utilisateur');
  582.                     } else {
  583.                         $user->setEmail($form['email']->getData());
  584.                     }
  585.                 } else {
  586.                     $this->get('session')->getFlashBag()->add('danger''Cette adresse mail n\'est pas valide');
  587.                 }
  588.             }
  589.             if ($user->getEmail()) {
  590.                 $now = new \DateTime("now");
  591.                 if (!$this->isGranted("ROLE_DPO")) {
  592.                     $user->setManager($this->getUser()->getManager());
  593.                 }
  594.                 $em->persist($user);
  595.                 $account = new Account();
  596.                 $account->setEmail($user->getEmail());
  597.                 $account->setEnabled(true);
  598.                 $account->setUser($user);
  599.                 $account->setRegistrationDate($now);
  600.                 $account->setRoles(["ROLE_USER"]);
  601.                 $salt md5(uniqid());
  602.                 $pwd "";
  603.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  604.                 $charactersLength strlen($characters);
  605.                 for ($i 0$i 12$i++) {
  606.                     $pwd .= $characters[rand(0$charactersLength 1)];
  607.                 }
  608.                 $account->setSalt($salt);
  609.                 $PasswordEncoder = new PasswordEncoder;
  610.                 $enc_pwd $PasswordEncoder->encodePassword($pwd$salt);
  611.                 $account->setPassword($enc_pwd);
  612.                 $em->persist($account);
  613.                 $em->flush();
  614.                 if ($form['childrenUsers']->getData()) {
  615.                     foreach ($form['childrenUsers']->getData() as $childUser) {
  616.                         $tmpChildUser $em->getRepository(User::class)->find($childUser->getId());
  617.                         if ($tmpChildUser) {
  618.                             $tmpChildUser->setParentUser($user);
  619.                             $em->flush();
  620.                         }
  621.                     }
  622.                 }
  623.                 $beginDate = new \DateTime("now");
  624.                 $beginDate->setTime(000);
  625.                 $endDate = clone $beginDate;
  626.                 $endDate->sub(new \DateInterval("P1D"));
  627.                 $endDate->add(new \DateInterval("P30D"));
  628.                 $defaultSubscriptionType $em->getRepository(\App\Entity\SubscriptionType::class)->findOneBy(["code" => "FREE30D"]);
  629.                 $defaultSubcription = new Subscription();
  630.                 $defaultSubcription->setCreationDate($beginDate);
  631.                 $defaultSubcription->setBeginDate($beginDate);
  632.                 $defaultSubcription->setEndDate($endDate);
  633.                 $defaultSubcription->setPaymentUntil($endDate);
  634.                 $defaultSubcription->setInvolvementMonths(0);
  635.                 $defaultSubcription->setBillingMonths(0);
  636.                 $defaultSubcription->setUnitBillingPrice(0);
  637.                 $defaultSubcription->setActive(true);
  638.                 $defaultSubcription->setUser($user);
  639.                 $defaultSubcription->setType($defaultSubscriptionType);
  640.                 $em->persist($defaultSubcription);
  641.                 $em->flush();
  642.                 $user->setCurrentSubscription($defaultSubcription);
  643.                 $em->flush();
  644.                 if ($user->getParentUser()) {
  645.                     $parentTreatments $em->getRepository(Treatment::class)->findBy(["user" => $user->getParentUser(), "group" => true]);
  646.                     foreach ($parentTreatments as $parentTreatment) {
  647.                         $user->getGroupTreatments()->add($parentTreatment);
  648.                     }
  649.                     $em->flush();
  650.                 }
  651.                 if ($user->getChildrenUsers()) {
  652.                     $parentTreatments $em->getRepository(Treatment::class)->findBy(["user" => $user"group" => true]);
  653.                     foreach ($user->getChildrenUsers() as $childUser) {
  654.                         foreach ($parentTreatments as $parentTreatment) {
  655.                             if (!$childUser->getGroupTreatments()->contains($parentTreatment)) {
  656.                                 $childUser->getGroupTreatments()->add($parentTreatment);
  657.                             }
  658.                         }
  659.                     }
  660.                     $em->flush();
  661.                 }
  662.                 $this->get('session')->getFlashBag()->add('success''Nouveau client ajouté');
  663.                 $this->get('session')->getFlashBag()->add('success''Abonnement attribué au nouveau client : '.$defaultSubscriptionType->getLibelle());
  664.                 if ($this->isGranted("ROLE_ADMIN")) {
  665.                     return $this->redirectToRoute("manager_subscriptions_user", ["id" => $user->getId()]);
  666.                 } else {
  667.                     return $this->redirectToRoute("manager_users");
  668.                 }
  669.             }
  670.         }
  671.         return $this->render('manager/users_add.html.twig', [
  672.             "form" => $form->createView(),
  673.         ]);
  674.     }
  675.     /**
  676.      * @Route("/users/{id}/edit", name="users_edit")
  677.      */
  678.     public function usersEditAction(Request $requestUser $user)
  679.     {
  680.         if (!$this->isGranted("ROLE_DPO")) {
  681.             if ($user->getManager()->getId() != $this->getUser()->getManager()->getId()) {
  682.                 throw new NotFoundHttpException();
  683.             }
  684.         }
  685.         if ($this->isGranted("ROLE_DPO")) {
  686.             $isAdmin true;
  687.         } else {
  688.             $isAdmin false;
  689.         }
  690.         $manager $this->getUser()->getManager();
  691.         $r_email $user->getEmail();
  692.         $hasParentUser = ($user->getParentUser() != null);
  693.         $childUsersIds = [];
  694.         foreach ($user->getChildrenUsers() as $childUser) {
  695.             $childUsersIds[] = $childUser->getId();
  696.         }
  697.         $form $this->createForm(UserType::class, $user)
  698.             ->add('enabled'CheckboxType::class, [
  699.                 'label' => "Compte actif",
  700.                 'required' => false,
  701.                 'mapped' => false
  702.             ])
  703.         ;
  704.         $form->add('parentUser'EntityType::class, [
  705.             'attr' => array(
  706.                 'placeholder' => 'Compte client principal',
  707.             ),
  708.             'label' => 'Compte client principal',
  709.             'placeholder' => 'Compte client principal',
  710.             'expanded' => false,
  711.             'multiple' => false,
  712.             'required' => false,
  713.             'class' => User::class,
  714.             'query_builder' => function (EntityRepository $er) use ( $user$manager$isAdmin ) {
  715.                 $qb $er->createQueryBuilder('u');
  716.                 $qb->where('u.id != :userId')
  717.                     ->setParameter("userId"$user->getId());
  718.                 if (!$isAdmin) {
  719.                     $qb->andWhere("u.manager = :manager")
  720.                         ->setParameter("manager"$manager);
  721.                 }
  722.                 return $qb->orderBy('u.companyName''ASC');
  723.             },
  724.             'choice_label' => function(User $queryUser) {
  725.                 return $queryUser->getCompanyName();
  726.             },
  727.         ])
  728.             ->add('childrenUsers'EntityType::class, [
  729.                 'attr' => array(
  730.                     'placeholder' => 'Comptes clients rattachés',
  731.                 ),
  732.                 'label' => 'Comptes clients rattachés',
  733.                 'placeholder' => 'Comptes clients rattachés',
  734.                 'expanded' => false,
  735.                 'multiple' => true,
  736.                 'required' => false,
  737.                 'class' => User::class,
  738.                 'query_builder' => function (EntityRepository $er) use ( $user$manager$isAdmin ) {
  739.                     $qb $er->createQueryBuilder('u');
  740.                     $qb->where('u.id != :userId')
  741.                         ->setParameter("userId"$user->getId());
  742.                     if (!$isAdmin) {
  743.                         $qb->andWhere("u.manager = :manager")
  744.                             ->setParameter("manager"$manager);
  745.                     }
  746.                     return $qb->orderBy('u.companyName''ASC');
  747.                 },
  748.                 'choice_label' => function(User $queryUser) {
  749.                     return $queryUser->getCompanyName();
  750.                 },
  751.             ])
  752.             ;
  753.         if ($this->isGranted("ROLE_DPO")) {
  754.             $form->add('manager'EntityType::class, [
  755.                 'attr' => array(
  756.                     'placeholder' => 'Délégué à la Protection des Données',
  757.                 ),
  758.                 'label' => 'Délégué à la Protection des Données',
  759.                 'expanded' => false,
  760.                 'multiple' => false,
  761.                 'required' => true,
  762.                 'class' => Manager::class,
  763.                 'choice_label' => function(Manager $manager) {
  764.                     return $manager->getFirstName().' '.$manager->getLastName().' ('.$manager->getCompanyName().')';
  765.                 },
  766.             ])
  767.                 ->add('managerDpo'CheckboxType::class, [
  768.                 'label' => "Délégué à la Protection des Données",
  769.                 'required' => false
  770.             ])
  771.                 ->add('lawyer'EntityType::class, [
  772.                     'attr' => array(
  773.                         'placeholder' => 'Juriste',
  774.                     ),
  775.                     'label' => 'Juriste',
  776.                     'expanded' => false,
  777.                     'multiple' => false,
  778.                     'required' => false,
  779.                     'class' => Manager::class,
  780.                     'choice_label' => function(Manager $manager) {
  781.                         return $manager->getFirstName().' '.$manager->getLastName().' ('.$manager->getCompanyName().')';
  782.                     },
  783.                 ]);
  784.         } else {
  785.             $form->add('managerDpo'CheckboxType::class, [
  786.                 'label' => "Vous êtes DPO pour ce client",
  787.                 'required' => false
  788.             ]);
  789.         }
  790.         $form['email']->setData($user->getEmail());
  791.         $form['enabled']->setData($user->getAccount()->isEnabled());
  792.         $form->handleRequest($request);
  793.         if ($form->isSubmitted() && $form->isValid()) {
  794.             $em $this->getDoctrine()->getManager();
  795.             $user->getAccount()->setEnabled($form['enabled']->getData());
  796.             /**
  797.              * @var UploadedFile $file
  798.              */
  799.             $file $form->get('pictureFile')->getData();
  800.             if ($file != NULL) {
  801.                 $fileName $user->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  802.                 $file->move(
  803.                     $this->getParameter('pictures_directory'), $fileName
  804.                 );
  805.                 $user->setPicture($fileName);
  806.             }
  807.             $this->get('session')->getFlashBag()->add('success''Compte mis à jour');
  808.             $em->flush();
  809.             if (!$hasParentUser && $user->getParentUser()) {
  810.                 $parentTreatments $em->getRepository(Treatment::class)->findBy(["user" => $user->getParentUser(), "group" => true]);
  811.                 foreach ($parentTreatments as $parentTreatment) {
  812.                     $user->getGroupTreatments()->add($parentTreatment);
  813.                 }
  814.                 $em->flush();
  815.             } elseif ($hasParentUser && !$user->getParentUser()) {
  816.                 $user->getGroupTreatments()->clear();
  817.                 $em->flush();
  818.             }
  819.             $parentTreatments $em->getRepository(Treatment::class)->findBy(["user" => $user"group" => true]);
  820.             if ($form['childrenUsers']->getData()) {
  821.                 foreach ($form['childrenUsers']->getData() as $childUser) {
  822.                     $keyExistingChildUser array_search($childUser->getId(), $childUsersIds);
  823.                     if ($keyExistingChildUser !== FALSE) {
  824.                         unset($childUsersIds[$keyExistingChildUser]);
  825.                     } else {
  826.                         $tmpChildUser $em->getRepository(User::class)->find($childUser->getId());
  827.                         if ($tmpChildUser) {
  828.                             $tmpChildUser->setParentUser($user);
  829.                             $em->flush();
  830.                             foreach ($parentTreatments as $parentTreatment) {
  831.                                 if (!$tmpChildUser->getGroupTreatments()->contains($parentTreatment)) {
  832.                                     $tmpChildUser->getGroupTreatments()->add($parentTreatment);
  833.                                 }
  834.                             }
  835.                             $em->flush();
  836.                         }
  837.                     }
  838.                 }
  839.             }
  840.             foreach ($childUsersIds as $childUserId) {
  841.                 $tmpChildUser $em->getRepository(User::class)->find($childUserId);
  842.                 if ($tmpChildUser) {
  843.                     $tmpChildUser->setParentUser(null);
  844.                     $em->flush();
  845.                     foreach ($parentTreatments as $parentTreatment) {
  846.                         if ($tmpChildUser->getGroupTreatments()->contains($parentTreatment)) {
  847.                             $tmpChildUser->getGroupTreatments()->removeElement($parentTreatment);
  848.                         }
  849.                     }
  850.                     $em->flush();
  851.                 }
  852.             }
  853.             if ($r_email != $form['email']->getData()) {
  854.                 if (filter_var($form['email']->getData(), FILTER_VALIDATE_EMAIL)) {
  855.                     $other_account $em->getRepository(Account::class)->findOneBy(['email' => $form['email']->getData()]);
  856.                     if ($other_account && $other_account->getId() != $user->getAccount()->getId()) {
  857.                         $this->get('session')->getFlashBag()->add('danger''Cette adresse mail est déjà utilisée par un autre utilisateur');
  858.                     } else {
  859.                         $user->getAccount()->setEmail($form['email']->getData());
  860.                         $user->setEmail($form['email']->getData());
  861.                         $em->flush();
  862.                         $this->get('session')->getFlashBag()->add('success''Identifiant de connexion modifié');
  863.                     }
  864.                 } else {
  865.                     $this->get('session')->getFlashBag()->add('danger''Cette adresse mail n\'est pas valide');
  866.                 }
  867.             }
  868.             return $this->redirectToRoute("manager_users");
  869.         }
  870.         return $this->render('manager/users_edit.html.twig', [
  871.             "form" => $form->createView(),
  872.             "user" => $user
  873.         ]);
  874.     }
  875.     /**
  876.      * @Route("/users/{id}/delete", name="users_delete")
  877.      */
  878.     public function usersDeleteAction(Request $requestUser $user)
  879.     {
  880.         if (!$this->isGranted("ROLE_DPO")) {
  881.             //if ($user->getManager()->getId() != $this->getUser()->getManager()->getId()) {
  882.                 throw new NotFoundHttpException();
  883.             //}
  884.         }
  885.         $em $this->getDoctrine()->getManager();
  886.         $em->remove($user);
  887.         $em->flush();
  888.         $this->get('session')->getFlashBag()->add('success''Compte client supprimé');
  889.         return $this->redirectToRoute("manager_users");
  890.     }
  891.     /**
  892.      * @Route("/users/{id}/print", name="users_print")
  893.      */
  894.     public function usersPrintAction(Request $requestUser $user)
  895.     {
  896.         $tcpdf = new TCPDFController('TCPDF');
  897.         $pdf $tcpdf->create('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  898.         $pdf->SetPrintHeader(false);
  899.         $pdf->SetAuthor('myDigitplace');
  900.         $pdf->SetTitle("Fiche société");
  901.         $pdf->AddPage('P''A4');
  902.         $html $this->renderView('manager/pdf/user.html.twig', [
  903.             "user" => $user
  904.         ]);
  905.         $filename 'fiche_societe';
  906.         $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  907.         return $pdf->Output($filename.".pdf",'I');
  908.     }
  909.     /**
  910.      * @Route("/documents", name="documents")
  911.      */
  912.     public function documentsAction(Request $request)
  913.     {
  914.         $documentsTypes $this->getDoctrine()->getRepository(DocumentType::class)->findBy(["parent" => null]);
  915.         $typesChoices = [];
  916.         $types $this->getDoctrine()->getRepository(DocumentType::class)->findBy(["parent" => null]);
  917.         foreach ($types as $type) {
  918.             $typesChoices[] = (object) ['value' => $type->getId(), 'label' => $type->getLibelle()];
  919.             foreach ($type->getChildren() as $child) {
  920.                 $typesChoices[] = (object) ['value' => $child->getId(), 'label' => "|----".$child->getLibelle()];
  921.             }
  922.         }
  923.         $form $this->createFormBuilder()
  924.             ->add('file'FileType::class, [
  925.                 'attr' => [
  926.                     'placeholder' => 'Fichier'
  927.                 ],
  928.                 'label' => 'Fichier',
  929.                 'required' => true,
  930.                 'mapped' => false
  931.             ])
  932.             ->add('name'TextType::class, [
  933.                 'attr' => [
  934.                     'placeholder' => 'Nom'
  935.                 ],
  936.                 'label' => 'Nom',
  937.                 'required' => false,
  938.                 'mapped' => false
  939.             ])
  940.             ->add('type'ChoiceType::class, [
  941.                 'attr' => array(
  942.                     'placeholder' => 'Type',
  943.                 ),
  944.                 'label' => 'Type',
  945.                 'expanded' => false,
  946.                 'multiple' => false,
  947.                 'required' => true,
  948.                 'mapped' => false,
  949.                 'choices' => $typesChoices,
  950.                 'choice_label' => function($entry) { return $entry!=null $entry->label ""; },
  951.                 'choice_value' => function($entry) { return $entry!=null $entry->value 0; },
  952.             ])->getForm();
  953.         $form->handleRequest($request);
  954.         if ($form->isSubmitted() && $form->isValid()) {
  955.             $em $this->getDoctrine()->getManager();
  956.             /**
  957.              * @var UploadedFile $file
  958.              */
  959.             $file $form->get('file')->getData();
  960.             if ($file != NULL) {
  961.                 $fileName $this->getUser()->getManager()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  962.                 $file->move(
  963.                     $this->getParameter('documents_directory'), $fileName
  964.                 );
  965.                 $docTitle $form['name']->getData()??$file->getClientOriginalName();
  966.                 $document = new Document();
  967.                 $document->setName($docTitle);
  968.                 $document->setFilename($fileName);
  969.                 $document->setManager($this->getUser()->getManager());
  970.                 if ($form['type']->getData()) {
  971.                     $type $em->getRepository(DocumentType::class)->find($form['type']->getData()->value);
  972.                     if ($type) {
  973.                         $document->setType($type);
  974.                     }
  975.                 }
  976.                 $em->persist($document);
  977.                 $em->flush();
  978.                 $this->get('session')->getFlashBag()->add('success''Nouveau document téléversé');
  979.             }
  980.             return $this->redirectToRoute("manager_documents");
  981.         }
  982.         return $this->render('manager/documents.html.twig', [
  983.             "documentsTypes" => $documentsTypes,
  984.             "form" => $form->createView(),
  985.         ]);
  986.     }
  987.     /**
  988.      * @Route("/documentstypes", name="documents_types")
  989.      */
  990.     public function documentsTypesAction(Request $request)
  991.     {
  992.         $documentsTypes $this->getDoctrine()->getRepository(DocumentType::class)->findAll();
  993.         return $this->render('manager/documents_types.html.twig', [
  994.             "documentsTypes" => $documentsTypes,
  995.         ]);
  996.     }
  997.     /**
  998.      * @Route("/documentstypes/add", name="documents_types_add")
  999.      */
  1000.     public function documentsTypesAddAction(Request $request)
  1001.     {
  1002.         $documentType = new DocumentType();
  1003.         $form $this->createFormBuilder($documentType)
  1004.             ->add("parent"EntityType::class, [
  1005.                 'attr' => array(
  1006.                     'placeholder' => 'Catégorie principale',
  1007.                 ),
  1008.                 'label' => 'Catégorie principale',
  1009.                 'expanded' => false,
  1010.                 'multiple' => false,
  1011.                 'required' => true,
  1012.                 'class' => DocumentType::class,
  1013.                 'query_builder' => function (EntityRepository $er) {
  1014.                     $qb $er->createQueryBuilder('dt');
  1015.                     return $qb->where($qb->expr()->isNull("dt.parent"))
  1016.                         ->orderBy('dt.libelle''ASC');
  1017.                 },
  1018.                 'choice_label' => function(DocumentType $documentType) {
  1019.                     return $documentType->getLibelle();
  1020.                 },
  1021.             ])
  1022.             ->add("libelle"TextType::class, [
  1023.                 "attr" => [
  1024.                     "placeholder" => "Nom"
  1025.                 ],
  1026.                 "label" => "Nom",
  1027.             ])
  1028.             ->add("libelle_en"TextType::class, [
  1029.                 "attr" => [
  1030.                     "placeholder" => "Nom EN (traduction)"
  1031.                 ],
  1032.                 "label" => "Nom EN (traduction)",
  1033.                 "mapped" => false,
  1034.             ])
  1035.             ->getForm();
  1036.         $form->handleRequest($request);
  1037.         if ($form->isSubmitted() && $form->isValid()) {
  1038.             $em $this->getDoctrine()->getManager();
  1039.             $em->persist($documentType);
  1040.             $em->flush();
  1041.             $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  1042.             $repository
  1043.                 ->translate($documentType'libelle''en'$form["libelle_en"]->getData())
  1044.             ;
  1045.             $em->flush();
  1046.             return $this->redirectToRoute("manager_documents_types");
  1047.         }
  1048.         return $this->render('manager/documents_types_add.html.twig', [
  1049.             "form" => $form->createView(),
  1050.         ]);
  1051.     }
  1052.     /**
  1053.      * @Route("/documentstypes/{id}/edit", name="documents_types_edit")
  1054.      */
  1055.     public function documentsTypesEditAction(Request $requestDocumentType $documentType)
  1056.     {
  1057.         $em $this->getDoctrine()->getManager();
  1058.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  1059.         $translations $repository->findTranslations($documentType);
  1060.         $form $this->createFormBuilder($documentType)
  1061.             ->add("parent"EntityType::class, [
  1062.                 'attr' => array(
  1063.                     'placeholder' => 'Catégorie principale',
  1064.                 ),
  1065.                 'label' => 'Catégorie principale',
  1066.                 'expanded' => false,
  1067.                 'multiple' => false,
  1068.                 'required' => true,
  1069.                 'class' => DocumentType::class,
  1070.                 'query_builder' => function (EntityRepository $er) {
  1071.                     $qb $er->createQueryBuilder('dt');
  1072.                     return $qb->where($qb->expr()->isNull("dt.parent"))
  1073.                         ->orderBy('dt.libelle''ASC');
  1074.                 },
  1075.                 'choice_label' => function(DocumentType $documentType) {
  1076.                     return $documentType->getLibelle();
  1077.                 },
  1078.             ])
  1079.             ->add("libelle"TextType::class, [
  1080.                 "attr" => [
  1081.                     "placeholder" => "Nom"
  1082.                 ],
  1083.                 "label" => "Nom",
  1084.             ])
  1085.             ->add("libelle_en"TextType::class, [
  1086.                 "attr" => [
  1087.                     "placeholder" => "Nom EN (traduction)"
  1088.                 ],
  1089.                 "label" => "Nom EN (traduction)",
  1090.                 "mapped" => false,
  1091.                 "data" => $translations["en"]["libelle"],
  1092.             ])
  1093.             ->getForm();
  1094.         $form->handleRequest($request);
  1095.         if ($form->isSubmitted() && $form->isValid()) {
  1096.             $em->persist($documentType);
  1097.             $em->flush();
  1098.             $repository
  1099.                 ->translate($documentType'libelle''en'$form["libelle_en"]->getData())
  1100.             ;
  1101.             $em->flush();
  1102.             return $this->redirectToRoute("manager_documents_types");
  1103.         }
  1104.         return $this->render('manager/documents_types_edit.html.twig', [
  1105.             "form" => $form->createView(),
  1106.         ]);
  1107.     }
  1108.     /**
  1109.      * @Route("/documentstypes/{id}/delete", name="documents_types_delete")
  1110.      */
  1111.     public function documentsTypesDeleteAction(Request $requestDocumentType $documentType)
  1112.     {
  1113.         $em $this->getDoctrine()->getManager();
  1114.         $parentId $documentType->getParent()->getId();
  1115.         $parentType $em->getRepository(DocumentType::class)->find($parentId);
  1116.         $documents $em->getRepository(Document::class)->findBy(["type" => $documentType]);
  1117.         foreach ($documents as $document) {
  1118.             $document->setType($parentType);
  1119.             $em->flush();
  1120.         }
  1121.         $em->remove($documentType);
  1122.         $em->flush();
  1123.         return $this->redirectToRoute("manager_documents_types");
  1124.     }
  1125.     /**
  1126.      * @Route("/documents/{id}/edit", name="documents_edit")
  1127.      */
  1128.     public function documentsEditAction(Request $requestDocument $document)
  1129.     {
  1130.         $em $this->getDoctrine()->getManager();
  1131.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  1132.         $translations $repository->findTranslations($document);
  1133.         $name $document->getName();
  1134.         $filename $document->getFilename();
  1135.         $name_en "";
  1136.         $filename_en "";
  1137.         if (isset($translations["en"])) {
  1138.             $name_en $translations["en"]["name"];
  1139.             $filename_en $translations["en"]["filename"];
  1140.         }
  1141.         $typesChoices = [];
  1142.         $types $this->getDoctrine()->getRepository(DocumentType::class)->findBy(["parent" => null]);
  1143.         foreach ($types as $type) {
  1144.             $typesChoices[] = (object) ['value' => $type->getId(), 'label' => $type->getLibelle()];
  1145.             foreach ($type->getChildren() as $child) {
  1146.                 $typesChoices[] = (object) ['value' => $child->getId(), 'label' => "|----".$child->getLibelle()];
  1147.             }
  1148.         }
  1149.         $form $this->createFormBuilder()
  1150.             ->add('name'TextType::class, [
  1151.                 'attr' => [
  1152.                     'placeholder' => 'Nom'
  1153.                 ],
  1154.                 'label' => 'Nom',
  1155.                 'required' => false,
  1156.                 'mapped' => false,
  1157.                 "data" => $name,
  1158.             ])
  1159.             ->add('file'FileType::class, [
  1160.                 'attr' => [
  1161.                     'placeholder' => 'Fichier'
  1162.                 ],
  1163.                 'label' => 'Remplacer le fichier',
  1164.                 'required' => false,
  1165.                 'mapped' => false
  1166.             ])
  1167.             ->add('type'ChoiceType::class, [
  1168.                 'attr' => array(
  1169.                     'placeholder' => 'Type',
  1170.                 ),
  1171.                 'label' => 'Type',
  1172.                 'expanded' => false,
  1173.                 'multiple' => false,
  1174.                 'required' => true,
  1175.                 'mapped' => false,
  1176.                 'choices' => $typesChoices,
  1177.                 'choice_label' => function($entry) { return $entry!=null $entry->label ""; },
  1178.                 'choice_value' => function($entry) { return $entry!=null $entry->value 0; },
  1179.                 "data" => (object) ['value' => $document->getType()->getId()],
  1180.             ]);
  1181.         if ($document->isTranslatedEn()) {
  1182.             $form->add('name_en'TextType::class, [
  1183.                 'attr' => [
  1184.                     'placeholder' => ' EN (traduction)'
  1185.                 ],
  1186.                 'label' => ' EN (traduction)',
  1187.                 'required' => false,
  1188.                 'mapped' => false,
  1189.                 "data" => $name_en,
  1190.             ])
  1191.                 ->add('file_en'FileType::class, [
  1192.                     'attr' => [
  1193.                         'placeholder' => 'Fichier'
  1194.                     ],
  1195.                     'label' => 'Remplacer le fichier EN (traduction)',
  1196.                     'required' => false,
  1197.                     'mapped' => false
  1198.                 ]);
  1199.         }
  1200.         $form $form->getForm();
  1201.         $form->handleRequest($request);
  1202.         if ($form->isSubmitted() && $form->isValid()) {
  1203.             if ($form['type']->getData()) {
  1204.                 $type $em->getRepository(DocumentType::class)->find($form['type']->getData()->value);
  1205.                 if ($type) {
  1206.                     $document->setType($type);
  1207.                 }
  1208.             }
  1209.             $docTitle $form['name']->getData()??$filename;
  1210.             $document->setName($docTitle);
  1211.             $em->flush();
  1212.             /**
  1213.              * @var UploadedFile $file
  1214.              */
  1215.             $file $form->get('file')->getData();
  1216.             if ($file != NULL) {
  1217.                 $fileName $this->getUser()->getManager()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  1218.                 $file->move(
  1219.                     $this->getParameter('documents_directory'), $fileName
  1220.                 );
  1221.                 $docTitle $form["name"]->getData()??$file->getClientOriginalName();
  1222.                 $document->setName($docTitle);
  1223.                 $document->setFilename($fileName);
  1224.                 $document->setManager($this->getUser()->getManager());
  1225.                 $em->flush();
  1226.             }
  1227.             if ($document->isTranslatedEn()) {
  1228.                 $repository
  1229.                     ->translate($document'name''en'$form["name_en"]->getData())
  1230.                 ;
  1231.                 $em->flush();
  1232.                 /**
  1233.                  * @var UploadedFile $file_en
  1234.                  */
  1235.                 $file_en $form->get('file_en')->getData();
  1236.                 if ($file_en != NULL) {
  1237.                     $fileName $this->getUser()->getManager()->getId()."_".md5(uniqid()) . '.' $file_en->guessExtension();
  1238.                     $file_en->move(
  1239.                         $this->getParameter('documents_directory'), $fileName
  1240.                     );
  1241.                     $docTitle $form["name_en"]->getData()??$file_en->getClientOriginalName();
  1242.                     $document->setName($docTitle);
  1243.                     $document->setFilename($fileName);
  1244.                     $repository
  1245.                         ->translate($document'name''en'$docTitle)
  1246.                         ->translate($document'filename''en'$fileName)
  1247.                     ;
  1248.                     $document->setManager($this->getUser()->getManager());
  1249.                     $em->flush();
  1250.                 }
  1251.             }
  1252.             return $this->redirectToRoute("manager_documents");
  1253.         }
  1254.         return $this->render('manager/documents_edit.html.twig', [
  1255.             "document" => $document,
  1256.             "form" => $form->createView(),
  1257.             "filename" => $filename,
  1258.             "filename_en" => $filename_en,
  1259.         ]);
  1260.     }
  1261.     /**
  1262.      * @Route("/documents/{id}/translate", name="documents_translate")
  1263.      */
  1264.     public function documentsTranslateAction(Request $requestDocument $document)
  1265.     {
  1266.         $form $this->createFormBuilder()
  1267.             ->add('documentFile'FileType::class, [
  1268.                 'attr' => [
  1269.                     'placeholder' => 'Document EN (traduction)'
  1270.                 ],
  1271.                 'label' => 'Document EN (traduction)',
  1272.                 'required' => true,
  1273.                 'mapped' => false
  1274.             ])
  1275.             ->add("libelle_en"TextType::class, [
  1276.                 "attr" => [
  1277.                     "placeholder" => "Nom EN (traduction)"
  1278.                 ],
  1279.                 "label" => "Nom EN (traduction)",
  1280.                 "mapped" => false,
  1281.             ])
  1282.             ->getForm();
  1283.         $form->handleRequest($request);
  1284.         $em $this->getDoctrine()->getManager();
  1285.         if ($form->isSubmitted() && $form->isValid()) {
  1286.             /**
  1287.              * @var UploadedFile $file
  1288.              */
  1289.             $file $form->get('documentFile')->getData();
  1290.             if ($file != NULL) {
  1291.                 $fileName $this->getUser()->getManager()->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  1292.                 $file->move(
  1293.                     $this->getParameter('documents_directory'), $fileName
  1294.                 );
  1295.                 $docTitle $form['libelle_en']->getData()??$file->getClientOriginalName();
  1296.                 $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  1297.                 $repository
  1298.                     ->translate($document'name''en'$docTitle)
  1299.                     ->translate($document'filename''en'$fileName)
  1300.                 ;
  1301.                 $document->setTranslatedEn(true);
  1302.                 $em->flush();
  1303.                 $this->get('session')->getFlashBag()->add('success''Nouveau document traduit');
  1304.             }
  1305.             return $this->redirectToRoute("manager_documents");
  1306.         }
  1307.         return $this->render('manager/documents_translate.html.twig', [
  1308.             "form" => $form->createView(),
  1309.         ]);
  1310.     }
  1311.     /**
  1312.      * @Route("/documents/{id}/delete", name="documents_delete")
  1313.      */
  1314.     public function documentsDeleteAction(Request $requestDocument $document)
  1315.     {
  1316.         $filePath $this->getParameter('documents_directory') . $document->getFilename();
  1317.         $em $this->getDoctrine()->getManager();
  1318.         $em->remove($document);
  1319.         $em->flush();
  1320.         unlink($filePath);
  1321.         $this->get('session')->getFlashBag()->add('success''Document supprimé');
  1322.         return $this->redirectToRoute("manager_documents");
  1323.     }
  1324.     /**
  1325.      * @Route("/switch/{id}", name="user_switch")
  1326.      */
  1327.     public function userSwitchAction(Request $requestUser $user)
  1328.     {
  1329.         if (!$this->isGranted("ROLE_DPO")) {
  1330.             if ($this->isGranted("ROLE_JURISTE") || $this->isGranted("ROLE_COMMERCE")) {
  1331.                 if ($this->isGranted("ROLE_JURISTE")) {
  1332.                     if ($user->getManager()->getId() != $this->getUser()->getManager()->getId()
  1333.                         && ($user->getLawyer() && $user->getLawyer()->getId() != $this->getUser()->getManager()->getId())) {
  1334.                         throw new NotFoundHttpException();
  1335.                     }
  1336.                 } else {
  1337.                     if (!$user->isDemo()) {
  1338.                         throw new NotFoundHttpException();
  1339.                     }
  1340.                 }
  1341.             } else {
  1342.                 throw new NotFoundHttpException();
  1343.             }
  1344.         }
  1345.         return $this->redirectToRoute("default_homepage", ['_switch_user' =>  $user->getAccount()->getEmail()]);
  1346.     }
  1347.     /**
  1348.      * @Route("/partners", name="partners")
  1349.      */
  1350.     public function partnersAction(Request $request)
  1351.     {
  1352.         if (!$this->isGranted("ROLE_DPO")) {
  1353.             throw new NotFoundHttpException();
  1354.         }
  1355.         $partners $this->getDoctrine()->getRepository(Partner::class)->findAll();
  1356.         return $this->render('manager/partners.html.twig', [
  1357.             "partners" => $partners
  1358.         ]);
  1359.     }
  1360.     /**
  1361.      * @Route("/partners/add", name="partners_add")
  1362.      */
  1363.     public function partnersAddAction(Request $request)
  1364.     {
  1365.         if (!$this->isGranted("ROLE_DPO")) {
  1366.             throw new NotFoundHttpException();
  1367.         }
  1368.         $partner = new Partner();
  1369.         $form $this->createForm(PartnerType::class, $partner);
  1370.         $form->handleRequest($request);
  1371.         if ($form->isSubmitted() && $form->isValid()) {
  1372.             $em $this->getDoctrine()->getManager();
  1373.             $em->persist($partner);
  1374.             $em->flush();
  1375.             /**
  1376.              * @var UploadedFile $file
  1377.              */
  1378.             $file $form->get('pictureFile')->getData();
  1379.             if ($file != NULL) {
  1380.                 $fileName $partner->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  1381.                 $file->move(
  1382.                     $this->getParameter('pictures_directory'), $fileName
  1383.                 );
  1384.                 $partner->setPicture($fileName);
  1385.                 $em->flush();
  1386.             }
  1387.             $this->get('session')->getFlashBag()->add('success''Nouveau partenaire ajouté');
  1388.             return $this->redirectToRoute("manager_partners");
  1389.         }
  1390.         return $this->render('manager/partners_add.html.twig', [
  1391.             "form" => $form->createView(),
  1392.         ]);
  1393.     }
  1394.     /**
  1395.      * @Route("/partners/{id}/edit", name="partners_edit")
  1396.      */
  1397.     public function partnersEditAction(Request $requestPartner $partner)
  1398.     {
  1399.         if (!$this->isGranted("ROLE_DPO")) {
  1400.             throw new NotFoundHttpException();
  1401.         }
  1402.         $form $this->createForm(PartnerType::class, $partner);
  1403.         $form->handleRequest($request);
  1404.         if ($form->isSubmitted() && $form->isValid()) {
  1405.             $em $this->getDoctrine()->getManager();
  1406.             $em->flush();
  1407.             /**
  1408.              * @var UploadedFile $file
  1409.              */
  1410.             $file $form->get('pictureFile')->getData();
  1411.             if ($file != NULL) {
  1412.                 $fileName $partner->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  1413.                 $file->move(
  1414.                     $this->getParameter('pictures_directory'), $fileName
  1415.                 );
  1416.                 $partner->setPicture($fileName);
  1417.                 $em->flush();
  1418.             }
  1419.             $this->get('session')->getFlashBag()->add('success''Partenaire mis à jour');
  1420.             return $this->redirectToRoute("manager_partners");
  1421.         }
  1422.         return $this->render('manager/partners_edit.html.twig', [
  1423.             "form" => $form->createView(),
  1424.             "partner" => $partner
  1425.         ]);
  1426.     }
  1427.     /**
  1428.      * @Route("/partners/{id}/delete", name="partners_delete")
  1429.      */
  1430.     public function partnersDeleteAction(Request $requestPartner $partner)
  1431.     {
  1432.         if (!$this->isGranted("ROLE_DPO")) {
  1433.             throw new NotFoundHttpException();
  1434.         }
  1435.         $em $this->getDoctrine()->getManager();
  1436.         $em->remove($partner);
  1437.         $em->flush();
  1438.         $this->get('session')->getFlashBag()->add('success''Partenaire supprimé');
  1439.         return $this->redirectToRoute("manager_partners");
  1440.     }
  1441.     /**
  1442.      * @Route("/systems", name="systems")
  1443.      */
  1444.     public function systemsAction(Request $request)
  1445.     {
  1446.         $systemsQuery $this->getDoctrine()->getRepository(SystemStd::class)->findAll();
  1447.         $systems = [
  1448.             "computing" => [
  1449.                 "network" => [],
  1450.                 "security" => [],
  1451.                 "administration" => [],
  1452.                 "device" => [],
  1453.                 "software" => [],
  1454.                 "server" => [],
  1455.             ],
  1456.             "physical" => [
  1457.                 "partitioning" => [],
  1458.                 "information" => [],
  1459.             ],
  1460.             "action" => [
  1461.                 "minimization" => [],
  1462.                 "anonymization" => [],
  1463.                 "pseudonymization" => [],
  1464.                 "sensitization" => [],
  1465.                 "supervision" => [],
  1466.                 "destruction" => [],
  1467.             ],
  1468.             "supplier" => [
  1469.                 "supplier" => []
  1470.             ]
  1471.         ];
  1472.         $systemsJs = [];
  1473.         $encoders = [new JsonEncoder()];
  1474.         $normalizer = new ObjectNormalizer();
  1475.         // $normalizer->setCircularReferenceLimit(1);
  1476.         // $normalizer->setCircularReferenceHandler(function ($object) {
  1477.         //     return $object->getId();
  1478.         // });
  1479.         $normalizers = [$normalizer];
  1480.         $serializer = new Serializer($normalizers$encoders);
  1481.         
  1482.         foreach ($systemsQuery as $system) {
  1483.             $systems[$system->getType()][$system->getSubtype()][] = $system;
  1484.             $systemsJs[$system->getId()] = json_decode($serializer->serialize($system'json', ["attributes" => ['id''name''data''type''subtype'], "circular_reference_handler" => function ($object) {return $object->getId();}]), true);
  1485.         }
  1486.         $systemsStd = [
  1487.             "computing" => [
  1488.                 "network" => [
  1489.                     "label" => "Réseau",
  1490.                     "items" => [],
  1491.                     "icon" => "mdi-ip-network"
  1492.                 ],
  1493.                 "security" => [
  1494.                     "label" => "Sécurité",
  1495.                     "items" => [],
  1496.                     "icon" => "mdi-security"
  1497.                 ],
  1498.                 "administration" => [
  1499.                     "label" => "Administration",
  1500.                     "items" => [],
  1501.                     "icon" => "mdi-account-multiple"
  1502.                 ],
  1503.                 "device" => [
  1504.                     "label" => "Périphérique",
  1505.                     "items" => [],
  1506.                     "icon" => "mdi-responsive"
  1507.                 ],
  1508.                 "software" => [
  1509.                     "label" => "Logiciel",
  1510.                     "items" => [],
  1511.                     "icon" => "mdi-console"
  1512.                 ],
  1513.                 "server" => [
  1514.                     "label" => "Serveur",
  1515.                     "items" => [],
  1516.                     "icon" => "mdi-server"
  1517.                 ],
  1518.             ],
  1519.             "physical" => [
  1520.                 "partitioning" => [
  1521.                     "label" => "Cloisonnement",
  1522.                     "items" => [],
  1523.                     "icon" => "mdi-view-module"
  1524.                 ],
  1525.                 "information" => [
  1526.                     "label" => "Information",
  1527.                     "items" => [],
  1528.                     "icon" => "mdi-lightbulb-on"
  1529.                 ],
  1530.             ],
  1531.             "action" => [
  1532.                 "minimization" => [
  1533.                     "label" => "Minimisation",
  1534.                     "items" => [],
  1535.                     "icon" => "mdi-tab-minus"
  1536.                 ],
  1537.                 "anonymization" => [
  1538.                     "label" => "Anonymisation",
  1539.                     "items" => [],
  1540.                     "icon" => "mdi-incognito"
  1541.                 ],
  1542.                 "pseudonymization" => [
  1543.                     "label" => "Pseudonymisation",
  1544.                     "items" => [],
  1545.                     "icon" => "mdi-account-question"
  1546.                 ],
  1547.                 "sensitization" => [
  1548.                     "label" => "Sensibilisation et formation",
  1549.                     "items" => [],
  1550.                     "icon" => "mdi-account-alert"
  1551.                 ],
  1552.                 "supervision" => [
  1553.                     "label" => "Contrôle",
  1554.                     "items" => [],
  1555.                     "icon" => "mdi-table-search"
  1556.                 ],
  1557.                 "destruction" => [
  1558.                     "label" => "Destruction et suppression",
  1559.                     "items" => [],
  1560.                     "icon" => "mdi-trash-can"
  1561.                 ],
  1562.             ],
  1563.             "supplier" => [
  1564.                 "supplier" => [
  1565.                     "label" => "Prestataires du SI",
  1566.                     "items" => [],
  1567.                     "icon" => "mdi-contacts"
  1568.                 ],
  1569.             ]
  1570.         ];
  1571.         $mindMapHeight 0;
  1572.         $mindMap = [
  1573.             "id" => "root",
  1574.             "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("manager_systems_export")."\" target='_blank' class=\"btn btn-sm btn-rounded-circle btn-primary\"><i class=\"mdi mdi-printer\"></i></a></span></div>",
  1575.             "children" => [
  1576.                 [
  1577.                     "id" => "computing",
  1578.                     "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("manager_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>",
  1579.                     "direction" => "right",
  1580.                     "expanded" => false,
  1581.                     "attr" => [
  1582.                         "class" => "jmnode-level-1",
  1583.                     ],
  1584.                     "children" => []
  1585.                 ],
  1586.                 [
  1587.                     "id" => "physical",
  1588.                     "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("manager_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>",
  1589.                     "direction" => "right",
  1590.                     "expanded" => false,
  1591.                     "attr" => [
  1592.                         "class" => "jmnode-level-1",
  1593.                     ],
  1594.                     "children" => []
  1595.                 ],
  1596.                 [
  1597.                     "id" => "action",
  1598.                     "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("manager_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>",
  1599.                     "direction" => "right",
  1600.                     "expanded" => false,
  1601.                     "attr" => [
  1602.                         "class" => "jmnode-level-1",
  1603.                     ],
  1604.                     "children" => []
  1605.                 ],
  1606.                 [
  1607.                     "id" => "supplier",
  1608.                     "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("manager_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>",
  1609.                     "direction" => "right",
  1610.                     "expanded" => false,
  1611.                     "attr" => [
  1612.                         "class" => "jmnode-level-1",
  1613.                     ],
  1614.                     "children" => []
  1615.                 ],
  1616.             ]
  1617.         ];
  1618.         $key1 0;
  1619.         foreach ($systemsStd as $systemStd) {
  1620.             foreach ($systemStd as $key2 => $value2) {
  1621.                 $data = [
  1622.                     "id" => $mindMap["children"][$key1]["id"]."_".$key2,
  1623.                     "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("manager_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>",
  1624.                     "direction" => "right",
  1625.                     "expanded" => false,
  1626.                     "attr" => [
  1627.                         "class" => "jmnode-level-2",
  1628.                     ],
  1629.                     "children" => []
  1630.                 ];
  1631.                 $itemsLenght count($systems[$mindMap["children"][$key1]["id"]][$key2]);
  1632.                 if ($itemsLenght 2) {
  1633.                     $mindMapHeight += $itemsLenght;
  1634.                 } else {
  1635.                     $mindMapHeight += 2;
  1636.                 }
  1637.                 foreach ($systems[$mindMap["children"][$key1]["id"]][$key2] as $item) {
  1638.                     $data["children"][] = [
  1639.                         "id" => $item->getId(),
  1640.                         "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("manager_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("manager_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>",
  1641.                         "attr" => [
  1642.                             "class" => "jmnode-level-3",
  1643.                             "onclick" => "openModalInfo(".$item->getId().")",
  1644.                         ]
  1645.                     ];
  1646.                 }
  1647.                 $mindMap["children"][$key1]["children"][] = $data;
  1648.             }
  1649.             $key1++;
  1650.         }
  1651.         return $this->render('manager/systems.html.twig', [
  1652.             "systems" => $systems,
  1653.             "mindMap" => $mindMap,
  1654.             "mindMapHeight" => 12 * (38 1.5),
  1655.             "systemsJs" => $systemsJs,
  1656.         ]);
  1657.     }
  1658.     /**
  1659.      * @Route("/systems/{id}/translate/{_locale}", name="systems_translate")
  1660.      */
  1661.     public function systemsTranslateAction(Request $requestSystemStd $system)
  1662.     {
  1663.         $em $this->getDoctrine()->getManager();
  1664.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  1665.         $translations $repository->findTranslations($system);
  1666.         if (!isset($translations[$request->get("_locale")])) {
  1667.             return $this->redirectToRoute("manager_systems_gen_translate", ["id" => $system->getId(), "_locale" => "fr""locale" => $request->get("_locale")]);
  1668.         }
  1669.         $system $em->find(SystemStd::class, $request->get("id"));
  1670.         $types = [
  1671.             "computing" => [
  1672.                 "network" => 4,
  1673.                 "security" => 4,
  1674.                 "administration" => 4,
  1675.                 "device" => 4,
  1676.                 "software" => 4,
  1677.                 "server" => 4,
  1678.             ],
  1679.             "physical" => [
  1680.                 "partitioning" => 2,
  1681.                 "information" => 2,
  1682.             ],
  1683.             "action" => [
  1684.                 "minimization" => 2,
  1685.                 "anonymization" => 2,
  1686.                 "pseudonymization" => 2,
  1687.                 "sensitization" => 2,
  1688.                 "supervision" => 2,
  1689.                 "destruction" => 2,
  1690.             ],
  1691.             "supplier" => [
  1692.                 "supplier" => 1
  1693.             ]
  1694.         ];
  1695.         $form $this->createForm(SystemStdTranslateType::class, $system);
  1696.         switch ($system->getSubtype()) {
  1697.             case "network":
  1698.                 $form->add('field1'ChoiceType::class, [
  1699.                     'attr' => [
  1700.                         'placeholder' => 'Type'
  1701.                     ],
  1702.                     'placeholder' => 'Type',
  1703.                     'label' => 'Type',
  1704.                     'choices' => [
  1705.                         "Filaire" => "Filaire",
  1706.                         "Sans-fil" => "Sans-fil",
  1707.                     ],
  1708.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  1709.                     'required' => false,
  1710.                     'mapped' => false
  1711.                 ])
  1712.                     ->add('field2'TextareaType::class, [
  1713.                         'attr' => [
  1714.                             'placeholder' => 'Informations complémentaires'
  1715.                         ],
  1716.                         'label' => 'Informations complémentaires',
  1717.                         'data' => isset($system->getData()[1])?$system->getData()[1]["value"]:null,
  1718.                         'required' => false,
  1719.                         'mapped' => false
  1720.                     ])
  1721.                     ->add('field3'ChoiceType::class, [
  1722.                         'attr' => [
  1723.                             'placeholder' => 'Type'
  1724.                         ],
  1725.                         'placeholder' => 'Type',
  1726.                         'label' => 'Si Wifi, sélectionnez le type',
  1727.                         'choices' => [
  1728.                             "Privé" => "Privé",
  1729.                             "Public" => "Public",
  1730.                         ],
  1731.                         'data' => isset($system->getData()[2])?$system->getData()[2]["value"]:null,
  1732.                         'required' => false,
  1733.                         'mapped' => false
  1734.                     ])
  1735.                     ->add('field4'TextType::class, [
  1736.                         'attr' => [
  1737.                             'placeholder' => 'Protocole'
  1738.                         ],
  1739.                         'label' => 'Si Wifi, quel protocole ?',
  1740.                         'data' => isset($system->getData()[3])?$system->getData()[3]["value"]:null,
  1741.                         'required' => false,
  1742.                         'mapped' => false
  1743.                     ])
  1744.                 ;
  1745.                 break;
  1746.             case "security":
  1747.             case "administration":
  1748.             case "device":
  1749.             case "software":
  1750.             case "server":
  1751.                 $form->add('field1'TextType::class, [
  1752.                     'attr' => [
  1753.                         'placeholder' => 'Type'
  1754.                     ],
  1755.                     'label' => 'Type',
  1756.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  1757.                     'required' => false,
  1758.                     'mapped' => false
  1759.                 ])
  1760.                     ->add('field2'TextareaType::class, [
  1761.                         'attr' => [
  1762.                             'placeholder' => 'Informations complémentaires'
  1763.                         ],
  1764.                         'label' => 'Informations complémentaires',
  1765.                         'data' => isset($system->getData()[1])?$system->getData()[1]["value"]:null,
  1766.                         'required' => false,
  1767.                         'mapped' => false
  1768.                     ])
  1769.                     ->add('field3'TextType::class, [
  1770.                         'attr' => [
  1771.                             'placeholder' => '__/__/____',
  1772.                             'data-mask' => '00/00/0000',
  1773.                             'data-mask-clearifnotmatch' => 'true'
  1774.                         ],
  1775.                         'label' => 'Date d\'achat',
  1776.                         'data' => isset($system->getData()[2])?$system->getData()[2]["value"]:null,
  1777.                         'required' => false,
  1778.                         'mapped' => false
  1779.                     ])
  1780.                     ->add('field4'TextType::class, [
  1781.                         'attr' => [
  1782.                             'placeholder' => 'N° d’identification'
  1783.                         ],
  1784.                         'label' => 'N° d’identification',
  1785.                         'data' => isset($system->getData()[3])?$system->getData()[3]["value"]:null,
  1786.                         'required' => false,
  1787.                         'mapped' => false
  1788.                     ]);
  1789.                 break;
  1790.             case "partitioning":
  1791.             case "minimization":
  1792.             case "anonymization":
  1793.             case "pseudonymization":
  1794.             case "sensitization":
  1795.             case "information":
  1796.             case "supervision":
  1797.             case "destruction":
  1798.                 $form->add('field1'TextareaType::class, [
  1799.                     'attr' => [
  1800.                         'placeholder' => 'Description'
  1801.                     ],
  1802.                     'label' => 'Description',
  1803.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  1804.                     'required' => false,
  1805.                     'mapped' => false
  1806.                 ])
  1807.                     ->add('field2'TextareaType::class, [
  1808.                         'attr' => [
  1809.                             'placeholder' => 'Informations complémentaires'
  1810.                         ],
  1811.                         'label' => 'Informations complémentaires',
  1812.                         'data' => isset($system->getData()[1])?$system->getData()[1]["value"]:null,
  1813.                         'required' => false,
  1814.                         'mapped' => false
  1815.                     ]);
  1816.                 break;
  1817.             case "supplier":
  1818.                 $form->add('field1'TextType::class, [
  1819.                     'attr' => [
  1820.                         'placeholder' => 'Type'
  1821.                     ],
  1822.                     'label' => 'Type',
  1823.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  1824.                     'required' => false,
  1825.                     'mapped' => false
  1826.                 ]);
  1827.                 break;
  1828.             default:
  1829.                 throw new NotFoundHttpException();
  1830.         }
  1831.         $form->handleRequest($request);
  1832.         if ($form->isSubmitted() && $form->isValid()) {
  1833.             $data = [];
  1834.             switch ($system->getSubtype()) {
  1835.                 case "network":
  1836.                     $data[] = [
  1837.                         "title" => 'Type',
  1838.                         "value" => $form['field1']->getData()
  1839.                     ];
  1840.                     $data[] = [
  1841.                         "title" => 'Informations complémentaires',
  1842.                         "value" => $form['field2']->getData()
  1843.                     ];
  1844.                     $data[] = [
  1845.                         "title" => 'Type de Wifi',
  1846.                         "value" => $form['field3']->getData()
  1847.                     ];
  1848.                     $data[] = [
  1849.                         "title" => 'Protocole Wifi',
  1850.                         "value" => $form['field4']->getData()
  1851.                     ];
  1852.                     ;
  1853.                     break;
  1854.                 case "security":
  1855.                 case "administration":
  1856.                 case "device":
  1857.                 case "software":
  1858.                 case "server":
  1859.                     $data[] = [
  1860.                         "title" => 'Type',
  1861.                         "value" => $form['field1']->getData()
  1862.                     ];
  1863.                     $data[] = [
  1864.                         "title" => 'Informations complémentaires',
  1865.                         "value" => $form['field2']->getData()
  1866.                     ];
  1867.                     $data[] = [
  1868.                         "title" => 'Date d\'achat',
  1869.                         "value" => $form['field3']->getData()
  1870.                     ];
  1871.                     $data[] = [
  1872.                         "title" => 'N° d’identification',
  1873.                         "value" => $form['field4']->getData()
  1874.                     ];
  1875.                     break;
  1876.                 case "partitioning":
  1877.                 case "minimization":
  1878.                 case "anonymization":
  1879.                 case "pseudonymization":
  1880.                 case "sensitization":
  1881.                 case "information":
  1882.                 case "supervision":
  1883.                 case "destruction":
  1884.                     $data[] = [
  1885.                         "title" => 'Description',
  1886.                         "value" => $form['field1']->getData()
  1887.                     ];
  1888.                     $data[] = [
  1889.                         "title" => 'Informations complémentaires',
  1890.                         "value" => $form['field2']->getData()
  1891.                     ];
  1892.                     break;
  1893.                 case "supplier":
  1894.                     $data[] = [
  1895.                         "title" => 'Type',
  1896.                         "value" => $form['field1']->getData()
  1897.                     ];
  1898.                     break;
  1899.                 default:
  1900.                     throw new NotFoundHttpException();
  1901.             }
  1902.             $system->setData($data);
  1903.             $em->persist($system);
  1904.             $em->flush();
  1905.             $this->get('session')->getFlashBag()->add('success''Traduction de l\'élément de cartographie mis à jour');
  1906.             return $this->redirectToRoute("manager_systems");
  1907.         }
  1908.         return $this->render('manager/systems_translate.html.twig', [
  1909.             "form" => $form->createView(),
  1910.             "system" => $system,
  1911.             "fields" => $types[$system->getType()][$system->getSubtype()]
  1912.         ]);
  1913.     }
  1914.     /**
  1915.      * @Route("/systems/{id}/gentranslate/{locale}_{_locale}", name="systems_gen_translate")
  1916.      */
  1917.     public function systemsGanTranslateAction(Request $requestSystemStd $system$locale$_locale)
  1918.     {
  1919.         $em $this->getDoctrine()->getManager();
  1920.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  1921.         $translations $repository->findTranslations($system);
  1922.         if (!isset($translations[$locale])) {
  1923.             $repository
  1924.                 ->translate($system'name'$locale$system->getName())
  1925.                 ->translate($system'data'$locale$system->getData())
  1926.             ;
  1927.             $em->persist($system);
  1928.             $em->flush();
  1929.             return $this->redirectToRoute("manager_systems_translate", ["id" => $system->getId(), "_locale" => $locale]);
  1930.         }
  1931.         return $this->redirectToRoute("manager_systems");
  1932.     }
  1933.     /**
  1934.      * @Route("/systems/export", name="systems_export")
  1935.      */
  1936.     public function systemsExportAction(Request $request)
  1937.     {
  1938.         $systemsQuery $this->getDoctrine()->getRepository(SystemStd::class)->findAll();
  1939.         $systems = [
  1940.             "computing" => [
  1941.                 "network" => [],
  1942.                 "security" => [],
  1943.                 "administration" => [],
  1944.                 "device" => [],
  1945.                 "software" => [],
  1946.                 "server" => [],
  1947.             ],
  1948.             "physical" => [
  1949.                 "partitioning" => [],
  1950.                 "information" => [],
  1951.             ],
  1952.             "action" => [
  1953.                 "minimization" => [],
  1954.                 "anonymization" => [],
  1955.                 "pseudonymization" => [],
  1956.                 "sensitization" => [],
  1957.                 "supervision" => [],
  1958.                 "destruction" => [],
  1959.             ],
  1960.             "supplier" => [
  1961.                 "supplier" => []
  1962.             ]
  1963.         ];
  1964.         foreach ($systemsQuery as $system) {
  1965.             $systems[$system->getType()][$system->getSubtype()][] = $system;
  1966.         }
  1967.         $pdf = new MyPdf('vertical'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
  1968.         $pdf->SetAuthor('myDigitplace');
  1969.         $pdf->SetTitle("Cartographie du SI");
  1970.         $pdf->SetMargins(10,22,10true);
  1971.         $pdf->SetAutoPageBreak(TRUE35);
  1972.         $pdf->AddPage('L''A4');
  1973.         $html $this->renderView('manager/pdf/systems.html.twig', [
  1974.             "systems" => $systems
  1975.         ]);
  1976.         $filename 'Cartographie_du_SI';
  1977.         $pdf->writeHTMLCell($w 0$h 0$x ''$y ''$html$border 0$ln 1$fill 0$reseth true$align ''$autopadding true);
  1978.         return $pdf->Output($filename.".pdf",'I');
  1979.     }
  1980.     /**
  1981.      * @Route("/systems/export/{type}", name="systems_export_excel")
  1982.      */
  1983.     public function systemsExportExcelAction(Request $request$type)
  1984.     {
  1985.         $systemsQuery $this->getDoctrine()->getRepository(SystemStd::class)->findAll();
  1986.         $systems = [
  1987.             "computing" => [
  1988.                 "network" => [],
  1989.                 "security" => [],
  1990.                 "administration" => [],
  1991.                 "device" => [],
  1992.                 "software" => [],
  1993.                 "server" => [],
  1994.             ],
  1995.             "physical" => [
  1996.                 "partitioning" => [],
  1997.                 "information" => [],
  1998.             ],
  1999.             "action" => [
  2000.                 "minimization" => [],
  2001.                 "anonymization" => [],
  2002.                 "pseudonymization" => [],
  2003.                 "sensitization" => [],
  2004.                 "supervision" => [],
  2005.                 "destruction" => [],
  2006.             ],
  2007.             "supplier" => [
  2008.                 "supplier" => []
  2009.             ]
  2010.         ];
  2011.         foreach ($systemsQuery as $system) {
  2012.             $systems[$system->getType()][$system->getSubtype()][] = $system;
  2013.         }
  2014.         $spreadsheet = new Spreadsheet();
  2015.         $translateSubtypes = [
  2016.             "network" => "Réseau",
  2017.             "security" => "Sécurité",
  2018.             "administration" => "Administration",
  2019.             "device" => "Périphérique",
  2020.             "software" => "Logiciel",
  2021.             "server" => "Serveur",
  2022.             "partitioning" => "Cloisonnement",
  2023.             "minimization" => "Minimisation",
  2024.             "anonymization" => "Anonymisation",
  2025.             "pseudonymization" => "Pseudonymisation",
  2026.             "sensitization" => "Sensibilisation et formation",
  2027.             "information" => "Information",
  2028.             "supervision" => "Contrôle et qualité",
  2029.             "destruction" => "Destruction et suppression",
  2030.             "supplier" => "Prestataires du SI"
  2031.         ];
  2032.         $i 0;
  2033.         foreach ($systems[$type] as $subtype => $systems) {
  2034.             $i++;
  2035.             $roomsWorkSheet = new Worksheet($spreadsheet$translateSubtypes[$subtype]);
  2036.             $spreadsheet->addSheet($roomsWorkSheet$i);
  2037.             $spreadsheet->setActiveSheetIndex($i);
  2038.             $sheet $spreadsheet->getActiveSheet();
  2039.             $sheet->setCellValue('A1''ID');
  2040.             $sheet->setCellValue('B1''Nom');
  2041.             switch ($subtype) {
  2042.                 case "network":
  2043.                     $sheet->setCellValue('C1''Type');
  2044.                     $sheet->setCellValue('D1''Informations complémentaires');
  2045.                     $sheet->setCellValue('E1''Type de Wifi');
  2046.                     $sheet->setCellValue('F1''Protocole Wifi');
  2047.                     break;
  2048.                 case "security":
  2049.                 case "administration":
  2050.                 case "device":
  2051.                 case "software":
  2052.                 case "server":
  2053.                     $sheet->setCellValue('C1''Type');
  2054.                     $sheet->setCellValue('D1''Informations complémentaires');
  2055.                     $sheet->setCellValue('E1''Date d\'achat');
  2056.                     $sheet->setCellValue('F1''N° d\'identification');
  2057.                     break;
  2058.                 case "partitioning":
  2059.                 case "minimization":
  2060.                 case "anonymization":
  2061.                 case "pseudonymization":
  2062.                 case "sensitization":
  2063.                 case "information":
  2064.                 case "supervision":
  2065.                 case "destruction":
  2066.                     $sheet->setCellValue('C1''Description');
  2067.                     $sheet->setCellValue('D1''Informations complémentaires');
  2068.                     break;
  2069.                 case "supplier":
  2070.                     $sheet->setCellValue('C1''Type');
  2071.                     break;
  2072.                 default:
  2073.                     throw new NotFoundHttpException();
  2074.             }
  2075.             $j 1;
  2076.             foreach ($systems as $system) {
  2077.                 $j++;
  2078.                 $sheet->setCellValue('A'.$j$system->getId());
  2079.                 $sheet->setCellValue('B'.$j$system->getName());
  2080.                 switch ($subtype) {
  2081.                     case "network":
  2082.                         $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  2083.                         $sheet->setCellValue('D'.$j, isset($system->getData()[1])?$system->getData()[1]["value"]:null);
  2084.                         $sheet->setCellValue('E'.$j, isset($system->getData()[2])?$system->getData()[2]["value"]:null);
  2085.                         $sheet->setCellValue('F'.$j, isset($system->getData()[3])?$system->getData()[3]["value"]:null);
  2086.                         break;
  2087.                     case "security":
  2088.                     case "administration":
  2089.                     case "device":
  2090.                     case "software":
  2091.                     case "server":
  2092.                         $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  2093.                         $sheet->setCellValue('D'.$j, isset($system->getData()[1])?$system->getData()[1]["value"]:null);
  2094.                         $sheet->setCellValue('E'.$j, isset($system->getData()[2])?$system->getData()[2]["value"]:null);
  2095.                         $sheet->setCellValue('F'.$j, isset($system->getData()[3])?$system->getData()[3]["value"]:null);
  2096.                         break;
  2097.                     case "partitioning":
  2098.                     case "minimization":
  2099.                     case "anonymization":
  2100.                     case "pseudonymization":
  2101.                     case "sensitization":
  2102.                     case "information":
  2103.                     case "supervision":
  2104.                     case "destruction":
  2105.                         $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  2106.                         $sheet->setCellValue('D'.$j, isset($system->getData()[1])?$system->getData()[1]["value"]:null);
  2107.                         break;
  2108.                     case "supplier":
  2109.                         $sheet->setCellValue('C'.$j, isset($system->getData()[0])?$system->getData()[0]["value"]:null);
  2110.                         break;
  2111.                     default:
  2112.                         throw new NotFoundHttpException();
  2113.                 }
  2114.             }
  2115.         }
  2116.         $spreadsheet->removeSheetByIndex(0);
  2117.         $writer = new Xlsx($spreadsheet);
  2118.         $response = new StreamedResponse();
  2119.         $response->setCallback(function () use ($writer) {
  2120.             $writer->save('php://output');
  2121.         });
  2122.         $response->setStatusCode(200);
  2123.         $response->headers->set('Content-Type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  2124.         $response->headers->set('Content-Disposition''attachment;filename="export_cartographie.xlsx"');
  2125.         $response->headers->set('Cache-Control','max-age=0');
  2126.         return $response;
  2127.     }
  2128.     /**
  2129.      * @Route("/systems/add", name="systems_add")
  2130.      */
  2131.     public function systemsAddAction(Request $request)
  2132.     {
  2133.         $types = [
  2134.             "computing" => [
  2135.                 "network" => 4,
  2136.                 "security" => 4,
  2137.                 "administration" => 4,
  2138.                 "device" => 4,
  2139.                 "software" => 4,
  2140.                 "server" => 4,
  2141.             ],
  2142.             "physical" => [
  2143.                 "partitioning" => 2,
  2144.                 "information" => 2,
  2145.             ],
  2146.             "action" => [
  2147.                 "minimization" => 2,
  2148.                 "anonymization" => 2,
  2149.                 "pseudonymization" => 2,
  2150.                 "sensitization" => 2,
  2151.                 "supervision" => 2,
  2152.                 "destruction" => 2,
  2153.             ],
  2154.             "supplier" => [
  2155.                 "supplier" => 1
  2156.             ]
  2157.         ];
  2158.         if (!$_GET['type'] || !$_GET['subtype']) {
  2159.             throw new NotFoundHttpException();
  2160.         }
  2161.         if (!key_exists($_GET['type'], $types)) {
  2162.             throw new NotFoundHttpException();
  2163.         }
  2164.         if (!key_exists($_GET['subtype'], $types[$_GET['type']])) {
  2165.             throw new NotFoundHttpException();
  2166.         }
  2167.         $system = new SystemStd();
  2168.         $form $this->createForm(SystemStdType::class, $system);
  2169.         switch ($_GET['subtype']) {
  2170.             case "network":
  2171.                 $form->add('field1'ChoiceType::class, [
  2172.                     'attr' => [
  2173.                         'placeholder' => 'Type'
  2174.                     ],
  2175.                     'placeholder' => 'Type',
  2176.                     'label' => 'Type',
  2177.                     'choices' => [
  2178.                         "Filaire" => "Filaire",
  2179.                         "Sans-fil" => "Sans-fil",
  2180.                     ],
  2181.                     'required' => false,
  2182.                     'mapped' => false
  2183.                 ])
  2184.                     ->add('field2'TextareaType::class, [
  2185.                         'attr' => [
  2186.                             'placeholder' => 'Informations complémentaires'
  2187.                         ],
  2188.                         'label' => 'Informations complémentaires',
  2189.                         'required' => false,
  2190.                         'mapped' => false
  2191.                     ])
  2192.                     ->add('field3'ChoiceType::class, [
  2193.                         'attr' => [
  2194.                             'placeholder' => 'Type'
  2195.                         ],
  2196.                         'placeholder' => 'Type',
  2197.                         'label' => 'Si Wifi, sélectionnez le type',
  2198.                         'choices' => [
  2199.                             "Privé" => "Privé",
  2200.                             "Public" => "Public",
  2201.                         ],
  2202.                         'required' => false,
  2203.                         'mapped' => false
  2204.                     ])
  2205.                     ->add('field4'TextType::class, [
  2206.                         'attr' => [
  2207.                             'placeholder' => 'Protocole'
  2208.                         ],
  2209.                         'label' => 'Si Wifi, quel protocole ?',
  2210.                         'required' => false,
  2211.                         'mapped' => false
  2212.                     ])
  2213.                 ;
  2214.                 break;
  2215.             case "security":
  2216.             case "administration":
  2217.             case "device":
  2218.             case "software":
  2219.             case "server":
  2220.                 $form->add('field1'TextType::class, [
  2221.                     'attr' => [
  2222.                         'placeholder' => 'Type'
  2223.                     ],
  2224.                     'label' => 'Type',
  2225.                     'required' => false,
  2226.                     'mapped' => false
  2227.                 ])
  2228.                     ->add('field2'TextareaType::class, [
  2229.                         'attr' => [
  2230.                             'placeholder' => 'Informations complémentaires'
  2231.                         ],
  2232.                         'label' => 'Informations complémentaires',
  2233.                         'required' => false,
  2234.                         'mapped' => false
  2235.                     ])
  2236.                     ->add('field3'TextType::class, [
  2237.                         'attr' => [
  2238.                             'placeholder' => '__/__/____',
  2239.                             'data-mask' => '00/00/0000',
  2240.                             'data-mask-clearifnotmatch' => 'true'
  2241.                         ],
  2242.                         'label' => 'Date d\'achat',
  2243.                         'required' => false,
  2244.                         'mapped' => false
  2245.                     ])
  2246.                     ->add('field4'TextType::class, [
  2247.                         'attr' => [
  2248.                             'placeholder' => 'N° d’identification'
  2249.                         ],
  2250.                         'label' => 'N° d’identification',
  2251.                         'required' => false,
  2252.                         'mapped' => false
  2253.                     ]);
  2254.                 break;
  2255.             case "partitioning":
  2256.             case "minimization":
  2257.             case "anonymization":
  2258.             case "pseudonymization":
  2259.             case "sensitization":
  2260.             case "information":
  2261.             case "supervision":
  2262.             case "destruction":
  2263.                 $form->add('field1'TextareaType::class, [
  2264.                     'attr' => [
  2265.                         'placeholder' => 'Description'
  2266.                     ],
  2267.                     'label' => 'Description',
  2268.                     'required' => false,
  2269.                     'mapped' => false
  2270.                 ])
  2271.                     ->add('field2'TextareaType::class, [
  2272.                         'attr' => [
  2273.                             'placeholder' => 'Informations complémentaires'
  2274.                         ],
  2275.                         'label' => 'Informations complémentaires',
  2276.                         'required' => false,
  2277.                         'mapped' => false
  2278.                     ]);
  2279.                 break;
  2280.             case "supplier":
  2281.                 $form->add('field1'TextType::class, [
  2282.                     'attr' => [
  2283.                         'placeholder' => 'Type'
  2284.                     ],
  2285.                     'label' => 'Type',
  2286.                     'required' => false,
  2287.                     'mapped' => false
  2288.                 ]);
  2289.                 break;
  2290.             default:
  2291.                 throw new NotFoundHttpException();
  2292.         }
  2293.         $form->handleRequest($request);
  2294.         if ($form->isSubmitted() && $form->isValid()) {
  2295.             $em $this->getDoctrine()->getManager();
  2296.             $data = [];
  2297.             switch ($_GET['subtype']) {
  2298.                 case "network":
  2299.                     $data[] = [
  2300.                         "title" => 'Type',
  2301.                         "value" => $form['field1']->getData()
  2302.                     ];
  2303.                     $data[] = [
  2304.                         "title" => 'Informations complémentaires',
  2305.                         "value" => $form['field2']->getData()
  2306.                     ];
  2307.                     $data[] = [
  2308.                         "title" => 'Type de Wifi',
  2309.                         "value" => $form['field3']->getData()
  2310.                     ];
  2311.                     $data[] = [
  2312.                         "title" => 'Protocole Wifi',
  2313.                         "value" => $form['field4']->getData()
  2314.                     ];
  2315.                     ;
  2316.                     break;
  2317.                 case "security":
  2318.                 case "administration":
  2319.                 case "device":
  2320.                 case "software":
  2321.                 case "server":
  2322.                     $data[] = [
  2323.                         "title" => 'Type',
  2324.                         "value" => $form['field1']->getData()
  2325.                     ];
  2326.                     $data[] = [
  2327.                         "title" => 'Informations complémentaires',
  2328.                         "value" => $form['field2']->getData()
  2329.                     ];
  2330.                     $data[] = [
  2331.                         "title" => 'Date d\'achat',
  2332.                         "value" => $form['field3']->getData()
  2333.                     ];
  2334.                     $data[] = [
  2335.                         "title" => 'N° d’identification',
  2336.                         "value" => $form['field4']->getData()
  2337.                     ];
  2338.                     break;
  2339.                 case "partitioning":
  2340.                 case "minimization":
  2341.                 case "anonymization":
  2342.                 case "pseudonymization":
  2343.                 case "sensitization":
  2344.                 case "information":
  2345.                 case "supervision":
  2346.                 case "destruction":
  2347.                     $data[] = [
  2348.                         "title" => 'Description',
  2349.                         "value" => $form['field1']->getData()
  2350.                     ];
  2351.                     $data[] = [
  2352.                         "title" => 'Informations complémentaires',
  2353.                         "value" => $form['field2']->getData()
  2354.                     ];
  2355.                     break;
  2356.                 case "supplier":
  2357.                     $data[] = [
  2358.                         "title" => 'Type',
  2359.                         "value" => $form['field1']->getData()
  2360.                     ];
  2361.                     break;
  2362.                 default:
  2363.                     throw new NotFoundHttpException();
  2364.             }
  2365.             $system->setData($data);
  2366.             $system->setType($_GET['type']);
  2367.             $system->setSubtype($_GET['subtype']);
  2368.             $system->setManager($this->getUser()->getManager());
  2369.             $em->persist($system);
  2370.             $em->flush();
  2371.             $this->get('session')->getFlashBag()->add('success''Nouvelle mesure technique standard créée');
  2372.             return $this->redirectToRoute("manager_systems");
  2373.         }
  2374.         return $this->render('manager/systems_add.html.twig', [
  2375.             "form" => $form->createView(),
  2376.             "fields" => $types[$_GET['type']][$_GET['subtype']]
  2377.         ]);
  2378.     }
  2379.     /**
  2380.      * @Route("/systems/{id}/edit", name="systems_edit")
  2381.      */
  2382.     public function systemsEditAction(Request $requestSystemStd $system)
  2383.     {
  2384.         $types = [
  2385.             "computing" => [
  2386.                 "network" => 4,
  2387.                 "security" => 4,
  2388.                 "administration" => 4,
  2389.                 "device" => 4,
  2390.                 "software" => 4,
  2391.                 "server" => 4,
  2392.             ],
  2393.             "physical" => [
  2394.                 "partitioning" => 2,
  2395.                 "information" => 2,
  2396.             ],
  2397.             "action" => [
  2398.                 "minimization" => 2,
  2399.                 "anonymization" => 2,
  2400.                 "pseudonymization" => 2,
  2401.                 "sensitization" => 2,
  2402.                 "supervision" => 2,
  2403.                 "destruction" => 2,
  2404.             ],
  2405.             "supplier" => [
  2406.                 "supplier" => 1
  2407.             ]
  2408.         ];
  2409.         $form $this->createForm(SystemStdType::class, $system);
  2410.         switch ($system->getSubtype()) {
  2411.             case "network":
  2412.                 $form->add('field1'ChoiceType::class, [
  2413.                     'attr' => [
  2414.                         'placeholder' => 'Type'
  2415.                     ],
  2416.                     'placeholder' => 'Type',
  2417.                     'label' => 'Type',
  2418.                     'choices' => [
  2419.                         "Filaire" => "Filaire",
  2420.                         "Sans-fil" => "Sans-fil",
  2421.                     ],
  2422.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  2423.                     'required' => false,
  2424.                     'mapped' => false
  2425.                 ])
  2426.                     ->add('field2'TextareaType::class, [
  2427.                         'attr' => [
  2428.                             'placeholder' => 'Informations complémentaires'
  2429.                         ],
  2430.                         'label' => 'Informations complémentaires',
  2431.                         'data' => isset($system->getData()[1])?$system->getData()[1]["value"]:null,
  2432.                         'required' => false,
  2433.                         'mapped' => false
  2434.                     ])
  2435.                     ->add('field3'ChoiceType::class, [
  2436.                         'attr' => [
  2437.                             'placeholder' => 'Type'
  2438.                         ],
  2439.                         'placeholder' => 'Type',
  2440.                         'label' => 'Si Wifi, sélectionnez le type',
  2441.                         'choices' => [
  2442.                             "Privé" => "Privé",
  2443.                             "Public" => "Public",
  2444.                         ],
  2445.                         'data' => isset($system->getData()[2])?$system->getData()[2]["value"]:null,
  2446.                         'required' => false,
  2447.                         'mapped' => false
  2448.                     ])
  2449.                     ->add('field4'TextType::class, [
  2450.                         'attr' => [
  2451.                             'placeholder' => 'Protocole'
  2452.                         ],
  2453.                         'label' => 'Si Wifi, quel protocole ?',
  2454.                         'data' => isset($system->getData()[3])?$system->getData()[3]["value"]:null,
  2455.                         'required' => false,
  2456.                         'mapped' => false
  2457.                     ])
  2458.                 ;
  2459.                 break;
  2460.             case "security":
  2461.             case "administration":
  2462.             case "device":
  2463.             case "software":
  2464.             case "server":
  2465.                 $form->add('field1'TextType::class, [
  2466.                     'attr' => [
  2467.                         'placeholder' => 'Type'
  2468.                     ],
  2469.                     'label' => 'Type',
  2470.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  2471.                     'required' => false,
  2472.                     'mapped' => false
  2473.                 ])
  2474.                     ->add('field2'TextareaType::class, [
  2475.                         'attr' => [
  2476.                             'placeholder' => 'Informations complémentaires'
  2477.                         ],
  2478.                         'label' => 'Informations complémentaires',
  2479.                         'data' => isset($system->getData()[1])?$system->getData()[1]["value"]:null,
  2480.                         'required' => false,
  2481.                         'mapped' => false
  2482.                     ])
  2483.                     ->add('field3'TextType::class, [
  2484.                         'attr' => [
  2485.                             'placeholder' => '__/__/____',
  2486.                             'data-mask' => '00/00/0000',
  2487.                             'data-mask-clearifnotmatch' => 'true'
  2488.                         ],
  2489.                         'label' => 'Date d\'achat',
  2490.                         'data' => isset($system->getData()[2])?$system->getData()[2]["value"]:null,
  2491.                         'required' => false,
  2492.                         'mapped' => false
  2493.                     ])
  2494.                     ->add('field4'TextType::class, [
  2495.                         'attr' => [
  2496.                             'placeholder' => 'N° d’identification'
  2497.                         ],
  2498.                         'label' => 'N° d’identification',
  2499.                         'data' => isset($system->getData()[3])?$system->getData()[3]["value"]:null,
  2500.                         'required' => false,
  2501.                         'mapped' => false
  2502.                     ]);
  2503.                 break;
  2504.             case "partitioning":
  2505.             case "minimization":
  2506.             case "anonymization":
  2507.             case "pseudonymization":
  2508.             case "sensitization":
  2509.             case "information":
  2510.             case "supervision":
  2511.             case "destruction":
  2512.                 $form->add('field1'TextareaType::class, [
  2513.                     'attr' => [
  2514.                         'placeholder' => 'Description'
  2515.                     ],
  2516.                     'label' => 'Description',
  2517.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  2518.                     'required' => false,
  2519.                     'mapped' => false
  2520.                 ])
  2521.                     ->add('field2'TextareaType::class, [
  2522.                         'attr' => [
  2523.                             'placeholder' => 'Informations complémentaires'
  2524.                         ],
  2525.                         'label' => 'Informations complémentaires',
  2526.                         'data' => isset($system->getData()[1])?$system->getData()[1]["value"]:null,
  2527.                         'required' => false,
  2528.                         'mapped' => false
  2529.                     ]);
  2530.                 break;
  2531.             case "supplier":
  2532.                 $form->add('field1'TextType::class, [
  2533.                     'attr' => [
  2534.                         'placeholder' => 'Type'
  2535.                     ],
  2536.                     'label' => 'Type',
  2537.                     'data' => isset($system->getData()[0])?$system->getData()[0]["value"]:null,
  2538.                     'required' => false,
  2539.                     'mapped' => false
  2540.                 ]);
  2541.                 break;
  2542.             default:
  2543.                 throw new NotFoundHttpException();
  2544.         }
  2545.         $form->handleRequest($request);
  2546.         if ($form->isSubmitted() && $form->isValid()) {
  2547.             $em $this->getDoctrine()->getManager();
  2548.             $data = [];
  2549.             switch ($system->getSubtype()) {
  2550.                 case "network":
  2551.                     $data[] = [
  2552.                         "title" => 'Type',
  2553.                         "value" => $form['field1']->getData()
  2554.                     ];
  2555.                     $data[] = [
  2556.                         "title" => 'Informations complémentaires',
  2557.                         "value" => $form['field2']->getData()
  2558.                     ];
  2559.                     $data[] = [
  2560.                         "title" => 'Type de Wifi',
  2561.                         "value" => $form['field3']->getData()
  2562.                     ];
  2563.                     $data[] = [
  2564.                         "title" => 'Protocole Wifi',
  2565.                         "value" => $form['field4']->getData()
  2566.                     ];
  2567.                     ;
  2568.                     break;
  2569.                 case "security":
  2570.                 case "administration":
  2571.                 case "device":
  2572.                 case "software":
  2573.                 case "server":
  2574.                     $data[] = [
  2575.                         "title" => 'Type',
  2576.                         "value" => $form['field1']->getData()
  2577.                     ];
  2578.                     $data[] = [
  2579.                         "title" => 'Informations complémentaires',
  2580.                         "value" => $form['field2']->getData()
  2581.                     ];
  2582.                     $data[] = [
  2583.                         "title" => 'Date d\'achat',
  2584.                         "value" => $form['field3']->getData()
  2585.                     ];
  2586.                     $data[] = [
  2587.                         "title" => 'N° d’identification',
  2588.                         "value" => $form['field4']->getData()
  2589.                     ];
  2590.                     break;
  2591.                 case "partitioning":
  2592.                 case "minimization":
  2593.                 case "anonymization":
  2594.                 case "pseudonymization":
  2595.                 case "sensitization":
  2596.                 case "information":
  2597.                 case "supervision":
  2598.                 case "destruction":
  2599.                     $data[] = [
  2600.                         "title" => 'Description',
  2601.                         "value" => $form['field1']->getData()
  2602.                     ];
  2603.                     $data[] = [
  2604.                         "title" => 'Informations complémentaires',
  2605.                         "value" => $form['field2']->getData()
  2606.                     ];
  2607.                     break;
  2608.                 case "supplier":
  2609.                     $data[] = [
  2610.                         "title" => 'Type',
  2611.                         "value" => $form['field1']->getData()
  2612.                     ];
  2613.                     break;
  2614.                 default:
  2615.                     throw new NotFoundHttpException();
  2616.             }
  2617.             $system->setData($data);
  2618.             $em->flush();
  2619.             $this->get('session')->getFlashBag()->add('success''Mise à jour de la mesure technique standard');
  2620.             return $this->redirectToRoute("manager_systems");
  2621.         }
  2622.         return $this->render('manager/systems_edit.html.twig', [
  2623.             "form" => $form->createView(),
  2624.             "fields" => $types[$system->getType()][$system->getSubtype()]
  2625.         ]);
  2626.     }
  2627.     /**
  2628.      * @Route("/systems/{id}/delete", name="systems_delete")
  2629.      */
  2630.     public function systemsDeleteAction(Request $requestSystemStd $system)
  2631.     {
  2632.         $em $this->getDoctrine()->getManager();
  2633.         $em->remove($system);
  2634.         $em->flush();
  2635.         $this->get('session')->getFlashBag()->add('success''Suppression de la mesure technique standard');
  2636.         return $this->redirectToRoute("manager_systems");
  2637.     }
  2638.     /**
  2639.      * @Route("/treatments", name="treatments")
  2640.      */
  2641.     public function treatmentsAction(Request $request)
  2642.     {
  2643.         $treatments $this->getDoctrine()->getRepository(TreatmentStd::class)->findBy(["user" => null]);
  2644.         
  2645.         return $this->render('manager/treatments.html.twig', [
  2646.             "treatments" => $treatments
  2647.         ]);
  2648.     }
  2649.     /**
  2650.      * @Route("/treatments/add", name="treatments_add")
  2651.      */
  2652.     public function treatmentsAddAction(Request $request)
  2653.     {
  2654.         $treatment = new TreatmentStd();
  2655.         $form $this->createForm(TreatmentStdType::class, $treatment);
  2656.         $personalDataFields = [
  2657.             [
  2658.                 "title" => "État civil, identité, données d'identification, images...",
  2659.                 "level" => 1,
  2660.             ],
  2661.             [
  2662.                 "title" => "Vie personnelle (habitudes de vie, situation familiale, etc.)",
  2663.                 "level" => 1,
  2664.             ],
  2665.             [
  2666.                 "title" => "Infos d'ordre économique et financier (revenus, situation financière, situation fiscale, etc.)",
  2667.                 "level" => 1,
  2668.             ],
  2669.             [
  2670.                 "title" => "Données de connexion (adress IP, logs, etc.)",
  2671.                 "level" => 1,
  2672.             ],
  2673.             [
  2674.                 "title" => "Données de localisation (déplacements, données GPS, GSM, etc.)",
  2675.                 "level" => 1,
  2676.             ],
  2677.             [
  2678.                 "title" => "Données Bancaires (données courantes « non sensible » mais classifié comme tel au vu des risques financiers)",
  2679.                 "level" => 2,
  2680.             ],
  2681.             [
  2682.                 "title" => "Numéro de Sécurité Sociale (ou NIR)",
  2683.                 "level" => 2,
  2684.             ],
  2685.             [
  2686.                 "title" => "Données révélant l'origine raciale ou ethnique",
  2687.                 "level" => 3,
  2688.             ],
  2689.             [
  2690.                 "title" => "Données révélant les opinions politiques",
  2691.                 "level" => 3,
  2692.             ],
  2693.             [
  2694.                 "title" => "Données révélant les convictions religieuses ou philosophiques",
  2695.                 "level" => 3,
  2696.             ],
  2697.             [
  2698.                 "title" => "Données révélant l'appartenance syndicale",
  2699.                 "level" => 3,
  2700.             ],
  2701.             [
  2702.                 "title" => "Données génétiques",
  2703.                 "level" => 3,
  2704.             ],
  2705.             [
  2706.                 "title" => "Données biométriques aux fins d'identifier une personne physique de manière unique",
  2707.                 "level" => 3,
  2708.             ],
  2709.             [
  2710.                 "title" => "Données concernant la santé",
  2711.                 "level" => 3,
  2712.             ],
  2713.             [
  2714.                 "title" => "Données concernant la vie sexuelle ou l'orientation sexuelle",
  2715.                 "level" => 3,
  2716.             ],
  2717.             [
  2718.                 "title" => "Données relatives à des condamnations pénales ou infractions",
  2719.                 "level" => 3,
  2720.             ],
  2721.         ];
  2722.         foreach ($personalDataFields as $key => $field) {
  2723.             $form->add("field_text_".$keyTextType::class, [
  2724.                 'attr' => [
  2725.                     'placeholder' => 'Zone de saisie'
  2726.                 ],
  2727.                 'label' => 'Zone de saisie',
  2728.                 'required' => false,
  2729.                 'mapped' => false
  2730.             ]);
  2731.             /*    ->add("field_duration_".$key, TextType::class, [
  2732.                 'attr' => [
  2733.                     'placeholder' => 'Durée de conservation'
  2734.                 ],
  2735.                 'label' => 'Durée de conservation',
  2736.                 'required' => false,
  2737.                 'mapped' => false
  2738.             ])*/
  2739.         }
  2740.         $form->handleRequest($request);
  2741.         if ($form->isSubmitted() && $form->isValid()) {
  2742.             $em $this->getDoctrine()->getManager();
  2743.             $now = new \DateTime("now");
  2744.             $personalData = [];
  2745.             $sensitiveData false;
  2746.             foreach ($personalDataFields as $key => $field) {
  2747.                 $personalData[] = [
  2748.                     "title" => $field['title'],
  2749.                     "level" => $field['level'],
  2750.                     "text" => $form["field_text_".$key]->getData(),
  2751.                     //"duration" => $form["field_duration_".$key]->getData(),
  2752.                 ];
  2753.                 if (($field['level'] == || $field['level'] == 3) && ($form["field_text_".$key]->getData()/* || $form["field_duration_".$key]->getData()*/)) {
  2754.                     $sensitiveData true;
  2755.                 }
  2756.             }
  2757.             $treatment->setPersonalData($personalData);
  2758.             $treatment->setSensitiveData($sensitiveData);
  2759.             $treatment->setCreationDate($now);
  2760.             $treatment->setEditDate($now);
  2761.             $treatment->setManager($this->getUser()->getManager());
  2762.             if ($treatment->isSensitiveData()) {
  2763.                 if (!in_array(1$treatment->getPiaCriteria())) {
  2764.                     $treatment->addPiaCriteria(1);
  2765.                 }
  2766.             } else {
  2767.                 $treatment->setInsufficientCriteria(true);
  2768.             }
  2769.             if (count($treatment->getPiaCriteria()) >= 2) {
  2770.                 $treatment->setPiaNeeded(true);
  2771.             } else {
  2772.                 $treatment->setPiaNeeded(false);
  2773.             }
  2774.             $em->persist($treatment);
  2775.             $em->flush();
  2776.             $this->get('session')->getFlashBag()->add('success''Nouveau traitement standard ajouté');
  2777.             return $this->redirectToRoute("manager_treatments");
  2778.         }
  2779.         return $this->render('manager/treatments_add.html.twig', [
  2780.             "form" => $form->createView(),
  2781.             "personalDataFields" => $personalDataFields
  2782.         ]);
  2783.     }
  2784.     /**
  2785.      * @Route("/treatments/{id}/edit", name="treatments_edit")
  2786.      */
  2787.     public function treatmentsEditAction(Request $requestTreatmentStd $treatment)
  2788.     {
  2789.         if (count($treatment->getPiaCriteria()) == 0) {
  2790.             if ($treatment->isAutomatedDecision()) {
  2791.                 $em $this->getDoctrine()->getManager();
  2792.                 $treatment->setPiaCriteria([4]);
  2793.                 $treatment->setAutomatedDecision(false);
  2794.                 $em->flush();
  2795.                 return $this->redirectToRoute("manager_treatments_edit", ["id" => $treatment->getId()]);
  2796.             }
  2797.         }
  2798.         $form $this->createForm(TreatmentStdType::class, $treatment);
  2799.         foreach ($treatment->getPersonalData() as $key => $field) {
  2800.             $form->add("field_text_".$keyTextType::class, [
  2801.                 'attr' => [
  2802.                     'placeholder' => 'Zone de saisie'
  2803.                 ],
  2804.                 'label' => 'Zone de saisie',
  2805.                 'data' => $field['text'],
  2806.                 'required' => false,
  2807.                 'mapped' => false
  2808.             ]);
  2809.             /*    ->add("field_duration_".$key, TextType::class, [
  2810.                 'attr' => [
  2811.                     'placeholder' => 'Durée de conservation'
  2812.                 ],
  2813.                 'label' => 'Durée de conservation',
  2814.                 'data' => $field['duration'],
  2815.                 'required' => false,
  2816.                 'mapped' => false
  2817.             ]);*/
  2818.         }
  2819.         $form->handleRequest($request);
  2820.         if ($form->isSubmitted() && $form->isValid()) {
  2821.             $em $this->getDoctrine()->getManager();
  2822.             $now = new \DateTime("now");
  2823.             $personalData = [];
  2824.             $sensitiveData false;
  2825.             foreach ($treatment->getPersonalData() as $key => $field) {
  2826.                 $personalData[] = [
  2827.                     "title" => $field['title'],
  2828.                     "level" => $field['level'],
  2829.                     "text" => $form["field_text_".$key]->getData(),
  2830.                     //"duration" => $form["field_duration_".$key]->getData(),
  2831.                 ];
  2832.                 if (($field['level'] == || $field['level'] == 3) && ($form["field_text_".$key]->getData()/* || $form["field_duration_".$key]->getData()*/)) {
  2833.                     $sensitiveData true;
  2834.                 }
  2835.             }
  2836.             $treatment->setPersonalData($personalData);
  2837.             $treatment->setSensitiveData($sensitiveData);
  2838.             if ($treatment->isSensitiveData()) {
  2839.                 if (!in_array(1$treatment->getPiaCriteria())) {
  2840.                     $treatment->addPiaCriteria(1);
  2841.                 }
  2842.             } else {
  2843.                 $treatment->setInsufficientCriteria(true);
  2844.             }
  2845.             $treatment->setEditDate($now);
  2846.             if (count($treatment->getPiaCriteria()) >= 2) {
  2847.                 $treatment->setPiaNeeded(true);
  2848.             } else {
  2849.                 $treatment->setPiaNeeded(false);
  2850.             }
  2851.             $em->flush();
  2852.             $this->get('session')->getFlashBag()->add('success''Traitement standard mis à jour');
  2853.             return $this->redirectToRoute("manager_treatments");
  2854.         }
  2855.         return $this->render('manager/treatments_edit.html.twig', [
  2856.             "form" => $form->createView(),
  2857.             "treatment" => $treatment,
  2858.             "personalDataFields" => $treatment->getPersonalData()
  2859.         ]);
  2860.     }
  2861.     /**
  2862.      * @Route("/treatments/{id}/translate/{_locale}", name="treatments_translate")
  2863.      */
  2864.     public function treatmentsTranslateAction(Request $requestTreatmentStd $treatment)
  2865.     {
  2866.         $em $this->getDoctrine()->getManager();
  2867.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  2868.         $translations $repository->findTranslations($treatment);
  2869.         if (!isset($translations[$request->get("_locale")])) {
  2870.             return $this->redirectToRoute("manager_treatments_gen_translate", ["id" => $treatment->getId(), "locale" => 'en']);
  2871.         }
  2872.         $treatment $em->find(TreatmentStd::class, $request->get("id"));
  2873.         $form $this->createForm(TreatmentStdTranslateType::class, $treatment);
  2874.         foreach ($treatment->getPersonalData() as $key => $field) {
  2875.             $form->add("field_text_".$keyTextType::class, [
  2876.                 'attr' => [
  2877.                     'placeholder' => 'Zone de saisie'
  2878.                 ],
  2879.                 'label' => 'Zone de saisie',
  2880.                 'data' => $field['text'],
  2881.                 'required' => false,
  2882.                 'mapped' => false
  2883.             ]);
  2884.         }
  2885.         $form->handleRequest($request);
  2886.         if ($form->isSubmitted() && $form->isValid()) {
  2887.             $personalData = [];
  2888.             foreach ($treatment->getPersonalData() as $key => $field) {
  2889.                 $personalData[] = [
  2890.                     "title" => $field['title'],
  2891.                     "level" => $field['level'],
  2892.                     "text" => $form["field_text_".$key]->getData(),
  2893.                 ];
  2894.             }
  2895.             $treatment->setPersonalData($personalData);
  2896.             $em->persist($treatment);
  2897.             $em->flush();
  2898.             $this->get('session')->getFlashBag()->add('success''Traduction du traitement standard mise à jour');
  2899.             return $this->redirectToRoute("manager_treatments");
  2900.         }
  2901.         return $this->render('manager/treatments_edit.html.twig', [
  2902.             "form" => $form->createView(),
  2903.             "treatment" => $treatment,
  2904.             "personalDataFields" => $treatment->getPersonalData()
  2905.         ]);
  2906.     }
  2907.     /**
  2908.      * @Route("/treatments/{id}/gentranslate/{locale}", name="treatments_gen_translate")
  2909.      */
  2910.     public function treatmentsGanTranslateAction(Request $requestTreatmentStd $treatment$locale)
  2911.     {
  2912.         $em $this->getDoctrine()->getManager();
  2913.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  2914.         $translations $repository->findTranslations($treatment);
  2915.         if (!isset($translations[$locale])) {
  2916.             $repository
  2917.                 ->translate($treatment'name''en'$treatment->getName())
  2918.                 ->translate($treatment'mainPurpose''en'$treatment->getMainPurpose())
  2919.                 ->translate($treatment'purpose1''en'$treatment->getPurpose1())
  2920.                 ->translate($treatment'purpose2''en'$treatment->getPurpose2())
  2921.                 ->translate($treatment'purpose3''en'$treatment->getPurpose3())
  2922.                 ->translate($treatment'purpose4''en'$treatment->getPurpose4())
  2923.                 ->translate($treatment'purpose5''en'$treatment->getPurpose5())
  2924.                 ->translate($treatment'othersPurpose''en'$treatment->getOthersPurpose())
  2925.                 ->translate($treatment'description''en'$treatment->getDescription())
  2926.                 ->translate($treatment'personalData''en'$treatment->getPersonalData())
  2927.                 ->translate($treatment'peopleData''en'$treatment->getPeopleData())
  2928.                 ->translate($treatment'transferOutsideUeCountries''en'$treatment->getTransferOutsideUeCountries())
  2929.                 ->translate($treatment'consentHow''en'$treatment->getConsentHow())
  2930.                 ->translate($treatment'legalBasis''en'$treatment->getLegalBasis())
  2931.                 ->translate($treatment'dataSource''en'$treatment->getDataSource())
  2932.             ;
  2933.             $em->persist($treatment);
  2934.             $em->flush();
  2935.             return $this->redirectToRoute("manager_treatments_translate", ["id" => $treatment->getId(), "_locale" => 'en']);
  2936.         }
  2937.         return $this->redirectToRoute("manager_treatments_translate", ["id" => $treatment->getId(), "_locale" => 'en']);
  2938.     }
  2939.     /**
  2940.      * @Route("/treatments/{id}/delete", name="treatments_delete")
  2941.      */
  2942.     public function treatmentsDeleteAction(Request $requestTreatmentStd $treatment)
  2943.     {
  2944.         $em $this->getDoctrine()->getManager();
  2945.         $em->remove($treatment);
  2946.         $em->flush();
  2947.         $this->get('session')->getFlashBag()->add('success''Traitement standard supprimé');
  2948.         return $this->redirectToRoute("manager_treatments");
  2949.     }
  2950.     /**
  2951.      * @Route("/subcontractors", name="subcontractors")
  2952.      */
  2953.     public function subcontractorsAction(Request $request)
  2954.     {
  2955.         $subcontractors $this->getDoctrine()->getRepository(SubcontractorStd::class)->findBy([], ["name" => "ASC"]);
  2956.         return $this->render('manager/subcontractors.html.twig', [
  2957.             "subcontractors" => $subcontractors
  2958.         ]);
  2959.     }
  2960.     /**
  2961.      * @Route("/subcontractors/add", name="subcontractors_add")
  2962.      */
  2963.     public function subcontractorsAddAction(Request $request)
  2964.     {
  2965.         $subcontractor = new SubcontractorStd();
  2966.         $form $this->createForm(SubcontractorStdType::class, $subcontractor);
  2967.         $form->handleRequest($request);
  2968.         if ($form->isSubmitted() && $form->isValid()) {
  2969.             $em $this->getDoctrine()->getManager();
  2970.             $now = new \DateTime("now");
  2971.             $subcontractor->setDate($now);
  2972.             $subcontractor->setEditDate($now);
  2973.             $subcontractor->setManager($this->getUser()->getManager());
  2974.             $em->persist($subcontractor);
  2975.             $em->flush();
  2976.             if (isset($_FILES['appbundle_subcontractor_documents'])) {
  2977.                 $files $_FILES['appbundle_subcontractor_documents'];
  2978.                 $fileNames $_POST['appbundle_subcontractor_documents_names'];
  2979.                 for ($i=0;$i<count($files['name']);$i++) {
  2980.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  2981.                         $name $files["name"][$i];
  2982.                         $parts explode("."$name);
  2983.                         $extension end($parts);
  2984.                         $fileName $subcontractor->getId()."_".md5(uniqid()) . '.' $extension;
  2985.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  2986.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  2987.                         $document = new SubcontractorStdDocument();
  2988.                         $document->setName($docTitle);
  2989.                         $document->setFilename($fileName);
  2990.                         $document->setUserFilename($files["name"][$i]);
  2991.                         $document->setManager($this->getUser()->getManager());
  2992.                         $document->setSubcontractorStd($subcontractor);
  2993.                         $em->persist($document);
  2994.                         $em->flush();
  2995.                     }
  2996.                 }
  2997.             }
  2998.             $this->get('session')->getFlashBag()->add('success''Nouveau sous-traitant standard ajouté');
  2999.             return $this->redirectToRoute("manager_subcontractors");
  3000.         }
  3001.         return $this->render('manager/subcontractors_add.html.twig', [
  3002.             "form" => $form->createView()
  3003.         ]);
  3004.     }
  3005.     /**
  3006.      * @Route("/subcontractors/{id}/edit", name="subcontractors_edit")
  3007.      */
  3008.     public function subcontractorsEditAction(Request $requestSubcontractorStd $subcontractor)
  3009.     {
  3010.         $form $this->createForm(SubcontractorStdType::class, $subcontractor);
  3011.         $form->handleRequest($request);
  3012.         if ($form->isSubmitted() && $form->isValid()) {
  3013.             $em $this->getDoctrine()->getManager();
  3014.             $subcontractor->setEditDate(new \DateTime("now"));
  3015.             $em->flush();
  3016.             foreach ($subcontractor->getDocuments() as $document) {
  3017.                 if (isset($_POST["appbundle_subcontractor_documents_".$document->getId()]) && !empty($_POST["appbundle_subcontractor_documents_".$document->getId()])) {
  3018.                     if ($document->getName() != $_POST["appbundle_subcontractor_documents_".$document->getId()]) {
  3019.                         $document->setTitle($_POST["appbundle_subcontractor_documents_".$document->getId()]);
  3020.                         $em->flush();
  3021.                     }
  3022.                 }
  3023.             }
  3024.             if (isset($_FILES['appbundle_subcontractor_documents'])) {
  3025.                 $files $_FILES['appbundle_subcontractor_documents'];
  3026.                 $fileNames $_POST['appbundle_subcontractor_documents_names'];
  3027.                 for ($i=0;$i<count($files['name']);$i++) {
  3028.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  3029.                         $name $files["name"][$i];
  3030.                         $parts explode("."$name);
  3031.                         $extension end($parts);
  3032.                         $fileName $subcontractor->getId()."_".md5(uniqid()) . '.' $extension;
  3033.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  3034.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  3035.                         $document = new SubcontractorStdDocument();
  3036.                         $document->setName($docTitle);
  3037.                         $document->setFilename($fileName);
  3038.                         $document->setUserFilename($files["name"][$i]);
  3039.                         $document->setManager($this->getUser()->getManager());
  3040.                         $document->setSubcontractorStd($subcontractor);
  3041.                         $em->persist($document);
  3042.                         $em->flush();
  3043.                     }
  3044.                 }
  3045.             }
  3046.             $this->get('session')->getFlashBag()->add('success''Sous-traitant standard mis à jour');
  3047.             return $this->redirectToRoute("manager_subcontractors");
  3048.         }
  3049.         return $this->render('manager/subcontractors_edit.html.twig', [
  3050.             "subcontractor" => $subcontractor,
  3051.             "form" => $form->createView()
  3052.         ]);
  3053.     }
  3054.     /**
  3055.      * @Route("/subcontractors/{id}/translate/{_locale}", name="subcontractors_translate")
  3056.      */
  3057.     public function subcontractorsTranslateAction(Request $requestSubcontractorStd $subcontractor)
  3058.     {
  3059.         $em $this->getDoctrine()->getManager();
  3060.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  3061.         $translations $repository->findTranslations($subcontractor);
  3062.         if (!isset($translations[$request->get("_locale")])) {
  3063.             return $this->redirectToRoute("manager_subcontractors_gen_translate", ["id" => $subcontractor->getId(), "_locale" => "fr""locale" => $request->get("_locale")]);
  3064.         }
  3065.         $subcontractor $em->find(SubcontractorStd::class, $request->get("id"));
  3066.         $form $this->createForm(SubcontractorStdTranslateType::class, $subcontractor);
  3067.         $form->handleRequest($request);
  3068.         if ($form->isSubmitted() && $form->isValid()) {
  3069.             $em->persist($subcontractor);
  3070.             $em->flush();
  3071.             $this->get('session')->getFlashBag()->add('success''Traduction du sous-traitant standard mis à jour');
  3072.             return $this->redirectToRoute("manager_subcontractors");
  3073.         }
  3074.         return $this->render('manager/subcontractors_translate.html.twig', [
  3075.             "form" => $form->createView(),
  3076.             "subcontractor" => $subcontractor,
  3077.         ]);
  3078.     }
  3079.     /**
  3080.      * @Route("/subcontractors/{id}/gentranslate/{locale}_{_locale}", name="subcontractors_gen_translate")
  3081.      */
  3082.     public function subcontractorsGanTranslateAction(Request $requestSubcontractorStd $subcontractor$locale$_locale)
  3083.     {
  3084.         $em $this->getDoctrine()->getManager();
  3085.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  3086.         $translations $repository->findTranslations($subcontractor);
  3087.         if (!isset($translations[$locale])) {
  3088.             $repository
  3089.                 ->translate($subcontractor'type'$locale$subcontractor->getType())
  3090.             ;
  3091.             $em->persist($subcontractor);
  3092.             $em->flush();
  3093.             return $this->redirectToRoute("manager_subcontractors_translate", ["id" => $subcontractor->getId(), "_locale" => $locale]);
  3094.         }
  3095.         return $this->redirectToRoute("manager_subcontractors");
  3096.     }
  3097.     /**
  3098.      * @Route("/subcontractors/{id}/delete", name="subcontractors_delete")
  3099.      */
  3100.     public function subcontractorsDeleteAction(Request $requestSubcontractorStd $subcontractor)
  3101.     {
  3102.         $em $this->getDoctrine()->getManager();
  3103.         $em->remove($subcontractor);
  3104.         $em->flush();
  3105.         $this->get('session')->getFlashBag()->add('success''Sous-traitant standard supprimé');
  3106.         return $this->redirectToRoute("manager_subcontractors");
  3107.     }
  3108.     /**
  3109.      * @Route("/subcontractors/deletedoc/{subcontractor}/{document}", name="subcontractor_deletedoc")
  3110.      */
  3111.     public function subcontractorsDeleteDocAction(Request $requestSubcontractorStd $subcontractorSubcontractorStdDocument $subcontractorStdDocument)
  3112.     {
  3113.         $em $this->getDoctrine()->getManager();
  3114.         $em->remove($subcontractorStdDocument);
  3115.         $em->flush();
  3116.         $this->get('session')->getFlashBag()->add('success''Document supprimé');
  3117.         return $this->redirectToRoute('manager_subcontractors_edit', ['id' => $subcontractor->getId()]);
  3118.     }
  3119.     /**
  3120.      * @Route("/actions", name="actions")
  3121.      */
  3122.     public function actionsAction(Request $request)
  3123.     {
  3124.         $actions $this->getDoctrine()->getRepository(ActionStd::class)->findBy([], ["name" => "ASC"]);
  3125.         return $this->render('manager/actions.html.twig', [
  3126.             "actions" => $actions
  3127.         ]);
  3128.     }
  3129.     /**
  3130.      * @Route("/actions/add", name="actions_add")
  3131.      */
  3132.     public function actionsAddAction(Request $request)
  3133.     {
  3134.         $action = new ActionStd();
  3135.         $form $this->createForm(ActionStdType::class, $action)
  3136.             ->add('sheets'EntityType::class, [
  3137.                 'attr' => array(
  3138.                     'placeholder' => 'Annexer des fiches pratiques',
  3139.                 ),
  3140.                 'placeholder' => 'Annexer des fiches pratiques',
  3141.                 'label' => 'Annexer des fiches pratiques',
  3142.                 'expanded' => false,
  3143.                 'multiple' => true,
  3144.                 'required' => false,
  3145.                 'class' => Document::class,
  3146.                 'query_builder' => function (EntityRepository $er) {
  3147.                     return $er->createQueryBuilder('d')
  3148.                         ->leftJoin("d.type""t")
  3149.                         ->leftJoin("t.parent""pt")
  3150.                         ->where('t.id = 2')
  3151.                         ->orWhere('pt.id = 2')
  3152.                         ->addOrderBy("d.name""ASC")
  3153.                         ->addOrderBy("d.filename""ASC");
  3154.                 }
  3155.             ]);
  3156.         $form->handleRequest($request);
  3157.         if ($form->isSubmitted() && $form->isValid()) {
  3158.             $em $this->getDoctrine()->getManager();
  3159.             $now = new \DateTime("now");
  3160.             $action->setDate($now);
  3161.             $action->setEditDate($now);
  3162.             $action->setManager($this->getUser()->getManager());
  3163.             $em->persist($action);
  3164.             $em->flush();
  3165.             if (isset($_FILES['appbundle_action_documents'])) {
  3166.                 $files $_FILES['appbundle_action_documents'];
  3167.                 $fileNames $_POST['appbundle_action_documents_names'];
  3168.                 for ($i=0;$i<count($files['name']);$i++) {
  3169.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  3170.                         $name $files["name"][$i];
  3171.                         $parts explode("."$name);
  3172.                         $extension end($parts);
  3173.                         $fileName $action->getId()."_".md5(uniqid()) . '.' $extension;
  3174.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  3175.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  3176.                         $document = new ActionStdDocument();
  3177.                         $document->setName($docTitle);
  3178.                         $document->setFilename($fileName);
  3179.                         $document->setUserFilename($files["name"][$i]);
  3180.                         $document->setManager($this->getUser()->getManager());
  3181.                         $document->setActionStd($action);
  3182.                         $em->persist($document);
  3183.                         $em->flush();
  3184.                     }
  3185.                 }
  3186.             }
  3187.             $this->get('session')->getFlashBag()->add('success''Nouvelle action standard ajoutée');
  3188.             return $this->redirectToRoute("manager_actions");
  3189.         }
  3190.         return $this->render('manager/actions_add.html.twig', [
  3191.             "form" => $form->createView()
  3192.         ]);
  3193.     }
  3194.     /**
  3195.      * @Route("/actions/{id}/edit", name="actions_edit")
  3196.      */
  3197.     public function actionsEditAction(Request $requestActionStd $action)
  3198.     {
  3199.         $form $this->createForm(ActionStdType::class, $action)
  3200.             ->add('sheets'EntityType::class, [
  3201.                 'attr' => array(
  3202.                     'placeholder' => 'Annexer des fiches pratiques',
  3203.                 ),
  3204.                 'placeholder' => 'Annexer des fiches pratiques',
  3205.                 'label' => 'Annexer des fiches pratiques',
  3206.                 'expanded' => false,
  3207.                 'multiple' => true,
  3208.                 'required' => false,
  3209.                 'class' => Document::class,
  3210.                 'query_builder' => function (EntityRepository $er) {
  3211.                     return $er->createQueryBuilder('d')
  3212.                         ->leftJoin("d.type""t")
  3213.                         ->leftJoin("t.parent""pt")
  3214.                         ->where('t.id = 2')
  3215.                         ->orWhere('pt.id = 2')
  3216.                         ->addOrderBy("d.name""ASC")
  3217.                         ->addOrderBy("d.filename""ASC");
  3218.                 }
  3219.             ]);
  3220.         $form->handleRequest($request);
  3221.         if ($form->isSubmitted() && $form->isValid()) {
  3222.             $em $this->getDoctrine()->getManager();
  3223.             $action->setEditDate(new \DateTime("now"));
  3224.             $em->flush();
  3225.             foreach ($action->getDocuments() as $document) {
  3226.                 if (isset($_POST["appbundle_action_documents_".$document->getId()]) && !empty($_POST["appbundle_action_documents_".$document->getId()])) {
  3227.                     if ($document->getName() != $_POST["appbundle_action_documents_".$document->getId()]) {
  3228.                         $document->setTitle($_POST["appbundle_action_documents_".$document->getId()]);
  3229.                         $em->flush();
  3230.                     }
  3231.                 }
  3232.             }
  3233.             if (isset($_FILES['appbundle_action_documents'])) {
  3234.                 $files $_FILES['appbundle_action_documents'];
  3235.                 $fileNames $_POST['appbundle_action_documents_names'];
  3236.                 for ($i=0;$i<count($files['name']);$i++) {
  3237.                     if ( is_uploaded_file$files["tmp_name"][$i] ) && file_exists($files["tmp_name"][$i]) && $files["error"][$i] === 0) {
  3238.                         $name $files["name"][$i];
  3239.                         $parts explode("."$name);
  3240.                         $extension end($parts);
  3241.                         $fileName $action->getId()."_".md5(uniqid()) . '.' $extension;
  3242.                         move_uploaded_file($files["tmp_name"][$i], $this->getParameter('documents_directory') . $fileName);
  3243.                         $docTitle = (isset($fileNames[$i]) && !empty($fileNames[$i]))?$fileNames[$i]:$files["name"][$i];
  3244.                         $document = new ActionStdDocument();
  3245.                         $document->setName($docTitle);
  3246.                         $document->setFilename($fileName);
  3247.                         $document->setUserFilename($files["name"][$i]);
  3248.                         $document->setManager($this->getUser()->getManager());
  3249.                         $document->setActionStd($action);
  3250.                         $em->persist($document);
  3251.                         $em->flush();
  3252.                     }
  3253.                 }
  3254.             }
  3255.             $this->get('session')->getFlashBag()->add('success''Action standard mise à jour');
  3256.             return $this->redirectToRoute("manager_actions");
  3257.         }
  3258.         return $this->render('manager/actions_edit.html.twig', [
  3259.             "action" => $action,
  3260.             "form" => $form->createView()
  3261.         ]);
  3262.     }
  3263.     /**
  3264.      * @Route("/actions/{id}/translate/{_locale}", name="actions_translate")
  3265.      */
  3266.     public function actionsTranslateAction(Request $requestActionStd $action)
  3267.     {
  3268.         $em $this->getDoctrine()->getManager();
  3269.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  3270.         $translations $repository->findTranslations($action);
  3271.         if (!isset($translations[$request->get("_locale")])) {
  3272.             return $this->redirectToRoute("manager_actions_gen_translate", ["id" => $action->getId(), "_locale" => "fr""locale" => $request->get("_locale")]);
  3273.         }
  3274.         $action $em->find(ActionStd::class, $request->get("id"));
  3275.         $form $this->createForm(ActionStdTranslateType::class, $action);
  3276.         $form->handleRequest($request);
  3277.         if ($form->isSubmitted() && $form->isValid()) {
  3278.             $em->persist($action);
  3279.             $em->flush();
  3280.             $this->get('session')->getFlashBag()->add('success''Traduction de l\'action standard mise à jour');
  3281.             return $this->redirectToRoute("manager_actions");
  3282.         }
  3283.         return $this->render('manager/actions_translate.html.twig', [
  3284.             "form" => $form->createView(),
  3285.             "action" => $action,
  3286.         ]);
  3287.     }
  3288.     /**
  3289.      * @Route("/actions/{id}/gentranslate/{locale}_{_locale}", name="actions_gen_translate")
  3290.      */
  3291.     public function actionsGanTranslateAction(Request $requestActionStd $action$locale$_locale)
  3292.     {
  3293.         $em $this->getDoctrine()->getManager();
  3294.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  3295.         $translations $repository->findTranslations($action);
  3296.         if (!isset($translations[$locale])) {
  3297.             $repository
  3298.                 ->translate($action'name'$locale$action->getName())
  3299.                 ->translate($action'goal'$locale$action->getGoal())
  3300.                 ->translate($action'information'$locale$action->getInformation())
  3301.             ;
  3302.             $em->persist($action);
  3303.             $em->flush();
  3304.             return $this->redirectToRoute("manager_actions_translate", ["id" => $action->getId(), "_locale" => $locale]);
  3305.         }
  3306.         return $this->redirectToRoute("manager_actions");
  3307.     }
  3308.     /**
  3309.      * @Route("/actions/{id}/delete", name="actions_delete")
  3310.      */
  3311.     public function actionsDeleteAction(Request $requestActionStd $action)
  3312.     {
  3313.         $em $this->getDoctrine()->getManager();
  3314.         $em->remove($action);
  3315.         $em->flush();
  3316.         $this->get('session')->getFlashBag()->add('success''Action standard supprimée');
  3317.         return $this->redirectToRoute("manager_actions");
  3318.     }
  3319.     /**
  3320.      * @Route("/actions/deletedoc/{action}/{document}", name="actions_deletedoc")
  3321.      */
  3322.     public function actionsDeleteDocAction(Request $requestActionStd $actionActionStdDocument $actionStdDocument)
  3323.     {
  3324.         $em $this->getDoctrine()->getManager();
  3325.         $em->remove($actionStdDocument);
  3326.         $em->flush();
  3327.         $this->get('session')->getFlashBag()->add('success''Document supprimé');
  3328.         return $this->redirectToRoute('manager_actions_edit', ['id' => $action->getId()]);
  3329.     }
  3330.     /**
  3331.      * @Route("/infos", name="infos")
  3332.      */
  3333.     public function infosAction(Request $request)
  3334.     {
  3335.         if (!$this->isGranted("ROLE_DPO")) {
  3336.             throw new NotFoundHttpException();
  3337.         }
  3338.         $infos $this->getDoctrine()->getRepository(Info::class)->findAll();
  3339.         return $this->render('manager/infos.html.twig', [
  3340.             "infos" => $infos
  3341.         ]);
  3342.     }
  3343.     /**
  3344.      * @Route("/infos/add", name="infos_add")
  3345.      */
  3346.     public function infosAddAction(Request $request)
  3347.     {
  3348.         if (!$this->isGranted("ROLE_DPO")) {
  3349.             throw new NotFoundHttpException();
  3350.         }
  3351.         $info = new Info();
  3352.         $form $this->createForm(InfoType::class, $info);
  3353.         $form->handleRequest($request);
  3354.         if ($form->isSubmitted() && $form->isValid()) {
  3355.             $em $this->getDoctrine()->getManager();
  3356.             $em->persist($info);
  3357.             $em->flush();
  3358.             /**
  3359.              * @var UploadedFile $file
  3360.              */
  3361.             $file $form->get('filePicture')->getData();
  3362.             if ($file != NULL) {
  3363.                 $fileName $info->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  3364.                 $file->move(
  3365.                     $this->getParameter('pictures_directory'), $fileName
  3366.                 );
  3367.                 $info->setPicture($fileName);
  3368.                 $em->flush();
  3369.             }
  3370.             $this->get('session')->getFlashBag()->add('success''Nouvelle info ajoutée');
  3371.             return $this->redirectToRoute("manager_infos");
  3372.         }
  3373.         return $this->render('manager/infos_add.html.twig', [
  3374.             "form" => $form->createView(),
  3375.         ]);
  3376.     }
  3377.     /**
  3378.      * @Route("/infos/{id}/edit", name="infos_edit")
  3379.      */
  3380.     public function infosEditAction(Request $requestInfo $info)
  3381.     {
  3382.         if (!$this->isGranted("ROLE_DPO")) {
  3383.             throw new NotFoundHttpException();
  3384.         }
  3385.         $form $this->createForm(InfoType::class, $info);
  3386.         $form->handleRequest($request);
  3387.         if ($form->isSubmitted() && $form->isValid()) {
  3388.             $em $this->getDoctrine()->getManager();
  3389.             $em->flush();
  3390.             /**
  3391.              * @var UploadedFile $file
  3392.              */
  3393.             $file $form->get('filePicture')->getData();
  3394.             if ($file != NULL) {
  3395.                 $fileName $info->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  3396.                 $file->move(
  3397.                     $this->getParameter('pictures_directory'), $fileName
  3398.                 );
  3399.                 $info->setPicture($fileName);
  3400.                 $em->flush();
  3401.             }
  3402.             $this->get('session')->getFlashBag()->add('success''Info mise à jour');
  3403.             return $this->redirectToRoute("manager_infos");
  3404.         }
  3405.         return $this->render('manager/infos_edit.html.twig', [
  3406.             "form" => $form->createView(),
  3407.             "info" => $info
  3408.         ]);
  3409.     }
  3410.     /**
  3411.      * @Route("/infos/{id}/delete", name="infos_delete")
  3412.      */
  3413.     public function infosDeleteAction(Request $requestInfo $info)
  3414.     {
  3415.         if (!$this->isGranted("ROLE_DPO")) {
  3416.             throw new NotFoundHttpException();
  3417.         }
  3418.         $em $this->getDoctrine()->getManager();
  3419.         $em->remove($info);
  3420.         $em->flush();
  3421.         $this->get('session')->getFlashBag()->add('success''Info supprimée');
  3422.         return $this->redirectToRoute("manager_infos");
  3423.     }
  3424.     /**
  3425.      * @Route("/loginlogs/{user}", name="login_logs")
  3426.      */
  3427.     public function loginLogsAction(Request $requestUser $user)
  3428.     {
  3429.         $loginLogs $this->getDoctrine()->getRepository(LoginLog::class)->findLast3Months($user);
  3430.         return $this->render('manager/login_logs.html.twig', [
  3431.             "loginLogs" => $loginLogs
  3432.         ]);
  3433.     }
  3434.     /**
  3435.      * @Route("/subscriptions", name="subscriptions")
  3436.      */
  3437.     public function subscriptionsAction(Request $request)
  3438.     {
  3439.         if (!$this->isGranted("ROLE_DPO")) {
  3440.             throw new NotFoundHttpException();
  3441.         }
  3442.         $subscriptions $this->getDoctrine()->getRepository(Subscription::class)->findAll();
  3443.         return $this->render('manager/subscriptions.html.twig', [
  3444.             "subscriptions" => $subscriptions
  3445.         ]);
  3446.     }
  3447.     /**
  3448.      * @Route("/subscriptions/export", name="subscriptions_export")
  3449.      */
  3450.     public function subscriptionsExportAction(Request $request)
  3451.     {
  3452.         if (!$this->isGranted("ROLE_DPO")) {
  3453.             throw new NotFoundHttpException();
  3454.         }
  3455.         $now = new \DateTime("now");
  3456.         $users $this->getDoctrine()->getRepository(User::class)->findBy([], ["companyName" => "ASC"]);
  3457.         $spreadsheet = new Spreadsheet();
  3458.         $spreadsheet->setActiveSheetIndex(0);
  3459.         $sheet $spreadsheet->getActiveSheet();
  3460.         $sheet->setCellValue('A1''Société');
  3461.         $sheet->setCellValue('B1''Abonnement');
  3462.         $sheet->setCellValue('C1''Début');
  3463.         $sheet->setCellValue('D1''Fin');
  3464.         $sheet->setCellValue('E1''A facturer');
  3465.         $sheet->setCellValue('F1''Informations abonnement');
  3466.         $sheet->setCellValue('G1''Informations facturation');
  3467.         $sheet->setCellValue('H1''Echéance');
  3468.         $sheet->setCellValue('I1''Tarif');
  3469.         $i 2;
  3470.         foreach ($users as $user) {
  3471.             $sheet->setCellValue('A'.$i$user->getCompanyName());
  3472.             if ($user->getCurrentSubscription()) {
  3473.                 $subscription $user->getCurrentSubscription();
  3474.                 $sheet->setCellValue('B'.$i$subscription->getType()?$subscription->getType()->getLibelle():"-");
  3475.                 $sheet->setCellValue('C'.$i$subscription->getBeginDate()?$subscription->getBeginDate()->format("d/m/Y"):"-");
  3476.                 $sheet->setCellValue('D'.$i$subscription->getEndDate()?$subscription->getEndDate()->format("d/m/Y"):"-");
  3477.                 if ($subscription->isActive() && ($subscription->getPaymentUntil() == null || $subscription->getPaymentUntil() < $now)) {
  3478.                     $sheet->setCellValue('E'.$i'OUI');
  3479.                 } else {
  3480.                     $sheet->setCellValue('E'.$i'NON');
  3481.                 }
  3482.                 $sheet->setCellValue('F'.$i$subscription->getOffer());
  3483.                 $sheet->setCellValue('G'.$i$subscription->getBilling());
  3484.                 if ($subscription->getBillingMonths() == 12) {
  3485.                     $sheet->setCellValue('H'.$i'Annuelle');
  3486.                 } elseif ($subscription->getBillingMonths() == 3) {
  3487.                     $sheet->setCellValue('H'.$i'Trimestrielle');
  3488.                 } elseif ($subscription->getBillingMonths() == 1) {
  3489.                     $sheet->setCellValue('H'.$i'Mensuelle');
  3490.                 }
  3491.                 $sheet->setCellValue('I'.$i$subscription->getUnitBillingPrice());
  3492.             }
  3493.             $i++;
  3494.         }
  3495.         $writer = new Xlsx($spreadsheet);
  3496.         $response = new StreamedResponse();
  3497.         $response->setCallback(function () use ($writer) {
  3498.             $writer->save('php://output');
  3499.         });
  3500.         $response->setStatusCode(200);
  3501.         $response->headers->set('Content-Type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  3502.         $response->headers->set('Content-Disposition''attachment;filename="export_abonnements.xlsx"');
  3503.         $response->headers->set('Cache-Control','max-age=0');
  3504.         return $response;
  3505.     }
  3506.     /**
  3507.      * @Route("/subscriptions/{id}", name="subscriptions_user")
  3508.      */
  3509.     public function subscriptionsUserAction(Request $requestUser $user)
  3510.     {
  3511.         if (!$this->isGranted("ROLE_DPO")) {
  3512.             throw new NotFoundHttpException();
  3513.         }
  3514.         $form $this->createFormBuilder()
  3515.             ->add("type"EntityType::class, [
  3516.                 'class' => \App\Entity\SubscriptionType::class,
  3517.                 'attr' => array(
  3518.                     'placeholder' => 'Type d\'abonnement',
  3519.                 ),
  3520.                 'label' => 'Type d\'abonnement',
  3521.                 'expanded' => false,
  3522.                 'multiple' => false,
  3523.                 'required' => true,
  3524.             ])
  3525.             ->getForm();
  3526.         $form->handleRequest($request);
  3527.         if ($form->isSubmitted() && $form->isValid()) {
  3528.             return $this->redirectToRoute("manager_subscriptions_user_add", ["user" => $user->getId(), "subscriptionType" => $form["type"]->getData()->getId()]);
  3529.         }
  3530.         $subscriptions $this->getDoctrine()->getRepository(Subscription::class)->findBy(["user" => $user]);
  3531.         return $this->render('manager/subscriptions_user.html.twig', [
  3532.             "user" => $user,
  3533.             "subscriptions" => $subscriptions,
  3534.             "form" => $form->createView(),
  3535.             "now" => new \DateTime("now")
  3536.         ]);
  3537.     }
  3538.     /**
  3539.      * @Route("/subscriptions/{user}/add/{subscriptionType}", name="subscriptions_user_add")
  3540.      */
  3541.     public function subscriptionsUserAddAction(Request $requestUser $user\App\Entity\SubscriptionType $subscriptionType)
  3542.     {
  3543.         if (!$this->isGranted("ROLE_DPO")) {
  3544.             throw new NotFoundHttpException();
  3545.         }
  3546.         $hasBillingType false;
  3547.         $hasBillingPrice false;
  3548.         $subscription = new Subscription();
  3549.         $subscription->setUser($user);
  3550.         $subscription->setType($subscriptionType);
  3551.         $form $this->createForm(SubscriptionUserType::class, $subscription);
  3552.         $form["subscriptionType"]->setData($subscriptionType->getLibelle());
  3553.         switch ($subscriptionType->getCode()) {
  3554.             case "ABOPLS":
  3555.             case "ABOSTD":
  3556.                 $form->add('billingType'ChoiceType::class, [
  3557.                         'attr' => [
  3558.                             'placeholder' => 'Type de facturation'
  3559.                         ],
  3560.                         'label' => 'Type de facturation',
  3561.                         'choices' => [
  3562.                             "Au mois" => "m",
  3563.                             "Au trimestre" => "t",
  3564.                             "A l'année" => "y",
  3565.                         ],
  3566.                         "data" => "y",
  3567.                         'required' => true,
  3568.                         'mapped' => false
  3569.                     ])
  3570.                     ->add('unitBillingPrice'NumberType::class, [
  3571.                         'attr' => [
  3572.                             'placeholder' => 'Montant HT facturé'
  3573.                         ],
  3574.                         'label' => 'Montant HT facturé (selon type de facturation)',
  3575.                         'data' => 0
  3576.                     ]);
  3577.                 $hasBillingType true;
  3578.                 $hasBillingPrice true;
  3579.                 break;
  3580.             case "ABOLIB":
  3581.                 $form->add('unitBillingPrice'NumberType::class, [
  3582.                         'attr' => [
  3583.                             'placeholder' => 'Montant HT facturé'
  3584.                         ],
  3585.                         'label' => 'Montant HT facturé au mois',
  3586.                         'data' => 0
  3587.                     ]);
  3588.                 $hasBillingPrice true;
  3589.                 break;
  3590.         }
  3591.         $form->handleRequest($request);
  3592.         if ($form->isSubmitted() && $form->isValid()) {
  3593.             $em $this->getDoctrine()->getManager();
  3594.             $now = new \DateTime("now");
  3595.             $subscription->setCreationDate($now);
  3596.             if ($form['beginDate']->getData()) {
  3597.                 $beginDate \DateTime::createFromFormat("d/m/Y"$form['beginDate']->getData());
  3598.                 if ($beginDate) {
  3599.                     $beginDate->setTime(000);
  3600.                     $subscription->setBeginDate($beginDate);
  3601.                     $endDate = clone $subscription->getBeginDate();
  3602.                     $endDate->sub(new \DateInterval("P1D"));
  3603.                     switch ($subscriptionType->getCode()) {
  3604.                         case "ABOPLS":
  3605.                         case "ABOSTD":
  3606.                             $subscription->setInvolvementMonths(12);
  3607.                             $endDate->add(new \DateInterval("P1Y"));
  3608.                             break;
  3609.                         case "PARTEN":
  3610.                             $subscription->setInvolvementMonths(12);
  3611.                             $endDate->add(new \DateInterval("P1Y"));
  3612.                             break;
  3613.                         case "ABOLIB":
  3614.                             $subscription->setInvolvementMonths(1);
  3615.                             $endDate->add(new \DateInterval("P1M"));
  3616.                             break;
  3617.                         case "FREE30D":
  3618.                         case "DEMO":
  3619.                             $subscription->setInvolvementMonths(0);
  3620.                             $endDate->add(new \DateInterval("P30D"));
  3621.                             break;
  3622.                     }
  3623.                     $subscription->setEndDate($endDate);
  3624.                     if ($hasBillingType) {
  3625.                         if ($form['billingType']->getData() == "m") {
  3626.                             $subscription->setBillingMonths(1);
  3627.                         } elseif ($form['billingType']->getData() == "t") {
  3628.                             $subscription->setBillingMonths(3);
  3629.                         } else {
  3630.                             $subscription->setBillingMonths(12);
  3631.                         }
  3632.                     } else {
  3633.                         $subscription->setBillingMonths(0);
  3634.                     }
  3635.                     if (!$hasBillingPrice) {
  3636.                         $subscription->setUnitBillingPrice(0);
  3637.                     }
  3638.                     $subscription->setActive(true);
  3639.                     $em->persist($subscription);
  3640.                     $em->flush();
  3641.                     if ($user->getCurrentSubscription()) {
  3642.                         $user->getCurrentSubscription()->setActive(false);
  3643.                         $em->flush();
  3644.                     }
  3645.                     $user->setCurrentSubscription($subscription);
  3646.                     $em->flush();
  3647.                     if ($user->getCurrentSubscription()->getUnitBillingPrice() == 0) {
  3648.                         switch ($user->getCurrentSubscription()->getType()->getCode()) {
  3649.                             case "ABOPLS":
  3650.                             case "ABOSTD":
  3651.                             case "PARTEN":
  3652.                             case "ABOLIB":
  3653.                                 $paymentUntil = clone $user->getCurrentSubscription()->getBeginDate();
  3654.                                 $paymentUntil->sub(new \DateInterval("P1D"));
  3655.                                 if ($user->getCurrentSubscription()->getBillingMonths()) {
  3656.                                     $paymentUntil->add(new \DateInterval("P".$user->getCurrentSubscription()->getBillingMonths()."M"));
  3657.                                 } else {
  3658.                                     $paymentUntil->add(new \DateInterval("P".$user->getCurrentSubscription()->getInvolvementMonths()."M"));
  3659.                                 }
  3660.                                 $user->getCurrentSubscription()->setPaymentUntil($paymentUntil);
  3661.                                 $em->flush();
  3662.                                 break;
  3663.                         }
  3664.                     }
  3665.                     $this->get('session')->getFlashBag()->add('success''Nouvel abonnement ajouté');
  3666.                     return $this->redirectToRoute("manager_subscriptions_user", ["id" => $user->getId()]);
  3667.                 }
  3668.             }
  3669.         }
  3670.         return $this->render('manager/subscriptions_user_add.html.twig', [
  3671.             "form" => $form->createView(),
  3672.             "hasBillingType" => $hasBillingType,
  3673.             "hasBillingPrice" => $hasBillingPrice,
  3674.         ]);
  3675.     }
  3676.     /**
  3677.      * @Route("/subscriptions/{user}/disable/{subscription}", name="subscriptions_user_disable")
  3678.      */
  3679.     public function subscriptionsUserDisableAction(Request $requestUser $userSubscription $subscription)
  3680.     {
  3681.         if (!$this->isGranted("ROLE_DPO")) {
  3682.             throw new NotFoundHttpException();
  3683.         }
  3684.         $em $this->getDoctrine()->getManager();
  3685.         $subscription->setActive(false);
  3686.         $subscription->setEndDate(new \DateTime("now"));
  3687.         $em->flush();
  3688.         return $this->redirectToRoute("manager_subscriptions_user", ["id" => $user->getId()]);
  3689.     }
  3690.     /**
  3691.      * @Route("/subscriptions/{user}/payment/{subscription}", name="subscriptions_user_payment")
  3692.      */
  3693.     public function subscriptionsUserPaymentAction(Request $requestUser $userSubscription $subscription)
  3694.     {
  3695.         if (!$this->isGranted("ROLE_DPO")) {
  3696.             throw new NotFoundHttpException();
  3697.         }
  3698.         $em $this->getDoctrine()->getManager();
  3699.         if ($subscription->getPaymentUntil() == null) {
  3700.             $subscription->setPaymentUntil($subscription->getEndDate());
  3701.             switch ($subscription->getType()->getCode()) {
  3702.                 case "ABOPLS":
  3703.                 case "ABOSTD":
  3704.                 case "PARTEN":
  3705.                     $subscription->getPaymentUntil()->sub(new \DateInterval("P1Y"));
  3706.                     break;
  3707.                 case "ABOLIB":
  3708.                     $subscription->getPaymentUntil()->sub(new \DateInterval("P1M"));
  3709.                     break;
  3710.             }
  3711.         }
  3712.         $paymentUntil = clone $subscription->getPaymentUntil();
  3713.         if ($subscription->getBillingMonths()) {
  3714.             $paymentUntil->add(new \DateInterval("P".$subscription->getBillingMonths()."M"));
  3715.         } else {
  3716.             $paymentUntil->add(new \DateInterval("P".$subscription->getInvolvementMonths()."M"));
  3717.         }
  3718.         $subscription->setPaymentUntil($paymentUntil);
  3719.         //$subscription->setEndDate($paymentUntil);
  3720.         $em->flush();
  3721.         return $this->redirectToRoute("manager_subscriptions_user", ["id" => $user->getId()]);
  3722.     }
  3723.     /**
  3724.      * @Route("/subscriptions/add", name="subscriptions_add")
  3725.      */
  3726.     public function subscriptionsAddAction(Request $request)
  3727.     {
  3728.         if (!$this->isGranted("ROLE_DPO")) {
  3729.             throw new NotFoundHttpException();
  3730.         }
  3731.         $subscription = new Subscription();
  3732.         $form $this->createForm(SubscriptionType::class, $subscription);
  3733.         $form->handleRequest($request);
  3734.         if ($form->isSubmitted() && $form->isValid()) {
  3735.             $em $this->getDoctrine()->getManager();
  3736.             $now = new \DateTime("now");
  3737.             $subscription->setCreationDate($now);
  3738.             $endDate = clone $subscription->getBeginDate();
  3739.             $endDate->sub(new \DateInterval("P1D"));
  3740.             if ($form['billingType']->getData() == "m") {
  3741.                 $endDate->add(new \DateInterval("P1M"));
  3742.             } else {
  3743.                 $endDate->add(new \DateInterval("P12M"));
  3744.             }
  3745.             $subscription->setEndDate($endDate);
  3746.             $em->persist($subscription);
  3747.             $em->flush();
  3748.             $this->get('session')->getFlashBag()->add('success''Nouvel abonnement ajouté');
  3749.             return $this->redirectToRoute("manager_subscriptions");
  3750.         }
  3751.         return $this->render('manager/subscriptions_add.html.twig', [
  3752.             "form" => $form->createView(),
  3753.         ]);
  3754.     }
  3755.     /**
  3756.      * @Route("/subscriptions/{id}/edit", name="subscriptions_edit")
  3757.      */
  3758.     public function subscriptionsEditAction(Request $requestSubscription $subscription)
  3759.     {
  3760.         if (!$this->isGranted("ROLE_DPO")) {
  3761.             throw new NotFoundHttpException();
  3762.         }
  3763.         $form $this->createForm(SubscriptionType::class, $subscription);
  3764.         if ($subscription->getBeginDate()->format('Y') != $subscription->getEndDate()->format('Y')) {
  3765.             $form['billingType']->setData('y');
  3766.         } else {
  3767.             $form['billingType']->setData('m');
  3768.         }
  3769.         $form->handleRequest($request);
  3770.         if ($form->isSubmitted() && $form->isValid()) {
  3771.             $em $this->getDoctrine()->getManager();
  3772.             $endDate = clone $subscription->getBeginDate();
  3773.             $endDate->sub(new \DateInterval("P1D"));
  3774.             if ($form['billingType']->getData() == "m") {
  3775.                 $endDate->add(new \DateInterval("P1M"));
  3776.             } else {
  3777.                 $endDate->add(new \DateInterval("P12M"));
  3778.             }
  3779.             $subscription->setEndDate($endDate);
  3780.             $em->flush();
  3781.             $this->get('session')->getFlashBag()->add('success''Abonnement modifié');
  3782.             return $this->redirectToRoute("manager_subscriptions");
  3783.         }
  3784.         return $this->render('manager/subscriptions_edit.html.twig', [
  3785.             "form" => $form->createView(),
  3786.         ]);
  3787.     }
  3788.     /**
  3789.      * @Route("/subscriptions/{id}/delete", name="subscriptions_delete")
  3790.      */
  3791.     public function subscriptionsDeleteAction(Request $requestSubscription $subscription)
  3792.     {
  3793.         if (!$this->isGranted("ROLE_DPO")) {
  3794.             throw new NotFoundHttpException();
  3795.         }
  3796.         $em $this->getDoctrine()->getManager();
  3797.         $em->remove($subscription);
  3798.         $em->flush();
  3799.         return $this->redirectToRoute("manager_subscriptions");
  3800.     }
  3801.     /**
  3802.      * @Route("/credits/{id}", name="credits_user")
  3803.      */
  3804.     public function creditsUserAction(Request $requestUser $user)
  3805.     {
  3806.         if (!$this->isGranted("ROLE_MANAGER")) {
  3807.             throw new NotFoundHttpException();
  3808.         }
  3809.         $credit = new Credit();
  3810.         $form $this->createFormBuilder($credit)
  3811.             ->add("title"TextType::class, [
  3812.                 'attr' => array(
  3813.                     'placeholder' => 'Action',
  3814.                 ),
  3815.                 'label' => 'Action',
  3816.                 'required' => true,
  3817.             ])
  3818.             ->add("stock"NumberType::class, [
  3819.                 'attr' => array(
  3820.                     'placeholder' => 'Stock',
  3821.                 ),
  3822.                 'label' => 'Stock',
  3823.                 'required' => true,
  3824.             ])
  3825.             ->getForm();
  3826.         $form->handleRequest($request);
  3827.         if ($form->isSubmitted() && $form->isValid()) {
  3828.             $em $this->getDoctrine()->getManager();
  3829.             $credit->convertToDecimal(true);
  3830.             $credit->setUser($user);
  3831.             $credit->setManager($this->getUser()->getManager());
  3832.             $credit->setCreationDate(new \DateTime("now"));
  3833.             $em->persist($credit);
  3834.             $em->flush();
  3835.             $user->setCredit($user->getCredit() + $credit->getStock());
  3836.             $em->flush();
  3837.             $this->get('session')->getFlashBag()->add('success''Crédits modifiés');
  3838.             return $this->redirectToRoute("manager_credits_user", ["id" => $user->getId()]);
  3839.         }
  3840.         $credits $this->getDoctrine()->getRepository(Credit::class)->findBy(["user" => $user]);
  3841.         return $this->render('manager/credits_user.html.twig', [
  3842.             "user" => $user,
  3843.             "credits" => $credits,
  3844.             "form" => $form->createView()
  3845.         ]);
  3846.     }
  3847.     /**
  3848.      * @Route("/trainings", name="trainings")
  3849.      */
  3850.     public function trainingsAction(Request $request)
  3851.     {
  3852.         $trainings $this->getDoctrine()->getRepository(Training::class)->findAll();
  3853.         return $this->render('manager/trainings.html.twig', [
  3854.             "trainings" => $trainings
  3855.         ]);
  3856.     }
  3857.     /**
  3858.      * @Route("/trainings/stats", name="trainings_requests_stats")
  3859.      */
  3860.     public function trainingsStatsAction(Request $request)
  3861.     {
  3862.         $training $this->getDoctrine()->getRepository(Training::class)->findOneBy(["id" => $request->get("training")]);
  3863.         if (!$training) {
  3864.             return new JsonResponse([
  3865.                 "success" => false
  3866.             ]);
  3867.         }
  3868.         $questionsChoices = [];
  3869.         $questionsChoicesTotal = [];
  3870.         $questionsCount = [];
  3871.         foreach ($training->getQuestions() as $questionKey => $question) {
  3872.             $questionsChoices[$questionKey] = $question["choices"];
  3873.             $questionsCount[$questionKey] = 0;
  3874.             $questionsChoicesTotal[$questionKey] = [];
  3875.             foreach ($question["choices"] as $choiceKey => $choice) {
  3876.                 $questionsChoicesTotal[$questionKey][$choiceKey] = 0;
  3877.             }
  3878.         }
  3879.         $trainingRequests $this->getDoctrine()->getRepository(TrainingRequest::class)->findForTraining($training);
  3880.         foreach ($trainingRequests as $trainingRequest) {
  3881.             if ($trainingRequest->getAnswerDate()) {
  3882.                 foreach ($training->getQuestions() as $key => $item) {
  3883.                     if (isset($questionsChoices[$key])) {
  3884.                         if ($item["choices"] == $questionsChoices[$key]) {
  3885.                             if (isset($trainingRequest->getUserAnswers()[$key])) {
  3886.                                 $questionsCount[$key] = $questionsCount[$key]+1;
  3887.                                 foreach ($item["choices"] as $choiceKey => $choice) {
  3888.                                     if ($item["multiple"]) {
  3889.                                         if (in_array($choiceKey$trainingRequest->getUserAnswers()[$key])) {
  3890.                                             $questionsChoicesTotal[$key][$choiceKey] = $questionsChoicesTotal[$key][$choiceKey]+1;
  3891.                                         }
  3892.                                     } else {
  3893.                                         if ($choiceKey == $trainingRequest->getUserAnswers()[$key]) {
  3894.                                             $questionsChoicesTotal[$key][$choiceKey] = $questionsChoicesTotal[$key][$choiceKey]+1;
  3895.                                         }
  3896.                                     }
  3897.                                 }
  3898.                             }
  3899.                         }
  3900.                     }
  3901.                 }
  3902.             }
  3903.         }
  3904.         return new JsonResponse([
  3905.             "success" => true,
  3906.             "html" => $this->renderView('manager/includes/training_stats.html.twig', [
  3907.                 "training" => $training,
  3908.                 "questionsChoices" => $questionsChoices,
  3909.                 "questionsChoicesTotal" => $questionsChoicesTotal,
  3910.                 "questionsCount" => $questionsCount,
  3911.             ])
  3912.         ]);
  3913.     }
  3914.     /**
  3915.      * @Route("/trainings/add", name="trainings_add")
  3916.      */
  3917.     public function trainingsAddAction(Request $request)
  3918.     {
  3919.         $training = new Training();
  3920.         $form $this->createForm(TrainingType::class, $training)
  3921.             ->add('users'EntityType::class, [
  3922.                 'attr' => array(
  3923.                     'placeholder' => 'Clients',
  3924.                 ),
  3925.                 'placeholder' => 'Clients',
  3926.                 'label' => 'Clients',
  3927.                 'expanded' => true,
  3928.                 'multiple' => true,
  3929.                 'required' => false,
  3930.                 'class' => User::class,
  3931.                 'query_builder' => function (EntityRepository $er) {
  3932.                     return $er->createQueryBuilder('u')
  3933.                         ->addOrderBy('u.companyName'"ASC");
  3934.                 },
  3935.                 'choice_label' => function(User $user) {
  3936.                     return $user->getCompanyName();
  3937.                 },
  3938.             ]);
  3939.         $form->handleRequest($request);
  3940.         if ($form->isSubmitted() && $form->isValid()) {
  3941.             $em $this->getDoctrine()->getManager();
  3942.             $em->persist($training);
  3943.             $training->setAnswered(false);
  3944.             $content = [];
  3945.             $questions $_POST['form_items']??[];
  3946.             $questions array_values($questions);
  3947.             if (count($questions)) {
  3948.                 foreach ($questions as $question) {
  3949.                     $content[] = [
  3950.                         'title' => $question[0]??null,
  3951.                         'choices' => explode("\n"str_replace("\r"""$question[1]??null)),
  3952.                         'multiple' => $question[2]==1?true:false,
  3953.                         'links' => explode("\n"str_replace("\r"""$question[3]??null)),
  3954.                         'explanations' => $question[4]??null,
  3955.                     ];
  3956.                 }
  3957.             }
  3958.             $training->setQuestions($content);
  3959.             $em->flush();
  3960.             /**
  3961.              * @var UploadedFile $file
  3962.              */
  3963.             $file $form->get('pictureFile')->getData();
  3964.             if ($file != NULL) {
  3965.                 $fileName "t".$training->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  3966.                 $file->move(
  3967.                     $this->getParameter('pictures_directory'), $fileName
  3968.                 );
  3969.                 $training->setPicture($fileName);
  3970.                 $em->flush();
  3971.             }
  3972.             $this->get('session')->getFlashBag()->add('success''Nouveau questionnaire créé');
  3973.             return $this->redirectToRoute("manager_trainings");
  3974.         }
  3975.         $users = [];
  3976.         $usersStr = [];
  3977.         foreach ($training->getUsers() as $user) {
  3978.             $users[] = $user->getId();
  3979.             $usersStr[] = $user->getCompanyName();
  3980.         }
  3981.         sort($usersStr);
  3982.         return $this->render('manager/trainings_add.html.twig', [
  3983.             "form" => $form->createView(),
  3984.             "users" => $users,
  3985.             "usersStr" => $usersStr,
  3986.         ]);
  3987.     }
  3988.     /**
  3989.      * @Route("/trainings/{id}/edit", name="trainings_edit")
  3990.      */
  3991.     public function trainingsEditAction(Request $requestTraining $training)
  3992.     {
  3993.         $form $this->createForm(TrainingType::class, $training)
  3994.             ->add('users'EntityType::class, [
  3995.                 'attr' => array(
  3996.                     'placeholder' => 'Clients',
  3997.                 ),
  3998.                 'placeholder' => 'Clients',
  3999.                 'label' => 'Clients',
  4000.                 'expanded' => true,
  4001.                 'multiple' => true,
  4002.                 'required' => false,
  4003.                 'class' => User::class,
  4004.                 'query_builder' => function (EntityRepository $er) {
  4005.                     return $er->createQueryBuilder('u')
  4006.                         ->addOrderBy('u.companyName'"ASC");
  4007.                 },
  4008.                 'choice_label' => function(User $user) {
  4009.                     return $user->getCompanyName();
  4010.                 },
  4011.             ]);
  4012.         $form->handleRequest($request);
  4013.         if ($form->isSubmitted() && $form->isValid()) {
  4014.             $em $this->getDoctrine()->getManager();
  4015.             $content $training->getQuestions();
  4016.             $questions_edit $_POST['form_e_items']??[];
  4017.             $questions_edit array_values($questions_edit);
  4018.             foreach ($content as $keyItem => $question) {
  4019.                 $toRemove true;
  4020.                 if (count($questions_edit)) {
  4021.                     if (isset($questions_edit[$keyItem])) {
  4022.                         $content[$keyItem]['title'] = $questions_edit[$keyItem][0]??null;
  4023.                         $content[$keyItem]['choices'] = explode("\n"str_replace("\r"""$questions_edit[$keyItem][1]??null));
  4024.                         $content[$keyItem]['multiple'] = $questions_edit[$keyItem][2]==1?true:false;
  4025.                         $content[$keyItem]['links'] = explode("\n"str_replace("\r"""$questions_edit[$keyItem][3]??null));
  4026.                         $content[$keyItem]['explanations'] = $questions_edit[$keyItem][4]??null;
  4027.                         if (count($content[$keyItem]['links']) == 1) {
  4028.                             if ($content[$keyItem]['links'][0] == "") {
  4029.                                 $content[$keyItem]['links'] = [];
  4030.                             }
  4031.                         }
  4032.                         $toRemove false;
  4033.                     }
  4034.                 }
  4035.                 if ($toRemove) {
  4036.                     unset($content[$keyItem]);
  4037.                 }
  4038.             }
  4039.             $questions $_POST['form_items']??[];
  4040.             $questions array_values($questions);
  4041.             if (count($questions)) {
  4042.                 foreach ($questions as $question) {
  4043.                     $content[] = [
  4044.                         'title' => $question[0]??null,
  4045.                         'choices' => explode("\n"str_replace("\r"""$question[1]??null)),
  4046.                         'multiple' => $question[2]==1?true:false,
  4047.                         'links' => explode("\n"str_replace("\r"""$question[3]??null)),
  4048.                         'explanations' => $question[4]??null,
  4049.                     ];
  4050.                 }
  4051.             }
  4052.             if ($training->getQuestions() != $content) {
  4053.                 $training->setAnswered(false);
  4054.             }
  4055.             $training->setQuestions($content);
  4056.             $em->flush();
  4057.             /**
  4058.              * @var UploadedFile $file
  4059.              */
  4060.             $file $form->get('pictureFile')->getData();
  4061.             if ($file != NULL) {
  4062.                 $fileName "t".$training->getId()."_".md5(uniqid()) . '.' $file->guessExtension();
  4063.                 $file->move(
  4064.                     $this->getParameter('pictures_directory'), $fileName
  4065.                 );
  4066.                 $training->setPicture($fileName);
  4067.                 $em->flush();
  4068.             }
  4069.             $this->get('session')->getFlashBag()->add('success''Questionnaire mis à jour');
  4070.             return $this->redirectToRoute("manager_trainings");
  4071.         }
  4072.         $users = [];
  4073.         $usersStr = [];
  4074.         foreach ($training->getUsers() as $user) {
  4075.             $users[] = $user->getId();
  4076.             $usersStr[] = $user->getCompanyName();
  4077.         }
  4078.         sort($usersStr);
  4079.         return $this->render('manager/trainings_edit.html.twig', [
  4080.             "form" => $form->createView(),
  4081.             "training" => $training,
  4082.             "users" => $users,
  4083.             "usersStr" => $usersStr,
  4084.         ]);
  4085.     }
  4086.     /**
  4087.      * @Route("/trainings/{id}/answer", name="trainings_answer")
  4088.      */
  4089.     public function trainingsAnswerAction(Request $requestTraining $training)
  4090.     {
  4091.         $form $this->createFormBuilder();
  4092.         foreach ($training->getQuestions() as $key => $question) {
  4093.             $choices = [];
  4094.             foreach ($question["choices"] as $choiceKey => $choiceValue) {
  4095.                 $choices[$choiceValue] = $choiceKey;
  4096.             }
  4097.             $answerData $training->getAnswers()[$key]??null;
  4098.             if ($question["multiple"]) {
  4099.                 if ($answerData != null) {
  4100.                     if (!is_array($answerData)) {
  4101.                         $answerData = [$answerData];
  4102.                     }
  4103.                 } else {
  4104.                     $answerData = [];
  4105.                 }
  4106.             } else {
  4107.                 if (is_array($answerData)) {
  4108.                     $answerData $answerData[0];
  4109.                 }
  4110.             }
  4111.             $form->add("question_".$keyChoiceType::class, [
  4112.                 "choices" => $choices,
  4113.                 "expanded" => true,
  4114.                 "multiple" => $question["multiple"],
  4115.                 "data" => $answerData
  4116.             ]);
  4117.         }
  4118.         $form $form->getForm();
  4119.         $form->handleRequest($request);
  4120.         if ($form->isSubmitted() && $form->isValid()) {
  4121.             $em $this->getDoctrine()->getManager();
  4122.             $training->setAnswered(true);
  4123.             $answers = [];
  4124.             foreach ($training->getQuestions() as $key => $question) {
  4125.                 $answers[$key] = $form["question_".$key]->getData();
  4126.             }
  4127.             $training->setAnswers($answers);
  4128.             $em->flush();
  4129.             $this->get('session')->getFlashBag()->add('success''Questionnaire répondu');
  4130.             return $this->redirectToRoute("manager_trainings");
  4131.         }
  4132.         return $this->render('manager/trainings_answer.html.twig', [
  4133.             "form" => $form->createView(),
  4134.             "training" => $training
  4135.         ]);
  4136.     }
  4137.     /**
  4138.      * @Route("/trainings/{id}/translate/{_locale}", name="trainings_translate")
  4139.      */
  4140.     public function trainingsTranslateAction(Request $requestTraining $training)
  4141.     {
  4142.         $em $this->getDoctrine()->getManager();
  4143.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  4144.         $translations $repository->findTranslations($training);
  4145.         if (!isset($translations[$request->get("_locale")])) {
  4146.             return $this->redirectToRoute("manager_trainings_gen_translate", ["id" => $training->getId(), "_locale" => "fr""locale" => $request->get("_locale")]);
  4147.         }
  4148.         $training $em->find(Training::class, $request->get("id"));
  4149.         $form $this->createForm(TrainingTranslateType::class, $training);
  4150.         $form->handleRequest($request);
  4151.         if ($form->isSubmitted() && $form->isValid()) {
  4152.             $content $training->getQuestions();
  4153.             $questions_edit $_POST['form_e_items']??[];
  4154.             $questions_edit array_values($questions_edit);
  4155.             foreach ($content as $keyItem => $question) {
  4156.                 if (count($questions_edit)) {
  4157.                     if (isset($questions_edit[$keyItem])) {
  4158.                         $content[$keyItem]['title'] = $questions_edit[$keyItem][0]??null;
  4159.                         $content[$keyItem]['choices'] = explode("\n"str_replace("\r"""$questions_edit[$keyItem][1]??null));
  4160.                         $content[$keyItem]['links'] = explode("\n"str_replace("\r"""$questions_edit[$keyItem][3]??null));
  4161.                         $content[$keyItem]['explanations'] = $questions_edit[$keyItem][4]??null;
  4162.                         if (count($content[$keyItem]['links']) == 1) {
  4163.                             if ($content[$keyItem]['links'][0] == "") {
  4164.                                 $content[$keyItem]['links'] = [];
  4165.                             }
  4166.                         }
  4167.                     }
  4168.                 }
  4169.             }
  4170.             $training->setQuestions($content);
  4171.             $em->persist($training);
  4172.             $em->flush();
  4173.             $this->get('session')->getFlashBag()->add('success''Traduction du questionnaire mis à jour');
  4174.             return $this->redirectToRoute("manager_trainings");
  4175.         }
  4176.         return $this->render('manager/trainings_translate.html.twig', [
  4177.             "form" => $form->createView(),
  4178.             "training" => $training,
  4179.         ]);
  4180.     }
  4181.     /**
  4182.      * @Route("/trainings/{id}/gentranslate/{locale}_{_locale}", name="trainings_gen_translate")
  4183.      */
  4184.     public function trainingsGanTranslateAction(Request $requestTraining $training$locale$_locale)
  4185.     {
  4186.         $em $this->getDoctrine()->getManager();
  4187.         $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  4188.         $translations $repository->findTranslations($training);
  4189.         if (!isset($translations[$locale])) {
  4190.             $repository
  4191.                 ->translate($training'title'$locale$training->getTitle())
  4192.                 ->translate($training'questions'$locale$training->getQuestions())
  4193.             ;
  4194.             $em->persist($training);
  4195.             $em->flush();
  4196.             return $this->redirectToRoute("manager_trainings_translate", ["id" => $training->getId(), "_locale" => $locale]);
  4197.         }
  4198.         return $this->redirectToRoute("manager_trainings");
  4199.     }
  4200.     /**
  4201.      * @Route("/trainings/{id}/delete", name="trainings_delete")
  4202.      */
  4203.     public function trainingsDeleteAction(Request $requestTraining $training)
  4204.     {
  4205.         $em $this->getDoctrine()->getManager();
  4206.         $em->remove($training);
  4207.         $em->flush();
  4208.         $this->get('session')->getFlashBag()->add('success''Questionnaire supprimé');
  4209.         return $this->redirectToRoute("manager_trainings");
  4210.     }
  4211.     /**
  4212.      * @Route("/treatments/gentranslations/{locale}", name="treatments_gen_translations")
  4213.      */
  4214.     public function treatmentsGanTranslationsAction(Request $request$locale)
  4215.     {
  4216.         $em $this->getDoctrine()->getManager();
  4217.         $treatments $em->getRepository(TreatmentStd::class)->findBy(["user" => null]);
  4218.         foreach ($treatments as $treatment) {
  4219.             $repository $em->getRepository('Gedmo\Translatable\Entity\Translation');
  4220.             $translations $repository->findTranslations($treatment);
  4221.             if (!isset($translations[$locale])) {
  4222.                 $repository
  4223.                     ->translate($treatment'name''en'$treatment->getName())
  4224.                     ->translate($treatment'mainPurpose''en'$treatment->getMainPurpose())
  4225.                     ->translate($treatment'purpose1''en'$treatment->getPurpose1())
  4226.                     ->translate($treatment'purpose2''en'$treatment->getPurpose2())
  4227.                     ->translate($treatment'purpose3''en'$treatment->getPurpose3())
  4228.                     ->translate($treatment'purpose4''en'$treatment->getPurpose4())
  4229.                     ->translate($treatment'purpose5''en'$treatment->getPurpose5())
  4230.                     ->translate($treatment'othersPurpose''en'$treatment->getOthersPurpose())
  4231.                     ->translate($treatment'description''en'$treatment->getDescription())
  4232.                     ->translate($treatment'personalData''en'$treatment->getPersonalData())
  4233.                     ->translate($treatment'peopleData''en'$treatment->getPeopleData())
  4234.                     ->translate($treatment'transferOutsideUeCountries''en'$treatment->getTransferOutsideUeCountries())
  4235.                     ->translate($treatment'consentHow''en'$treatment->getConsentHow())
  4236.                     ->translate($treatment'legalBasis''en'$treatment->getLegalBasis())
  4237.                     ->translate($treatment'dataSource''en'$treatment->getDataSource())
  4238.                 ;
  4239.                 $em->persist($treatment);
  4240.                 $em->flush();
  4241.             }
  4242.         }
  4243.         return $this->redirectToRoute("manager_treatments");
  4244.     }
  4245.     /**
  4246.      * @Route("/substitute/{account}", name="substitute")
  4247.      */
  4248.     public function substituteAction(Request $requestAccount $account)
  4249.     {
  4250.         if ($this->getUser()->getId() == 1) {
  4251.             $session $this->get('session');
  4252.             $firewall 'main';
  4253.             $token = new UsernamePasswordToken($accountnull$firewall$account->getRoles());
  4254.             $this->get('security.token_storage')->setToken($token);
  4255.             $session->set('_security_'.$firewallserialize($token));
  4256.             $event = new InteractiveLoginEvent($request$token);
  4257.             $this->get("event_dispatcher")->dispatch("security.interactive_login"$event);
  4258.             return $this->redirectToRoute("default_homepage");
  4259.         }
  4260.         throw new NotFoundHttpException();
  4261.     }
  4262.     /**
  4263.      * @Route("/json/users", name="json_users")
  4264.      */
  4265.     public function jsonUsersAction(Request $request)
  4266.     {
  4267.         $users $this->getDoctrine()->getRepository(User::class)->findBy([], ["companyName" => "ASC"]);
  4268.         $returnResponse = [];
  4269.         foreach ($users as $user) {
  4270.             $returnResponse[] = [
  4271.                 "id" => $user->getId(),
  4272.                 "text" => $user->getCompanyName(),
  4273.             ];
  4274.         }
  4275.         return new JsonResponse($returnResponse);
  4276.     }
  4277. }