src/Controller/SpectresController.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  10. use App\Repository\AntibiotiqueRepository;
  11. use App\Repository\CelluleRepository;
  12. use App\Repository\ContenuRepository;
  13. use App\Repository\FamilleAntibiotiqueRepository;
  14. use App\Repository\LangueRepository;
  15. use App\Repository\MicroorganismeRepository;
  16. use App\Repository\ParametreRepository;
  17. use App\Repository\VersionRepository;
  18. use App\Service\ContentHandler;
  19. use App\Controller\ReferencesController;
  20. class SpectresController extends ATBGController
  21. {
  22.     /**
  23.      * @var ContainerHandler
  24.      */
  25.     private $gestionBalises;
  26.     public function __construct(
  27.         private TranslatorInterface $translator,   
  28.         private VersionRepository $versionRepo,
  29.         private CelluleRepository $celluleRepo,     
  30.         private ContenuRepository $contenuRepo,
  31.         private FamilleAntibiotiqueRepository $familleAntibiotiqueRepo,
  32.         private AntibiotiqueRepository $antibiotiqueRepo,
  33.         private MicroorganismeRepository $microorganismeRepo,
  34.         private LangueRepository $langueRepo,
  35.         private ReferencesController $referenceService,
  36.         private ParametreRepository $parametreRepo,
  37.         ContentHandler $gestionBalises
  38.     ){
  39.         $this->gestionBalises $gestionBalises;
  40.     }
  41.     /**
  42.      * Require ROLE_AUTHENTICATED only for this action
  43.      * 
  44.      * @IsGranted("ROLE_AUTHENTICATED")
  45.      */
  46.     public function index(Request $request)
  47.     {
  48.         $returned parent::suppression_parametres_get($request);
  49.         if ($returned != null
  50.         {
  51.             return $returned;
  52.         }
  53.         return $this->render('Spectres/index.html.twig');
  54.     }
  55.     /**
  56.      * Require ROLE_AUTHENTICATED only for this action
  57.      * 
  58.      * @IsGranted("ROLE_AUTHENTICATED")
  59.      */
  60.     public function displaySommaire(Request $request$selectedId)
  61.     {
  62.         if ($request->isXmlHttpRequest())
  63.         {
  64.             $em $this->getDoctrine()->getManager();
  65.             $session $request->getSession();
  66.             $client_id_adada $session->get('client_id_adada');
  67.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  68.             // Titre
  69.             $content $this->render('Spectres/spectres-sommaire-titre.html.twig', array('type_contenu' => $this->getParameter('categorie_spectres')))->getContent();
  70.             // Titre contenu
  71.             $menus_cellules $this->celluleRepo->getSommaire($this->getParameter('categorie_spectres'),$session->get("_locale"),$pays_code);
  72.             foreach ($menus_cellules as $cellule) {
  73.                 $contentSommaire $this->render('Spectres/spectres-sommaire.html.twig', array('cellule' => $cellule'selectedId' => $selectedId));
  74.                 $content .= $contentSommaire->getContent();
  75.             }
  76.             return new JsonResponse( array ( 
  77.                 'responseCode' => 0,
  78.                 'content' => $content
  79.             ));
  80.         } else throw $this->createNotFoundException();
  81.     }
  82.     /**
  83.      * Require ROLE_AUTHENTICATED only for this action
  84.      * 
  85.      * @IsGranted("ROLE_AUTHENTICATED")
  86.      */
  87.     public function displayNode(Request $request$nodeId)
  88.     {
  89.         if ($request->isXmlHttpRequest())
  90.         {
  91.             $em $this->getDoctrine()->getManager();
  92.             $session $request->getSession();
  93.             $client_id_adada $session->get('client_id_adada');
  94.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  95.             $celluleLangue $this->celluleRepo->findCelluleLangueWithIdCellule($nodeId,$session->get("_locale"));
  96.             // dump($celluleLangue);
  97.             
  98.             $content '';
  99.             $parents = array();
  100.             $isTrueNode true;
  101.             // dd($request);
  102.             $type_spectre $celluleLangue->getMotsClefs();
  103.             if($celluleLangue->getMotsClefs() != null) {
  104.                 $session->set('type_spectre_code'$celluleLangue->getMotsClefs());
  105.             }
  106.             $type_spectre $session->get('type_spectre_code');
  107.             switch ($type_spectre) {
  108.                 case $this->getParameter('spectres_antibiotiques_code'):
  109.                     $arbres['code'] = "0";
  110.                     $arbres['message'] = "";
  111.                     $arbres['content'] = "";
  112.                     $arbres['nbAntibiotiques'] = 0;
  113.                     $arbres['antibiotiques'] = array();
  114.                     $this->remplirAntibiotiques($arbres$arbres$session->get("_locale"));
  115.                     $atbs = array();
  116.                     foreach ($arbres['antibiotiques'] as $cle => $famille) {
  117.                         $suffixe '(famille)';
  118.                         $atbs[$famille['libelle'].$suffixe] = array(
  119.                             'id' => $famille['idFamilleAntibiotique'],
  120.                             'idParent' => null,
  121.                             'isFamille' => (!empty($famille['sousFamilles']))?1:0,
  122.                             'isSousFamille' => (!empty($famille['antibiotiques']))?1:0,
  123.                             'suffixe' => $suffixe
  124.                         );
  125.                         if(!empty($famille['sousFamilles'])) {
  126.                             foreach ($famille['sousFamilles'] as $cle => $ssFamille) {
  127.                                 $suffixe '(sous famille)';
  128.                                 $atbs[$ssFamille['libelle'].$suffixe] = array(
  129.                                     'id' => $ssFamille['idFamilleAntibiotique'],
  130.                                     'idParent' => $famille['idFamilleAntibiotique'],
  131.                                     'isFamille' => (!empty($ssFamille['sousFamilles']))?1:0,
  132.                                     'isSousFamille' => (!empty($ssFamille['antibiotiques']))?1:0,
  133.                                     'suffixe' => $suffixe
  134.                                 );
  135.                                 if(!empty($ssFamille['antibiotiques'])) {
  136.                                     foreach ($ssFamille['antibiotiques'] as $cle => $atb) {
  137.                                         $suffixe '(antibiotique)';
  138.                                         $atbs[$atb['libelle'].$suffixe] = array(
  139.                                             'id' => $atb['idantibiotique'],
  140.                                             'idParent' => $ssFamille['idFamilleAntibiotique'],
  141.                                             'isFamille' => 0,
  142.                                             'isSousFamille' => 0,
  143.                                             'suffixe' => $suffixe
  144.                                         );
  145.                                     }
  146.                                 }
  147.                             }
  148.                         }
  149.                     }
  150.                     ksort($atbs);
  151.                     
  152.                     $content $this->render('Antibiotiques/antibiotique-liste.html.twig', array('titre' => $celluleLangue->getTitrecourt(), 'antibiotiques' => $atbs))->getContent();
  153.                     $data['responseCode'] = 0;
  154.                     $data['content'] = $content;
  155.                     $data['nodeId'] = $nodeId*1;
  156.                     $data['isTrueNode'] = $isTrueNode;
  157.                     $data['parentNodes'] = $parents;
  158.                     return new JsonResponse($data);
  159.                     break;
  160.                 
  161.                 case $this->getParameter('spectres_microorganismes_code'):
  162.                     $arbres['code'] = "0";
  163.                     $arbres['message'] = "";
  164.                     $arbres['content'] = "";
  165.                     $arbres['nbMicroorganismes'] = 0;
  166.                     $arbres['microorganismes'] = array();
  167.                     $this->remplirMicroorganismes($arbres$request->getLocale(), false$arbres);
  168.                     $mos = array();
  169.                     foreach ($arbres['microorganismes'] as $cle => $famille) {
  170.                         $libelle str_replace('<i>'''str_replace('</i>'''$famille['libelle']));
  171.                         $suffixe '(famille)';
  172.                         $mos[$libelle.$suffixe] = array(
  173.                             'id' => $famille['idmicroorganisme'],
  174.                             'idParent' => null,
  175.                             'isFamille' => (!empty($famille['microorganismesfils']))?1:0,
  176.                             'suffixe' => $suffixe
  177.                         );
  178.                         if(!empty($famille['microorganismesfils'])) {
  179.                             foreach ($famille['microorganismesfils'] as $cle => $mo) {
  180.                                 $libelle str_replace('<i>'''str_replace('</i>'''$mo['libelle']));
  181.                                 $suffixe '(microorganisme)';
  182.                                 $mos[$libelle.$suffixe] = array(
  183.                                     'id' => $mo['idmicroorganisme'],
  184.                                     'idParent' => $famille['idmicroorganisme'],
  185.                                     'isFamille' => 0,
  186.                                     'suffixe' => $suffixe
  187.                                 );
  188.                             }
  189.                         }
  190.                     }
  191.                     ksort($mos);
  192.                     
  193.                     $content $this->render('Microorganismes/microorganismes-liste.html.twig', array('titre' => $celluleLangue->getTitrecourt(), 'microorganismes' => $mos))->getContent();
  194.                     $data['responseCode'] = 0;
  195.                     $data['content'] = $content;
  196.                     $data['nodeId'] = $nodeId*1;
  197.                     $data['isTrueNode'] = $isTrueNode;
  198.                     $data['parentNodes'] = $parents;
  199.                     return new JsonResponse($data);
  200.                     break;
  201.                                
  202.                 default:
  203.                     break;
  204.             }
  205.             return new JsonResponse( array ( 
  206.                 'responseCode' => 0,
  207.                 'nodeId' => $nodeId*1,
  208.                 'content' => $content,
  209.                 'isTrueNode' => $isTrueNode,
  210.                 'parentNodes' => $parents
  211.              ));
  212.         } else throw $this->createNotFoundException();
  213.     }
  214.     /**
  215.      * Require ROLE_AUTHENTICATED only for this action
  216.      * 
  217.      * @IsGranted("ROLE_AUTHENTICATED")
  218.      */
  219.     public function detailsSpectres(Request $request$id$idParent)
  220.     {
  221.         if ($request->isXmlHttpRequest())
  222.         {
  223.             $em $this->getDoctrine()->getManager();
  224.             $session $request->getSession();
  225.             $client_id_adada $session->get('client_id_adada');
  226.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  227.             $ref $this->contenuRepo->findContenusWithIdCellule($id,null,$pays_code);
  228.             $content '';
  229.             if($idParent  == $id) {
  230.                 $param = array( 'references' => (!empty($ref[0])?$ref[0]->getContenuhtml():null) );
  231.                 $content $this->render('Spectres/spectres-references.html.twig'$param)->getContent();
  232.             }
  233.             return new JsonResponse( array ( 
  234.                 'responseCode' => 0,
  235.                 'content' => $content
  236.             ));
  237.         } else throw $this->createNotFoundException();
  238.     }
  239.     /**
  240.      * Require ROLE_AUTHENTICATED only for this action
  241.      * 
  242.      * @IsGranted("ROLE_AUTHENTICATED")
  243.      */
  244.     public function references(Request $request)
  245.     {
  246.         if ($request->isXmlHttpRequest())
  247.         {            
  248.             // Titre
  249.             $content $this->render('Spectres/spectres-references.html.twig', array())->getContent();
  250.             
  251.             return new JsonResponse( array ( 
  252.                 'responseCode' => 0,
  253.                 'content' => $content
  254.             ));
  255.         } else throw $this->createNotFoundException();
  256.     }
  257.     /**
  258.      * Require ROLE_AUTHENTICATED only for this action
  259.      * 
  260.      * @IsGranted("ROLE_AUTHENTICATED")
  261.      */
  262.     public function redirectSpectres(String $url)
  263.     {
  264.         return $this->redirect($this->get('router')->generate('spectres_home') . '#/' $url);
  265.     }
  266.     /**
  267.      * Require ROLE_AUTHENTICATED only for this action
  268.      * 
  269.      * @IsGranted("ROLE_AUTHENTICATED")
  270.      */
  271.     public function filariane(Request $request$nodes)
  272.     {
  273.         // exemple #/PARENT/CHILD
  274.         if ($request->isXmlHttpRequest())
  275.         {
  276.             global $nodesid;
  277.             $content '';
  278.             $hascontent preg_match('/^#(\/?[0-9]+)*(?:\/famille)?\/?$/'$nodes);
  279.             $content $this->render('Spectres/spectres-filariane-sommaire.html.twig', array('hascontent' => $hascontent))->getContent();
  280.             if ($hascontent)
  281.             {
  282.                 $nodesid = array();
  283.                 preg_replace_callback('/\/?([0-9]+)/', function($matches){
  284.                     global $nodesid;
  285.                     $nodesid[] = $matches[1];
  286.                 }, $nodes);
  287.             
  288.                 $em $this->getDoctrine()->getManager();
  289.                 $session $request->getSession();
  290.                 $client_id_adada $session->get('client_id_adada');
  291.                 $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  292.                 $langue $this->langueRepo->findOneBy(array("code"=>$request->getLocale()));
  293.                 if(!empty($nodesid)) {
  294.                     // Type spectre (antibiotique ou microorganisme)
  295.                     $nodeTypeSpectre = (isset($nodesid[0]))?$nodesid[0]:NULL;
  296.                     $nodeSpectre = (isset($nodesid[1]))?$nodesid[1]:NULL;
  297.                     $type_spectre "";
  298.                     $celluleLangue $this->celluleRepo->findCelluleLangueWithIdCellule($nodeTypeSpectre,$session->get("_locale"));
  299.                     if($celluleLangue != null) {
  300.                         if($celluleLangue->getMotsClefs() != null) {
  301.                             $session->set('type_spectre_code'$celluleLangue->getMotsClefs());
  302.                         }
  303.                     }
  304.                     $type_spectre $session->get('type_spectre_code');
  305.                     switch ($type_spectre) {
  306.                         case $this->getParameter('spectres_antibiotiques_code'):
  307.                             $content .= $this->render('Spectres/spectres-filariane-famille.html.twig', array('hascontent' => ($nodeSpectre != null)?true:false'type_spectre' => $celluleLangue->getTitreCourt($session->get("_locale"))))->getContent();
  308.                             if($nodeSpectre != null) {
  309.                                 $atb "";
  310.                                 if(strpos($nodes'famille') == false){
  311.                                     $atb $this->antibiotiqueRepo->findLibById($langue->getIdLangue(), $nodeSpectre)[0]['libelleAntibiotique'];
  312.                                 }
  313.                                 else {
  314.                                     $atb $this->familleAntibiotiqueRepo->getLibFamilleById($langue->getIdLangue(), $nodeSpectre)['libelleFamilleAntibiotique'];
  315.                                 }
  316.                                 $content .= $this->render('Spectres/spectres-filariane-titre.html.twig', array('hascontent' => false'libelle_spectre' => $atb))->getContent();
  317.                             }
  318.                             break;
  319.                         case $this->getParameter('spectres_microorganismes_code'):
  320.                             $content .= $this->render('Spectres/spectres-filariane-famille.html.twig', array('hascontent' => ($nodeSpectre != null)?true:false'type_spectre' => $celluleLangue->getTitreCourt($session->get("_locale"))))->getContent();
  321.                             if($nodeSpectre != null) {
  322.                                 $mo $this->microorganismeRepo->findLibById($langue->getIdLangue(), $nodeSpectre);
  323.                                 $content .= $this->render('Spectres/spectres-filariane-titre.html.twig', array('hascontent' => false'libelle_spectre' => $mo[0]['libelleMicroorganisme']))->getContent();
  324.                             }
  325.                             break;
  326.                         case $this->getParameter('spectres_references_code'):
  327.                             $content .= $this->render('Spectres/spectres-filariane-famille.html.twig', array('hascontent' => ($nodeSpectre != null)?true:false'type_spectre' => $celluleLangue->getTitreCourt($session->get("_locale"))))->getContent();
  328.                     }
  329.                 }
  330.             }
  331.             return new JsonResponse( array ( 
  332.                 'responseCode' => 0,
  333.                 'content' => $content
  334.             ));
  335.         } else throw $this->createNotFoundException();
  336.     }
  337.     public function informationsTableau(Request $request$id$idParent$famille) {
  338.         if ($request->isXmlHttpRequest())
  339.         {
  340.             $em $this->getDoctrine()->getManager();
  341.             $session $request->getSession();
  342.             $client_id_adada $session->get('client_id_adada');
  343.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  344.             $idLangue $this->langueRepo->findOneBy(array("code"=>$request->getLocale()));
  345.             $locale $idLangue->getIdLangue();
  346.             $celluleLangue $this->celluleRepo->findCelluleLangueWithIdCellule($idParent,$session->get("_locale"));
  347.             $type '';
  348.             $url '';
  349.             $type_spectre $celluleLangue->getMotsClefs();
  350.             switch ($type_spectre) {
  351.                 case $this->getParameter('spectres_antibiotiques_code'):
  352.                     $type $type_spectre;
  353.                     $atbs $this->familleAntibiotiqueRepo->findFamilleAntibiotiqueFromId($id,null,$pays_code);
  354.                     if($atbs != null && $famille == "famille"){
  355.                         if($atbs->getFamilleAntibiotiquePere() != null && $atbs->getAntibiotiques() != null) {
  356.                             $url 'tableau_sandford_with_famille';
  357.                         }
  358.                         else if($atbs->getFamilleAntibiotiquePere() == null && $atbs->getAntibiotiques() != null){
  359.                             $url 'tableau_sandford_with_all_one_famille';
  360.                         }
  361.                     }
  362.                     else $url 'tableau_sandford';
  363.                     break;
  364.                 case $this->getParameter('spectres_microorganismes_code'):
  365.                     $type $type_spectre;
  366.                     $mos $this->microorganismeRepo->findAllMicroorganismeByLocaleAndFamille($locale$id);
  367.                     if(empty($mos)) $url 'tableau_sandford';
  368.                     else $url 'tableau_sandford_with_all_one_famille';
  369.                     break;
  370.                 default:
  371.                     break;
  372.             }
  373.             return new JsonResponse(array (
  374.                 'type' => $type,
  375.                 'url' => $url
  376.             ));
  377.         } else throw $this->createNotFoundException();
  378.     }
  379.     private function remplirAntibiotiques(&$pere, &$arbres$lang){
  380.         ini_set ('set_time_limit',3600);
  381.         ini_set ('mysql.connect_timeout',3600);
  382.         $link mysqli_connect($this->getParameter('database_host'), $this->getParameter('database_user'), $this->getParameter('database_password'));
  383.         mysqli_select_db($link$this->getParameter('database_name'));
  384.         mysqli_set_charset($link'utf8');
  385.         $famillesAntibiotique mysqli_query($link"SELECT fa_l.id_famille_antibiotique, fa_l.libelle_famille_antibiotique, fa.visible_famille_antibiotique, fa.id_famille_antibiotique_pere, fa_l.mots_clefs
  386.                                         FROM v2_famille_antibiotique fa
  387.                                         INNER JOIN v2_famille_antibiotique_langue fa_l ON fa_l.id_famille_antibiotique = fa.id_famille_antibiotique
  388.                                         INNER JOIN v2_langue lang ON lang.id_langue = fa_l.id_langue AND lang.code_langue = '".$lang."'
  389.                                         INNER JOIN v2_pays_relation pr ON pr.id_famille_antibiotique = fa.id_famille_antibiotique AND pr.id_pays = 1 
  390.                                         WHERE fa.id_famille_antibiotique_reference IS NULL 
  391.                                         AND fa.id_famille_antibiotique_pere IS NULL");
  392.         if (mysqli_num_rows($famillesAntibiotique) > 0
  393.         {
  394.             while($resultFamilleAntibiotique mysqli_fetch_array($famillesAntibiotique))
  395.             {
  396.                 $addfamilleantibiotique = array();
  397.                 $addfamilleantibiotique['idFamilleAntibiotique'] = $resultFamilleAntibiotique['id_famille_antibiotique'];
  398.                 $addfamilleantibiotique['libelle'] = $resultFamilleAntibiotique['libelle_famille_antibiotique'];
  399.                 $addfamilleantibiotique['visible'] = $resultFamilleAntibiotique['visible_famille_antibiotique'];
  400.                 $addfamilleantibiotique['motsClefs'] = $resultFamilleAntibiotique['mots_clefs'];
  401.                 $addfamilleantibiotique['antibiotiques'] = array();
  402.                 $sousFamillesAntibiotique mysqli_query($link"SELECT fa_l.id_famille_antibiotique, fa_l.libelle_famille_antibiotique, fa.visible_famille_antibiotique, fa.id_famille_antibiotique_pere, fa_l.mots_clefs
  403.                                         FROM v2_famille_antibiotique fa
  404.                                         INNER JOIN v2_famille_antibiotique_langue fa_l ON fa_l.id_famille_antibiotique = fa.id_famille_antibiotique
  405.                                         INNER JOIN v2_langue lang ON lang.id_langue = fa_l.id_langue AND lang.code_langue = '".$lang."'
  406.                                         INNER JOIN v2_pays_relation pr ON pr.id_famille_antibiotique = fa.id_famille_antibiotique AND pr.id_pays = 1 
  407.                                         WHERE fa.id_famille_antibiotique_reference IS NULL 
  408.                                         AND fa.id_famille_antibiotique_pere = '".mysqli_real_escape_string($link$addfamilleantibiotique['idFamilleAntibiotique'])."'");
  409.                 if (mysqli_num_rows($sousFamillesAntibiotique) > 0
  410.                 {
  411.                     while($resultSousFamilleAntibiotique mysqli_fetch_array($sousFamillesAntibiotique))
  412.                     {
  413.                         $addCell $this->traitementAntibiotique($link$resultSousFamilleAntibiotique$arbres$lang$pere);
  414.                         $addfamilleantibiotique['sousFamilles'][] = $addCell;
  415.                     }
  416.                 }
  417.                 
  418.                 $pere['antibiotiques'][] = $addfamilleantibiotique;
  419.             }
  420.         }
  421.     }
  422.     private function traitementAntibiotique($link$result, &$arbre$lang$pere=false){
  423.         $addfamilleantibiotique = array();
  424.         $addfamilleantibiotique['idFamilleAntibiotique'] = $result['id_famille_antibiotique'];
  425.         $addfamilleantibiotique['libelle'] = $result['libelle_famille_antibiotique'];
  426.         $addfamilleantibiotique['motsClefs'] = $result['mots_clefs'];
  427.         $addfamilleantibiotique['visible'] = $result['visible_famille_antibiotique'];
  428.         //$addfamilleantibiotique['idfamilleantibiotiquepere'] = $result['id_famille_antibiotique_pere'];
  429.         $addfamilleantibiotique['antibiotiques'] = array();
  430.         $addfamilleantibiotique['sousFamilles'] = array();
  431.         // Liste antibiotique de la famille
  432.         $antibiotiques mysqli_query($link"SELECT a_l.id_antibiotique, a_l.libelle_antibiotique, a_l.mots_clefs
  433.                                     FROM v2_antibiotique a
  434.                                     INNER JOIN v2_antibiotique_langue a_l on a_l.id_antibiotique = a.id_antibiotique
  435.                                     INNER JOIN v2_langue lang ON lang.id_langue = a_l.id_langue AND lang.code_langue = '".$lang."'
  436.                                     INNER JOIN v2_pays_relation pr ON pr.id_antibiotique = a_l.id_antibiotique AND pr.id_pays = 1 
  437.                                     INNER JOIN v2_antibiotique_famille_antibiotique afa ON afa.id_antibiotique = a_l.id_antibiotique
  438.                                     WHERE afa.id_famille_antibiotique = '".mysqli_real_escape_string($link$result['id_famille_antibiotique'])."'
  439.                                     AND a.id_antibiotique_reference IS NULL");
  440.        
  441.         if (mysqli_num_rows($antibiotiques) > 0
  442.         {
  443.             while($resultAntibiotique mysqli_fetch_array($antibiotiques))
  444.             {
  445.                 $addAntibiotique = array();
  446.                 $addAntibiotique['idantibiotique'] = $resultAntibiotique['id_antibiotique'];
  447.                 $addAntibiotique['libelle'] = $resultAntibiotique['libelle_antibiotique'];
  448.                 $addAntibiotique['motsClefs'] = $resultAntibiotique['mots_clefs'];
  449.                 $addAntibiotique['gpr'] = array();
  450.                 // Liste antibiotique de la famille
  451.                 $gpr mysqli_query($link"SELECT gpr.id_gpr
  452.                                     FROM v2_antibiotique_correspondance_gpr gpr                                    
  453.                                     INNER JOIN v2_pays_relation pr ON pr.id_antibiotique_correspondance_gpr = gpr.id_antibiotique_correspondance_gpr AND pr.id_pays = 1  
  454.                                     WHERE gpr.id_antibiotique = '".mysqli_real_escape_string($link$resultAntibiotique['id_antibiotique'])."'
  455.                                     LIMIT 1");
  456.                 $resultGpr mysqli_fetch_array($gpr);
  457.                 $addAntibiotique['gpr'] = (($resultGpr != NULL)?$resultGpr['id_gpr']:array());
  458.                 // if (mysqli_num_rows($gpr) > 0) 
  459.                 // {
  460.                 //     while($resultGpr = mysqli_fetch_array($gpr))
  461.                 //     {
  462.                 //         $addAntibiotique['gpr'][] = $resultGpr['id_gpr'];
  463.                 //     }
  464.                 // }
  465.                 ///// Correspond au spectres : ils font juste mettre les id_spectre correspondant qui ont étaient créés plus avant.
  466.                 // $addAntibiotique['spectres'] = array();
  467.                 // $addAntibiotique['spectres'] =  $this->rechercheIdSpectreByAntibiotique($pere, $resultAntibiotique['id_antibiotique']);
  468.                 /////// Fin spectre
  469.                 ///// Correspond aux indications
  470.                 $addAntibiotique['indications'] = array();
  471.                 $indications mysqli_query($link"SELECT ai.id_indication, ai_l.indication_texte, i.libelle_indication_".$lang."
  472.                                             FROM v2_indication i
  473.                                             INNER JOIN v2_antibiotique_indication ai ON ai.id_indication = i.id_indication
  474.                                             INNER JOIN v2_antibiotique_indication_langue ai_l ON ai_l.id_antibiotique_indication = ai.id_antibiotique_indication
  475.                                             INNER JOIN v2_langue lang ON lang.id_langue = ai_l.id_langue AND lang.code_langue = '".$lang."'
  476.                                             INNER JOIN v2_pays_relation pr ON pr.id_indication = i.id_indication AND pr.id_pays = 1                                  
  477.                                             WHERE ai.id_antibiotique_indication_reference IS NULL 
  478.                                             AND i.actif_indication = 1
  479.                                             AND ai.id_antibiotique = '".mysqli_real_escape_string($link$resultAntibiotique['id_antibiotique'])."'
  480.                                             ORDER BY i.ordre_affichage_indication, i.id_indication");
  481.                 if (mysqli_num_rows($indications) > 0
  482.                 {
  483.                     while($resultindication mysqli_fetch_array($indications))
  484.                     {
  485.                         $addindication = array();
  486.                         $addindication['idindication'] = $resultindication['id_indication'];
  487.                         $addindication['libelle'] = $resultindication['libelle_indication_'.$lang];
  488.                         $addindication['texte'] = $resultindication['indication_texte'];
  489.                         $addAntibiotique['indications'][] =  $addindication;
  490.                     }
  491.                 }
  492.                 /////// Fin indication    
  493.                 /////// CALCUL DOSAGE
  494.                 $dosages mysqli_query($link"SELECT co.id_antibiotique_calcul,co.situation, co.y_drogue, co_l.algorithme
  495.                                             FROM v2_co_antibiotique_calcul co 
  496.                                             INNER JOIN v2_co_antibiotique_calcul_langue co_l ON co_l.id_antibiotique_calcul = co.id_antibiotique_calcul
  497.                                             INNER JOIN v2_langue lang ON lang.id_langue = co_l.id_langue AND lang.code_langue = '".$lang."'                              
  498.                                             WHERE co.id_famille_antibiotique = '".mysqli_real_escape_string($link$result['id_famille_antibiotique'])."' AND
  499.                                                   co.id_antibiotique = '".mysqli_real_escape_string($link$resultAntibiotique['id_antibiotique'])."'");
  500.                 if (mysqli_num_rows($dosages) > 0
  501.                 {
  502.                     while($resultDosage mysqli_fetch_array($dosages))
  503.                     {
  504.                         $addDosage = array();
  505.                         $addDosage['situation'] = $resultDosage['situation'];
  506.                         $addDosage['y_drogue'] = $resultDosage['y_drogue'];
  507.                         $addDosage['algorithme'] = $this->gestionBalises->viderPosologie($link$resultDosage['algorithme']);
  508.                         $addDosage['references'] = array();
  509.                         $referencesDosage mysqli_query($link"SELECT ref_l.texte_co_reference,ref_l.document_pdf_reference
  510.                                                         FROM v2_co_reference ref
  511.                                                         INNER JOIN v2_co_reference_langue ref_l ON ref_l.id_reference = ref.id_co_reference
  512.                                                         INNER JOIN v2_langue lang ON lang.id_langue = ref_l.id_langue AND lang.code_langue = '".$lang."'
  513.                                                         INNER JOIN v2_co_calcul_reference calref ON calref.id_co_reference = ref.id_co_reference                          
  514.                                                         WHERE calref.id_antibiotique_calcul = '".mysqli_real_escape_string($link$resultDosage['id_antibiotique_calcul'])."'");
  515.                         if (mysqli_num_rows($referencesDosage) > 0
  516.                         {
  517.                             while($resultReferenceDosage mysqli_fetch_array($referencesDosage))
  518.                             {
  519.                                 $addReferenceDosage = array();
  520.                                 $addReferenceDosage['texte'] = $resultReferenceDosage["texte_co_reference"];
  521.                                 $addReferenceDosage['documentPDF'] = $resultReferenceDosage["document_pdf_reference"];
  522.                                 $addDosage['references'][] = $addReferenceDosage;
  523.                             }
  524.                         }
  525.                         $addAntibiotique['dosage'] =  $addDosage;  
  526.                     }
  527.                 }
  528.                 ///////
  529.                 $arbre['nbAntibiotiques'] = $arbre['nbAntibiotiques'] + 1;    
  530.                 $addfamilleantibiotique['antibiotiques'][] = $addAntibiotique;
  531.             }
  532.         }
  533.         
  534.         return $addfamilleantibiotique;
  535.     } 
  536.     private function remplirMicroorganismes(&$pere$lang$rechercheFils=false, &$arbre=null){
  537.         ini_set ('set_time_limit',3600);
  538.         ini_set ('mysql.connect_timeout',3600);
  539.         $link mysqli_connect($this->getParameter('database_host'), $this->getParameter('database_user'), $this->getParameter('database_password'));
  540.         mysqli_select_db($link$this->getParameter('database_name'));
  541.         mysqli_set_charset($link'utf8');
  542.         $finRequete "";
  543.         if($rechercheFils === true)
  544.         {
  545.             $finRequete "INNER JOIN v2_microorganisme_relation mor ON mor.id_microorganisme_fils = mo.id_microorganisme and mor.id_microorganisme_pere='".mysqli_real_escape_string($link$pere['idmicroorganisme'])."' WHERE mo.id_microorganisme_reference IS NULL";
  546.         }
  547.         else {
  548.             $finRequete " WHERE mo.id_microorganisme_reference IS NULL AND (select count(*) from v2_microorganisme m inner join v2_microorganisme_relation mrel on mrel.id_microorganisme_pere = m.id_microorganisme where mrel.id_microorganisme_fils = mo.id_microorganisme ) = 0 ";
  549.         }
  550.         $microorganismes mysqli_query($link"SELECT mo.id_microorganisme, mo.hidden, mo_l.libelle_microorganisme, mo.afficher_fils, mo_l.mots_clefs
  551.                                         FROM v2_microorganisme mo
  552.                                         INNER JOIN v2_microorganisme_langue mo_l ON mo_l.id_microorganisme = mo.id_microorganisme
  553.                                         INNER JOIN v2_langue lang ON lang.id_langue = mo_l.id_langue AND lang.code_langue = '".$lang."'
  554.                                         INNER JOIN v2_pays_relation pr ON pr.id_microorganisme = mo.id_microorganisme AND pr.id_pays = 1 ".$finRequete);
  555.         if (mysqli_num_rows($microorganismes) > 0
  556.         {
  557.             while($resultMicroorganismes mysqli_fetch_array($microorganismes))
  558.             {
  559.                 $addCell $this->traitementMicroorganisme($link$resultMicroorganismes$arbre);                
  560.                 $this->remplirMicroorganismes($addCell$langtrue$arbre);
  561.                 if($rechercheFils === true){
  562.                     $pere['microorganismesfils'][] = $addCell;
  563.                     $arbre['nbMicroorganismes'] = $arbre['nbMicroorganismes'] + 1;
  564.                 }
  565.                 else{
  566.                     $pere['microorganismes'][] = $addCell
  567.                     $arbre['nbMicroorganismes'] = $arbre['nbMicroorganismes'] + 1;   
  568.                 }
  569.             }
  570.         }
  571.        /* else {
  572.             echo "error:0";
  573.             exit;
  574.         }*/
  575.     }   
  576.     /**
  577.      * Retourne toutes les informations d'un microorganisme donnée
  578.     **/
  579.     private function traitementMicroorganisme($link$result$arbre){
  580.         $addMicroorganisme = array();
  581.         $addMicroorganisme['idmicroorganisme'] = $result['id_microorganisme'];
  582.         $addMicroorganisme['hidden'] = $result['hidden'];
  583.         $addMicroorganisme['libelle'] = $result['libelle_microorganisme'];
  584.         $addMicroorganisme['motsClefs'] = $result['mots_clefs'];
  585.         $addMicroorganisme['afficherfils'] = $result['afficher_fils'];
  586.         ///// Correspond au spectres : ils font juste mettre les id_spectre correspondant qui ont étaient créés plus avant.
  587.         // $addMicroorganisme['spectres'] = array();
  588.         // $addMicroorganisme['spectres'] =  $this->rechercheIdSpectreByMicroorganisme($arbre, $result['id_microorganisme']); 
  589.         $addMicroorganisme['microorganismesfils'] = array();
  590.         
  591.         /////// Fin spectre
  592.         //return $addMicroorganisme
  593.         return $addMicroorganisme;
  594.     }
  595. }