src/Controller/SearchController.php line 16

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