src/Controller/SearchController.php line 353

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Nette\Utils\Paginator;
  8. class SearchController extends AbstractController
  9. {
  10.      /**
  11.      * @Route("/search", name="app_search")
  12.      */
  13.     public function search(Request $request)
  14.     {
  15.         if($request->query->has('search'))
  16.         {
  17.             $data $request->query->all('search'); 
  18.             if(!empty($data['molecule_uuid']))
  19.             {
  20.                 return $this->redirectToRoute('app_molecule_show',['uuid' => $data['molecule_uuid']]);
  21.             }
  22.             elseif(!empty($data['plant_uuid']))
  23.             {    
  24.                 $arr = !empty($data['plant_part']) ? ['slug' => $data['plant_uuid'], "plant_part" => $data['plant_part']] : ['slug' => $data['plant_uuid']];
  25.                 if(!empty($data['molecular_group']))
  26.                 {
  27.                     $arr['molecular_group'] = $data['molecular_group'];
  28.                 }
  29.                 
  30.                 return $this->redirectToRoute('app_search_plant'$arr);
  31.             }
  32.             elseif(!empty($data['molecular_group']))
  33.             {
  34.                 return $this->redirectToRoute('app_search_molecular_group', ['group' => $data['molecular_group']]);
  35.             }
  36.         }
  37.         return $this->redirectToRoute('app_default');
  38.     }
  39.      /**
  40.      * @Route("/search/molecular_group/{group}", name="app_search_molecular_group")
  41.      */
  42.     public function searchByMolecularGroup(string $groupRequest $request)
  43.     {
  44.         $limit 30;
  45.         $page $request->query->get('page'1);
  46.         $offset = ($page-1) * $limit;
  47.         $exp = new \App\Api\Types\String_comparison_exp;
  48.         $exp->_eq $group;
  49.         $input = new \App\Api\Types\molecule_struct_bool_exp();
  50.         $input->molgroup $exp;
  51.         $count = \App\Api\Operations\MoleculeWhereCount::execute($input)->data->molecule_struct_aggregate->aggregate->count;
  52.         $result = \App\Api\Operations\MoleculeWhere::execute($input$limit$offset)->data->molecule_struct;
  53.         $paginator = new Paginator;
  54.         $paginator->setItemCount($count);
  55.         $paginator->setItemsPerPage($limit);
  56.         $paginator->setPage($page);
  57.         return $this->render('search/result.html.twig', [
  58.             'result'             => $result,
  59.             'paginator'         => $paginator,
  60.             'searchLabel'          => 'Molecular group',
  61.             'searchPattern'     => ucfirst($group),
  62.         ]);  
  63.     }
  64.     /**
  65.     * @Route("/search/systemic_toxicity", name="app_search_systemic_toxicity")
  66.     */
  67.     public function searchBySystemicToxicity(Request $request)
  68.     {    
  69.         $limit 30;
  70.         $page $request->query->get('page'1);
  71.         $offset = ($page-1) * $limit;
  72.         if($request->query->has('search'))
  73.         {
  74.             $data $request->query->all('search'); 
  75.             if(!empty($data['systemic_toxicity']))
  76.             {
  77.                 $scExp = new \App\Api\Types\String_comparison_exp;
  78.                 $scExp->_eq $data['systemic_toxicity'];
  79.                 $stbExp = new \App\Api\Types\systemic_toxicity_bool_exp;
  80.                 $stbExp->shortcramerclass =  $scExp
  81.                 $input = new \App\Api\Types\molecule_struct_bool_exp();
  82.                 $input->systemic_toxicity $stbExp;
  83.                 if(!empty($data['molecular_group']))
  84.                 {
  85.                     $expStr = new \App\Api\Types\String_comparison_exp;
  86.                     $expStr->_eq $data['molecular_group'];
  87.                     $input->molgroup $expStr
  88.                 }
  89.                                 //dd(\App\Api\Operations\MoleculeWhereCount::execute($input));
  90.                 $count = \App\Api\Operations\MoleculeWhereCount::execute($input)->data->molecule_struct_aggregate->aggregate->count;
  91.                 $result = \App\Api\Operations\MoleculeWhere::execute($input$limit$offset)->data->molecule_struct;
  92.                 // dump($result);
  93.                 $molecularGroups = \App\Api\Operations\MolecularGroup::execute()->data->molecular_group_view;
  94.                 $paginator = new Paginator;
  95.                 $paginator->setItemCount($count);
  96.                 $paginator->setItemsPerPage($limit);
  97.                 $paginator->setPage($page);
  98.                 return $this->render('search/result.html.twig', [
  99.                     'result'             => $result,
  100.                     'paginator'         => $paginator,
  101.                     'searchLabel'          => 'Systemic toxicity',
  102.                     'searchPattern'     => sprintf('Cramer class %s',$data['systemic_toxicity']),
  103.                     'searchValue'       => $data['systemic_toxicity'],
  104.                      'molecularGroups'     => $molecularGroups,
  105.                      'molecularGroup'    => !empty($data['molecular_group']) ? $data['molecular_group'] : null
  106.                 ]);  
  107.             }
  108.         }
  109.         return $this->redirectToRoute('app_toxicity_search');
  110.     }
  111.     /**
  112.     * @Route("/search/skin-sensitization", name="app_search_skin_sensitization")
  113.     */
  114.     public function searchBySkinSensitization(Request $request)
  115.     {    
  116.         $limit 30;
  117.         $page $request->query->get('page'1);
  118.         $offset = ($page-1) * $limit;
  119.         if($request->query->has('search'))
  120.         {
  121.             $data $request->query->all('search'); 
  122.             if(!empty($data['skin_sensitization']))
  123.             {
  124.                 $boolExp = new \App\Api\Types\Boolean_comparison_exp;
  125.                 $boolExp->_eq trim($data['skin_sensitization']) == 'sensitizer' true false;
  126.                 $mcbExp = new \App\Api\Types\molecule_criticity_bool_exp;
  127.                 $mcbExp->is_sensitizer $boolExp
  128.                 $input = new \App\Api\Types\molecule_struct_bool_exp();
  129.                 $input->criticity $mcbExp;
  130.                 if(!empty($data['molecular_group']))
  131.                 {
  132.                     $expStr = new \App\Api\Types\String_comparison_exp;
  133.                     $expStr->_eq $data['molecular_group'];
  134.                     $input->molgroup $expStr
  135.                 }
  136.                 $count = \App\Api\Operations\MoleculeWhereCount::execute($input)->data->molecule_struct_aggregate->aggregate->count;
  137.                 $result = \App\Api\Operations\MoleculeWhere::execute($input$limit$offset)->data->molecule_struct;
  138.                 $molecularGroups = \App\Api\Operations\MolecularGroup::execute()->data->molecular_group_view;
  139.                 $paginator = new Paginator;
  140.                 $paginator->setItemCount($count);
  141.                 $paginator->setItemsPerPage($limit);
  142.                 $paginator->setPage($page);
  143.                 return $this->render('search/result.html.twig', [
  144.                     'result'             => $result,
  145.                     'paginator'         => $paginator,
  146.                     'searchLabel'          => 'Skin sensitization',
  147.                     'searchPattern'     => ucfirst(str_replace('-'''$data['skin_sensitization'])),
  148.                     'molecularGroups'     => $molecularGroups,
  149.                     'searchValue'       => $data['skin_sensitization'],
  150.                     'molecularGroup'    => !empty($data['molecular_group']) ? $data['molecular_group'] : null
  151.                 ]);  
  152.             }
  153.         }
  154.         return $this->redirectToRoute('app_toxicity_search');
  155.     }
  156.     /**
  157.     * @Route("/search/genotoxicity", name="app_search_genotoxicity")
  158.     */
  159.     public function searchByGenotoxicity(Request $request)
  160.     {    
  161.         $limit 30;
  162.         $page $request->query->get('page'1);
  163.         $offset = ($page-1) * $limit;
  164.         if($request->query->has('search'))
  165.         {
  166.             $data $request->query->all('search'); 
  167.             if(!empty($data['genotoxicity']))
  168.             {
  169.                 $boolExp = new \App\Api\Types\Boolean_comparison_exp;
  170.                 $mcbExp = new \App\Api\Types\molecule_criticity_bool_exp;
  171.                 if($data['genotoxicity'] == 'mutagenic')
  172.                 {
  173.                     $boolExp->_eq =  true;
  174.                     $mcbExp->is_mutagenic $boolExp
  175.                 }
  176.                 elseif($data['genotoxicity'] == 'clastogenic')
  177.                 {
  178.                     $boolExp->_eq =  true;
  179.                     $mcbExp->is_clastogenic $boolExp
  180.                 }
  181.                 elseif($data['genotoxicity'] == 'non-genotoxic')
  182.                 {
  183.                     $boolExp->_eq =  false;
  184.                     $mcbExp->is_genotoxic $boolExp
  185.                 }
  186.                 $input = new \App\Api\Types\molecule_struct_bool_exp();
  187.                 $input->criticity $mcbExp;
  188.                 if(!empty($data['molecular_group']))
  189.                 {
  190.                     $expStr = new \App\Api\Types\String_comparison_exp;
  191.                     $expStr->_eq $data['molecular_group'];
  192.                     $input->molgroup $expStr
  193.                 }
  194.                 $count = \App\Api\Operations\MoleculeWhereCount::execute($input)->data->molecule_struct_aggregate->aggregate->count;
  195.                 $result = \App\Api\Operations\MoleculeWhere::execute($input$limit$offset)->data->molecule_struct;
  196.                 $molecularGroups = \App\Api\Operations\MolecularGroup::execute()->data->molecular_group_view;
  197.                 $paginator = new Paginator;
  198.                 $paginator->setItemCount($count);
  199.                 $paginator->setItemsPerPage($limit);
  200.                 $paginator->setPage($page);
  201.                 return $this->render('search/result.html.twig', [
  202.                     'result'             => $result,
  203.                     'paginator'         => $paginator,
  204.                     'searchLabel'          => 'Genotoxicity',
  205.                     'searchPattern'     => ucfirst(str_replace('-'' '$data['genotoxicity'])),
  206.                     'searchValue'       => $data['genotoxicity'],
  207.                     'molecularGroups'     => $molecularGroups,
  208.                     'molecularGroup'    => !empty($data['molecular_group']) ? $data['molecular_group'] : null
  209.                 ]);  
  210.             }
  211.         }
  212.         return $this->redirectToRoute('app_toxicity_search');
  213.     }
  214.     /**
  215.     * @Route("/search/critical", name="app_search_critical")
  216.     */
  217.     public function searchCritical(Request $request)
  218.     {    
  219.         $limit 30;
  220.         $page $request->query->get('page'1);
  221.         $offset = ($page-1) * $limit;
  222.         if($request->query->has('search'))
  223.         {
  224.             $data $request->query->all('search'); 
  225.             if(!empty($data['critical']))
  226.             {
  227.                 $boolExp = new \App\Api\Types\Boolean_comparison_exp;
  228.                 $boolExp->_eq true;
  229.                 $mcbExp = new \App\Api\Types\molecule_criticity_bool_exp;
  230.                 if($data['critical'] == "inrs")
  231.                 {
  232.                     $mcbExp->inrs $boolExp;
  233.                 }
  234.                 else if($data['critical'] == "cpr")
  235.                 {
  236.                     $mcbExp->scss $boolExp;
  237.                 }
  238.                 else if($data['critical'] == "unitis-allergen")
  239.                 {
  240.                     return $this->redirectToRoute('app_plant_unitis_allergen');
  241.                 }
  242.                 $input = new \App\Api\Types\molecule_struct_bool_exp();
  243.                 $input->criticity $mcbExp;
  244.                 if(!empty($data['molecular_group']))
  245.                 {
  246.                     $expStr = new \App\Api\Types\String_comparison_exp;
  247.                     $expStr->_eq $data['molecular_group'];
  248.                     $input->molgroup $expStr
  249.                 }
  250.                 $count = \App\Api\Operations\MoleculeWhereCount::execute($input)->data->molecule_struct_aggregate->aggregate->count;
  251.                 $result = \App\Api\Operations\MoleculeWhere::execute($input$limit$offset)->data->molecule_struct;
  252.                 $molecularGroups = \App\Api\Operations\MolecularGroup::execute()->data->molecular_group_view;
  253.                 $paginator = new Paginator;
  254.                 $paginator->setItemCount($count);
  255.                 $paginator->setItemsPerPage($limit);
  256.                 $paginator->setPage($page);
  257.                 return $this->render('search/result.html.twig', [
  258.                     'result'         => $result,
  259.                     'paginator'     => $paginator,
  260.                     'searchLabel'      => 'Allergen',
  261.                     'searchPattern' => ucfirst(str_replace('-'' '$data['critical'])),
  262.                     'searchValue'       => $data['critical'],
  263.                     'molecularGroups'     => $molecularGroups,
  264.                     'molecularGroup'    => !empty($data['molecular_group']) ? $data['molecular_group'] : null
  265.                 ]);  
  266.             }
  267.         }
  268.         return $this->redirectToRoute('app_toxicity_search');
  269.     }
  270.     /**
  271.     * @Route("/search/plant/{slug}", name="app_search_plant")
  272.     */
  273.     public function searchPlant(Request $requeststring $slug)
  274.     {    
  275.         $arr             = [];
  276.         $plantParts     = [];
  277.         $limit             30;
  278.         $page             = !empty($request->query->get('page')) ? $request->query->get('page') : 1;
  279.         $offset         = ($page-1) * $limit;
  280.         $organs         = [];
  281.         $molOrgans         = [];
  282.         $plantPart         = !empty($request->query->get('search')['plant_part']) ? $request->query->get('search')['plant_part'] : null;
  283.         $molecularGroup = !empty($request->query->get('search')['molecular_group']) ? $request->query->get('search')['molecular_group'] : null;
  284.         $organs = \App\Api\Operations\PlantPartByPlant::execute($slug)->data->molecule_plant_data;
  285.         $exp     = new \App\Api\Types\String_comparison_exp;
  286.         $exp->_eq $slug;
  287.         $input = new \App\Api\Types\molecule_plant_data_bool_exp();
  288.         $input->plant_name_slug $exp;
  289.         if($plantPart)
  290.         {
  291.             $expStr = new \App\Api\Types\String_comparison_exp;
  292.             $expStr->_eq $plantPart;
  293.             $input->plant_part $expStr;
  294.         }
  295.         if($molecularGroup)
  296.         {
  297.             $inputMolecule = new \App\Api\Types\molecule_struct_bool_exp();
  298.             $expStr = new \App\Api\Types\String_comparison_exp;
  299.             $expStr->_eq $molecularGroup;
  300.             $inputMolecule->molgroup $expStr
  301.             $input->molecule $inputMolecule;
  302.         }
  303.  
  304.         // $result = \App\Api\Operations\PlantMoleculeWhere::execute($input, $limit, $offset);
  305.         try {
  306.             $result = \App\Api\Operations\MoleculePlantDataWhere::execute($input$limit$offset);
  307.         }catch( \Exception $e)
  308.         {
  309.             die($e->getMessage());            
  310.         }
  311.         foreach($result->data->molecule_plant_data as $item)
  312.         {    
  313.             if($item->molecule)
  314.             {
  315.                 $molecule = new \stdClass;
  316.                 $molecule->plantpart         $item->plant_part;
  317.                 // $molecule->bingo_inchikey     = $item->molecule->bingo_inchikey;
  318.                 // $molecule->inchi             = $item->molecule->inchi;
  319.                 // $molecule->inchikey         = $item->molecule->inchikey;
  320.                 // $molecule->molecularformula = $item->molecule->molecularformula;
  321.                 // $molecule->molecularweight     = $item->molecule->molecularweight;
  322.                 $molecule->molgroup         $item->molecule->molgroup;
  323.                 $molecule->molname             $item->molname;
  324.                 $molecule->smiles             $item->molecule->smiles;
  325.                 $molecule->uuid             $item->molecule->uuid;
  326.                 if(!array_key_exists($item->molecule->bingo_inchikey,$molOrgans))
  327.                 {
  328.                     $molOrgans[$item->molecule->inchikey] = [];
  329.                 }
  330.                 $molOrgans[$item->molecule->inchikey][$item->plant_part] = $item->plant_part;
  331.                 $arr[] = $molecule;
  332.             }
  333.         }
  334.         $count $result->data->molecule_plant_data_aggregate->aggregate->count;
  335.         $molecularGroups = \App\Api\Operations\MolecularGroup::execute()->data->molecular_group_view;
  336.         $paginator = new Paginator;
  337.         $paginator->setItemCount($count);
  338.         $paginator->setItemsPerPage($limit);
  339.         $paginator->setPage($page);
  340.         return $this->render('search/result.html.twig', [
  341.             'result'             => $arr,
  342.             'paginator'         => $paginator,
  343.             'searchLabel'          => 'Plant',
  344.             'searchPattern'     => ucfirst(str_replace('_'' '$slug)),
  345.             'plantNameSlug'        => $slug,
  346.             'show_plantpart'     => true,
  347.             'plantPart'            => $plantPart,
  348.             'organs'            => $organs,
  349.             'molecularGroups'     => $molecularGroups,
  350.             'molOrgans'            => $molOrgans,
  351.             // 'molGroup'          => $molGroup
  352.         ]);  
  353.     }
  354.     /**
  355.     * @Route("/search/eu-regulation", name="app_search_eu_regulation")
  356.     */
  357.     public function searchByRegulation(Request $request)
  358.     {    
  359.         $limit 30;
  360.         $page $request->query->get('page'1);
  361.         $offset = ($page-1) * $limit;
  362.         if($request->query->has('search'))
  363.         {
  364.             $molecularGroups = \App\Api\Operations\MolecularGroup::execute()->data->molecular_group_view;
  365.             $data $request->query->all('search'); 
  366.             if(!empty($data['eu_regulation']))
  367.             {
  368.                 $exp     = new \App\Api\Types\String_comparison_exp;
  369.                 $shperaExp = new \App\Api\Types\sphera_result_bool_exp;
  370.                 if($data['eu_regulation'] == 'found_in_clp_list')
  371.                 {
  372.                     $exp->_eq 'Yes';
  373.                     $shperaExp->found_in_clp_list $exp
  374.                 }
  375.                 elseif($data['eu_regulation'] == 'found_in_annex_list')
  376.                 {
  377.                     $exp->_neq '';
  378.                     $shperaExp->found_in_annex_list $exp;     
  379.                 }
  380.                 $input = new \App\Api\Types\molecule_struct_bool_exp();
  381.                 $input->sphera_result $shperaExp;    
  382.                 // dd($input);
  383.                 if(!empty($data['molecular_group']))
  384.                 {
  385.                     $expStr = new \App\Api\Types\String_comparison_exp;
  386.                     $expStr->_eq $data['molecular_group'];
  387.                     $input->molgroup $expStr
  388.                 }
  389.                 // dd($input);
  390.                 $count = \App\Api\Operations\MoleculeWhereCount::execute($input)->data->molecule_struct_aggregate->aggregate->count;
  391.                 $result = \App\Api\Operations\MoleculeWhere::execute($input$limit$offset)->data->molecule_struct;
  392.                 $molecularGroups = \App\Api\Operations\MolecularGroup::execute()->data->molecular_group_view;
  393.                 $paginator = new Paginator;
  394.                 $paginator->setItemCount($count);
  395.                 $paginator->setItemsPerPage($limit);
  396.                 $paginator->setPage($page);
  397.                 return $this->render('search/result.html.twig', [
  398.                     'result'             => $result,
  399.                     'paginator'         => $paginator,
  400.                     'searchLabel'          => 'Eu regulation',
  401.                     'searchPattern'     => ucfirst(str_replace('_'' '$data['eu_regulation'])),
  402.                     'molecularGroups'     => $molecularGroups,
  403.                     'searchValue'       => $data['eu_regulation'],
  404.                     'molecularGroup'    => !empty($data['molecular_group']) ? $data['molecular_group'] : null,
  405.                     'molecularGroups'     => $molecularGroups
  406.                 ]);  
  407.             }
  408.         }
  409.         return $this->redirectToRoute('app_toxicity_search');
  410.     }
  411. }