src/Controller/ApprenantController.php line 100

Open in your IDE?
  1. <?php
  2. // src/Controller/ApprenantController.php
  3. namespace App\Controller;
  4. use DateTimeZone;
  5. use IntlDateFormatter;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  10. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\Filesystem\Filesystem;
  13. use Symfony\Contracts\HttpClient\HttpClientInterface;
  14. use Symfony\Component\DependencyInjection\ContainerInterface;
  15. use App\Classes\GeneratePDF;
  16. /**
  17.  * @Route("/apprenant", name="apprenant_")
  18.  */
  19. class ApprenantController extends DigiEntityController
  20. {
  21.     const REF 'apprenant';
  22.     const NAME 'Apprenant';
  23.     const CERFA_PDF_NUM '14';
  24.     public function field_format($name$field$options=[])
  25.     {
  26.         $html '';
  27.         $style '';
  28.         $digi_map = (!empty($field['digi_map']) && is_string($field['digi_map']) ?' data-digi="'.$field['digi_map'].'"' :'');
  29.         if (!empty($field['align']))
  30.             $style .= 'text-align: '.$field['align'].';';
  31.         if (!empty($field['width']))
  32.             $style .= 'width: '.$field['width'].';';
  33.         // True par défaut
  34.         $required = !isset($field['required']) || $field['required'];
  35.         $class = ($required ?'required' :'');
  36.         if (!empty($field['premsg']))
  37.             $html .= '<span class="msg">'.$field['premsg'].'</span>&nbsp;';
  38.         if (!empty($options['checkbox_to_radio']))
  39.             $class .= ' radio';
  40.         if ($field['type']=='checkbox') {
  41.             if (isset($field['values']['Yes']))
  42.                 $value_ok 'Yes';
  43.             else
  44.                 $value_ok 'Oui';
  45.             $html .= '<input type="checkbox" id="'.$name.'"'.$digi_map.' name="'.$name.'" value="'.$value_ok.'"'.($field['value']==$value_ok ?' checked' :'').($class ?' class="'.$class.'" ' :'').($style ?' style="'.$style.'" ' :'').' />&nbsp;<label for="'.$name.'">'.$field['values'][$value_ok].'</label>';
  46.         }
  47.         elseif ($field['type']=='radio') {
  48.             foreach($field['values'] as $value=>$label)
  49.                 $html .= '<input type="radio" id="'.$name.'_'.$value.'"'.$digi_map.' name="'.$name.'" value="'.$value.'"'.($field['value']==$value ?' checked' :'').' />&nbsp;<label for="'.$name.'_'.$value.'">'.$label.'</label>';
  50.         }
  51.         elseif ($field['type']=='select') {
  52.             $html .= '<select id="'.$name.'"'.$digi_map.' name="'.$name.'"'.($class ?' class="'.$class.'" ' :'').($style ?' style="'.$style.'" ' :'').' data-value="'.$field['value'].'"'.($required ?' required' :'').'>'.(empty($field['noempty']) ?'<option value=""></option>' :'');
  53.             foreach($field['values'] as $value=>$select_option) {
  54.                 if (is_array($select_option)) {
  55.                     $label $select_option['label'];
  56.                     $disabled = !empty($select_option['disabled']) || in_array('disabled'$select_option);
  57.                 }
  58.                 else {
  59.                     $label $select_option;
  60.                     $disabled false;
  61.                 }
  62.                 $html .= '<option value="'.$value.'"'.($field['value']==$value ?' selected' :'').($disabled ?' disabled' :'').' data-detail="'.htmlspecialchars(json_encode($select_option)).'">'.$label.'</option>';
  63.             }
  64.             $html .= '</select>';
  65.         }
  66.         elseif ($field['type'] =='date') {
  67.             $html .= '<input type="date" id="'.$name.'"'.$digi_map.' name="'.$name.'" placeholder="'.$field['label'].'" value="'.$field['value'].'" data-value="'.$field['value'].'"'.(!empty($field['maxlength']) ?' size="'.$field['maxlength'].'" maxlength="'.$field['maxlength'].'"' :'').($class ?' class="'.$class.'" ' :'').($style ?' style="'.$style.'" ' :'').($required ?' required' :'').' />';
  68.         }
  69.         elseif ($field['type'] =='textarea') {
  70.             $html .= '<textarea id="'.$name.'"'.$digi_map.' name="'.$name.'" placeholder="'.$field['label'].'" data-value="'.$field['value'].'"'.(!empty($field['maxlength']) ?' size="'.$field['maxlength'].'" maxlength="'.$field['maxlength'].'"' :'').($class ?' class="'.$class.'" ' :'').($style ?' style="'.$style.'" ' :'').($required ?' required' :'').' />'.$field['value'].'</texrarea>';
  71.         }
  72.         else { // text
  73.             $html .= '<input type="text" id="'.$name.'"'.$digi_map.' name="'.$name.'" placeholder="'.$field['label'].'" value="'.$field['value'].'" data-value="'.(isset($field['value']) ?$field['value'] :'').'"'.(!empty($field['maxlength']) ?' size="'.$field['maxlength'].'" maxlength="'.$field['maxlength'].'"' :'').($class ?' class="'.$class.'" ' :'').($style ?' style="'.$style.'" ' :'').($required ?' required' :'').' />'.(!empty($field['unit']) ?'&nbsp;'.$field['unit'] :'');
  74.         }
  75.         if (empty($field['noreset']) && empty($options['noreset']) && ! in_array($field['type'], ['checkbox']))
  76.             $html .= '&nbsp;<span class="reset" data-for="'.$name.'">X</span>';
  77.         if (!empty($field['digi_map']))
  78.             $html .= '&nbsp;<span class="digi_mapped" title="'.$field['digi_map'].'">D</span>';
  79.         elseif (!isset($field['digi_map']) || $field['digi_map']!==false)
  80.             $html .= '&nbsp;<span class="digi_unmapped">D</span>';
  81.         if (!empty($field['postmsg']))
  82.             $html .= '&nbsp;<span class="msg">'.$field['postmsg'].'</span>';
  83.         return $html;
  84.     }
  85.     /**
  86.     * @Route("/{id}/certificat", name="certificat")
  87.     */
  88.     public function CertificatAction(Request $request): Response
  89.     {
  90.         if (!($params $this->cerfa_params($request)))
  91.             die('Paramètres invalides');
  92.         extract($params);
  93.         //var_dump($params); die();
  94.         $locale 'fr_FR';
  95.         $timezone 'Europe/Paris';
  96.         setlocale(LC_ALL$locale);
  97.         date_default_timezone_set($timezone);
  98.         $datetimezone = new DateTimeZone($timezone);
  99.         $dayformatter = new IntlDateFormatter(
  100.             $locale,  // the locale to use, e.g. 'en_GB'
  101.             IntlDateFormatter::FULL,  // how the date should be formatted, e.g. IntlDateFormatter::FULL
  102.             IntlDateFormatter::FULL,  // how the time should be formatted, e.g. IntlDateFormatter::FULL 
  103.             $timezone  // the time should be returned in which timezone?
  104.         );
  105.         $dayformatter->setPattern('dd/mm/YYYY');
  106.         $dayformatter = new IntlDateFormatter(
  107.             $locale,  // the locale to use, e.g. 'en_GB'
  108.             IntlDateFormatter::FULL,  // how the date should be formatted, e.g. IntlDateFormatter::FULL
  109.             IntlDateFormatter::FULL,  // how the time should be formatted, e.g. IntlDateFormatter::FULL 
  110.             $timezone  // the time should be returned in which timezone?
  111.         );
  112.         $dayformatter->setPattern('d MMMM YYYY');
  113.         // Params
  114.         $this->params = [
  115.             'date' => $dayformatter->format(new \DateTime()),
  116.             'apprenant' => $apprenant,
  117.             'session' => $session,
  118.             'company' => $company,
  119.             'program' => $program,
  120.         ];
  121.         // Twig template
  122.         $tplfile 'apprenant/certificat.html.twig';
  123.         
  124.         return $this->render($tplfile$this->params);
  125.     }
  126.     /**
  127.     * @Route("/cerfa_list", name="cerfa_list")
  128.     */
  129.     public function CERFAListAction(Request $request): Response
  130.     {
  131.         $repository $this->em->getRepository('App\\Entity\\Financeur');
  132.         $f $repository->findByQ('CERFA');
  133.         //var_dump($f);
  134.         $repository $this->em->getRepository('App\\Entity\\SessionCustomer');
  135.         $customer_list $repository->findByQ('CERFA');
  136.         // Traitement
  137.         $list = [];
  138.         foreach($customer_list as $customer) {
  139.             foreach($customer->getApprenants() as $apprenant) {
  140.                 $list[] = [
  141.                     'customer'=>$customer,
  142.                     'apprenant'=>$apprenant,
  143.                     'entreprise'=>$customer->getEntreprise(),
  144.                     'session'=>$customer->getSession(),
  145.                 ];
  146.             }
  147.         }
  148.         usort($list, function($a$b){
  149.             $i $a['apprenant']->getContratSignature();
  150.             $j $b['apprenant']->getContratSignature();
  151.             //var_dump($a['apprenant']->getNom(), $i); echo '<br />'; var_dump($b['apprenant'], $b['apprenant']->getNom(), $j, $i==$j, $i<$j); echo '<hr />';
  152.             if ($i==$j)
  153.                 return 0;
  154.             return ($i<$j) ?-:1;
  155.         });
  156.         //var_dump($list);
  157.         //die();
  158.         // Params
  159.         $this->params();
  160.         $this->params['page']['head']['title'] = 'Formulaires Cerfa';
  161.         $this->params['page']['subtitle'] = 'Liste des CERFA à faire';
  162.         $this->params['page']['breadcrumbs'][] = [
  163.             'route' => static::REF.'_cerfa_list',
  164.             'label' => 'Liste',
  165.         ];
  166.         $this->params['f'] = $f;
  167.         $this->params['list'] = $list;
  168.         // Twig template
  169.         $tplfile 'apprenant/cerfa_list.html.twig';
  170.         
  171.         return $this->render($tplfile$this->params);
  172.     }
  173.     /**
  174.     * @Route("/{id}/cerfa", name="cerfa")
  175.     */
  176.     public function CERFAAction(Request $request): Response
  177.     {
  178.         if (!($params $this->cerfa_params($request)))
  179.             die('Paramètres invalides');
  180.         extract($params);
  181.         //var_dump($session); die();
  182.         $cerfa $this->getCERFA();
  183.         $data $cerfa->cerfa_mapping($id$customer_id);
  184.         $mapping $data['mapping'];
  185.         $cat_list $data['cat_list'];
  186.         $html '<table style="width: 100%;" border="0" cellpadding="1">';
  187.         $cat '';
  188.         $group '';
  189.         foreach($mapping as $name=>$field) {
  190.             if (!empty($field['cat']) && $field['cat'] != $cat) {
  191.                 if ($cat)
  192.                     $html .= '<tr><td colspan="3"><hr /></td></tr></tbody>';
  193.                 $cat $field['cat'];
  194.                 $html .= '<tr><th>'.$cat_list[$cat]['label'].'</th></tr>';
  195.                 $html .= '<tbody border="1" style="border: 1px solid black;">';
  196.             }
  197.             if (!empty($field['group']) && $field['group'] != $group) {
  198.                 $group $field['group'];
  199.                 $html .= '<tr><th>'.$group.'</th></tr>';
  200.             }    
  201.             // Mise en page particulière
  202.             if (!empty($field['noauto']))
  203.                 continue;
  204.             $html .= '<tr>';
  205.             $html .= '<td class="label"><label for="'.$name.'">'.$field['label'].'</label>';
  206.             
  207.             $html .= '<td>';
  208.             $options = [];
  209.             if (!empty($field['checkbox_to_radio']))
  210.                 $options['checkbox_to_radio'] = true;
  211.             if ($field['type']=='group') {
  212.                 foreach($field['list'] as $ename=>$efield) {
  213.                     if (!is_numeric($ename))
  214.                         $html .= $this->field_format($ename$efield$options);
  215.                     else
  216.                         $html .= $efield['info'];
  217.                 }
  218.             }
  219.             else
  220.                 $html .= $this->field_format($name$field$options);
  221.             $html .= '</td>';
  222.             if (!empty($field['help'])) {
  223.                 $html .= '<td><div class="help_container"><div class="help_icon">?</div><div class="help">'.$field['help'].'</div></div></td>';
  224.             }
  225.             $html .= '</tr>';
  226.         }
  227.         $html .= '</tbody></table>';
  228.         // History
  229.         $repo $this->em->getRepository('App\\Entity\\CERFA');
  230.         $histo $repo->findBy(['apprenant'=>$id'session'=>$session_id]);
  231.         //var_dump($histo); die();
  232.         
  233.         $this->params();
  234.         $this->params['page']['head']['title'] = 'Formulaire Cerfa '.$apprenant;
  235.         $this->params['page']['subtitle'] = 'CERFA '.$apprenant.' pour '.$session;
  236.         $this->params['page']['breadcrumbs'][] = [
  237.             'route' => static::REF.'_list',
  238.             'label' => 'Liste',
  239.         ];
  240.         $this->params['form'] = $html;
  241.         $this->params['data'] = $data;
  242.         $this->params['cerfa_pdf_url'] = $this->generateUrl('apprenant_cerfa_pdf', ['id'=>$id'customer_id'=>$customer_id]);
  243.         $this->params['cerfa_save_url'] = $this->generateUrl('apprenant_cerfa_save', ['id'=>$id'customer_id'=>$customer_id]);
  244.         $this->params['cerfa_api_update_url'] = $this->generateUrl('apprenant_cerfa_api_update', ['id'=>$id'customer_id'=>$customer_id]);;
  245.         $this->params['cerfa_resync_urls'] = [
  246.             ['Apprenant'$this->generateUrl('apprenant_api_sync', ['id'=>$data['trainee']['id']])],
  247.             ['Entreprise'$this->generateUrl('entreprise_api_sync', ['id'=>$data['company']['id']])],
  248.             ['Session'$this->generateUrl('session_api_sync', ['id'=>$data['session']['id']])],
  249.             ['Programme'$this->generateUrl('formation_programme_api_sync', ['id'=>$data['program']['id']])],
  250.         ];
  251.         $this->params['cerfa_linked_urls'] = [
  252.             ['Apprenant'$this->generateUrl('apprenant_read', ['id'=>$apprenant->getID()])],
  253.             ['Entreprise'$this->generateUrl('entreprise_read', ['id'=>$company->getID()])],
  254.             ['Customer'$this->generateUrl('entreprise_read', ['id'=>$customer->getID()])],
  255.             ['Session'$this->generateUrl('session_read', ['id'=>$session->getID()])],
  256.             ['Programme'$this->generateUrl('formation_programme_read', ['id'=>$program->getID()])],
  257.         ];
  258.         $this->params['cerfa_histo'] = $histo;
  259.         // Twig template
  260.         $tplfile 'apprenant/cerfa_form.html.twig';
  261.         
  262.         return $this->render($tplfile$this->params);
  263.     }
  264.     
  265.     /**
  266.      * Enregiostre les données à jour dans Digiforma
  267.      * 
  268.      * @Route("/{id}/cerfa_api_update", name="cerfa_api_update")
  269.      */
  270.     public function CERFAAPIUpdateAction(Request $requestHttpClientInterface $client): Response
  271.     {
  272.         if (!($params $this->cerfa_params($request)))
  273.             return new JsonResponse(['r'=>false'msg'=>'Paramètres invalides']);
  274.         extract($params);
  275.         if(empty($u_data))
  276.             return new JsonResponse(['r'=>false'msg'=>'Missing user data']);
  277.         // Mapping
  278.         $cerfa $this->getCERFA();
  279.         $mdata $cerfa->cerfa_mapping($id$customer_id$u_data);
  280.         //var_dump($mdata['d_data']); die();
  281.         //var_dump($u_data, $mdata['mapping']); die();
  282.         //var_dump($mdata['mapping']['apprenant_dernierdiplome']['list']['apprenant_dernierdiplome_code']['values']); die();
  283.         $rdata = [];
  284.         $l = [
  285.             'apprenant' => ['updateTrainee''traineeInput''trainee''Apprenant'],
  286.             'company' => ['updateCompany''companyInput''company''Entreprise'],
  287.             'customer' => ['updateCustomer''customerInput''customer''SessionCustomer'],
  288.             'session' => ['updateTrainingSession''trainingSessionInput''session''Session'],
  289.             'program' => ['updateProgram''programInput''program''FormationProgramme'],
  290.         ];
  291.         $ok true;
  292.         foreach($mdata['d_data'] as $type=>$data) {
  293.             if(!isset($l[$type]))
  294.                 continue;
  295.             
  296.             $query = <<<'GRAPHQL'
  297.                 mutation {
  298.                     \$mutationName(id: \$id, \$inputName: {
  299.                         \$data
  300.                     }) {
  301.                         id
  302.                     }
  303.                 }
  304.                 GRAPHQL;
  305.             $dataText = [];
  306.             foreach($data as $name=>$value){
  307.                 if (is_array($value)) {
  308.                     $valueText = [];
  309.                     if ($name=='customFields') {
  310.                         foreach($value as $ename=>$evalue) {
  311.                             $valueText[] .= '{field: "'.$ename.'", value: "'.(is_array($evalue) ?(!empty($evalue['digi'] ?$evalue['digi'] :$evalue['label'])) :$evalue).'"}';
  312.                         }
  313.                         $dataText[] .= $name.': ['."\r\n".implode("\r\n"$valueText)."\r\n".']';
  314.                     }
  315.                     else {
  316.                         foreach($value as $ename=>$evalue) {
  317.                             $valueText[] .= $ename.': '.$this->digi_value($evalue);
  318.                         }
  319.                         $dataText[] .= $name.': {'."\r\n".implode("\r\n"$valueText)."\r\n".'}';
  320.                     }
  321.                 }
  322.                 else {
  323.                     $dataText[] .= $name.': '.$this->digi_value($value);
  324.                 }
  325.             }
  326.             if (empty($dataText))
  327.                 continue;
  328.             $query str_replace(['\$mutationName''\$inputName''\$id''\$data'], [$l[$type][0], $l[$type][1], $mdata[$l[$type][2]]['id'], implode("\r\n"$dataText)], $query);
  329.             //echo '<pre>'.$query.'</pre>';
  330.             $repo $this->em->getRepository('App\\Entity\\'.$l[$type][3]);
  331.             $res $repo->api_query($query, ['user' => 'dunglas']);
  332.             if (!$rok = !empty($res['data'][$l[$type][0]]['id']))
  333.                 $ok false;
  334.             //var_dump($res);
  335.             $rdata[] = [$type$query$res$rok];
  336.         }
  337.         return new JsonResponse(['r'=>$ok'data'=>$rdata]);
  338.     }
  339.     public function digi_value($value)
  340.     {
  341.         if (is_bool($value))
  342.             return $value ?'true' :'false';
  343.         elseif (is_int($value) || is_float($value))
  344.             return ''.$value;
  345.         else
  346.             return '"'.$value.'"';
  347.     }
  348.     public function getCERFA()
  349.     {
  350.         $classname '\\App\\Classes\\CERFA_10103_'.static::CERFA_PDF_NUM;
  351.         $cerfa = new $classname($this->em);
  352.         return $cerfa;
  353.     }
  354.     
  355.     /**
  356.      * Enregistre les données mises à jour localement
  357.      * 
  358.      * @Route("/{id}/cerfa_save", name="cerfa_save")
  359.      */
  360.     public function CERFASaveAction(Request $requestHttpClientInterface $client): Response
  361.     {
  362.         if (!($params $this->cerfa_params($request)))
  363.             die('Paramètres invalides');
  364.         extract($params);
  365.         if(empty($u_data))
  366.             die('Missing user data');
  367.         // Mapping
  368.         $cerfa $this->getCERFA();
  369.         $mdata $cerfa->cerfa_mapping($id$customer_id$u_data);
  370.         $o_data $mdata['o_data'];
  371.         //var_dump($o_data); die();
  372.         // Enregistrement des données du CERFA en local
  373.         $object = new \App\Entity\CERFA();
  374.         $object->setSession($session);
  375.         $object->setApprenant($apprenant);
  376.         $object->setData(json_encode($u_data));
  377.         $this->em->persist($object);
  378.         // Apprenant
  379.         $apprenant->setCERFAData($o_data['apprenant']);
  380.         $this->em->persist($apprenant);
  381.         // Company
  382.         $company->setCERFAData($o_data['company']);
  383.         $this->em->persist($company);
  384.         // Customer
  385.         $customer->setCERFAData($o_data['customer']);
  386.         $this->em->persist($customer);
  387.         // Session
  388.         $session->setCERFAData($o_data['session']);
  389.         $this->em->persist($session);
  390.         // Program
  391.         if (!empty($program)) {
  392.             $program->setCERFAData($o_data['program']);
  393.             $this->em->persist($program);
  394.         }
  395.         $this->em->flush();
  396.         
  397.         // Save cerfa related informations into digiforma
  398.         
  399.         //$html = '';
  400.         return new JsonResponse(['r'=>true]);
  401.     }
  402.     /**
  403.     * @Route("/{id}/cerfa_pdf", name="cerfa_pdf")
  404.     */
  405.     public function CERFAPDFAction(Request $request): Response
  406.     {
  407.         if (!($params $this->cerfa_params($request)))
  408.             die('Paramètres invalides');
  409.         extract($params);
  410.         
  411.         // Mapping        
  412.         $cerfa $this->getCERFA();
  413.         $mdata $cerfa->cerfa_mapping($id$customer_id);
  414.         $mapping $mdata['mapping'];
  415.         $pdf_data = [];
  416.         //var_dump($request->request->all()); die();
  417.         foreach($mapping as $name=>&$field) {
  418.             if ($field['type']=='group') {
  419.                 foreach($field['list'] as $ename=>&$efield) {
  420.                     if (!empty($efield['pdf_name'])) {
  421.                         $value $request->request->get($ename);
  422.                         if (!is_null($value) && $value != '') {
  423.                             $efield['value'] = $value;
  424.                             if (!empty($efield['type'])) {
  425.                                 if ($efield['type']=='date')
  426.                                     $efield['value'] = implode('/'array_reverse(explode('-'$efield['value'])));
  427.                             }
  428.                             $pdf_data[$efield['pdf_name']] = $efield['value'];
  429.                         }
  430.                     }
  431.                 }
  432.                 unset($efield);
  433.             }
  434.             else {
  435.                 if (!empty($field['pdf_name'])) {
  436.                     $value $request->request->get($name);
  437.                     if (!is_null($value) && $value != '')
  438.                         $field['value'] = $value;
  439.                     if (!empty($field['type'])) {
  440.                         if ($field['type']=='date')
  441.                             $field['value'] = implode('/'array_reverse(explode('-'$field['value'])));
  442.                     }
  443.                     $pdf_data[$field['pdf_name']] = $field['value'];
  444.                 }
  445.             }
  446.         }
  447.         unset($field);
  448.         // PDF
  449.         $folder 'cerfa_filled';
  450.         $pdf = new GeneratePdf('cerfa/'.$cerfa->getFilename(), $folder);
  451.         $filename 'cerfa-'.$id.'-'.$session_id.'.pdf';
  452.         $ret $pdf->generate($filename$pdf_data);
  453.         if ($ret !== true) {
  454.             return new JsonResponse($pdf_data);
  455.             //var_dump($ret);
  456.         }
  457.         return (new BinaryFileResponse('../data/'.$folder.'/'.$filenameResponse::HTTP_OK))
  458.             ->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT'cerfa-'.$id.'-'.$session_id.'-'.$apprenant.'.pdf');
  459.     }
  460.     /**
  461.      * Request analysis to retrieve all CERFA data
  462.      * @return []|boolean
  463.      */
  464.     public function cerfa_params(Request $request)
  465.     {
  466.         $id $request->attributes->get('id');
  467.         $apprenant $this->em->getRepository('App\\Entity\\Apprenant')->find($id);
  468.         if (empty($apprenant)) {
  469.             throw $this->createNotFoundException('Missing Trainee'); 
  470.             return false;
  471.         }
  472.         
  473.         if ($customer_id $request->query->get('customer_id')) {
  474.             $customer $this->em->getRepository('App\\Entity\\SessionCustomer')->find($customer_id);
  475.             $session $customer->getSession();
  476.             $session_id $session->getID();
  477.         }
  478.         elseif ($session_id $request->query->get('session_id'))
  479.         {
  480.             if ($session $this->em->getRepository('App\\Entity\\Session')->find($session_id)) {
  481.                 foreach($session->getCustomers() as $session_customer) {
  482.                     //var_dump($session_customer);
  483.                     if ($session_customer->getApprenants()->contains($apprenant)) {
  484.                         $customer $session_customer;
  485.                         $customer_id $customer->getID();
  486.                         break;
  487.                     }
  488.                 }
  489.             }
  490.         }
  491.         else {
  492.             throw $this->createNotFoundException('Missing Session/Customer'); 
  493.             return false;
  494.         }
  495.         if (empty($customer))
  496.             //die('Customer invalide');
  497.             return false;
  498.         // Données complémentaires
  499.         $program $session->getProgramme();
  500.         if (empty($program)) {
  501.             throw $this->createNotFoundException('Missing Program'); 
  502.             return false;
  503.         }
  504.         $company $customer->getEntreprise();
  505.         if (empty($company)) {
  506.             throw $this->createNotFoundException('Missing Company'); 
  507.             return false;
  508.         }
  509.         // User data
  510.         $u_data = [];
  511.         if (!empty($sdata $request->get('data'))) {
  512.             //var_dump($_POST);
  513.             foreach($sdata as $v) {
  514.                 $u_data[$v['name']] = $v['value'];
  515.             }
  516.         }
  517.         return [
  518.             'id' => $id,
  519.             'apprenant' => $apprenant,
  520.             'customer' => $customer,
  521.             'customer_id' => $customer_id,
  522.             'session' => $session,
  523.             'session_id' => $session_id,
  524.             'company' => $company,
  525.             'program' => $program,
  526.             'u_data' => $u_data,
  527.         ];
  528.     }
  529.     
  530.     /**
  531.     * API Setter/Modifier
  532.     */
  533.     protected function apisettel($row)
  534.     {
  535.         if (!empty($row['phone'])) {
  536.             return str_replace(' '''$row['phone']);
  537.         }
  538.         return $row['phone'];
  539.     }
  540. }