src/Services/UploadService.php line 77

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  */
  5. namespace App\Services;
  6. use App\Entity\DocUpload;
  7. use App\Entity\DocUploadPartageProject;
  8. use App\Entity\Etap1;
  9. use App\Entity\Etap10;
  10. use App\Entity\Etap11;
  11. use App\Entity\Etap12;
  12. use App\Entity\Etap13;
  13. use App\Entity\Etap14;
  14. use App\Entity\Etap15;
  15. use App\Entity\Etap159;
  16. use App\Entity\Etap16;
  17. use App\Entity\Etap160;
  18. use App\Entity\Etap161;
  19. use App\Entity\Etap17;
  20. use App\Entity\Etap171;
  21. use App\Entity\Etap172;
  22. use App\Entity\Etap173;
  23. use App\Entity\Etap174;
  24. use App\Entity\Etap175;
  25. use App\Entity\Etap18;
  26. use App\Entity\Etap19;
  27. use App\Entity\Etap2;
  28. use App\Entity\Etap20;
  29. use App\Entity\Etap201;
  30. use App\Entity\Etap21;
  31. use App\Entity\Etap22;
  32. use App\Entity\Etap23;
  33. use App\Entity\Etap3;
  34. use App\Entity\Etap4;
  35. use App\Entity\Etap5;
  36. use App\Entity\Etap6;
  37. use App\Entity\Etap7;
  38. use App\Entity\Etap8;
  39. use App\Entity\Etap9;
  40. use App\Entity\ImfomationContratAchat;
  41. use App\Entity\Project;
  42. use App\Entity\User;
  43. use App\Form\UserType;
  44. use Kunnu\Dropbox\Dropbox;
  45. use Kunnu\Dropbox\DropboxApp;
  46. use Kunnu\Dropbox\Exceptions\DropboxClientException;
  47. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  48. use Doctrine\ORM\EntityManagerInterface;
  49. use Symfony\Component\Form\FormFactoryInterface;
  50. use Symfony\Component\HttpFoundation\File\UploadedFile;
  51. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  52. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  53. use Symfony\Contracts\Translation\TranslatorInterface;
  54. use Symfony\Component\Security\Core\Security;
  55. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  56. use Twig\Environment;
  57. use App\Entity\Centrale;
  58. use Symfony\Component\Validator\Constraints as Assert;
  59. use Symfony\Component\Validator\Validator\ValidatorInterface;
  60. class UploadService
  61. {
  62.     private $em;
  63.     private $trans;
  64.     private $params;
  65.     private $security;
  66.     private $session;
  67.     private $twig;
  68.     private $notification;
  69.     public function __construct(
  70.         Environment $twig,
  71.         SessionInterface $session,
  72.         Security $security,
  73.         ParameterBagInterface $params,
  74.         EntityManagerInterface $em,
  75.         TranslatorInterface $trans,
  76.         ValidatorInterface $validator,
  77.         FlashBagInterface $flashBag,
  78.         UserPasswordEncoderInterface $passwordEncoder,
  79.         Notifications $notifications,
  80.         FormFactoryInterface $form
  81.     ) {
  82.         $this->em = $em;
  83.         $this->trans = $trans;
  84.         $this->params = $params;
  85.         $this->security = $security;
  86.         $this->session = $session;
  87.         $this->twig = $twig;
  88.         $this->validator = $validator;
  89.         $this->form = $form;
  90.         $this->flashBag = $flashBag;
  91.         $this->passwordEncoder = $passwordEncoder;
  92.         $this->notification = $notifications;
  93.     }
  94.     public function upload(UploadedFile $file)
  95.     {
  96.         set_time_limit(0);
  97.         if (is_object($file)) {
  98.             $filenameGenerate = $this->generateUniqueFileName();
  99.             $fileName = $filenameGenerate . '.' . $file->guessExtension();
  100.             if($file->guessExtension() == 'bin'){
  101.                 $fileName = $filenameGenerate . '.' . $file->getClientOriginalName();
  102.             }
  103.             $file->move($this->params->get('uploads_directory'), $fileName);
  104.             $docUpload = new DocUpload();
  105.             $docUpload->setName($file->getClientOriginalName());
  106.             $docUpload->setPath($fileName);
  107.             $docUpload->setUserCreated($this->security->getUser());
  108.             $this->em->persist($docUpload);
  109.             $this->em->flush();
  110.             return array('token' => $docUpload->getToken(), 'filename' => $docUpload->getName());
  111.         }
  112.         return false;
  113.     }
  114.     public function removeFile($file){
  115.         if(is_object($file)) {
  116.             if ($file->getPath() and trim($file->getPath()) != '') {
  117.                 $this->deleteFileToDropbox($file);
  118.                 $filePath = $this->params->get('uploads_directory') . '/' . $file->getPath();
  119.                 if (file_exists($filePath)) unlink($filePath);
  120.             }
  121.             $this->em->remove($file);
  122.             $this->em->flush();
  123.         }
  124.     }
  125.     public function archiveFile($file){
  126.         if(is_object($file)) {
  127.             $file->setIsArchived(true);
  128.             $this->em->persist($file);
  129.             $this->em->flush();
  130.         }
  131.     }
  132.     public function removeFilePartage($file){
  133.         if(is_object($file)) {
  134.             if ($file->getDoc()->getPath() and trim($file->getDoc()->getPath()) != '') {
  135.                 $filePath = $this->params->get('uploads_directory') . '/' . $file->getDoc()->getPath();
  136.                 if (file_exists($filePath)) unlink($filePath);
  137.             }
  138.             $this->em->remove($file->getDoc());
  139.             $this->em->remove($file);
  140.             $this->em->flush();
  141.         }
  142.     }
  143.     public function getFilesPorjectPartage($project){
  144.         if(is_object($project)) {
  145.             $docs = $this->em->getRepository(DocUploadPartageProject::class)->findBy(['project'=>$project->getId()]);
  146.             return $docs;
  147.         }
  148.         return false;
  149.     }
  150.     public function generateUniqueFileName() {
  151.         return md5(uniqid());
  152.     }
  153.     public function exportZip($token){
  154.         $project = $this->em->getRepository(Project::class)->findOneBy(['token'=>$token]);
  155.         if($project){
  156.             $etap1 = $this->em->getRepository(Etap1::class)->findOneBy(['project'=>$project->getId()]);
  157.             $etap2 = $this->em->getRepository(Etap2::class)->findOneBy(['project'=>$project->getId()]);
  158.             $etap3 = $this->em->getRepository(Etap3::class)->findOneBy(['project'=>$project->getId()]);
  159.             $etap4 = $this->em->getRepository(Etap4::class)->findOneBy(['project'=>$project->getId()]);
  160.             $etap5 = $this->em->getRepository(Etap5::class)->findOneBy(['project'=>$project->getId()]);
  161.             $etap6 = $this->em->getRepository(Etap6::class)->findOneBy(['project'=>$project->getId()]);
  162.             $etap7 = $this->em->getRepository(Etap7::class)->findOneBy(['project'=>$project->getId()]);
  163.             $etap8 = $this->em->getRepository(Etap8::class)->findOneBy(['project'=>$project->getId()]);
  164.             $etap9 = $this->em->getRepository(Etap9::class)->findOneBy(['project'=>$project->getId()]);
  165.             $etap10 = $this->em->getRepository(Etap10::class)->findOneBy(['project'=>$project->getId()]);
  166.             $etap11 = $this->em->getRepository(Etap11::class)->findOneBy(['project'=>$project->getId()]);
  167.             $etap12 = $this->em->getRepository(Etap12::class)->findOneBy(['project'=>$project->getId()]);
  168.             $etap13 = $this->em->getRepository(Etap13::class)->findOneBy(['project'=>$project->getId()]);
  169.             $etap14 = $this->em->getRepository(Etap14::class)->findOneBy(['project'=>$project->getId()]);
  170.             $etap15 = $this->em->getRepository(Etap15::class)->findOneBy(['project'=>$project->getId()]);
  171.             $etap16 = $this->em->getRepository(Etap16::class)->findOneBy(['project'=>$project->getId()]);
  172.             $etap17 = $this->em->getRepository(Etap17::class)->findOneBy(['project'=>$project->getId()]);
  173.             $etap18 = $this->em->getRepository(Etap18::class)->findOneBy(['project'=>$project->getId()]);
  174.             $etap19 = $this->em->getRepository(Etap19::class)->findOneBy(['project'=>$project->getId()]);
  175.             $etap20 = $this->em->getRepository(Etap20::class)->findOneBy(['project'=>$project->getId()]);
  176.             $etap201 = $this->em->getRepository(Etap201::class)->findOneBy(['project'=>$project->getId()]);
  177.             $etap21 = $this->em->getRepository(Etap21::class)->findOneBy(['project'=>$project->getId()]);
  178.             $etap22 = $this->em->getRepository(Etap22::class)->findOneBy(['project'=>$project->getId()]);
  179.             $etap160 = $this->em->getRepository(Etap160::class)->findOneBy(['project'=>$project->getId()]);
  180.             $etap161 = $this->em->getRepository(Etap161::class)->findOneBy(['project'=>$project->getId()]);
  181.             $etap171 = $this->em->getRepository(Etap171::class)->findOneBy(['project'=>$project->getId()]);
  182.             $etap172 = $this->em->getRepository(Etap172::class)->findOneBy(['project'=>$project->getId()]);
  183.             $etap173 = $this->em->getRepository(Etap173::class)->findOneBy(['project'=>$project->getId()]);
  184.             $etap174 = $this->em->getRepository(Etap174::class)->findOneBy(['project'=>$project->getId()]);
  185.             $etap175 = $this->em->getRepository(Etap175::class)->findOneBy(['project'=>$project->getId()]);
  186.             //Présentation générale
  187.             $fileEtudeProductibleName = 'Présentation générale/Étude de productible/';
  188.             $fileEtudeProductiblePath = null;
  189.             if($project->getFileEtudeProductible()){
  190.                 $extension = substr($project->getFileEtudeProductible()->getPath(), strrpos($project->getFileEtudeProductible()->getPath(), ".",-1) + 1);
  191.                 $fileEtudeProductibleName =  'Présentation générale/Étude de productible/'.$project->getName().' - '.$project->getSpv().' - Ã‰tude de productible.'.$extension;
  192.                 $fileEtudeProductiblePath = $this->params->get('uploads_directory').'/'.$project->getFileEtudeProductible()->getPath();
  193.             }
  194.             $filePromessebailProjectName = 'Présentation générale/Promesse de bail/';
  195.             $filePromessebailProjectPath = null;
  196.             if($project->getFilePromessebail()){
  197.                 $extension = substr($project->getFilePromessebail()->getPath(), strrpos($project->getFilePromessebail()->getPath(), ".",-1) + 1);
  198.                 $filePromessebailProjectName =  'Présentation générale/Promesse de bail/'.$project->getName().' - '.$project->getSpv().' - Promesse de bail.'.$extension;
  199.                 $filePromessebailProjectPath = $this->params->get('uploads_directory').'/'.$project->getFilePromessebail()->getPath();
  200.             }
  201.             $fileDocCompementaireName = 'Présentation générale/Visite Technique devéloppeur/';
  202.             $arrayDocCompementairePath = [];
  203.             if(count($project->getFileDocCompementaire())>0){
  204.                 foreach ($project->getFileDocCompementaire() as $key => $item){
  205.                     $extension = substr($item->getPath(), strrpos($item->getPath(), ".",-1) + 1);
  206.                     $arrayDocCompementairePath[$item->getId()]['name'] = 'Présentation générale/Visite Technique devéloppeur/'.$key.' - '.$project->getName().' - '.$project->getSpv().' - Visite Technique devéloppeur.'.$extension;
  207.                     $arrayDocCompementairePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  208.                 }
  209.             }
  210.             //Urbanisme
  211.             $fileDossierPcDpName = 'Urbanisme/Dossier PC/';
  212.             $fileDossierPcDpPath = [];
  213.             if(count($etap1->getFileDossierPcDpMultiple()) > 0){
  214.                 foreach ($etap1->getFileDossierPcDpMultiple() as $key => $item){
  215.                     $fileDossierPcDpPath[$item->getId()]['name'] = 'Urbanisme/Dossier PC/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  216.                     $fileDossierPcDpPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  217.                 }
  218.             }
  219.             $fileArretePcDpName = 'Urbanisme/Arrêté PC/';
  220.             $fileArretePcDpPath = [];
  221.             if(count($etap1->getFileArretePcDpMultiple()) > 0){
  222.                 foreach ($etap1->getFileArretePcDpMultiple() as $key => $item){
  223.                     $fileArretePcDpPath[$item->getId()]['name'] = 'Urbanisme/Arrêté PC/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  224.                     $fileArretePcDpPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  225.                 }
  226.             }
  227.             $filePVPassageHuissierName = 'Urbanisme/PV passage huissier/';
  228.             $filePVPassageHuissierPath = [];
  229.             if(count($etap2->getFilePVPassageHuissierMultiple()) > 0){
  230.                 foreach ($etap2->getFilePVPassageHuissierMultiple() as $key => $item){
  231.                     $filePVPassageHuissierPath[$item->getId()]['name'] = 'Urbanisme/PV passage huissier/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  232.                     $filePVPassageHuissierPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  233.                 };
  234.             }
  235.             $fileCertificatNonRecoursName = 'Urbanisme/Certificat de non-recours (Tribunal Administratif)/';
  236.             $fileCertificatNonRecoursPath = [];
  237.             if(count($etap2->getFileCertificatNonRecoursMultiple()) > 0){
  238.                 foreach ($etap2->getFileCertificatNonRecoursMultiple() as $key => $item){
  239.                     $fileCertificatNonRecoursPath[$item->getId()]['name'] = 'Urbanisme/Certificat de non-recours (Tribunal Administratif)/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  240.                     $fileCertificatNonRecoursPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  241.                 };
  242.             }
  243.             $fileCertificatNonOppositionName = 'Urbanisme/Certificat de non opposition/';
  244.             $fileCertificatNonOppositionPath = [];
  245.             if(count($etap1->getFileCertificatNonOppositionEtap1Multiple()) > 0){
  246.                 foreach ($etap1->getFileCertificatNonOppositionEtap1Multiple() as $key => $item){
  247.                     $fileCertificatNonOppositionPath[$item->getId()]['name'] = 'Urbanisme/Certificat de non opposition/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  248.                     $fileCertificatNonOppositionPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  249.                 };
  250.             }
  251.             $fileCertificatNonRetraitName = 'Urbanisme/Certificat de non retrait/';
  252.             $fileCertificatNonRetraitPath = [];
  253.             if(count($etap2->getFileCertificatNonRetraitMultiple()) > 0){
  254.                 foreach ($etap2->getFileCertificatNonRetraitMultiple() as $key => $item){
  255.                     $fileCertificatNonRetraitPath[$item->getId()]['name'] = 'Urbanisme/Certificat de non opposition/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  256.                     $fileCertificatNonRetraitPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  257.                 };
  258.             }
  259.             $fileDocDrocName = 'Urbanisme/DROC - DOC/';
  260.             $fileDocDrocPath = [];
  261.             if(count($etap3->getFileDocDrocMultiple()) > 0){
  262.                 foreach ($etap3->getFileDocDrocMultiple() as $key => $item){
  263.                     $fileDocDrocPath[$item->getId()]['name'] = 'Urbanisme/DROC - DOC/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  264.                     $fileDocDrocPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  265.                 };
  266.             }
  267.             $fileDaactName = 'Urbanisme/DAACT/';
  268.             $fileDaactPath = [];
  269.             if(count($etap4->getFileDaactMultiple()) > 0){
  270.                 foreach ($etap4->getFileDaactMultiple() as $key => $item){
  271.                     $fileDaactPath[$item->getId()]['name'] = 'Urbanisme/DAACT/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  272.                     $fileDaactPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  273.                 };
  274.             }
  275.             //foncier
  276.             $filePromessebailName = 'Maitrise foncière/Promesse de bail/';
  277.             $filePromessebailPath = [];
  278.             if(count($etap5->getFilePromessebailMultiple()) > 0){
  279.                 foreach ($etap5->getFilePromessebailMultiple() as $key => $item){
  280.                     $filePromessebailPath[$item->getId()]['name'] = 'Maitrise foncière/Promesse de bail/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  281.                     $filePromessebailPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  282.                 };
  283.             }
  284.             $fileEtatDecriptifName = 'Maitrise foncière/Etat Descriptif de Division volumétrique/';
  285.             $fileEtatDecriptifPath = [];
  286.             if(count($etap6->getFileEtatDecriptifMultiple()) > 0){
  287.                 foreach ($etap6->getFileEtatDecriptifMultiple() as $key => $item){
  288.                     $fileEtatDecriptifPath[$item->getId()]['name'] = 'Maitrise foncière/Etat Descriptif de Division volumétrique/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  289.                     $fileEtatDecriptifPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  290.                 };
  291.             }
  292.             $fileEtatHypothecaireName = 'Maitrise foncière/Etat hypothécaire/';
  293.             $fileEtatHypothecairePath = [];
  294.             if(count($etap6->getFileEtatHypothecaireMultiple()) > 0){
  295.                 foreach ($etap6->getFileEtatHypothecaireMultiple() as $key => $item){
  296.                     $fileEtatHypothecairePath[$item->getId()]['name'] = 'Maitrise foncière/Etat hypothécaire/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  297.                     $fileEtatHypothecairePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  298.                 };
  299.             }
  300.             $filePublicationSPRName = 'Maitrise foncière/Publication SPF/';
  301.             $filePublicationSPRPath = [];
  302.             if(count($etap6->getFilePublicationSPRMultiple()) > 0){
  303.                 foreach ($etap6->getFilePublicationSPRMultiple() as $key => $item){
  304.                     $filePublicationSPRPath[$item->getId()]['name'] = 'Maitrise foncière/Publication SPF/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  305.                     $filePublicationSPRPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  306.                 };
  307.             }
  308.             $fileTitreProprieteName = 'Maitrise foncière/Titre de propriété/';
  309.             $fileTitreProprietePath =  [];
  310.             if(count($etap6->getFileTitreProprieteMultiple()) > 0){
  311.                 foreach ($etap6->getFileTitreProprieteMultiple() as $key => $item){
  312.                     $fileTitreProprietePath[$item->getId()]['name'] = 'Maitrise foncière/Titre de propriété/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  313.                     $fileTitreProprietePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  314.                 };
  315.             }
  316.             $fileAutreEtap6Name = 'Maitrise foncière/Autres  (Cession de bail, projet de bail…)/';
  317.             $arrayAutreEtap6Path = [];
  318.             if(count($etap6->getFileAutreEtap6())>0){
  319.                 foreach ($etap6->getFileAutreEtap6() as $key => $item){
  320.                     $arrayAutreEtap6Path[$item->getId()]['name'] = 'Maitrise foncière/Autres  (Cession de bail, projet de bail…)/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  321.                     $arrayAutreEtap6Path[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  322.                 }
  323.             }
  324.             $fileProcurationBailleurName = 'Maitrise foncière/Procuration Bailleur/';
  325.             $arrayProcurationBailleurPath = [];
  326.             if(count($etap6->getFileProcurationBailleur())>0){
  327.                 foreach ($etap6->getFileProcurationBailleur() as $key => $item){
  328.                     $arrayProcurationBailleurPath[$item->getId()]['name'] = 'Maitrise foncière/Procuration Bailleur/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  329.                     $arrayProcurationBailleurPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  330.                 }
  331.             }
  332.             $fileBailSigneName = 'Maitrise foncière/Bail signé/';
  333.             $fileBailSignePath =   [];
  334.             if(count($etap7->getFileBailSigneMultiple()) > 0){
  335.                 foreach ($etap7->getFileBailSigneMultiple() as $key => $item){
  336.                     $fileBailSignePath[$item->getId()]['name'] = 'Maitrise foncière/Bail signé/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  337.                     $fileBailSignePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  338.                 };
  339.             }
  340.             $fileAvenantBailName = 'Maitrise foncière/Avenant au Bail/';
  341.             $fileAvenantBailPath = [];
  342.             if(count($etap7->getFileAvenantBailMultiple()) > 0){
  343.                 foreach ($etap7->getFileAvenantBailMultiple() as $key => $item){
  344.                     $fileAvenantBailPath[$item->getId()]['name'] = 'Maitrise foncière/Avenant au Bail/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  345.                     $fileAvenantBailPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  346.                 };
  347.             }
  348.             //Raccordement ENEDIS
  349.             $fileKbisEtsName = 'Raccordement ENEDIS/Kibis/';
  350.             $fileKbisEtsPath = [];
  351.             if(count($etap8->getFileKbisEtsMultiple()) > 0){
  352.                 foreach ($etap8->getFileKbisEtsMultiple() as $key => $item){
  353.                     $fileKbisEtsPath[$item->getId()]['name'] = 'Raccordement ENEDIS/Kibis/'.($item->getNomenclature()? $key.' - '.$item->getNomenclature(): $item->getPath());
  354.                     $fileKbisEtsPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  355.                 };
  356.             }
  357.             $fileMailEnedisConfirmationName = 'Raccordement ENEDIS/Mail d’ENEDIS de confirmation/';
  358.             $fileMailEnedisConfirmationPath = [];
  359.             if(count($etap9->getFileMailEnedisConfirmationMultiple()) > 0){
  360.                 foreach ($etap9->getFileMailEnedisConfirmationMultiple() as $key => $item){
  361.                     $fileMailEnedisConfirmationPath[$item->getId()]['name'] = 'Raccordement ENEDIS/Mail d’ENEDIS de confirmation/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  362.                     $fileMailEnedisConfirmationPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  363.                 }
  364.             }
  365.             $filePtfName = 'Raccordement ENEDIS/PTF/';
  366.             $filePtfPath = [];
  367.             if(count($etap10->getFilePtfMultiple()) > 0){
  368.                 foreach ($etap10->getFilePtfMultiple() as $key => $item){
  369.                     $filePtfPath[$item->getId()]['name'] = 'Raccordement ENEDIS/PTF/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  370.                     $filePtfPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  371.                 }
  372.             }
  373.             $fileCrdSigneeName = 'Raccordement ENEDIS/CRD signée/';
  374.             $fileCrdSigneePath = [];
  375.             if(count($etap10->getFileCrdSigneeMultiple()) > 0){
  376.                 foreach ($etap10->getFileCrdSigneeMultiple() as $key => $item){
  377.                     $fileCrdSigneePath[$item->getId()]['name'] = 'Raccordement ENEDIS/CRD signée/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  378.                     $fileCrdSigneePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  379.                 }
  380.             }elseif(count($etap10->getFileCrdSigneeSansPtfMultiple()) > 0){
  381.                 foreach ($etap10->getFileCrdSigneeSansPtfMultiple() as $key => $item){
  382.                     $fileCrdSigneePath[$item->getId()]['name'] = 'Raccordement ENEDIS/CRD signée/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  383.                     $fileCrdSigneePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  384.                 }
  385.             }
  386.             $filePreuveVirementName = 'Raccordement ENEDIS/Preuve de virement/';
  387.             $filePreuveVirementPath = [];
  388.             if(count($etap10->getFilePreuveVirementMultiple()) > 0){
  389.                 foreach ($etap10->getFilePreuveVirementMultiple() as $key => $item){
  390.                     $filePreuveVirementPath[$item->getId()]['name'] = 'Raccordement ENEDIS/Preuve de virement/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  391.                     $filePreuveVirementPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  392.                 }
  393.             }elseif(count($etap10->getFilePreuveVirementSansPtfMultiple()) > 0){
  394.                 foreach ($etap10->getFilePreuveVirementSansPtfMultiple() as $key => $item){
  395.                     $filePreuveVirementPath[$item->getId()]['name'] = 'Raccordement ENEDIS/Preuve de virement/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  396.                     $filePreuveVirementPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  397.                 }
  398.             }
  399.             $fileCexSigneName = 'Raccordement ENEDIS/CEX signé/';
  400.             $fileCexSignePath = [];
  401.             if(count($etap12->getFileCexSigneMultiple()) > 0){
  402.                 foreach ($etap12->getFileCexSigneMultiple() as $key => $item){
  403.                     $fileCexSignePath[$item->getId()]['name'] = 'Raccordement ENEDIS/CEX signé/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  404.                     $fileCexSignePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  405.                 }
  406.             }
  407.             $fileCardiSigneName = 'Raccordement ENEDIS/CARDi signé/';
  408.             $fileCardiSignePath = [];
  409.             if(count($etap12->getFileCardiSigneMultiple()) > 0){
  410.                 foreach ($etap12->getFileCardiSigneMultiple() as $key => $item){
  411.                     $fileCardiSignePath[$item->getId()]['name'] = 'Raccordement ENEDIS/CARDi signé/'.($item->getNomenclature()? $key.' - '. $item->getNomenclature(): $item->getPath());
  412.                     $fileCardiSignePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  413.                 }
  414.             }
  415.             $fileConsuelName = 'Raccordement ENEDIS/Consuel/';
  416.             $fileConsuelPath = [];
  417.             if(count($etap13->getFileConsuelMultiple()) > 0){
  418.                 foreach ($etap13->getFileConsuelMultiple() as $key => $item){
  419.                     $fileConsuelPath[$item->getId()]['name'] = 'Raccordement ENEDIS/Consuel/'.($item->getNomenclature()? $key.' - '. $item->getNomenclature(): $item->getPath());
  420.                     $fileConsuelPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  421.                 }
  422.             }
  423.             $fileDREName = 'Raccordement ENEDIS/DRE/';
  424.             $fileDREPath = [];
  425.             if(count($etap13->getFileDREMultiple()) > 0){
  426.                 foreach ($etap13->getFileDREMultiple() as $key => $item){
  427.                     $fileDREPath[$item->getId()]['name'] = 'Raccordement ENEDIS/DRE/'.($item->getNomenclature()? $key.' - '. $item->getNomenclature(): $item->getPath());
  428.                     $fileDREPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  429.                 }
  430.             }
  431.             $fileAttestationBureauControleMultipleName = 'Raccordement ENEDIS/Attestation bureau de contrôle S21/';
  432.             $fileAttestationBureauControleMultiplePath = [];
  433.             if(count($etap13->getFileAttestationBureauControleMultiple()) > 0){
  434.                 foreach ($etap13->getFileAttestationBureauControleMultiple() as $key => $item){
  435.                     $fileAttestationBureauControleMultiplePath[$item->getId()]['name'] = 'Raccordement ENEDIS/Attestation bureau de contrôle S21/'.($item->getNomenclature()? $key.' - '. $item->getNomenclature(): $item->getPath());
  436.                     $fileAttestationBureauControleMultiplePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  437.                 }
  438.             }
  439.             $fileDoeName = 'Raccordement ENEDIS/DOE/';
  440.             $fileDoePath = [];
  441.             if(count($etap14->getFileDoeMultiple()) > 0){
  442.                 foreach ($etap14->getFileDoeMultiple() as $key => $item){
  443.                     $fileDoePath[$item->getId()]['name'] = 'Raccordement ENEDIS/Attestation de mise en service /'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  444.                     $fileDoePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  445.                 }
  446.             }
  447.             $fileContratAchatSigneName = 'Raccordement ENEDIS/Contrat d’achat signé/';
  448.             $fileContratAchatSignePath = [];
  449.             if(count($etap15->getFileContratAchatSigneMultiple()) > 0){
  450.                 foreach ($etap15->getFileContratAchatSigneMultiple() as $key => $item){
  451.                     $fileContratAchatSignePath[$item->getId()]['name'] = 'Raccordement ENEDIS/Contrat d’achat signé/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  452.                     $fileContratAchatSignePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  453.                 }
  454.             }
  455.             $fileAttestionProducteurName = 'Raccordement ENEDIS/Attestation de producteur/';
  456.             $fileAttestionProducteurPath = [];
  457.             if(count($etap15->getFileAttestionProducteurMultiple()) > 0){
  458.                 foreach ($etap15->getFileAttestionProducteurMultiple() as $key => $item){
  459.                     $fileAttestionProducteurPath[$item->getId()]['name'] = 'Raccordement ENEDIS/Attestation de producteur/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  460.                     $fileAttestionProducteurPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  461.                 }
  462.             }
  463.             $fileAttestionInstallateurName = 'Raccordement ENEDIS/Attestation de l’installateur/';
  464.             $fileAttestionInstallateurPath = [];
  465.             if(count($etap15->getFileAttestionInstallateurMultiple()) > 0){
  466.                 foreach ($etap15->getFileAttestionInstallateurMultiple() as $key => $item){
  467.                     $fileAttestionInstallateurPath[$item->getId()]['name'] = 'Raccordement ENEDIS/Attestation de l’installateur/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  468.                     $fileAttestionInstallateurPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  469.                 }
  470.             }
  471.             $user = $this->security->getUser();
  472.             //Contrats de development et construction
  473.             $fileContratEpcName = 'Contrats de development et construction/Contrat de construction/';
  474.             $fileContratEpcPath = [];
  475.             if($user and (!in_array('ROLE_DEV',$user->getRoles()) or !in_array('ROLE_EPC',$user->getRoles()))) {
  476.                 if(count($etap16->getFileContratEpcMultiple()) > 0){
  477.                     foreach ($etap16->getFileContratEpcMultiple() as $key => $item){
  478.                         $fileContratEpcPath[$item->getId()]['name'] = 'Contrats de development et construction/Contrat de construction/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  479.                         $fileContratEpcPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  480.                     }
  481.                 }
  482.             }
  483.             $fileAnnexesName = 'Contrats de development et construction/Annexes (fiches techniques…)/';
  484.             $fileAnnexesPath =[];
  485.             if($user and (!in_array('ROLE_DEV',$user->getRoles()) or !in_array('ROLE_EPC',$user->getRoles()))) {
  486.                 if(count($etap16->getFileAnnexesMultiple()) > 0){
  487.                     foreach ($etap16->getFileAnnexesMultiple() as $key => $item){
  488.                         $fileAnnexesPath[$item->getId()]['name'] = 'Contrats de development et construction/Annexes/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  489.                         $fileAnnexesPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  490.                     }
  491.                 }
  492.             }
  493.             $fileDocumentGeometreName = 'Contrats de development et construction/Documents de géomètre/';
  494.             $arrayDocumentGeometrePath = [];
  495.             if(count($etap17->getFileDocumentGeometre())>0){
  496.                 foreach ($etap17->getFileDocumentGeometre() as $key => $item){
  497.                     $arrayDocumentGeometrePath[$item->getId()]['name'] = 'Contrats de development et construction/Documents de géomètre/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  498.                     $arrayDocumentGeometrePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  499.                 }
  500.             }
  501.             $filePlanExecutionName = 'Contrats de development et construction/Plan exécution et Ã©tude de structure/';
  502.             $arrayPlanExecutionPath = [];
  503.             if(count($etap17->getFilePlanExecution())>0){
  504.                 foreach ($etap17->getFilePlanExecution() as $key => $item){
  505.                     $arrayPlanExecutionPath[$item->getId()]['name'] = 'Contrats de development et construction/Plan exécution et Ã©tude de structure/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  506.                     $arrayPlanExecutionPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  507.                 }
  508.             }
  509.             $filePhotosFondationName = 'Contrats de development et construction/Photos des fondations/';
  510.             $arrayPhotosFondationPath = [];
  511.             if(count($etap18->getFilePhotosFondation())>0){
  512.                 foreach ($etap18->getFilePhotosFondation() as $key => $item){
  513.                     $arrayPhotosFondationPath[$item->getId()]['name'] = 'Contrats de development et construction/Photos des fondations/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  514.                     $arrayPhotosFondationPath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  515.                 }
  516.             }
  517.             $filePhotosBatimentName = 'Contrats de development et construction/Photos du bâtiment/';
  518.             $filePhotosBatimentPath = null;
  519.             if($etap19->getFilePhotosBatiment()){
  520.                 $filePhotosBatimentName =  'Contrats de development et construction/Photos du bâtiment/'.($etap19->getFilePhotosBatiment()->getNomenclature()? $etap19->getFilePhotosBatiment()->getNomenclature(): $etap19->getFilePhotosBatiment()->getPath());
  521.                 $filePhotosBatimentPath = $this->params->get('uploads_directory').'/'.$etap19->getFilePhotosBatiment()->getPath();
  522.             }
  523. //            $fileConsuelEtap20Name = 'Contrats de development et construction/Consuel Etap 5/';
  524. //            $fileConsuelEtap20Path = null;
  525. //            if($etap20->getFileConsuelEtap20()){
  526. //                $fileConsuelEtap20Name =  'Contrats de development et construction/Consuel Etap 5/'.($etap20->getFileConsuelEtap20()->getNomenclature()? $etap20->getFileConsuelEtap20()->getNomenclature(): $etap20->getFileConsuelEtap20()->getPath());
  527. //                $fileConsuelEtap20Path = $this->params->get('uploads_directory').'/'.$etap20->getFileConsuelEtap20()->getPath();
  528. //            }
  529.             $fileTestReceptionName = 'Contrats de development et construction/Tests de réception/';
  530.             $fileTestReceptionPath = [];
  531.             if(count($etap21->getFileTestReceptionMultiple())>0){
  532.                 foreach ($etap21->getFileTestReceptionMultiple() as $key => $item){
  533.                     $arrayTestReceptionMultiplePath[$item->getId()]['name'] = 'Contrats de development et construction/Tests de réception/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  534.                     $arrayTestReceptionMultiplePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  535.                 }
  536.             }
  537.             $fileTestPrName = 'Contrats de development et construction/Tests de PR/';
  538.             $fileTestPrPath = [];
  539.             if(count($etap22->getFileTestPrMultiple())>0){
  540.                 foreach ($etap22->getFileTestPrMultiple() as $key => $item){
  541.                     $arrayTestPrMultiplePath[$item->getId()]['name'] = 'Contrats de development et construction/Tests de PR/'.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  542.                     $arrayTestPrMultiplePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  543.                 }
  544.             }
  545.             $zip = new \ZipArchive();
  546.             $zipfile = $this->params->get('zips_directory') . '/project-' . $project->getName() .'.zip';
  547.             if (file_exists($zipfile)) unlink($zipfile);
  548.             if ($zip->open($zipfile, \ZipArchive::CREATE) === TRUE) {
  549.                 //project
  550.                 $fileEtudeProductiblePath ? $zip->addFile($fileEtudeProductiblePath,$fileEtudeProductibleName):$zip->addEmptyDir($fileEtudeProductibleName);
  551.                 $filePromessebailProjectPath ? $zip->addFile($filePromessebailProjectPath,$filePromessebailProjectName):$zip->addEmptyDir($filePromessebailProjectName);
  552.                 if(count($arrayDocCompementairePath)>0){
  553.                     foreach ($arrayDocCompementairePath as $item){
  554.                         $zip->addFile($item['path'],$item['name']);
  555.                     }
  556.                 }else{
  557.                     $zip->addEmptyDir($fileDocCompementaireName);
  558.                 }
  559.                 //urbanisme
  560.                 if(count($fileDossierPcDpPath)>0){
  561.                     foreach ($fileDossierPcDpPath as $item){
  562.                         $zip->addFile($item['path'],$item['name']);
  563.                     }
  564.                 }else{
  565.                     $zip->addEmptyDir($fileDossierPcDpName);
  566.                 }
  567.                 if(count($fileArretePcDpPath)>0){
  568.                     foreach ($fileArretePcDpPath as $item){
  569.                         $zip->addFile($item['path'],$item['name']);
  570.                     }
  571.                 }else{
  572.                     $zip->addEmptyDir($fileArretePcDpName);
  573.                 }
  574.                 if(count($fileCertificatNonRecoursPath)>0){
  575.                     foreach ($fileCertificatNonRecoursPath as $item){
  576.                         $zip->addFile($item['path'],$item['name']);
  577.                     }
  578.                 }else{
  579.                     $zip->addEmptyDir($fileCertificatNonRecoursName);
  580.                 }
  581.                 if(count($fileCertificatNonOppositionPath)>0){
  582.                     foreach ($fileCertificatNonOppositionPath as $item){
  583.                         $zip->addFile($item['path'],$item['name']);
  584.                     }
  585.                 }else{
  586.                     $zip->addEmptyDir($fileCertificatNonOppositionName);
  587.                 }
  588.                 if(count($fileCertificatNonRetraitPath)>0){
  589.                     foreach ($fileCertificatNonRetraitPath as $item){
  590.                         $zip->addFile($item['path'],$item['name']);
  591.                     }
  592.                 }else{
  593.                     $zip->addEmptyDir($fileCertificatNonRetraitName);
  594.                 }
  595.                 if(count($fileDocDrocPath)>0){
  596.                     foreach ($fileDocDrocPath as $item){
  597.                         $zip->addFile($item['path'],$item['name']);
  598.                     }
  599.                 }else{
  600.                     $zip->addEmptyDir($fileDocDrocName);
  601.                 }
  602.                 if(count($filePVPassageHuissierPath)>0){
  603.                     foreach ($filePVPassageHuissierPath as $item){
  604.                         $zip->addFile($item['path'],$item['name']);
  605.                     }
  606.                 }else{
  607.                     $zip->addEmptyDir($filePVPassageHuissierName);
  608.                 }
  609.                 if(count($fileDaactPath)>0){
  610.                     foreach ($fileDaactPath as $item){
  611.                         $zip->addFile($item['path'],$item['name']);
  612.                     }
  613.                 }else{
  614.                     $zip->addEmptyDir($fileDaactName);
  615.                 }
  616.                 //foncier
  617.                 if(count($filePromessebailPath)>0){
  618.                     foreach ($filePromessebailPath as $item){
  619.                         $zip->addFile($item['path'],$item['name']);
  620.                     }
  621.                 }else{
  622.                     $zip->addEmptyDir($filePromessebailName);
  623.                 }
  624.                 if(count($fileBailSignePath)>0){
  625.                     foreach ($fileBailSignePath as $item){
  626.                         $zip->addFile($item['path'],$item['name']);
  627.                     }
  628.                 }else{
  629.                     $zip->addEmptyDir($fileBailSigneName);
  630.                 }
  631.                 if(count($fileAvenantBailPath)>0){
  632.                     foreach ($fileAvenantBailPath as $item){
  633.                         $zip->addFile($item['path'],$item['name']);
  634.                     }
  635.                 }else{
  636.                     $zip->addEmptyDir($fileAvenantBailName);
  637.                 }
  638.                 if(count($fileEtatDecriptifPath)>0){
  639.                     foreach ($fileEtatDecriptifPath as $item){
  640.                         $zip->addFile($item['path'],$item['name']);
  641.                     }
  642.                 }else{
  643.                     $zip->addEmptyDir($fileEtatDecriptifName);
  644.                 }
  645.                 if(count($fileEtatHypothecairePath)>0){
  646.                     foreach ($fileEtatHypothecairePath as $item){
  647.                         $zip->addFile($item['path'],$item['name']);
  648.                     }
  649.                 }else{
  650.                     $zip->addEmptyDir($fileEtatHypothecaireName);
  651.                 }
  652.                 if(count($filePublicationSPRPath)>0){
  653.                     foreach ($filePublicationSPRPath as $item){
  654.                         $zip->addFile($item['path'],$item['name']);
  655.                     }
  656.                 }else{
  657.                     $zip->addEmptyDir($filePublicationSPRName);
  658.                 }
  659.                 if(count($fileTitreProprietePath)>0){
  660.                     foreach ($fileTitreProprietePath as $item){
  661.                         $zip->addFile($item['path'],$item['name']);
  662.                     }
  663.                 }else{
  664.                     $zip->addEmptyDir($fileTitreProprieteName);
  665.                 }
  666.                 if(count($arrayAutreEtap6Path)>0){
  667.                     foreach ($arrayAutreEtap6Path as $item){
  668.                         $zip->addFile($item['path'],$item['name']);
  669.                     }
  670.                 }else{
  671.                     $zip->addEmptyDir($fileAutreEtap6Name);
  672.                 }
  673.                 if(count($arrayProcurationBailleurPath)>0){
  674.                     foreach ($arrayProcurationBailleurPath as $item){
  675.                         $zip->addFile($item['path'],$item['name']);
  676.                     }
  677.                 }else{
  678.                     $zip->addEmptyDir($fileProcurationBailleurName);
  679.                 }
  680.                 // Raccordement
  681.                 if(count($fileKbisEtsPath)>0){
  682.                     foreach ($fileKbisEtsPath as $item){
  683.                         $zip->addFile($item['path'],$item['name']);
  684.                     }
  685.                 }else{
  686.                     $zip->addEmptyDir($fileKbisEtsName);
  687.                 }
  688.                 if(count($fileMailEnedisConfirmationPath)>0){
  689.                     foreach ($fileMailEnedisConfirmationPath as $item){
  690.                         $zip->addFile($item['path'],$item['name']);
  691.                     }
  692.                 }else{
  693.                     $zip->addEmptyDir($fileMailEnedisConfirmationName);
  694.                 }
  695.                 if(count($filePtfPath)>0){
  696.                     foreach ($filePtfPath as $item){
  697.                         $zip->addFile($item['path'],$item['name']);
  698.                     }
  699.                 }else{
  700.                     $zip->addEmptyDir($filePtfName);
  701.                 }
  702.                 if(count($filePreuveVirementPath)>0){
  703.                     foreach ($filePreuveVirementPath as $item){
  704.                         $zip->addFile($item['path'],$item['name']);
  705.                     }
  706.                 }else{
  707.                     $zip->addEmptyDir($filePreuveVirementName);
  708.                 }
  709.                 if(count($fileCrdSigneePath)>0){
  710.                     foreach ($fileCrdSigneePath as $item){
  711.                         $zip->addFile($item['path'],$item['name']);
  712.                     }
  713.                 }else{
  714.                     $zip->addEmptyDir($fileCrdSigneeName);
  715.                 }
  716.                 if(count($fileCexSignePath)>0){
  717.                     foreach ($fileCexSignePath as $item){
  718.                         $zip->addFile($item['path'],$item['name']);
  719.                     }
  720.                 }else{
  721.                     $zip->addEmptyDir($fileCexSigneName);
  722.                 }
  723.                 if(count($fileCardiSignePath)>0){
  724.                     foreach ($fileCardiSignePath as $item){
  725.                         $zip->addFile($item['path'],$item['name']);
  726.                     }
  727.                 }else{
  728.                     $zip->addEmptyDir($fileCardiSigneName);
  729.                 }
  730.                 if(count($fileCardiSignePath)>0){
  731.                     foreach ($fileCardiSignePath as $item){
  732.                         $zip->addFile($item['path'],$item['name']);
  733.                     }
  734.                 }else{
  735.                     $zip->addEmptyDir($fileCardiSigneName);
  736.                 }
  737.                 if(count($fileConsuelPath)>0){
  738.                     foreach ($fileConsuelPath as $item){
  739.                         $zip->addFile($item['path'],$item['name']);
  740.                     }
  741.                 }else{
  742.                     $zip->addEmptyDir($fileConsuelName);
  743.                 }
  744.                 if(count($fileDREPath)>0){
  745.                     foreach ($fileDREPath as $item){
  746.                         $zip->addFile($item['path'],$item['name']);
  747.                     }
  748.                 }else{
  749.                     $zip->addEmptyDir($fileDREName);
  750.                 }
  751.                 if(count($fileAttestationBureauControleMultiplePath)>0){
  752.                     foreach ($fileAttestationBureauControleMultiplePath as $item){
  753.                         $zip->addFile($item['path'],$item['name']);
  754.                     }
  755.                 }else{
  756.                     $zip->addEmptyDir($fileAttestationBureauControleMultipleName);
  757.                 }
  758.                 if(count($fileContratAchatSignePath)>0){
  759.                     foreach ($fileContratAchatSignePath as $item){
  760.                         $zip->addFile($item['path'],$item['name']);
  761.                     }
  762.                 }else{
  763.                     $zip->addEmptyDir($fileContratAchatSigneName);
  764.                 }
  765.                 if(count($fileDoePath)>0){
  766.                     foreach ($fileDoePath as $item){
  767.                         $zip->addFile($item['path'],$item['name']);
  768.                     }
  769.                 }else{
  770.                     $zip->addEmptyDir($fileDoeName);
  771.                 }
  772.                 if(count($fileAttestionProducteurPath)>0){
  773.                     foreach ($fileAttestionProducteurPath as $item){
  774.                         $zip->addFile($item['path'],$item['name']);
  775.                     }
  776.                 }else{
  777.                     $zip->addEmptyDir($fileAttestionProducteurName);
  778.                 }
  779.                 if(count($fileAttestionInstallateurPath)>0){
  780.                     foreach ($fileAttestionInstallateurPath as $item){
  781.                         $zip->addFile($item['path'],$item['name']);
  782.                     }
  783.                 }else{
  784.                     $zip->addEmptyDir($fileAttestionInstallateurName);
  785.                 }
  786.                 //construction
  787.                 if(count($fileContratEpcPath)>0){
  788.                     foreach ($fileContratEpcPath as $item){
  789.                         $zip->addFile($item['path'],$item['name']);
  790.                     }
  791.                 }else{
  792.                     $zip->addEmptyDir($fileContratEpcName);
  793.                 }
  794.                 if(count($fileAnnexesPath)>0){
  795.                     foreach ($fileAnnexesPath as $item){
  796.                         $zip->addFile($item['path'],$item['name']);
  797.                     }
  798.                 }else{
  799.                     $zip->addEmptyDir($fileAnnexesName);
  800.                 }
  801.                if(count($arrayDocumentGeometrePath)>0){
  802.                    foreach ($arrayDocumentGeometrePath as $item){
  803.                        $zip->addFile($item['path'],$item['name']);
  804.                    }
  805.                }else{
  806.                    $zip->addEmptyDir($fileDocumentGeometreName);
  807.                }
  808.                if(count($arrayPlanExecutionPath)>0){
  809.                   foreach ($arrayPlanExecutionPath as $item){
  810.                       $zip->addFile($item['path'],$item['name']);
  811.                   }
  812.                }else{
  813.                   $zip->addEmptyDir($filePlanExecutionName);
  814.                }
  815.                if(count($arrayPhotosFondationPath)>0){
  816.                  foreach ($arrayPhotosFondationPath as $item){
  817.                      $zip->addFile($item['path'],$item['name']);
  818.                  }
  819.                }else{
  820.                  $zip->addEmptyDir($filePhotosFondationName);
  821.                }
  822.                 $filePhotosBatimentPath ? $zip->addFile($filePhotosBatimentPath,$filePhotosBatimentName):$zip->addEmptyDir($filePhotosBatimentName);
  823. //                $fileConsuelEtap20Path ? $zip->addFile($fileConsuelEtap20Path,$fileConsuelEtap20Name):$zip->addEmptyDir($fileConsuelEtap20Name);
  824.                 $fileTestReceptionPath ? $zip->addFile($fileTestReceptionPath,$fileTestReceptionName):$zip->addEmptyDir($fileTestReceptionName);
  825.                 $fileTestPrPath ? $zip->addFile($fileTestPrPath,$fileTestPrName):$zip->addEmptyDir($fileTestPrName);
  826.                 if($user and (!in_array('ROLE_DEV',$user->getRoles()) or !in_array('ROLE_EPC',$user->getRoles()))) {
  827.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap171,'getFilePVDemarrageMultiple','Contrats de development et construction/Pré-requis avant démarage de la construction/PV de démarrage/');
  828.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap171,'getFileDocEtap171Multiple','Contrats de development et construction/Pré-requis avant démarage de la construction/DOC/');
  829.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap171,'getFileOrderServiceMultiple','Contrats de development et construction/Pré-requis avant démarage de la construction/Ordre de service/');
  830.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap171,'getFilePlanningPrevisionnelMultiple','Contrats de development et construction/Pré-requis avant démarage de la construction/Planning prévisionnel/');
  831.                     $zip = $this->getNameAndPathCategoryAndAddToZip($zip,$etap171,'Contrats de development et construction/Pré-requis avant démarage de la construction/');
  832.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap172,'getFileNoteCalculBetonFeraillageMultiple','Contrats de development et construction/LOT Génie civil et fondations/Note de calcul béton et féraillage/');
  833.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap172,'getFilePlanImplantationBatimentAvecDalleBetonMultiple','Contrats de development et construction/LOT Génie civil et fondations/Plan implantation bâtiment avec dalle béton du local onduleur/');
  834.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap172,'getFilePVReceptionMultiple','Contrats de development et construction/LOT Génie civil et fondations/PV de réception/');
  835.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap172,'getFileFondationTermineesMultiple','Contrats de development et construction/LOT Génie civil et fondations/Fondations terminées/');
  836.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap172,'getFileDalleBetonShelterMultiple','Contrats de development et construction/LOT Génie civil et fondations/Dalle béton shelter/');
  837.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap172,'getFileCheminAccesMultiple','Contrats de development et construction/LOT Génie civil et fondations/Chemin d’accès/');
  838.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap172,'getFilePhotosPlateformeMultiple','Contrats de development et construction/LOT Génie civil et fondations/Photos de la plateforme/');
  839.                     $zip = $this->getNameAndPathCategoryAndAddToZip($zip,$etap172,'Contrats de development et construction/LOT Génie civil et fondations/');
  840.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFileNoteCalculCharpente173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Notes de calcul charpente/');
  841. //                    $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFilePhotoRenforcementcharpente173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Photos de renforcement charpente/');
  842.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFileOssatureSecondaireBardage173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Plan de bardage/');
  843. //                    $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFilePhotoRenforcementBardage173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Photos de renforcement des bardages/');
  844.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFilePVreception173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/PV de réception/');
  845. //                    $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFilePhotoRenforcementCouvertureTermine173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Photos de renforcement de la couverture terminée/');
  846.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFilePlansCharpente173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Plans de charpente/');
  847.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFilePlansCharpente173SigneMultiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Plans de charpente signé par le bailleur/');
  848.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFileVues3d173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Vues 3D/');
  849.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFilePlanCouverture173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Plan de couverture/');
  850.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFilePlanDescriptionTravauxRenforcementCharpente173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Plan et descriptifs des travaux de renforcement de charpente/');
  851.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap173,'getFilePlanDescriptionTravauxDeposeCouverture173Multiple','Contrats de development et construction/LOT Charpente et couverture - bardage/Plan et descriptifs des travaux de dépose , repose de couverture/');
  852.                     $zip = $this->getNameAndPathCategoryAndAddToZip($zip,$etap173,'Contrats de development et construction/LOT Charpente et couverture - bardage/');
  853.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFilePlanCalepinageModule174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Plan de calepinage & câblage/');
  854. //                    $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFilePlanCaplageStrings174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Plan de câblage des strings/');
  855.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFileNoteCalculSousLisePV174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Note de calcul sous Lise PV/');
  856.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFileSchemaUnifilaireInstallation174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Schéma Unifilaire de l’installation/');
  857.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFileShemaAgencementShelterPhotos174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Schéma d’agencement du shelter ou photos/');
  858.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFileTestPrMiseService174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Test de PR Ã  la mise en service/');
  859.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFileShemaUnifilaireSystemeMonitoring174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Schéma unifilaire du système de monitoring/');
  860.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFileTestVerificationTravauxElectriqueFiche174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Tests et vérifications des travaux Ã©lectriques, fiche d’auto-contrôle de l’installateur/');
  861.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFilePVReception174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/PV de réception lot photovoltaïque & Ã©lec & AMO/');
  862.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFilePhotosGenerateur174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Photos de la centrale solaire/');
  863.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFilePvTerminees174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Pv terminées/');
  864.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFileDescentesCables174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Descentes de câbles/');
  865.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap174,'getFileRaccordementLocalOnduleur174Multiple','Contrats de development et construction/LOT photovoltaïque et Ã©lec/Raccordement du local onduleur/');
  866.                     $zip = $this->getNameAndPathCategoryAndAddToZip($zip,$etap174,'Contrats de development et construction/LOT photovoltaïque et Ã©lec/');
  867.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap175,'getFileNoteCalculCableAcLiaison175Multiple','Contrats de development et construction/LOT Raccordement, liaison PDL/Notes de calcul des câbles AC de la liaison/');
  868.                     $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap175,'getFilePlanTranchee175Multiple','Contrats de development et construction/LOT Raccordement, liaison PDL/Plans de la tranchée (coupe et plan de localisation)/');
  869. //                    $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap175,'getFileDaact175Multiple','Contrats de development et construction/LOT Raccordement, liaison PDL/DAACT : cerfa signé tamponné mairie/');
  870. //                    $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap175,'getFilePVReception175Multiple','Contrats de development et construction/LOT Raccordement, liaison PDL/PV de réception/');
  871. //                    $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap175,'getFilePhotosLiaisonTerminee175Multiple','Contrats de development et construction/LOT Raccordement, liaison PDL/Photos de la liaison terminée/');
  872.                     $zip = $this->getNameAndPathCategoryAndAddToZip($zip,$etap175,'Contrats de development et construction/LOT Raccordement, liaison PDL/');
  873.                     $zip = $this->getNameAndPathCategoryAndAddToZip($zip,$etap161,'Contrats de development et construction/Devis fournisseurs et sous-traitants/');
  874.                 }
  875.                 $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap201,'getFileDoeEtap201Multiple','Contrats de development et construction/Dossier des Ouvrages Exécutés/DOE/');
  876.                 $zip = $this->getNameAndPathCategoryAndAddToZip($zip,$etap160,'Contrats de development et construction/Informations Techniques/');
  877.                 $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap2,'getFileDemandeAnrMarieMultiple','Urbanisme/Demande d’ANR Mairie/');
  878.                 $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap2,'getFileDemandeAnrTaMultiple','Urbanisme/Demande d’ANR TA/');
  879.                 $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap2,'getFileAttestationHonneurAnrMairieTaMultiple','Urbanisme/Attestation sur l’honneur ANR Mairie / TA/');
  880.                 $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap10,'getFileAvenantCrdMultiple','Raccordement ENEDIS/Avenant CRD/');
  881.                 $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap10,'getFileAvenantCrdMesMultiple','Raccordement ENEDIS/Avenant CRD pour MES/');
  882.                 $zip = $this->getMultipleNameAndPathAndAddToZip($zip,$etap12,'getFileAvenantCardiMultiple','Raccordement ENEDIS/Avenant CARDI/');
  883.                 $zip->close();
  884.                 return $zipfile;
  885.             }else{
  886.                 return false;
  887.             }
  888.         }
  889.         return false;
  890.     }
  891.     public function exportZips($zips,$request = null){
  892.        if($zips){
  893.            $zip = new \ZipArchive();
  894.            $zipName = time().'project-exported.zip';
  895.            $zipfile = $this->params->get('zips_directory') . '/'.$zipName;
  896.            if (file_exists($zipfile)) unlink($zipfile);
  897.            if ($zip->open($zipfile, \ZipArchive::CREATE) === TRUE) {
  898.                 foreach ($zips as $item){
  899.                     $zip->addFile($item['zip'],$item['name'].'.zip');
  900.                 }
  901.                $zip->close();
  902.                 if($request){
  903.                     $baseurl = $request->getScheme() . '://' . $request->getHttpHost();
  904.                     return $baseurl.'/zips/'.$zipName;
  905.                 }else{
  906.                     return $zipfile;
  907.                 }
  908.             }else{
  909.                return 0;
  910.            }
  911.        }
  912.         return 0;
  913.     }
  914.     public function getMultipleNameAndPathAndAddToZip($zip,$etap,$file,$name){
  915.         $filePath =[];
  916.         if(count($etap->{$file}()) > 0){
  917.             foreach ($etap->{$file}() as $key => $item){
  918.                 $filePath[$item->getId()]['name'] = $name.($item->getNomenclature()?  $key.' - '.$item->getNomenclature(): $item->getPath());
  919.                 $filePath[$item->getId()]['path'] =  $this->params->get('uploads_directory').'/'.$item->getPath();
  920.             }
  921.         }
  922.         if(count($filePath)>0){
  923.             foreach ($filePath as $item){
  924.                 $zip->addFile($item['path'],$item['name']);
  925.             }
  926.         }else{
  927.             $zip->addEmptyDir($name);
  928.         }
  929.         return $zip;
  930.     }
  931.     public function getNameAndPathAndAddToZip($zip,$etap,$file,$name){
  932.         $fileName = $name;
  933.         $filePath = null;
  934.         if($etap->{$file}()){
  935.             $fileName =  $name.($etap->{$file}()->getNomenclature()? $etap->{$file}()->getNomenclature(): $etap->{$file}()->getPath());
  936.             $filePath = $this->params->get('uploads_directory').'/'.$etap->{$file}()->getPath();
  937.         }
  938.         $filePath ? $zip->addFile($filePath,$fileName):$zip->addEmptyDir($fileName);
  939.         return $zip;
  940.     }
  941.     public function getNameAndPathCategoryAndAddToZip($zip,$etap,$name){
  942.         if(count($etap->getCategorys()) > 0){
  943.               foreach ($etap->getCategorys() as $category){
  944.                  if(count($category->getDocuments())>0){
  945.                      foreach ($category->getDocuments() as $document){
  946.                        $nameDoc = $document->getName();
  947.                        $fileName = $name.$nameDoc."/";
  948.                        $filePath = null;
  949.                        $doc = $document->getDocUpload();
  950.                        if($doc){
  951.                          $fileName =  $name.$nameDoc."/".($doc->getNomenclature()? $doc->getNomenclature(): $doc->getPath());
  952.                          $filePath = $this->params->get('uploads_directory').'/'.$doc->getPath();
  953.                        }
  954.                        $filePath ? $zip->addFile($filePath,$fileName):$zip->addEmptyDir($fileName);
  955.                      }
  956.                  }
  957.               }
  958.         }
  959.         return $zip;
  960.     }
  961.     public function deleteFileToDropbox($doc){
  962.         $dropboxKey = $this->params->get('dropbox_key');
  963.         $dropboxSecret = $this->params->get('dropbox_secret');
  964.         $dropboxToken= $this->params->get('dropbox_token');
  965.         $app = new DropboxApp($dropboxKey,$dropboxSecret,$dropboxToken);
  966.         $dropbox = new Dropbox($app);
  967.         if(is_object($doc) && $doc->getPathDropbox() ) {
  968.             try {
  969.                 $file = $dropbox->delete($doc->getPathDropbox());
  970.                 return true;
  971.             } catch (DropboxClientException $e) {
  972.                 return false;
  973.             }
  974.         }
  975.         return true;
  976.     }
  977.     public function switchDocInProsess(){
  978.         $etap1 = $this->em->getRepository(Etap1::class)->findAll();
  979.         $etap9 = $this->em->getRepository(Etap9::class)->findAll();
  980.         $etap10 = $this->em->getRepository(Etap10::class)->findAll();
  981.         $etap12 = $this->em->getRepository(Etap12::class)->findAll();
  982.         $etap14 = $this->em->getRepository(Etap14::class)->findAll();
  983.         $etap15 = $this->em->getRepository(Etap15::class)->findAll();
  984.         foreach ($etap1 as $item){
  985.             if($item->getFileArretePcDp()){
  986.                 $item->addFileArretePcDpMultiple($item->getFileArretePcDp());
  987.             }
  988.             if($item->getFileDossierPcDp()){
  989.                 $item->addFileDossierPcDpMultiple($item->getFileDossierPcDp());
  990.             }
  991.             $this->em->persist($item);
  992.             $this->em->flush();
  993.         }
  994.         foreach ($etap9 as $item){
  995.             if($item->getFileMailEnedisConfirmation()){
  996.                 $item->addFileMailEnedisConfirmationMultiple($item->getFileMailEnedisConfirmation());
  997.             }
  998.             $this->em->persist($item);
  999.             $this->em->flush();
  1000.         }
  1001.         foreach ($etap10 as $item){
  1002.             if($item->getFileCrdSignee()){
  1003.                 $item->addFileCrdSigneeMultiple($item->getFileCrdSignee());
  1004.             }
  1005.             if($item->getFileCrdSigneeSansPtf()){
  1006.                 $item->addFileCrdSigneeSansPtfMultiple($item->getFileCrdSigneeSansPtf());
  1007.             }
  1008.             if($item->getFilePreuveVirement()){
  1009.                 $item->addFilePreuveVirementMultiple($item->getFilePreuveVirement());
  1010.             }
  1011.             if($item->getFilePreuveVirementSansPtf()){
  1012.                 $item->addFilePreuveVirementSansPtfMultiple($item->getFilePreuveVirementSansPtf());
  1013.             }
  1014.             if($item->getFilePtf()){
  1015.                 $item->addFilePtfMultiple($item->getFilePtf());
  1016.             }
  1017.             $this->em->persist($item);
  1018.             $this->em->flush();
  1019.         }
  1020.         foreach ($etap12 as $item){
  1021.             if($item->getFileCardiSigne()){
  1022.                 $item->addFileCardiSigneMultiple($item->getFileCardiSigne());
  1023.             }
  1024.             if($item->getFileCexSigne()){
  1025.                 $item->addFileCexSigneMultiple($item->getFileCexSigne());
  1026.             }
  1027.             $this->em->persist($item);
  1028.             $this->em->flush();
  1029.         }
  1030.         foreach ($etap14 as $item){
  1031.             if($item->getFileDoe()){
  1032.                 $item->addFileDoeMultiple($item->getFileDoe());
  1033.             }
  1034.             $this->em->persist($item);
  1035.             $this->em->flush();
  1036.         }
  1037.         foreach ($etap15 as $item){
  1038.             if($item->getFileAttestionInstallateur()){
  1039.                 $item->addFileAttestionInstallateurMultiple($item->getFileAttestionInstallateur());
  1040.             }
  1041.             if($item->getFileAttestionProducteur()){
  1042.                 $item->addFileAttestionProducteurMultiple($item->getFileAttestionProducteur());
  1043.             }
  1044.             if($item->getFileContratAchatSigne()){
  1045.                 $item->addFileContratAchatSigneMultiple($item->getFileContratAchatSigne());
  1046.             }
  1047.             $this->em->persist($item);
  1048.             $this->em->flush();
  1049.         }
  1050.     }
  1051.     public function switchDocFileDiagnostiqueCharpente(){
  1052.         $projects = $this->em->getRepository(Project::class)->findAll();
  1053.         foreach ($projects as $project){
  1054.             $etap160 = $this->em->getRepository(Etap160::class)->findOneBy(['project'=>$project->getId()]);
  1055.             $etap159 = $this->em->getRepository(Etap159::class)->findOneBy(['project'=>$project->getId()]);
  1056.             if($etap160 && $etap159){
  1057.                 if(count($etap160->getFileDiagnostiqueCharpenteMultiple())>0){
  1058.                     foreach ($etap160->getFileDiagnostiqueCharpenteMultiple() as $item){
  1059.                         $etap159->addFileDiagnostiqueCharpente159Multiple($item);
  1060.                     }
  1061.                 }
  1062.                 if(count($etap159->getFileDiagnostiqueCharpente159Multiple())>0){
  1063.                     foreach ($etap159->getFileDiagnostiqueCharpente159Multiple() as $item){
  1064.                         $etap160->addFileDiagnostiqueCharpenteMultiple($item);
  1065.                     }
  1066.                 }
  1067.             }
  1068.             $this->em->persist($etap159);
  1069.             $this->em->persist($etap160);
  1070.         }
  1071.         $this->em->flush();
  1072.     }
  1073.     public function switchDocInProsess2(){
  1074.         // urbanisme
  1075.         $etap2 = $this->em->getRepository(Etap2::class)->findAll();
  1076.         $etap3 = $this->em->getRepository(Etap3::class)->findAll();
  1077.         $etap4 = $this->em->getRepository(Etap4::class)->findAll();
  1078.         foreach ($etap2 as $item){
  1079.             if($item->getFilePVPassageHuissier()){
  1080.                 $item->addFilePVPassageHuissierMultiple($item->getFilePVPassageHuissier());
  1081.             }
  1082.             if($item->getFileCertificatNonRecours()){
  1083.                 $item->addFileCertificatNonRecoursMultiple($item->getFileCertificatNonRecours());
  1084.             }
  1085.             if($item->getFileCertificatNonRetrait()){
  1086.                 $item->addFileCertificatNonRetraitMultiple($item->getFileCertificatNonRetrait());
  1087.             }
  1088.             if($item->getFileCertificatNonOpposition()){
  1089.                 $item->addFileCertificatNonOppositionMultiple($item->getFileCertificatNonOpposition());
  1090.             }
  1091.             $this->em->persist($item);
  1092.             $this->em->flush();
  1093.         }
  1094.         foreach ($etap3 as $item){
  1095.             if($item->getFileDocDroc()){
  1096.                 $item->addFileDocDrocMultiple($item->getFileDocDroc());
  1097.             }
  1098.             $this->em->persist($item);
  1099.             $this->em->flush();
  1100.         }
  1101.         foreach ($etap4 as $item){
  1102.             if($item->getFileDaact()){
  1103.                 $item->addFileDaactMultiple($item->getFileDaact());
  1104.             }
  1105.             $this->em->persist($item);
  1106.             $this->em->flush();
  1107.         }
  1108.         // foncier
  1109.         $etap5 = $this->em->getRepository(Etap5::class)->findAll();
  1110.         $etap6 = $this->em->getRepository(Etap6::class)->findAll();
  1111.         $etap7 = $this->em->getRepository(Etap7::class)->findAll();
  1112.         foreach ($etap5 as $item){
  1113.             if($item->getFilePromessebail()){
  1114.                 $item->addFilePromessebailMultiple($item->getFilePromessebail());
  1115.             }
  1116.             $this->em->persist($item);
  1117.             $this->em->flush();
  1118.         }
  1119.         foreach ($etap6 as $item){
  1120.             if($item->getFileEtatDecriptif()){
  1121.                 $item->addFileEtatDecriptifMultiple($item->getFileEtatDecriptif());
  1122.             }
  1123.             if($item->getFileEtatHypothecaire()){
  1124.                 $item->addFileEtatHypothecaireMultiple($item->getFileEtatHypothecaire());
  1125.             }
  1126.             if($item->getFilePublicationSPR()){
  1127.                 $item->addFilePublicationSPRMultiple($item->getFilePublicationSPR());
  1128.             }
  1129.             if($item->getFileTitrePropriete()){
  1130.                 $item->addFileTitreProprieteMultiple($item->getFileTitrePropriete());
  1131.             }
  1132.             $this->em->persist($item);
  1133.             $this->em->flush();
  1134.         }
  1135.         foreach ($etap7 as $item){
  1136.             if($item->getFileBailSigne()){
  1137.                 $item->addFileBailSigneMultiple($item->getFileBailSigne());
  1138.             }
  1139.             if($item->getFileAvenantBail()){
  1140.                 $item->addFileAvenantBailMultiple($item->getFileAvenantBail());
  1141.             }
  1142.             $this->em->persist($item);
  1143.             $this->em->flush();
  1144.         }
  1145.         // Raccordement
  1146.         $etap8 = $this->em->getRepository(Etap8::class)->findAll();
  1147.         $etap13 = $this->em->getRepository(Etap13::class)->findAll();
  1148.         foreach ($etap8 as $item){
  1149.             if($item->getFileKbisEts()){
  1150.                 $item->addFileKbisEtsMultiple($item->getFileKbisEts());
  1151.             }
  1152.             $this->em->persist($item);
  1153.             $this->em->flush();
  1154.         }
  1155.         foreach ($etap13 as $item){
  1156.             if($item->getFileConsuel()){
  1157.                 $item->addFileConsuelMultiple($item->getFileConsuel());
  1158.             }
  1159.             $this->em->persist($item);
  1160.             $this->em->flush();
  1161.         }
  1162.         // Construction
  1163.         $etap16 = $this->em->getRepository(Etap16::class)->findAll();
  1164.         $etap20 = $this->em->getRepository(Etap20::class)->findAll();
  1165.         $etap21 = $this->em->getRepository(Etap21::class)->findAll();
  1166.         $etap22 = $this->em->getRepository(Etap22::class)->findAll();
  1167.         $etap160 = $this->em->getRepository(Etap160::class)->findAll();
  1168.         $etap201 = $this->em->getRepository(Etap201::class)->findAll();
  1169.         $etap171 = $this->em->getRepository(Etap171::class)->findAll();
  1170.         $etap172 = $this->em->getRepository(Etap172::class)->findAll();
  1171.         $etap173 = $this->em->getRepository(Etap173::class)->findAll();
  1172.         $etap174 = $this->em->getRepository(Etap174::class)->findAll();
  1173.         $etap175 = $this->em->getRepository(Etap175::class)->findAll();
  1174.         foreach ($etap16 as $item){
  1175.             if($item->getFileContratEpc()){
  1176.                 $item->addFileContratEpcMultiple($item->getFileContratEpc());
  1177.             }
  1178.             if($item->getFileAnnexes()){
  1179.                 $item->addFileAnnexesMultiple($item->getFileAnnexes());
  1180.             }
  1181.             $this->em->persist($item);
  1182.             $this->em->flush();
  1183.         }
  1184.         foreach ($etap20 as $item){
  1185.             if($item->getFileConsuelEtap20()){
  1186.                 $item->addFileConsuelEtap20Multiple($item->getFileConsuelEtap20());
  1187.             }
  1188.             $this->em->persist($item);
  1189.             $this->em->flush();
  1190.         }
  1191.         foreach ($etap21 as $item){
  1192.             if($item->getFileTestReception()){
  1193.                 $item->addFileTestReceptionMultiple($item->getFileTestReception());
  1194.             }
  1195.             $this->em->persist($item);
  1196.             $this->em->flush();
  1197.         }
  1198.         foreach ($etap22 as $item){
  1199.             if($item->getFileTestPr()){
  1200.                 $item->addFileTestPrMultiple($item->getFileTestPr());
  1201.             }
  1202.             $this->em->persist($item);
  1203.             $this->em->flush();
  1204.         }
  1205.         foreach ($etap160 as $item){
  1206.             if($item->getFileDiagnostiqueCharpente()){
  1207.                 $item->addFileDiagnostiqueCharpenteMultiple($item->getFileDiagnostiqueCharpente());
  1208.             }
  1209.             if($item->getFileEtudeSole()){
  1210.                 $item->addFileEtudeSoleMultiple($item->getFileEtudeSole());
  1211.             }
  1212.             $this->em->persist($item);
  1213.             $this->em->flush();
  1214.         }
  1215.         foreach ($etap201 as $item){
  1216.             if($item->getFileDoeEtap201()){
  1217.                 $item->addFileDoeEtap201Multiple($item->getFileDoeEtap201());
  1218.             }
  1219.             $this->em->persist($item);
  1220.             $this->em->flush();
  1221.         }
  1222.         foreach ($etap171 as $item){
  1223.             if($item->getFileDocEtap171()){
  1224.                 $item->addFileDocEtap171Multiple($item->getFileDocEtap171());
  1225.             }
  1226.             if($item->getFileOrderService()){
  1227.                 $item->addFileOrderServiceMultiple($item->getFileOrderService());
  1228.             }
  1229.             if($item->getFilePlanningPrevisionnel()){
  1230.                 $item->addFilePlanningPrevisionnelMultiple($item->getFilePlanningPrevisionnel());
  1231.             }
  1232.             if($item->getFilePVDemarrage()){
  1233.                 $item->addFilePVDemarrageMultiple($item->getFilePVDemarrage());
  1234.             }
  1235.             $this->em->persist($item);
  1236.             $this->em->flush();
  1237.         }
  1238.         foreach ($etap172 as $item){
  1239.             if($item->getFilePVReception()){
  1240.                 $item->addFilePVReceptionMultiple($item->getFilePVReception());
  1241.             }
  1242.             if($item->getFilePlanImplantationBatimentAvecDalleBeton()){
  1243.                 $item->addFilePlanImplantationBatimentAvecDalleBetonMultiple($item->getFilePlanImplantationBatimentAvecDalleBeton());
  1244.             }
  1245.             if($item->getFilePhotosPlateforme()){
  1246.                 $item->addFilePhotosPlateformeMultiple($item->getFilePhotosPlateforme());
  1247.             }
  1248.             if($item->getFileNoteCalculBetonFeraillage()){
  1249.                 $item->addFileNoteCalculBetonFeraillageMultiple($item->getFileNoteCalculBetonFeraillage());
  1250.             }
  1251.             if($item->getFileFondationTerminees()){
  1252.                 $item->addFileFondationTermineesMultiple($item->getFileFondationTerminees());
  1253.             }
  1254.             if($item->getFileDalleBetonShelter()){
  1255.                 $item->addFileDalleBetonShelterMultiple($item->getFileDalleBetonShelter());
  1256.             }
  1257.             if($item->getFileCheminAcces()){
  1258.                 $item->addFileCheminAccesMultiple($item->getFileCheminAcces());
  1259.             }
  1260.             $this->em->persist($item);
  1261.             $this->em->flush();
  1262.         }
  1263.         foreach ($etap173 as $item){
  1264.             if($item->getFileNoteCalculCharpente173()){
  1265.                 $item->addFileNoteCalculCharpente173Multiple($item->getFileNoteCalculCharpente173());
  1266.             }
  1267.             if($item->getFileOssatureSecondaireBardage173()){
  1268.                 $item->addFileOssatureSecondaireBardage173Multiple($item->getFileOssatureSecondaireBardage173());
  1269.             }
  1270.             if($item->getFilePhotoRenforcementBardage173()){
  1271.                 $item->addFilePhotoRenforcementBardage173Multiple($item->getFilePhotoRenforcementBardage173());
  1272.             }
  1273.             if($item->getFilePhotoRenforcementcharpente173()){
  1274.                 $item->addFilePhotoRenforcementcharpente173Multiple($item->getFilePhotoRenforcementcharpente173());
  1275.             }
  1276.             if($item->getFilePhotoRenforcementCouvertureTermine173()){
  1277.                 $item->addFilePhotoRenforcementCouvertureTermine173Multiple($item->getFilePhotoRenforcementCouvertureTermine173());
  1278.             }
  1279.             if($item->getFilePlanCouverture173()){
  1280.                 $item->addFilePlanCouverture173Multiple($item->getFilePlanCouverture173());
  1281.             }
  1282.             if($item->getFilePlanDescriptionTravauxDeposeCouverture173()){
  1283.                 $item->addFilePlanDescriptionTravauxDeposeCouverture173Multiple($item->getFilePlanDescriptionTravauxDeposeCouverture173());
  1284.             }
  1285.             if($item->getFilePlanDescriptionTravauxRenforcementCharpente173()){
  1286.                 $item->addFilePlanDescriptionTravauxRenforcementCharpente173Multiple($item->getFilePlanDescriptionTravauxRenforcementCharpente173());
  1287.             }
  1288.             if($item->getFilePlansCharpente173()){
  1289.                 $item->addFilePlansCharpente173Multiple($item->getFilePlansCharpente173());
  1290.             }
  1291.             if($item->getFilePVreception173()){
  1292.                 $item->addFilePVreception173Multiple($item->getFilePVreception173());
  1293.             }
  1294.             if($item->getFileVues3d173()){
  1295.                 $item->addFileVues3d173Multiple($item->getFileVues3d173());
  1296.             }
  1297.             $this->em->persist($item);
  1298.             $this->em->flush();
  1299.         }
  1300.         foreach ($etap174 as $item) {
  1301.             if ($item->getFileTestVerificationTravauxElectriqueFiche174()) {
  1302.                 $item->addFileTestVerificationTravauxElectriqueFiche174Multiple($item->getFileTestVerificationTravauxElectriqueFiche174());
  1303.             }
  1304.             if ($item->getFileTestPrMiseService174()) {
  1305.                 $item->addFileTestPrMiseService174Multiple($item->getFileTestPrMiseService174());
  1306.             }
  1307.             if ($item->getFileShemaUnifilaireSystemeMonitoring174()) {
  1308.                 $item->addFileShemaUnifilaireSystemeMonitoring174Multiple($item->getFileShemaUnifilaireSystemeMonitoring174());
  1309.             }
  1310.             if ($item->getFileShemaAgencementShelterPhotos174()) {
  1311.                 $item->addFileShemaAgencementShelterPhotos174Multiple($item->getFileShemaAgencementShelterPhotos174());
  1312.             }
  1313.             if ($item->getFileSchemaUnifilaireInstallation174()) {
  1314.                 $item->addFileSchemaUnifilaireInstallation174Multiple($item->getFileSchemaUnifilaireInstallation174());
  1315.             }
  1316.             if ($item->getFileRaccordementLocalOnduleur174()) {
  1317.                 $item->addFileRaccordementLocalOnduleur174Multiple($item->getFileRaccordementLocalOnduleur174());
  1318.             }
  1319.             if ($item->getFilePvTerminees174()) {
  1320.                 $item->addFilePvTerminees174Multiple($item->getFilePvTerminees174());
  1321.             }
  1322.             if ($item->getFilePVReception174()) {
  1323.                 $item->addFilePVReception174Multiple($item->getFilePVReception174());
  1324.             }
  1325.             if ($item->getFilePlanCaplageStrings174()) {
  1326.                 $item->addFilePlanCaplageStrings174Multiple($item->getFilePlanCaplageStrings174());
  1327.             }
  1328.             if ($item->getFilePlanCalepinageModule174()) {
  1329.                 $item->addFilePlanCalepinageModule174Multiple($item->getFilePlanCalepinageModule174());
  1330.             }
  1331.             if ($item->getFilePhotosGenerateur174()) {
  1332.                 $item->addFilePhotosGenerateur174Multiple($item->getFilePhotosGenerateur174());
  1333.             }
  1334.             if ($item->getFileNoteCalculSousLisePV174()) {
  1335.                 $item->addFileNoteCalculSousLisePV174Multiple($item->getFileNoteCalculSousLisePV174());
  1336.             }
  1337.             if ($item->getFileDescentesCables174()) {
  1338.                 $item->addFileDescentesCables174Multiple($item->getFileDescentesCables174());
  1339.             }
  1340.             $this->em->persist($item);
  1341.             $this->em->flush();
  1342.         }
  1343.         foreach ($etap175 as $item) {
  1344.             if ($item->getFileDaact175()) {
  1345.                 $item->addFileDaact175Multiple($item->getFileDaact175());
  1346.             }
  1347.             if ($item->getFileNoteCalculCableAcLiaison175()) {
  1348.                 $item->addFileNoteCalculCableAcLiaison175Multiple($item->getFileNoteCalculCableAcLiaison175());
  1349.             }
  1350.             if ($item->getFilePhotosLiaisonTerminee175()) {
  1351.                 $item->addFilePhotosLiaisonTerminee175Multiple($item->getFilePhotosLiaisonTerminee175());
  1352.             }
  1353.             if ($item->getFilePlanTranchee175()) {
  1354.                 $item->addFilePlanTranchee175Multiple($item->getFilePlanTranchee175());
  1355.             }
  1356.             if ($item->getFilePVReception175()) {
  1357.                 $item->addFilePVReception175Multiple($item->getFilePVReception175());
  1358.             }
  1359.             $this->em->persist($item);
  1360.             $this->em->flush();
  1361.         }
  1362.     }
  1363.     public function switchDocInProsess3(){
  1364.         $etap15 = $this->em->getRepository(Etap15::class)->findAll();
  1365.         foreach ($etap15 as $item){
  1366.             if($item->getTarifContratAchat() or $item->getDateDebutContratAchat() or $item->getDateFinContratAchat() or $item->getPeridiciteFacturation() or $item->getNumeroContratAchat()){
  1367.                 $imformationContratAchat = new ImfomationContratAchat();
  1368.                 $imformationContratAchat->setDateDebutContratAchat($item->getDateDebutContratAchat());
  1369.                 $imformationContratAchat->setDateFinContratAchat($item->getDateFinContratAchat());
  1370.                 $imformationContratAchat->setNumeroContratAchat($item->getNumeroContratAchat());
  1371.                 $imformationContratAchat->setPeridiciteFacturation($item->getPeridiciteFacturation());
  1372.                 $imformationContratAchat->setTarifContratAchat($item->getTarifContratAchat());
  1373.                 $imformationContratAchat->setEtap15($item);
  1374.                 $this->em->persist($imformationContratAchat);
  1375.                 $this->em->flush();
  1376.             }
  1377.         }
  1378.     }
  1379.     public function switchDocEnterTowEtaps(){
  1380.         $projects = $this->em->getRepository(Project::class)->findAll();
  1381.         foreach ($projects as $project){
  1382.             $etap171 = $this->em->getRepository(Etap171::class)->findOneBy(['project'=>$project->getId()]);
  1383.             $etap172 = $this->em->getRepository(Etap172::class)->findOneBy(['project'=>$project->getId()]);
  1384.             if($etap171 && $etap172){
  1385.                 if(count($etap172->getFileCheminAccesMultiple())>0){
  1386.                     foreach ($etap172->getFileCheminAccesMultiple() as $item){
  1387.                         $etap171->addFileCheminAccesMultiple($item);
  1388.                     }
  1389.                 }
  1390.                 if(count($etap172->getFilePhotosPlateformeMultiple())>0){
  1391.                     foreach ($etap172->getFilePhotosPlateformeMultiple() as $item){
  1392.                         $etap171->addFilePhotosPlateformeMultiple($item);
  1393.                     }
  1394.                 }
  1395.             }
  1396.             $this->em->persist($etap171);
  1397.         }
  1398.         $this->em->flush();
  1399.     }
  1400.     public function uploadFileImport(UploadedFile $file)
  1401.     {
  1402.         set_time_limit(0);
  1403.         if (is_object($file)) {
  1404.             $filenameGenerate = $this->generateUniqueFileName();
  1405.             $fileName = $filenameGenerate . '_' . $file->getClientOriginalName();
  1406.             $file->move($this->params->get('uploads_directory'), $fileName);
  1407.             return array('filename' => $fileName,'filenameOrigine'=>$file->getClientOriginalName());
  1408.         }
  1409.         return false;
  1410.     }
  1411.     public function addEtap15Information(){
  1412.         $etaps15 = $this->em->getRepository(Etap15::class)->findAll();
  1413.         foreach ($etaps15 as $etap15){
  1414.             $information = new ImfomationContratAchat();
  1415.             if($etap15->getNumeroContratAchat()){
  1416.                 $information->setNumeroContratAchat($etap15->getNumeroContratAchat());
  1417.             }
  1418.             if($etap15->getPeridiciteFacturation()){
  1419.                 $information->setPeridiciteFacturation($etap15->getPeridiciteFacturation());
  1420.             }
  1421.             if($etap15->getDateFinContratAchat()){
  1422.                 $information->setDateFinContratAchat($etap15->getDateFinContratAchat());
  1423.             }
  1424.             if($etap15->getDateDebutContratAchat()){
  1425.                 $information->setDateDebutContratAchat($etap15->getDateDebutContratAchat());
  1426.             }
  1427.             if($etap15->getTarifContratAchat()){
  1428.                 $information->setTarifContratAchat($etap15->getTarifContratAchat());
  1429.             }
  1430.             $information->setEtap15($etap15);
  1431.             $this->em->persist($information);
  1432.             $this->em->flush();
  1433.         }
  1434.     }
  1435.     public function addVisiteTerrainOld(){
  1436.         $etaps23 = $this->em->getRepository(Etap23::class)->findAll();
  1437.         foreach ($etaps23 as $etap23){
  1438.             $visiteOld = $etap23->getVisiteTerrain();
  1439.             if(count($visiteOld)>0){
  1440.                 foreach ($visiteOld as $item){
  1441.                     $photosOld = $item->getFilePhotosVisiteTerainMultiple();
  1442.                     if(count($photosOld)>0){
  1443.                         foreach ($photosOld as $value){
  1444.                             $etap23->addFilePhotosVisiteTerainEtap23Multiple($value);
  1445.                             $this->em->persist($etap23);
  1446.                         }
  1447.                     }
  1448.                 }
  1449.             }
  1450.             $this->em->flush();
  1451.         }
  1452.     }
  1453. }