src/OceanExpertBundle/Controller/SearchController.php line 2673

Open in your IDE?
  1. <?php
  2. namespace OceanExpertBundle\Controller;
  3. use Doctrine\Common\Persistence\ManagerRegistry;
  4. use Doctrine\ORM\AbstractQuery;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\Request;
  9. class SearchController extends AbstractController
  10. {
  11.     public function generalSearchAction(Request $request): Response
  12.     {
  13.         $searchParams['searchQuery'] = $request->query->get('q');
  14.         $searchParams['searchQuery'] = self::cleaned($searchParams['searchQuery']);
  15.         if (null !== ($request->query->get('limit'))) {
  16.             $limit $request->query->get('limit');
  17.         } else {
  18.             $limit 10;
  19.         }
  20.         $em self::getDoctrine()->getManager();
  21.         $connection $em->getConnection();
  22.         $statement $connection->prepare("
  23.             SELECT 
  24.                 * 
  25.             FROM 
  26.                 indiv 
  27.             WHERE 
  28.                 ( 
  29.                      MATCH (fname,mname,sname) AGAINST (:searchQuery IN BOOLEAN MODE) 
  30.                      OR fname LIKE :percSearchQuery 
  31.                      OR fname LIKE :searchQueryPerc  
  32.                      OR mname LIKE :percSearchQuery 
  33.                      OR mname LIKE :searchQueryPerc 
  34.                      OR sname LIKE :percSearchQuery 
  35.                      OR sname LIKE :searchQueryPerc
  36.                 ) 
  37.                 AND status = 1;
  38.             ");
  39.         $statement->bindValue('searchQuery'$searchParams['searchQuery']);
  40.         $statement->bindValue('percSearchQuery''%' $searchParams['searchQuery']);
  41.         $statement->bindValue('searchQueryPerc'$searchParams['searchQuery'] . '%');
  42.         $statement->execute();
  43.         $query $statement->fetchAll();
  44.         $paginator $this->get('knp_paginator');
  45.         $pagination $paginator->paginate(
  46.             $query,
  47.             $request->query->getInt('experts'1),
  48.             $limit,
  49.             array('pageParameterName' => 'experts''sortDirectionParameterName' => 'dir')
  50.         );
  51.         $ids = array();
  52.         foreach ($pagination->getItems() as $value) {
  53.             $ids[] = $value['id_ind'];
  54.         }
  55.         $indiv $em->getRepository('OceanExpertBundle:Indiv');
  56.         $experts $indiv->createQueryBuilder('i')
  57.             ->select('i,ix.instName,g.groupname,m.idGroup,m.role,c.country')
  58.             ->leftJoin('OceanExpertBundle:IndivInstitution''ii''WITH''ii.idInd = i.idInd')
  59.             ->leftJoin('OceanExpertBundle:Institutions''ix''WITH''ix.idInst = ii.idInst')
  60.             ->leftJoin('OceanExpertBundle:MemberGroups''m''WITH''i.idInd = m.idInd')
  61.             ->leftJoin('OceanExpertBundle:Groups''g''WITH''g.idGroup = m.idGroup')
  62.             ->leftJoin('OceanExpertBundle:Countries''c''WITH''c.idCountry = i.countryCode')
  63.             ->where('i.idInd IN (:group)')
  64.             ->andWhere('i.status = 1')
  65.             ->setParameter('group'$ids)
  66.             ->addOrderBy('ix.instName''DESC')
  67.             ->addOrderBy('i.sname''ASC')
  68.             ->getQuery()
  69.             ->getResult();
  70.         $em self::getDoctrine()->getManager();
  71.         $connection $em->getConnection();
  72.         $statement $connection->prepare("
  73.             SELECT 
  74.                 * 
  75.             FROM 
  76.                 institutions 
  77.             WHERE 
  78.                 (
  79.                     MATCH (inst_name,inst_name_eng,acronym) AGAINST (:searchQuery IN BOOLEAN MODE)
  80.                     OR inst_name LIKE :percSearchQuery 
  81.                     OR inst_name LIKE :searchQueryPerc 
  82.                     OR inst_name_eng LIKE :percSearchQuery 
  83.                     OR inst_name_eng LIKE :searchQueryPerc 
  84.                     OR acronym LIKE :percSearchQuery 
  85.                     OR acronym LIKE :searchQueryPerc
  86.                     OR activities LIKE :percSearchQueryPerc
  87.                 )
  88.                 AND activated = 1;
  89.         ");
  90.         $statement->bindValue('searchQuery'$searchParams['searchQuery']);
  91.         $statement->bindValue('percSearchQuery''%' $searchParams['searchQuery']);
  92.         $statement->bindValue('searchQueryPerc'$searchParams['searchQuery'] . '%');
  93.         $statement->bindValue('percSearchQueryPerc''%' $searchParams['searchQuery'] . '%');
  94.         $statement->execute();
  95.         $institutes $statement->fetchAll();
  96.         $institutesPage $paginator->paginate(
  97.             $institutes,
  98.             $request->query->getInt('insts'1),
  99.             12,
  100.             array(
  101.                 'pageParameterName' => 'insts',
  102.                 'sortDirectionParameterName' => 'dir'
  103.             )
  104.         );
  105.         $events $em->getRepository('OceanExpertBundle:Events');
  106.         $events $events->createQueryBuilder('e')
  107.             ->select('e')
  108.             ->where('e.title LIKE :searchQuery')
  109.             ->where('e.shorttitle LIKE :searchQuery')
  110.             ->where('e.summary LIKE :searchQuery')
  111.             ->setParameter('searchQuery''%' $searchParams['searchQuery'] . '%')
  112.             ->addOrderBy('e.title''ASC')
  113.             ->getQuery()
  114.             ->getResult();
  115.         $eventsPage $paginator->paginate(
  116.             $events,
  117.             $request->query->getInt('events'1),
  118.             10,
  119.             array('pageParameterName' => 'events''sortDirectionParameterName' => 'dir')
  120.         );
  121.         return $this->render(
  122.             'Search/generalSearch.html.twig',
  123.             array(
  124.                 'pagination' => $pagination,
  125.                 'experts' => $experts,
  126.                 'institutions' => $institutesPage,
  127.                 'events' => $eventsPage,
  128.                 'items' => array(),
  129.                 'qry' => $searchParams['searchQuery']
  130.             )
  131.         );
  132.     }
  133.     /**
  134.      * extract the possible filters from the results
  135.      * these can be used to filter down the results even move (especially in the webinterface)
  136.      *
  137.      * @param array $dataResult the results from a search
  138.      *
  139.      * @return array
  140.      */
  141.     static function getFilters(array $dataResult): array
  142.     {
  143.         $filters = array();
  144.         foreach(['type''country'] as $type) {
  145.             $filters[$type] = SearchController::getUnique(
  146.                 $dataResult,
  147.               $type
  148.             );
  149.         }
  150.         return $filters;
  151.     }
  152.     /**
  153.      * Extract all the params we need to do the search.
  154.      * These params should be reflected in the documentation of the API.
  155.      * As these are all the possible params that can be given and have effect on the result.
  156.      * They are shown here in alphabetic order to be sure there are no doubles in the variables.
  157.      *
  158.      * @param Request $request
  159.      *
  160.      * @return array all the params in an array
  161.      */
  162.     static function extractParams(Request $request): array
  163.     {
  164.         $searchParams['queryString']    = $request->query->all();
  165.         $searchParams['action']         = $request->query->get('action') ?? 'advSearch';
  166.         $searchParams['endDate']        = $request->query->get('endDate');
  167.         $searchParams['expertLname']    = $request->query->get('expertLname') ?? '';
  168.         $searchParams['expertSubject']  = $request->query->get('expertSubject') ?? '';
  169.         $searchParams['expertRegion']   = $request->query->get('expertRegion') ?? '';
  170.         $searchParams['instCountry']    = $request->query->get('instCountry') ?? '';
  171.         $searchParams['instName']       = $request->query->get('instName') ?? '';
  172.         $searchParams['instRegion']     = $request->query->get('instRegion') ?? '';
  173.         $searchParams['instType']       = $request->query->get('instType') ?? '';
  174.         $searchParams['searchKeywords'] = $request->query->get('keywords', array());
  175.         $searchParams['limit']          = $request->query->get('limit') ?? 10;
  176.         $searchParams['sortOrder']      = $request->query->get('order') ?? 'ASC';
  177.         $searchParams['searchQuery']    = $request->query->get('query') ?? '';
  178.         $searchParams['sortby']         = $request->query->get('sortby') ?? '';
  179.         $searchParams['startDate']      = $request->query->get('startDate');
  180.         $searchParams['searchToggle']   = $request->query->get('toggle');
  181.         //what kind of items are we looking for
  182.         $searchParams['searchType']     = $request->query->get('type', array());
  183.         //default value for the type when using browse should be 'all'
  184.         if (null == $request->query->get('type')
  185.             || $request->query->get('type') == ''
  186.             || (is_array($searchParams['searchType'])
  187.                 && !count($searchParams['searchType']))
  188.         ) {
  189.             $searchParams['searchType'] = array('all');
  190.         }
  191.         //search types should always be an array, even with one element
  192.         if (!is_array($searchParams['searchType'])) {
  193.             $searchParams['searchType'] = array($searchParams['searchType']);
  194.         }
  195.         //get rid of those empty types that get added somewhere by javascript
  196.         foreach ($searchParams['searchType'] as $key => $val) {
  197.             if ($val === '') {
  198.                 unset($searchParams['searchType'][$key]);
  199.             }
  200.         }
  201.         //independent of the searchType, what type should we use to filter the results
  202.         //typically after a search with searchType == all
  203.         $searchParams['searchFilterType']= $request->query->get('filterType');
  204.         //cleanup the filters
  205.         $searchParams['searchFilterType'] = array_unique(
  206.             explode(
  207.                 ',',
  208.                 $searchParams['searchFilterType']
  209.             )
  210.         );
  211.         if ($searchParams['searchFilterType'][0] == '') {
  212.             unset($searchParams['searchFilterType']);
  213.         }
  214.         //special case of FilterType
  215.         $searchParams['filterCountry']  = $request->query->get('filterCountry');
  216.         //not sure if this is used everywhere/somewhere and what it should do
  217.         $searchParams['searchFilter']   = $request->query->get('filter');
  218.         //cleanup the query
  219.         $searchParams['searchQuery'] = self::cleaned($searchParams['searchQuery']);
  220.         //remember the search conditions, so we can recreate the search in the interface
  221.         $conditions = array();
  222.         foreach ($searchParams['searchType'] as $i => $value) {
  223.             $conditions[$i]['type'] = $value;
  224.             if (!isset($searchParams['searchFilter'][$i])) {
  225.                 $searchParams['searchFilter'][$i] = '';
  226.             }
  227.             $conditions[$i]['filter'] = $searchParams['searchFilter'][$i];
  228.             $conditions[$i]['keywords'] = $searchParams['searchKeywords'][$i] ?? '';
  229.             if (!isset($searchParams['searchToggle'][$i])) {
  230.                 $searchParams['searchToggle'][$i] = ' OR ';
  231.             }
  232.             $conditions[$i]['toggle'] = $searchParams['searchToggle'][$i];
  233.             if (!isset($searchParams['startDate'][$i])) {
  234.                 $searchParams['startDate'][$i] = '';
  235.             }
  236.             $conditions[$i]['startDate'] = $searchParams['startDate'][$i];
  237.             if (!isset($searchParams['endDate'][$i])) {
  238.                 $searchParams['endDate'][$i] = '';
  239.             }
  240.             $conditions[$i]['endDate'] = $searchParams['endDate'][$i];
  241.         }
  242.         $searchParams['conditions'] = $conditions;
  243.         //what to do with the sortby if there is none defined (yet)
  244.         $sortFields = array(
  245.             'relevance' => 'Relevance'
  246.         );
  247.         if ($searchParams['sortby'] == '') {
  248.             //for all, experts and institutions use 'relevance' as sortby in case we have a search for 'name contains'
  249.             //in other cases use inst_name for institutions
  250.             // or sname for experts
  251.             if (!empty(array_intersect($searchParams['searchType'], array('all''experts''institutions')))
  252.                 && !empty(array_intersect(['Name contains'], $searchParams['searchFilter']))
  253.             ) {
  254.                 $searchParams['sortby'] = 'relevance';
  255.                 $sortFields['relevance'] = 'Relevance';
  256.             } elseif (!empty(array_intersect($searchParams['searchType'], array('experts')))) {
  257.                 $searchParams['sortby'] = 'sname';
  258.                 $sortFields['sname'] = 'Last Name';
  259.             } elseif (!empty(array_intersect($searchParams['searchType'], array('documents')))) {
  260.                 $searchParams['sortby'] = 'title';
  261.                 $sortFields['country'] = 'Country';
  262.             } elseif (!empty(array_intersect($searchParams['searchType'], array('institutions')))) {
  263.                 $searchParams['sortby'] = 'inst_name';
  264.                 $sortFields['inst_name'] = 'Institute Name';
  265.             }
  266.         }
  267.         //if we still have no sortby, default to sname for both browse and advSearch
  268.         if ($searchParams['sortby'] == ''
  269.             && ($searchParams['action'] == 'browse'
  270.                 || $searchParams['action'] == 'advSearch')
  271.         ) {
  272.             $searchParams['sortby'] = 'sname';
  273.             unset($sortFields['relevance']);
  274.             $sortFields['sname'] = 'Last Name';
  275.         }
  276.         if (count($searchParams['searchType'])) {
  277.             if (in_array('institutions'$searchParams['searchType'])) {
  278.                 unset($sortFields['relevance']);
  279.                 $sortFields['instType'] = 'Institute Type';
  280.                 $sortFields['name'] = 'Institute Name';
  281.             }
  282.             if (in_array('experts'$searchParams['searchType'])) {
  283.                 $sortFields['jobtitle'] = 'Position';
  284.                 $sortFields['sname'] = 'Last Name';
  285.             }
  286.             if (in_array('events'$searchParams['searchType'])) {
  287.                 $sortFields['eventtype'] = 'Event Type';
  288.             }
  289.             $sortFields['country'] = 'Country';
  290.         }
  291.         $searchParams['sortFields'] = $sortFields;
  292.         return $searchParams;
  293.     }
  294.     /**
  295.      * get the results for the search when action=browse
  296.      *
  297.      * @param array  $searchParams all the search parameters that have been passed in this request
  298.      * @param object $doctrine
  299.      *
  300.      * @return array with the results
  301.      */
  302.     public static function getBrowseSearchResults(array $searchParamsobject $doctrine): array
  303.     {
  304.         $connection $doctrine->getManager()->getConnection();
  305.         $searchResultType 'Browse Results';
  306.         $dataResult = array();
  307.         $sortFields $searchParams['sortFields'];
  308.         $message '';
  309.         //status=0 means everything is ok
  310.         $status 0;
  311.         if (is_array($searchParams['searchType'])
  312.             && count($searchParams['searchType']) > 1
  313.         ) {
  314.             //impossible for action=browse, this should be a simple query in the end
  315.             $message 'You can only have one (filter)type when you use action=browse.';
  316.             $message .= ' Provided (filter)types: ' implode(', '$searchParams['searchType']);
  317.             return array(
  318.                 'status' => 1,
  319.                 'message' => $message
  320.             );
  321.         }
  322.         //for the searchtype 'browse' we do not need an array of search types
  323.         if (isset($searchParams['searchType'])
  324.             && is_array($searchParams['searchType'])
  325.             && count($searchParams['searchType'])
  326.         ) {
  327.             $searchParams['searchType'] = $searchParams['searchType'][0];
  328.         }
  329.         if ($searchParams['searchQuery'] != '') {
  330.             $indiv = array();
  331.             $indivNames = array();
  332.             $indivGroups = array();
  333.             if (($searchParams['searchType'] == 'all'
  334.                     || $searchParams['searchType'] == 'experts'
  335.                 )
  336.                 && !(isset($searchParams['queryString']['searchType'])
  337.                     && $searchParams['queryString']['searchType'] === 'group')
  338.             ) {
  339.                 $newString self::fulltext($searchParams['searchQuery']);
  340.                 $stmtInd $connection->prepare("
  341.                         SELECT 
  342.                             'experts' AS type, 
  343.                             i.status, 
  344.                             i.id_ind, 
  345.                             i.title,   
  346.                             concat(i.fname,' ',i.sname) AS name,
  347.                             i.fname,
  348.                             i.mname,
  349.                             i.sname,
  350.                             i.jobtitle,
  351.                             i.addr_1,
  352.                             i.addr_2,
  353.                             i.city,
  354.                             i.state,
  355.                             i.postcode,
  356.                             i.use_inst_addr, 
  357.                             i.deceased, 
  358.                             i.retired, 
  359.                             i.quality_checked, 
  360.                             inst.inst_name,
  361.                             inst.inst_address,
  362.                             inst.addr_2 AS instAddr2,
  363.                             inst.city AS instCity,
  364.                             inst.state AS instState,
  365.                             inst.postcode AS instPostCode, 
  366.                             (IF(i.use_inst_addr = 1, ic.country, c.country)) AS country, 
  367.                             MATCH (i.fname,i.sname) AGAINST (:newString IN BOOLEAN MODE) AS relevance, 
  368.                             'zz' AS instType, 
  369.                             'zz' AS eventtype, 
  370.                             '' AS inst_logo, 
  371.                             'zz' AS name
  372.                         FROM 
  373.                             indiv i
  374.                             LEFT JOIN countries c ON c.id_country = i.country_code
  375.                             LEFT JOIN indiv_institution ii ON ii.id_ind = i.id_ind
  376.                             LEFT JOIN institutions inst ON inst.id_inst = ii.id_inst
  377.                             LEFT JOIN countries ic ON ic.id_country = inst.country_code
  378.                         WHERE 
  379.                             ( 
  380.                                 MATCH (fname, mname, sname) AGAINST (:newString IN BOOLEAN MODE) 
  381.                                 OR i.fname LIKE :percSearchQuery
  382.                                 OR i.fname LIKE :searchQueryPerc 
  383.                                 OR i.mname LIKE :percSearchQuery
  384.                                 OR i.mname LIKE :searchQueryPerc 
  385.                                 OR i.sname LIKE :percSearchQuery
  386.                                 OR i.sname LIKE :searchQueryPerc
  387.                                 OR i.private_address LIKE :percSearchQueryPerc
  388.                                 OR i.addr_1 LIKE :percSearchQueryPerc
  389.                                 OR i.addr_2 LIKE :percSearchQueryPerc
  390.                                 OR i.city LIKE :percSearchQueryPerc
  391.                                 OR i.state LIKE :percSearchQueryPerc
  392.                             ) 
  393.                             " $searchParams['indivStatus'] . '
  394.                         ORDER BY relevance DESC, sname ASC;
  395.                     ');
  396.                 $stmtInd->bindValue('newString'$newString);
  397.                 $stmtInd->bindValue('percSearchQuery''%' $searchParams['searchQuery']);
  398.                 $stmtInd->bindValue('searchQueryPerc'$searchParams['searchQuery'] . '%');
  399.                 $stmtInd->bindValue('percSearchQueryPerc''%' $searchParams['searchQuery'] . '%');
  400.                 $stmtInd->execute();
  401.                 $indiv $stmtInd->fetchAll();
  402.                 $sortFields['jobtitle'] = 'Position';
  403.             }
  404.             if ($searchParams['searchType'] == 'name') {
  405.                 $newString self::fulltext($searchParams['searchQuery']);
  406.                 $stmtInd $connection->prepare("
  407.                         SELECT 
  408.                             'experts' AS type, 
  409.                             i.status, 
  410.                             i.id_ind, 
  411.                             i.title,   
  412.                             concat(i.fname,' ',i.sname) AS name,
  413.                             i.fname,
  414.                             i.mname,
  415.                             i.sname,
  416.                             i.jobtitle,
  417.                             i.addr_1,
  418.                             i.addr_2,
  419.                             i.city,
  420.                             i.state,
  421.                             i.postcode,
  422.                             i.use_inst_addr, 
  423.                             i.deceased, 
  424.                             i.retired, 
  425.                             i.quality_checked, 
  426.                             inst.inst_name,
  427.                             inst.inst_address,
  428.                             inst.addr_2 AS instAddr2,
  429.                             inst.city AS instCity,
  430.                             inst.state AS instState,
  431.                             inst.postcode AS instPostCode, 
  432.                             (IF(i.use_inst_addr = 1, ic.country, c.country)) AS country, 
  433.                             MATCH (i.fname,i.sname) AGAINST (:newString IN BOOLEAN MODE) AS relevance, 
  434.                             'zz' AS instType, 
  435.                             'zz' AS eventtype, 
  436.                             '' AS inst_logo, 
  437.                             'zz' AS name
  438.                         FROM 
  439.                             indiv i
  440.                             LEFT JOIN countries c ON c.id_country = i.country_code
  441.                             LEFT JOIN indiv_institution ii ON ii.id_ind = i.id_ind
  442.                             LEFT JOIN institutions inst ON inst.id_inst = ii.id_inst
  443.                             LEFT JOIN countries ic ON ic.id_country = inst.country_code
  444.                         WHERE 
  445.                             ( 
  446.                                 MATCH (fname, mname, sname) AGAINST (:newString IN BOOLEAN MODE) 
  447.                                 OR i.fname LIKE :percSearchQuery
  448.                                 OR i.fname LIKE :searchQueryPerc 
  449.                                 OR i.mname LIKE :percSearchQuery
  450.                                 OR i.mname LIKE :searchQueryPerc 
  451.                                 OR i.sname LIKE :percSearchQuery
  452.                                 OR i.sname LIKE :searchQueryPerc
  453.                             ) 
  454.                             " $searchParams['indivStatus'] . '
  455.                         ORDER BY relevance DESC, sname ASC;
  456.                     ');
  457.                 $stmtInd->bindValue('newString'$newString);
  458.                 $stmtInd->bindValue('percSearchQuery''%' $searchParams['searchQuery']);
  459.                 $stmtInd->bindValue('searchQueryPerc'$searchParams['searchQuery'] . '%');
  460.                 $stmtInd->execute();
  461.                 $indivNames $stmtInd->fetchAll();
  462.                 $sortFields['jobtitle'] = 'Position';
  463.             }
  464.             if ($searchParams['searchType'] == 'all'
  465.                 || (isset($searchParams['queryString']['searchType'])
  466.                 && $searchParams['queryString']['searchType'] == 'group'
  467.                 && $searchParams['searchType'] == 'experts')
  468.                 || $searchParams['searchType'] == 'group'
  469.             ) {
  470.                 //looking for experts that are in a group that matches the searchTerm
  471.                 $newString self::fulltext($searchParams['searchQuery']);
  472.                 $stmtInd $connection->prepare("
  473.                         SELECT 
  474.                             'experts' AS type, 
  475.                             i.status, 
  476.                             i.id_ind, 
  477.                             i.title,   
  478.                             concat(i.fname,' ',i.sname) AS name,
  479.                             i.fname,
  480.                             i.mname,
  481.                             i.sname,
  482.                             i.jobtitle,
  483.                             i.addr_1,
  484.                             i.addr_2,
  485.                             i.city,
  486.                             i.state,
  487.                             i.postcode,
  488.                             i.use_inst_addr, 
  489.                             i.deceased, 
  490.                             i.retired, 
  491.                             i.quality_checked, 
  492.                             inst.inst_name,
  493.                             inst.inst_address,
  494.                             inst.addr_2 AS instAddr2,
  495.                             inst.city AS instCity,
  496.                             inst.state AS instState,
  497.                             inst.postcode AS instPostCode, 
  498.                             g.groupname AS groupName,
  499.                             g.id_group AS groupId,
  500.                             '' AS relevance,   
  501.                             (IF(i.use_inst_addr = 1, ic.country, c.country)) AS country
  502.                         FROM 
  503.                             indiv i
  504.                             LEFT JOIN countries c ON c.id_country = i.country_code
  505.                             LEFT JOIN indiv_institution ii ON ii.id_ind = i.id_ind
  506.                             LEFT JOIN institutions inst ON inst.id_inst = ii.id_inst
  507.                             LEFT JOIN countries ic ON ic.id_country = inst.country_code
  508.                             LEFT JOIN member_groups mg ON mg.id_ind = i.id_ind
  509.                             LEFT JOIN groups g ON mg.id_group = g.id_group
  510.                         WHERE 
  511.                             ( 
  512.                                 g.groupname LIKE :percSearchQueryPerc
  513.                             ) 
  514.                             " $searchParams['indivStatus'] . '
  515.                         ORDER BY sname ASC;
  516.                     ');
  517.                 $stmtInd->bindValue('percSearchQueryPerc''%' $searchParams['searchQuery'] . '%');
  518.                 $stmtInd->execute();
  519.                 $indivGroups $stmtInd->fetchAll();
  520.                 $sortFields['jobtitle'] = 'Position';
  521.             }
  522.             $institutes = array();
  523.             if ($searchParams['searchType'] == 'all'
  524.                 || $searchParams['searchType'] == 'institutions'
  525.             ) {
  526.                 $newString self::fulltext($searchParams['searchQuery']);
  527.                 $stmtInst $connection->prepare("
  528.                         SELECT 
  529.                             'institutions' AS type, 
  530.                             i.activated, 
  531.                             i.id_inst, 
  532.                             insttype_name AS instType, 
  533.                             inst_name,
  534.                             inst_name_eng,
  535.                             inst_address,
  536.                             addr_2,
  537.                             city AS instCity,
  538.                             state AS instState,
  539.                             postcode AS instPostCode,
  540.                             country,
  541.                             inst_logo,
  542.                             activities, 
  543.                             MATCH (inst_name,inst_name_eng,acronym) AGAINST (:newString) AS relevance, 
  544.                             'zz' AS jobtitle, 
  545.                             'zz' AS eventtype,
  546.                             'zz' AS fname,  
  547.                             'zz' AS sname, 
  548.                             'zz' AS name
  549.                         FROM 
  550.                             institutions i
  551.                             LEFT JOIN countries c ON c.id_country =  i.country_code
  552.                             LEFT JOIN insttypes it ON it.id_insttype =  i.inst_type_id
  553.                         WHERE 
  554.                             (
  555.                                 MATCH (inst_name,inst_name_eng,acronym) AGAINST (:newString IN BOOLEAN MODE)
  556.                                 OR inst_name LIKE :percSearchQueryPerc 
  557.                                 OR inst_name_eng LIKE :percSearchQueryPerc 
  558.                                 OR inst_address LIKE :percSearchQueryPerc 
  559.                                 OR addr_2 LIKE :percSearchQueryPerc 
  560.                                 OR city LIKE :percSearchQueryPerc 
  561.                                 OR state LIKE :percSearchQueryPerc 
  562.                                 OR acronym LIKE :percSearchQueryPerc 
  563.                                 OR activities LIKE :percSearchQueryPerc
  564.                             )
  565.                             " $searchParams['instStatus'] . '
  566.                         ORDER BY relevance DESC, i.inst_name ASC;
  567.                     ');
  568.                 $stmtInst->bindValue('newString'$newString);
  569.                 $stmtInst->bindValue('percSearchQueryPerc''%'.$searchParams['searchQuery'].'%');
  570.                 $stmtInst->execute();
  571.                 $institutes $stmtInst->fetchAll();
  572.                 $sortFields['instType'] = 'Institution Type';
  573.             }
  574.             $events = array();
  575.             if ($searchParams['searchType'] == 'all'
  576.                 || $searchParams['searchType'] == 'events'
  577.             ) {
  578.                 $sortFields['name'] = 'Event Title';
  579.                 if ($searchParams['sortby'] == '') {
  580.                     $searchParams['sortby'] = 'name';
  581.                 }
  582.                 $query "
  583.                         SELECT 
  584.                             'events' AS type, 
  585.                             et.eventtype_name AS eventtype, 
  586.                             e.status AS activated,
  587.                             e.id_event, 
  588.                             e.title AS name, 
  589.                             e.start_on,
  590.                             e.end_on, 
  591.                             e.address AS addr_1,
  592.                             e.city, 
  593.                             e.state, 
  594.                             c.country AS country,
  595.                             'zz' AS jobtitle, 
  596.                             'zz' AS instType,
  597.                             'zz' AS fname,
  598.                             'zz' AS sname,
  599.                             'zz' AS inst_name
  600.                         FROM 
  601.                             events e
  602.                             LEFT JOIN countries c on c.id_country =  e.id_country
  603.                             LEFT JOIN eventtypes et on et.id_eventtype =  e.id_eventtype
  604.                         WHERE 
  605.                             (
  606.                                 e.title LIKE :percSearchQueryPerc 
  607.                                 OR e.summary LIKE :percSearchQueryPerc
  608.                                 OR e.shorttitle LIKE :percSearchQueryPerc
  609.                                 OR e.keywords LIKE :percSearchQueryPerc
  610.                                 OR e.website LIKE :percSearchQueryPerc
  611.                                 OR e.city LIKE :percSearchQueryPerc
  612.                                 OR e.address LIKE :percSearchQueryPerc
  613.                             )
  614.                             " $searchParams['eventStatus'] . '
  615.                          ORDER BY e.title ASC;
  616.                      ';
  617.                 $stmtEvent $connection->prepare($query);
  618.                 $stmtEvent->bindValue('searchQuery'$searchParams['searchQuery']);
  619.                 $stmtEvent->bindValue('percSearchQueryPerc''%' $searchParams['searchQuery'] . '%');
  620.                 $stmtEvent->execute();
  621.                 $events $stmtEvent->fetchAll();
  622.                 $sortFields['eventtype'] = 'Event Type';
  623.             }
  624.             $documents = array();
  625.             if ($searchParams['searchType'] == 'all'
  626.                 || $searchParams['searchType'] == 'documents'
  627.             ) {
  628.                 $sortFields['title'] = 'Document Title';
  629.                 if ($searchParams['sortby'] == '') {
  630.                     $searchParams['sortby'] = 'title';
  631.                 }
  632.                 $query "
  633.                         SELECT 
  634.                             'documents' AS type, 
  635.                             d.id_doc,
  636.                             dt.doctypename AS documenttype, 
  637.                             d.title, 
  638.                             d.created_at,
  639.                             'undefined' AS country
  640.                         FROM 
  641.                              documents d, 
  642.                              doctypes dt 
  643.                         WHERE 
  644.                             dt.id_doctype = d.id_doctype
  645.                             AND d.title LIKE :percSearchQueryPerc
  646.                         ORDER BY d.title ASC
  647.                     ";
  648.                 $stmtDocument $connection->prepare($query);
  649.                 $stmtDocument->bindValue('percSearchQueryPerc''%' $searchParams['searchQuery'] . '%');
  650.                 $stmtDocument->execute();
  651.                 $documents $stmtDocument->fetchAll();
  652.                 $sortFields['documenttype'] = 'Document Type';
  653.             }
  654.             $dataResult array_unique(
  655.                 array_merge(
  656.                     $indiv,
  657.                     $indivNames,
  658.                     $indivGroups,
  659.                     $institutes,
  660.                     $events,
  661.                     $documents
  662.                 ),
  663.                 SORT_REGULAR
  664.             );
  665.             if ($searchParams['searchType'] == 'all') {
  666.                 if (count($dataResult) == 0) {
  667.                     $message 'We could not find any results matching "<strong>' self::cleaned($searchParams['searchQuery']) . ' </strong>". ';
  668.                     $message.= 'Please try again with different keyword(s).';
  669.                     return array(
  670.                         'status' => 3,
  671.                         'message' => $message,
  672.                         'dataResult' => array(),
  673.                         'searchResultType' => '',
  674.                         'sortFields' => array()
  675.                     );
  676.                 }
  677.                 $message 'Your search for "<strong>' self::cleaned($searchParams['searchQuery']) . '</strong>" ';
  678.                 $message.= 'returned <strong>' count($dataResult) . '</strong> result(s).';
  679.             } elseif ($searchParams['searchType'] == 'experts') {
  680.                 if (count($dataResult) == 0) {
  681.                     $message 'We could not find any results matching "<strong>' self::cleaned($searchParams['searchQuery']) . '</strong>" in Experts. ';
  682.                     $message.= 'Please try again with different keyword(s).';
  683.                     return array(
  684.                         'status' => 3,
  685.                         'message' => $message,
  686.                         'dataResult' => array(),
  687.                         'searchResultType' => '',
  688.                         'sortFields' => array()
  689.                     );
  690.                 }
  691.                 $message 'Your search for "<strong>' self::cleaned($searchParams['searchQuery']) . '</strong>" in "<strong>Experts</strong>" ';
  692.                 $message.= 'returned <strong>' count($dataResult) . '</strong> result(s).';
  693.             } elseif ($searchParams['searchType'] == 'institutions') {
  694.                 if (count($dataResult) == 0) {
  695.                     $message 'We could not find any results matching "<strong>' self::cleaned($searchParams['searchQuery']) . '</strong>" in Institutions. ';
  696.                     $message.= 'Please try again with different keyword(s).';
  697.                     return array(
  698.                         'status' => 3,
  699.                         'message' => $message,
  700.                         'dataResult' => array(),
  701.                         'searchResultType' => '',
  702.                         'sortFields' => array()
  703.                     );
  704.                 }
  705.                 $message 'Your search for "<strong>' self::cleaned($searchParams['searchQuery']) . '</strong>" in "<strong>Institutions</strong>" ';
  706.                 $message.= 'returned <strong>' count($dataResult) . '</strong> result(s).';
  707.             } elseif ($searchParams['searchType'] == 'documents') {
  708.                 $searchParams['countryName'] = '';
  709.                 $searchParams['expertLname'] = '';
  710.                 if (count($dataResult) == 0) {
  711.                     $message 'We could not find any results matching "<strong>' self::cleaned($searchParams['searchQuery']) . '</strong>" in the title of Documents. ';
  712.                     $message .= 'Please try again with different word(s).';
  713.                     return array(
  714.                         'status' => 3,
  715.                         'message' => $message,
  716.                         'dataResult' => array(),
  717.                         'searchResultType' => '',
  718.                         'sortFields' => array()
  719.                     );
  720.                 }
  721.                 $message "Your search for \"<strong>" self::cleaned($searchParams['searchQuery']) . "</strong>\" ";
  722.                 $message .= "in \"<strong>Documents</strong>\" ";
  723.                 $message .= "returned <strong>" count($dataResult) . "</strong> result(s).";
  724.             }
  725.         }
  726.         if ($searchParams['expertLname'] != '') {
  727.             $stmtInd $connection->prepare("
  728.                     SELECT 
  729.                         'experts' AS type, 
  730.                         i.status, 
  731.                         i.id_ind, 
  732.                         concat(i.fname, ' ', i.sname) AS name,
  733.                         i.fname,
  734.                         i.mname,
  735.                         i.sname,
  736.                         inst_name,
  737.                         jobtitle,
  738.                         i.addr_1,
  739.                         i.addr_2,
  740.                         i.city,
  741.                         i.state,
  742.                         i.postcode,
  743.                         inst.inst_address,
  744.                         inst.addr_2 AS instAddr2,
  745.                         inst.city AS instCity,
  746.                         inst.state AS instState,
  747.                         inst.postcode AS instPostCode, 
  748.                         use_inst_addr, 
  749.                         deceased, 
  750.                         retired, 
  751.                         quality_checked, 
  752.                         (IF(use_inst_addr = 1, ic.country, c.country)) AS country, 
  753.                         'zz' AS instType, 
  754.                         'zz' AS eventtype, 
  755.                         '' AS inst_logo
  756.                     FROM 
  757.                         indiv i
  758.                         LEFT JOIN countries c on c.id_country =  i.country_code
  759.                         LEFT JOIN indiv_institution ii on ii.id_ind = i.id_ind
  760.                         LEFT JOIN institutions inst on inst.id_inst = ii.id_inst
  761.                         LEFT JOIN countries ic on ic.id_country =  inst.country_code
  762.                     WHERE 
  763.                         (sname LIKE :expertLNamePerc)
  764.                         " $searchParams['indivStatus'] . 
  765.                     ORDER BY sname, fname ASC
  766.                 ');
  767.             $stmtInd->bindValue('expertLNamePerc'$searchParams['expertLname'] . '%');
  768.             $stmtInd->execute();
  769.             $dataResult $stmtInd->fetchAll();
  770.             $sortFields['jobtitle'] = 'Position';
  771.             $message 'There are <strong>' count($dataResult) . '</strong> experts ';
  772.             $message.= 'with their <strong>last name</strong> starting with "<strong>' self::cleaned($searchParams['expertLname']) . '</strong>".';
  773.         }
  774.         if ($searchParams['countryName'] != '') {
  775.             if ($searchParams['searchType'] == 'experts') {
  776.                 $query "
  777.                         SELECT 
  778.                             'experts' AS type, 
  779.                             i.status, 
  780.                             i.id_ind, 
  781.                             concat(i.fname,' ',i.sname) AS name,
  782.                             i.fname,
  783.                             i.mname,
  784.                             i.sname,
  785.                             inst_name,
  786.                             jobtitle,
  787.                             i.addr_1,
  788.                             i.addr_2,
  789.                             i.city,
  790.                             i.state,
  791.                             i.postcode,
  792.                             inst.inst_address,
  793.                             inst.addr_2 AS instAddr2,
  794.                             inst.city AS instCity,
  795.                             inst.state AS instState,
  796.                             inst.postcode AS instPostCode, 
  797.                             use_inst_addr, 
  798.                             deceased, 
  799.                             retired, 
  800.                             quality_checked, 
  801.                             (IF(use_inst_addr = 1, ic.country, c.country)) AS country, 
  802.                             'zz' AS instType, 
  803.                             'zz' AS eventtype, 
  804.                             '' AS inst_logo
  805.                         FROM    
  806.                             indiv i
  807.                             LEFT JOIN countries c on c.id_country =  i.country_code
  808.                             LEFT JOIN indiv_institution ii on ii.id_ind = i.id_ind
  809.                             LEFT JOIN institutions inst on inst.id_inst = ii.id_inst
  810.                             LEFT JOIN countries ic on ic.id_country =  inst.country_code
  811.                         WHERE 
  812.                             ( CASE WHEN use_inst_addr = 1 THEN ";
  813.                 if (strlen($searchParams['countryName']) === 1) {
  814.                     $query .= 'ic.country LIKE :countryNamePerc ELSE c.country LIKE :countryNamePerc END) ';
  815.                 } else {
  816.                     $query .= 'ic.country LIKE :countryName ELSE c.country LIKE :countryName END) ';
  817.                 }
  818.                 $query .=  $searchParams['indivStatus'] . ' ORDER BY sname ASC ';
  819.                 $stmtInd $connection->prepare($query);
  820.                 $stmtInd->bindValue('countryName'$searchParams['countryName']);
  821.                 $stmtInd->bindValue('countryNamePerc'$searchParams['countryName'] . '%');
  822.                 $stmtInd->execute();
  823.                 $dataResult $stmtInd->fetchAll();
  824.                 $sortFields['jobtitle'] = 'Position';
  825.                 $message 'There are <strong>' count($dataResult) . '</strong> experts ';
  826.                 $message.= 'located in <strong>countries with names</strong> starting with "<strong>' self::cleaned($searchParams['countryName']) . '</strong>".';
  827.                 if (isset($searchParams['referrer'])
  828.                     && ($searchParams['referrer'] == 'map')
  829.                 ) {
  830.                     $message 'There are <strong>' count($dataResult) . '</strong> experts ';
  831.                     $message.= 'located in  "<strong>' self::cleaned($searchParams['countryName']) . '</strong>".';
  832.                 }
  833.             } elseif ($searchParams['searchType'] == 'institution') {
  834.                 $stmtInd $connection->prepare("
  835.                         SELECT 
  836.                             'institutions' AS type, 
  837.                             insttype_name AS jobtitle, 
  838.                             i.activated, 
  839.                             i.id_inst, 
  840.                             insttype_name AS instType, 
  841.                             inst_name,
  842.                             inst_name_eng,
  843.                             inst_address,
  844.                             addr_2,
  845.                             city AS instCity,
  846.                             state AS instState,
  847.                             postcode AS instPostCode,
  848.                             country,
  849.                             activities, 
  850.                             inst_logo, 
  851.                             'zz' AS jobtitle,
  852.                             'zz' AS fname, 
  853.                             'zz' AS sname
  854.                         FROM 
  855.                             institutions i
  856.                             LEFT JOIN countries c on c.id_country =  i.country_code
  857.                             LEFT JOIN insttypes it on it.id_insttype =  i.inst_type_id
  858.                         WHERE 
  859.                             ( c.country LIKE '" $searchParams['countryName'] . "' )
  860.                             " $searchParams['instStatus'] . 
  861.                         ORDER BY inst_name ASC
  862.                     ');
  863.                 $stmtInd->execute();
  864.                 $dataResult $stmtInd->fetchAll();
  865.                 $sortFields['instType'] = 'Institution Type';
  866.                 $message 'There are <strong>' count($dataResult) . '</strong> experts ';
  867.                 $message.= 'located in <strong>countries with names</strong> starting with "<strong>' self::cleaned($searchParams['countryName']) . '</strong>".';
  868.                 if (isset($searchParams['referrer'])
  869.                     && ($searchParams['referrer'] == 'map')
  870.                 ) {
  871.                     $message 'There are <strong>' count($dataResult) . '</strong> experts ';
  872.                     $message.= 'located in  "<strong>' self::cleaned($searchParams['countryName']) . '</strong>".';
  873.                 }
  874.             }
  875.         }
  876.         if ($searchParams['expertSubject'] != '') {
  877.             $stmtInd $connection->prepare("
  878.                     SELECT 
  879.                         'experts' AS type, 
  880.                         i.status, 
  881.                         i.id_ind, 
  882.                         concat(i.fname,' ',i.sname) AS name,
  883.                         i.fname,
  884.                         i.mname,
  885.                         i.sname,
  886.                         inst_name,
  887.                         jobtitle,
  888.                         i.addr_1,
  889.                         i.addr_2,
  890.                         i.city,
  891.                         i.state,
  892.                         i.postcode,
  893.                         inst.inst_address,
  894.                         inst.addr_2 AS instAddr2,
  895.                         inst.city AS instCity,
  896.                         inst.state AS instState,
  897.                         inst.postcode AS instPostCode, 
  898.                         use_inst_addr, 
  899.                         deceased, 
  900.                         retired, 
  901.                         quality_checked, 
  902.                         (IF(use_inst_addr = 1, ic.country, c.country)) AS country, 
  903.                         'zz' AS instType, 
  904.                         'zz' AS eventtype, 
  905.                         '' AS inst_logo
  906.                     FROM 
  907.                         indiv i
  908.                         LEFT JOIN countries c on c.id_country =  i.country_code
  909.                         LEFT JOIN indiv_institution ii on ii.id_ind = i.id_ind
  910.                         LEFT JOIN institutions inst on inst.id_inst = ii.id_inst
  911.                         LEFT JOIN indiv_subjects ins on ins.id_ind = i.id_ind
  912.                         LEFT JOIN countries ic on ic.id_country =  inst.country_code
  913.                     WHERE 
  914.                         (ins.id_sub = :expertSubject)
  915.                         " $searchParams['indivStatus'] . 
  916.                     ORDER BY sname ASC
  917.                 ');
  918.             $stmtInd->bindValue('expertSubject'$searchParams['expertSubject']);
  919.             $stmtInd->execute();
  920.             $dataResult $stmtInd->fetchAll();
  921.             $sortFields['jobtitle'] = 'Position';
  922.             $message 'There are <strong>' count($dataResult) . '</strong> experts ';
  923.             $message.= "working in \"<strong>" self::getSubjectAreaById($searchParams['expertSubject'], $doctrine) . "</strong>\".";
  924.         }
  925.         if ($searchParams['expertRegion'] != '') {
  926.             $stmtInd $connection->prepare("
  927.                     SELECT 
  928.                         'experts' AS type, 
  929.                         i.status, 
  930.                         i.id_ind, 
  931.                         concat(i.fname,' ',i.sname) AS name,
  932.                         i.fname,
  933.                         i.mname,
  934.                         i.sname,
  935.                         inst_name,
  936.                         jobtitle,
  937.                         i.addr_1,
  938.                         i.addr_2,
  939.                         i.city,
  940.                         i.state,
  941.                         i.postcode,
  942.                         inst.inst_address,
  943.                         inst.addr_2 AS instAddr2,
  944.                         inst.city AS instCity,
  945.                         inst.state AS instState,
  946.                         inst.postcode AS instPostCode, 
  947.                         use_inst_addr, 
  948.                         deceased, 
  949.                         retired, 
  950.                         quality_checked, 
  951.                         (IF(use_inst_addr = 1, ic.country, c.country)) AS country, 
  952.                         'zz' AS instType, 
  953.                         'zz' AS eventtype, 
  954.                         '' AS inst_logo
  955.                     FROM 
  956.                         indiv i
  957.                         LEFT JOIN countries c on c.id_country =  i.country_code
  958.                         LEFT JOIN indiv_institution ii on ii.id_ind = i.id_ind
  959.                         LEFT JOIN institutions inst on inst.id_inst = ii.id_inst
  960.                         LEFT JOIN countries ic on ic.id_country =  inst.country_code
  961.                     WHERE 
  962.                         FIND_IN_SET (
  963.                             :expertRegion, 
  964.                             i.studyregion
  965.                         )
  966.                         " $searchParams['indivStatus'] . 
  967.                     ORDER BY sname ASC
  968.                 ');
  969.             $stmtInd->bindValue('expertRegion'$searchParams['expertRegion']);
  970.             $stmtInd->execute();
  971.             $dataResult $stmtInd->fetchAll();
  972.             $sortFields['jobtitle'] = 'Position';
  973.             $message 'There are <strong>' count($dataResult) . '</strong> experts ';
  974.             $message.= "working in the \"<strong>" self::getSeaRegionById($searchParams['expertRegion'], $doctrine) . "</strong>\".";
  975.         }
  976.         if ($searchParams['instName'] != '') {
  977.             $stmtInst $connection->prepare("
  978.                     SELECT 
  979.                         'institutions' AS type, 
  980.                         i.activated, 
  981.                         i.id_inst, 
  982.                         insttype_name AS instType, 
  983.                         inst_name,
  984.                         inst_name_eng,
  985.                         inst_address,
  986.                         addr_2,
  987.                         city AS instCity,
  988.                         state AS instState,
  989.                         postcode AS instPostCode,
  990.                         country,
  991.                         activities, 
  992.                         inst_logo, 
  993.                         'zz' AS jobtitle, 
  994.                         'zz' AS eventtype,
  995.                         'zz' AS fname, 
  996.                         'zz' AS sname
  997.                     FROM 
  998.                         institutions i
  999.                         LEFT JOIN countries c on c.id_country =  i.country_code
  1000.                         LEFT JOIN insttypes it on it.id_insttype =  i.inst_type_id
  1001.                     WHERE 
  1002.                         ( 
  1003.                             inst_name LIKE :instNamePerc
  1004.                             OR inst_name_eng LIKE :instNamePerc 
  1005.                             OR acronym LIKE :instNamePerc
  1006.                         )
  1007.                         " $searchParams['instStatus'] . 
  1008.                     ORDER BY inst_name ASC 
  1009.                 ");
  1010.             $stmtInst->bindValue('instNamePerc'$searchParams['instName'] . '%');
  1011.             $stmtInst->execute();
  1012.             $dataResult $stmtInst->fetchAll();
  1013.             $sortFields['instType'] = 'Institution Type';
  1014.             $sortFields['inst_name'] = 'Institution Name';
  1015.             $searchParams['sortby'] = 'inst_name';
  1016.             $message 'There are <strong>' count($dataResult) . '</strong> institutions ';
  1017.             $message.= 'with their name starting with "<strong>' self::cleaned($searchParams['instName']) . '</strong>".';
  1018.         }
  1019.         if ($searchParams['instCountry'] != '') {
  1020.             $stmtInst $connection->prepare("
  1021.                     SELECT 
  1022.                         'institutions' AS type, 
  1023.                         i.activated, 
  1024.                         i.id_inst, 
  1025.                         insttype_name AS instType, 
  1026.                         inst_name,
  1027.                         inst_name_eng,
  1028.                         inst_address,
  1029.                         addr_2,
  1030.                         city AS instCity,
  1031.                         state AS instState,
  1032.                         postcode AS instPostCode,
  1033.                         country,
  1034.                         activities, 
  1035.                         inst_logo, 
  1036.                         'zz' AS jobtitle, 
  1037.                         'zz' AS eventtype,
  1038.                         'zz' AS fname, 
  1039.                         'zz' AS sname
  1040.                     FROM 
  1041.                         institutions i
  1042.                         LEFT JOIN countries c on c.id_country =  i.country_code
  1043.                         LEFT JOIN insttypes it on it.id_insttype =  i.inst_type_id
  1044.                     WHERE 
  1045.                         ( c.country LIKE :instCountryPerc )
  1046.                         " $searchParams['instStatus'] . 
  1047.                     ORDER BY inst_name ASC 
  1048.                 ');
  1049.             $stmtInst->bindValue('instCountryPerc'$searchParams['instCountry'] . '%');
  1050.             $stmtInst->execute();
  1051.             $dataResult $stmtInst->fetchAll();
  1052.             $sortFields['instType'] = 'Institution Type';
  1053.             $sortFields['inst_name'] = 'Institution Name';
  1054.             $searchParams['sortby'] = 'inst_name';
  1055.             $message 'There are <strong>' count($dataResult) . '</strong> institutions ';
  1056.             $message.= 'located in countries with names starting with "<strong>' self::cleaned($searchParams['instCountry']) . '</strong>".';
  1057.         }
  1058.         if ($searchParams['instRegion'] != '') {
  1059.             $stmtInst $connection->prepare("
  1060.                     SELECT 
  1061.                         'institutions' AS type, 
  1062.                         i.activated, 
  1063.                         i.id_inst, 
  1064.                         insttype_name AS instType, 
  1065.                         inst_name,
  1066.                         inst_name_eng,
  1067.                         inst_address,
  1068.                         addr_2,
  1069.                         city AS instCity,
  1070.                         state AS instState,
  1071.                         postcode AS instPostCode,
  1072.                         country,
  1073.                         activities,
  1074.                         inst_logo, 
  1075.                         'zz' AS jobtitle, 
  1076.                         'zz' AS eventtype,
  1077.                         'zz' AS fname, 
  1078.                         'zz' AS sname
  1079.                     FROM 
  1080.                         institutions i
  1081.                         LEFT JOIN countries c on c.id_country =  i.country_code
  1082.                         LEFT JOIN insttypes it on it.id_insttype =  i.inst_type_id
  1083.                     WHERE 
  1084.                         FIND_IN_SET (
  1085.                             :instRegion, 
  1086.                             i.inst_region
  1087.                         )
  1088.                         " $searchParams['instStatus'] . 
  1089.                     ORDER BY inst_name ASC 
  1090.                 ');
  1091.             $stmtInst->bindValue('instRegion'$searchParams['instRegion']);
  1092.             $stmtInst->execute();
  1093.             $dataResult $stmtInst->fetchAll();
  1094.             $sortFields['instType'] = 'Institution Type';
  1095.             $sortFields['inst_name'] = 'Institution Name';
  1096.             $searchParams['sortby'] = 'inst_name';
  1097.             $message 'There are <strong>' count($dataResult) . '</strong> institutions ';
  1098.             $message.= 'working in the "<strong>' self::getSeaRegionById($searchParams['instRegion'], $doctrine) . '</strong>".';
  1099.         }
  1100.         if ($searchParams['instType'] != '') {
  1101.             $stmtInst $connection->prepare("
  1102.                     SELECT 
  1103.                         'institutions' AS type, 
  1104.                         i.activated, 
  1105.                         i.id_inst, 
  1106.                         insttype_name AS instType, 
  1107.                         inst_name,
  1108.                         inst_name_eng,
  1109.                         inst_address,
  1110.                         addr_2,
  1111.                         city AS instCity,
  1112.                         state AS instState,
  1113.                         postcode AS instPostCode,
  1114.                         country,
  1115.                         activities,
  1116.                         inst_logo, 
  1117.                         'zz' AS jobtitle, 
  1118.                         'zz' AS eventtype,
  1119.                         'zz' AS fname, 
  1120.                         'zz' AS sname
  1121.                     FROM 
  1122.                         institutions i
  1123.                         LEFT JOIN countries c on c.id_country =  i.country_code
  1124.                         LEFT JOIN insttypes it on it.id_insttype =  i.inst_type_id
  1125.                     WHERE 
  1126.                         ( i.inst_type_id = :instType) 
  1127.                         " $searchParams['instStatus'] . 
  1128.                     ORDER BY inst_name ASC 
  1129.                 ');
  1130.             $stmtInst->bindValue('instType'$searchParams['instType']);
  1131.             $stmtInst->execute();
  1132.             $dataResult $stmtInst->fetchAll();
  1133.             $sortFields['instType'] = 'Institution Type';
  1134.             $sortFields['inst_name'] = 'Institution Name';
  1135.             $searchParams['sortby'] = 'inst_name';
  1136.             $message 'There are <strong>' count($dataResult) . '</strong> institutions ';
  1137.             $message.= 'with type "<strong>' SearchController::getInstituteTypeById($searchParams['instType'], $doctrine) . '</strong>".';
  1138.         }
  1139.         //status=0 means everything is ok
  1140.         return array(
  1141.             'status' => $status,
  1142.             'dataResult' => $dataResult,
  1143.             'sortFields' => $sortFields,
  1144.             'sortby' => $searchParams['sortby'],
  1145.             'message' => $message,
  1146.             'searchResultType' => $searchResultType
  1147.         );
  1148.     }
  1149.     /**
  1150.      * get the results for the search when action=advSearch
  1151.      *
  1152.      * @param array  $searchParams all the search parameters that have been passed in this request
  1153.      * @param object $doctrine
  1154.      *
  1155.      * @return array with the results
  1156.      */
  1157.     public static function getAdvSearchResults(array $searchParamsobject $doctrine): array
  1158.     {
  1159.         $connection $doctrine->getManager()->getConnection();
  1160.         $searchResultType 'Advanced Search Results';
  1161.         $dataResult = array();
  1162.         $sortBy $searchParams['sortby'];
  1163.         //$searchParams['sortby'] = 'sname';
  1164.         $messageStart 'Your search for ';
  1165.         $messagePart '';
  1166.         $sortFields $searchParams['sortFields'];
  1167.         if (isset($searchParams['searchType'])
  1168.             && isset($searchParams['searchType'][0])
  1169.             && $searchParams['searchType'][0] === 'all'
  1170.             && !count($searchParams['queryString'])
  1171.         ) {
  1172.             //we don't want a search for all types with specific search params
  1173.             return array(
  1174.                 'status' => 0,
  1175.                 'dataResult' => array(),
  1176.                 'sortFields' => $sortFields,
  1177.                 'sortby' => 'relevance',
  1178.                 'message' => 'we cannot show the results, too many results!!!!',
  1179.                 'searchResultType' => $searchResultType
  1180.             );
  1181.         } elseif (isset($searchParams['searchType'])
  1182.             && count($searchParams['searchType']) > 0
  1183.         ) {
  1184.             //dump($searchParams);
  1185.             //where to store the results for the different types
  1186.             $dataResultInd = array();
  1187.             $dataResultInst = array();
  1188.             $dataResultEvent = array();
  1189.             $dataResultDocument = array();
  1190.             $instCondCnt 1;
  1191.             $endQueryInst false;
  1192.             $endQueryInd false;
  1193.             $endQueryEvent false;
  1194.             $endQueryDocument false;
  1195.             $whereInd ' WHERE ( 1=1 ';
  1196.             $whereInst ' WHERE ( 1=1 ';
  1197.             $whereEvent ' WHERE ( 1=1 ';
  1198.             $whereDocument '';
  1199.             $joinsInd '';
  1200.             $searchParams['searchToggle'][-1] = ' AND ';
  1201.             $operationInd ' AND ';
  1202.             $operationInst ' AND ';
  1203.             $operationEvent ' AND ';
  1204.             $operation '';
  1205.             foreach ($searchParams['searchType'] as $key => $type) {
  1206.                 if (isset($searchParams['searchKeywords'])
  1207.                     && isset($searchParams['searchKeywords'][$key])
  1208.                 ) {
  1209.                     if (is_array($searchParams['searchKeywords'][$key])) {
  1210.                         $tmpString = array();
  1211.                         foreach($searchParams['searchKeywords'][$key] as $value) {
  1212.                             $tmpString[] = addcslashes($value,'\'');
  1213.                         }
  1214.                         $string implode(','$tmpString);
  1215.                     } else {
  1216.                         $string addcslashes($searchParams['searchKeywords'][$key], '\'');
  1217.                     }
  1218.                 } else {
  1219.                     $string '';
  1220.                 }
  1221.                 //what kind of filter are we using
  1222.                 //there should be one at least, except for type=all
  1223.                 if (isset($searchParams['searchFilter'][$key])) {
  1224.                     $value $searchParams['searchFilter'][$key] ?? '';
  1225.                 } else {
  1226.                     $value $searchParams['searchFilter'][array_key_last($searchParams['searchFilter'])];
  1227.                 }
  1228.                 if ($type != 'all'
  1229.                     && $value == ''
  1230.                 ) {
  1231.                     continue;
  1232.                 }
  1233.                 if ($type == 'experts') {
  1234.                     if ($sortBy == '') {
  1235.                         $sortBy 'sname';
  1236.                     }
  1237.                     $bindValues[$type][$key] = array();
  1238.                     $selectQryInd "
  1239.                             SELECT 
  1240.                                 'experts' AS type, 
  1241.                                 i.status, 
  1242.                                 i.id_ind, 
  1243.                                 concat(i.fname,' ',i.sname) AS name,
  1244.                                 i.fname,
  1245.                                 i.mname,
  1246.                                 i.sname,
  1247.                                 inst.inst_name,
  1248.                                 i.jobtitle,
  1249.                                 i.addr_1,
  1250.                                 i.addr_2,
  1251.                                 i.city,
  1252.                                 i.state,
  1253.                                 i.postcode,
  1254.                                 inst.inst_address,
  1255.                                 inst.addr_2 AS instAddr2,
  1256.                                 inst.city AS instCity,
  1257.                                 inst.state AS instState,
  1258.                                 inst.postcode AS instPostCode, 
  1259.                                 i.use_inst_addr, 
  1260.                                 deceased, 
  1261.                                 retired, 
  1262.                                 quality_checked, 
  1263.                                 (CASE WHEN i.use_inst_addr = 1 THEN ic.country ELSE c.country END) AS country, 
  1264.                                 'zz' AS instType, 
  1265.                                 'zz' AS eventtype, 
  1266.                                 '' AS inst_logo ";
  1267.                     $commonJoins ' LEFT JOIN countries c on c.id_country =  i.country_code
  1268.                                 LEFT JOIN indiv_institution ii on ii.id_ind = i.id_ind
  1269.                                 LEFT JOIN institutions inst on inst.id_inst = ii.id_inst
  1270.                                 LEFT JOIN countries ic on ic.id_country =  inst.country_code ';
  1271.                     $matchOrder '';
  1272.                     switch ($value) {
  1273.                         case 'Name contains':
  1274.                             $newString self::fulltext($string);
  1275.                             $selectQryInd .= " , MATCH (fname, mname, sname) AGAINST ('$newString' IN BOOLEAN MODE) AS relevance ";
  1276.                             $whereInd .= ' ' $operationInd " ( i.fname LIKE  :percString$key
  1277.                                                     OR i.fname LIKE  :stringPerc$key
  1278.                                                     OR i.mname LIKE  :percString$key
  1279.                                                     OR i.mname LIKE  :stringPerc$key
  1280.                                                     OR i.sname LIKE  :percString$key
  1281.                                                     OR i.sname LIKE  :stringPerc$key
  1282.                                                     OR MATCH (fname, mname, sname) AGAINST ('$newString' IN BOOLEAN MODE) ) ";
  1283.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1284.                             $messagePart .= "in $type ";
  1285.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1286.                             $matchOrder ' ORDER BY relevance DESC';
  1287.                             //remember what value has to be bound to what placeholder
  1288.                             $bindValues[$type][$key] = array(
  1289.                                 'percString' $key => '%' $string,
  1290.                                 'stringPerc' $key => $string '%'
  1291.                             );
  1292.                             break;
  1293.                         case 'First name contains':
  1294.                             $whereInd .= ' ' $operationInd " ( 
  1295.                                                        i.fname LIKE  :percString$key
  1296.                                                     OR i.fname LIKE  :stringPerc$key ) ";
  1297.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1298.                             $messagePart .= "in $type ";
  1299.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1300.                             //remember what value has to be bound to what placeholder
  1301.                             $bindValues[$type][$key] = array(
  1302.                                 'percString' $key => '%' $string,
  1303.                                 'stringPerc' $key => $string '%'
  1304.                             );
  1305.                             break;
  1306.                         case 'Last name contains':
  1307.                             $whereInd .= ' ' $operationInd "( 
  1308.                                                        i.sname LIKE  :percString$key
  1309.                                                     OR i.sname LIKE  :stringPerc$key ) ";
  1310.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1311.                             $messagePart .= "in $type ";
  1312.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1313.                             //remember what value has to be bound to what placeholder
  1314.                             $bindValues[$type][$key] = array(
  1315.                                 'percString' $key => '%' $string,
  1316.                                 'stringPerc' $key => $string '%'
  1317.                             );
  1318.                             break;
  1319.                         case 'Worklocation contains':
  1320.                             $whereInd .= ' ' $operationInd 
  1321.                                         ( CASE 
  1322.                                             WHEN i.use_inst_addr = 1 THEN 
  1323.                                                 inst.inst_address LIKE  :percStringPerc$key
  1324.                                                     OR inst.addr_2 LIKE  :percStringPerc$key
  1325.                                                     OR inst.city LIKE  :percStringPerc$key
  1326.                                                     OR inst.state LIKE  :percStringPerc$key
  1327.                                             ELSE 
  1328.                                                 i.addr_1 LIKE  :percStringPerc$key
  1329.                                                     OR i.addr_2 LIKE  :percStringPerc$key
  1330.                                                     OR i.city LIKE  :percStringPerc$key
  1331.                                                     OR i.state LIKE  :percStringPerc$key
  1332.                                                     OR i.private_address LIKE  :percStringPerc$key
  1333.                                             END
  1334.                                         ) ";
  1335.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1336.                             $messagePart .= "in $type ";
  1337.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1338.                             //remember what value has to be bound to what placeholder
  1339.                             $bindValues[$type][$key] = array(
  1340.                                 'percStringPerc' $key => '%' $string '%'
  1341.                             );
  1342.                             break;
  1343.                         /*
  1344.                          * should not be used
  1345.                          * #680
  1346.                         case 'Current/Previous addresses contain':
  1347.                             $joinsInd .= ' LEFT JOIN previous_addresses pa on pa.id_record = i.id_ind ';
  1348.                             $whereInd .= ' ' . $operationInd . "
  1349.                                             ( CASE
  1350.                                                 WHEN i.use_inst_addr = 1 THEN
  1351.                                                     inst.inst_address LIKE  :percStringPerc$key
  1352.                                                         OR inst.addr_2 LIKE  :percStringPerc$key
  1353.                                                         OR inst.city LIKE  :percStringPerc$key
  1354.                                                         OR inst.state LIKE  :percStringPerc$key
  1355.                                                 ELSE
  1356.                                                     i.addr_1 LIKE  :percStringPerc$key
  1357.                                                         OR i.addr_2 LIKE  :percStringPerc$key
  1358.                                                         OR i.city LIKE  :percStringPerc$key
  1359.                                                         OR i.state LIKE  :percStringPerc$key
  1360.                                                         OR i.private_address LIKE  :percStringPerc$key
  1361.                                                         OR pa.city LIKE  :percStringPerc$key
  1362.                                                         OR pa.state LIKE  :percStringPerc$key
  1363.                                                         OR pa.address LIKE  :percStringPerc$key
  1364.                                                 END
  1365.                                             ) ";
  1366.                             $messagePart .= "$operation \"<strong>" . self::cleaned($string) . "</strong>\" ";
  1367.                             $messagePart .= "in $type ";
  1368.                             $messagePart .= "using filter \"<strong>" . self::readableFilter($value) . "</strong>\" ";
  1369.                             //remember what value has to be bound to what placeholder
  1370.                             $bindValues[$type][$key] = array(
  1371.                                 'percStringPerc' . $key => '%' . $string . '%'
  1372.                             );
  1373.                             break;
  1374.                         */
  1375.                         case 'Phone/Fax contains':
  1376.                             $whereInd .= ' ' $operationInd " (
  1377.                                                        i.tel LIKE  :percStringPerc$key
  1378.                                                     OR i.fax LIKE  :percStringPerc$key
  1379.                                                     )";
  1380.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1381.                             $messagePart .= "in $type ";
  1382.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1383.                             //remember what value has to be bound to what placeholder
  1384.                             $bindValues[$type][$key] = array(
  1385.                                 'percStringPerc' $key => '%' $string '%'
  1386.                             );
  1387.                             break;
  1388.                         case 'Email contains':
  1389.                             $whereInd .= ' ' $operationInd " (
  1390.                                                        i.email1 LIKE  :percStringPerc$key
  1391.                                                     OR i.email2 LIKE  :percStringPerc$key
  1392.                                                     OR i.email3 LIKE  :percStringPerc$key
  1393.                                                     ) ";
  1394.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1395.                             $messagePart .= "in $type ";
  1396.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1397.                             //remember what value has to be bound to what placeholder
  1398.                             $bindValues[$type][$key] = array(
  1399.                                 'percStringPerc' $key => '%' $string '%'
  1400.                             );
  1401.                             break;
  1402.                         case 'Website URL contains':
  1403.                             $whereInd .= ' ' $operationInd " (
  1404.                                                        i.url1 LIKE  :percStringPerc$key
  1405.                                                     OR i.url2 LIKE  :percStringPerc$key
  1406.                                                     OR i.url3 LIKE  :percStringPerc$key
  1407.                                                     ) ";
  1408.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1409.                             $messagePart .= "in $type ";
  1410.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1411.                             //remember what value has to be bound to what placeholder
  1412.                             $bindValues[$type][$key] = array(
  1413.                                 'percStringPerc' $key => '%' $string '%'
  1414.                             );
  1415.                             break;
  1416.                         case 'Worklocation is':
  1417.                             $whereInd .= ' ' $operationInd 
  1418.                                             ( CASE 
  1419.                                                 WHEN i.use_inst_addr = 1 THEN
  1420.                                                        inst.country_code = $string
  1421.                                                 ELSE
  1422.                                                        i.country_code = $string
  1423.                                                 END
  1424.                                             ) ";
  1425.                             $messagePart .= "$operation $type from  \"<strong>" self::getCountryById($string$doctrine) . "</strong>\" ";
  1426.                             break;
  1427.                         case 'In multiple countries':
  1428.                             $string implode(','$string);
  1429.                             $whereInd .= ' ' $operationInd 
  1430.                                             ( CASE 
  1431.                                                 WHEN i.use_inst_addr = 1 THEN
  1432.                                                     inst.country_code in ($string)
  1433.                                                 ELSE
  1434.                                                     i.country_code in ($string)
  1435.                                                 END
  1436.                                             ) ";
  1437.                             $messagePart .= "$operation $type from the region ";
  1438.                             $messagePart .= '"<strong>' self::getRegionById($idRegion$doctrine) . '</strong>" ';
  1439.                             $messagePart .= ' (' implode(', 'self::getMultipleCountriesById($string$doctrine)) . ') ';
  1440.                             break;
  1441.                         case 'Sea regions of study is':
  1442.                             $whereInd .= ' ' $operationInd " (
  1443.                                                        FIND_IN_SET ('$string', i.studyregion)
  1444.                                                     ) ";
  1445.                             $messagePart .= "$operation \"<strong>" self::getSeaRegionById($string$doctrine) . "</strong>\" ";
  1446.                             $messagePart .= "in $type ";
  1447.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1448.                             break;
  1449.                         case 'Member of group or sub-group':
  1450.                             $groups implode(','self::getChildGroup($string$doctrine));
  1451.                             $joinsInd .= ' LEFT JOIN member_groups mg ON mg.id_ind = i.id_ind ';
  1452.                             $whereInd .= ' ' $operationInd " (
  1453.                                                         mg.id_group IN ($groups)
  1454.                                                     ) ";
  1455.                             $messagePart .= "$operation \"<strong>" self::getGroupById($string$doctrine) . "</strong>\" ";
  1456.                             $messagePart .= "in $type ";
  1457.                             $messagePart .= "using filter \"<strong>Member of group OR sub-group</strong>\" ";
  1458.                             break;
  1459.                         case 'Job type is':
  1460.                             $joinsInd .= " LEFT JOIN indiv_jobtype ij ON ij.id_ind = i.id_ind ";
  1461.                             $whereInd .= ' ' $operationInd " (
  1462.                                                        id_job = $string
  1463.                                                     ) ";
  1464.                             $messagePart .= "$operation \"<strong>" self::getJobTypesById($string$doctrine) . "</strong>\" ";
  1465.                             $messagePart .= "in $type ";
  1466.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1467.                             break;
  1468.                         case 'Job title contains':
  1469.                             $whereInd .= ' ' $operationInd " (
  1470.                                                        i.jobtitle LIKE  :percString$key
  1471.                                                     OR i.jobtitle LIKE  :stringPerc$key
  1472.                                                     ) ";
  1473.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1474.                             $messagePart .= "in $type ";
  1475.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1476.                             //remember what value has to be bound to what placeholder
  1477.                             $bindValues[$type][$key] = array(
  1478.                                 'percString' $key => '%' $string,
  1479.                                 'stringPerc' $key => $string '%'
  1480.                             );
  1481.                             break;
  1482.                         case 'Department contains':
  1483.                             $whereInd .= ' ' $operationInd " (
  1484.                                                        i.dept LIKE  :percString$key
  1485.                                                     OR i.dept LIKE  :stringPerc$key
  1486.                                                     ) ";
  1487.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1488.                             $messagePart .= "in $type ";
  1489.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1490.                             //remember what value has to be bound to what placeholder
  1491.                             $bindValues[$type][$key] = array(
  1492.                                 'percString' $key => '%' $string,
  1493.                                 'stringPerc' $key => $string '%'
  1494.                             );
  1495.                             break;
  1496.                         case 'Institution name contains':
  1497.                             $whereInd .= ' ' $operationInd " (
  1498.                                                        inst.inst_name LIKE  :percStringPerc$key
  1499.                                                     OR inst.inst_name_eng LIKE  :percStringPerc$key
  1500.                                                     OR inst.acronym LIKE  :percStringPerc$key
  1501.                                                     ) ";
  1502.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1503.                             $messagePart .= "in $type ";
  1504.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1505.                             //remember what value has to be bound to what placeholder
  1506.                             $bindValues[$type][$key] = array(
  1507.                                 'percStringPerc' $key => '%' $string '%'
  1508.                             );
  1509.                             break;
  1510.                         case 'Subject Area is':
  1511.                             $joinsInd .= " LEFT JOIN indiv_meta im ON im.indiv_id = i.id_ind ";
  1512.                             $whereInd .= ' ' $operationInd " (
  1513.                                                        im.meta_option = 'researcharea'
  1514.                                                     AND im.meta_value LIKE  :percStringPerc$key
  1515.                                                     ) ";
  1516.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1517.                             $messagePart .= "in $type ";
  1518.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1519.                             //remember what value has to be bound to what placeholder
  1520.                             $bindValues[$type][$key] = array(
  1521.                                 'percStringPerc' $key => '%' $string '%'
  1522.                             );
  1523.                             break;
  1524.                         case 'Activities include':
  1525.                             $whereInd .= ' ' $operationInd " (
  1526.                                                        i.activeng LIKE  :percStringPerc$key
  1527.                                                     ) ";
  1528.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1529.                             $messagePart .= "in $type ";
  1530.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1531.                             //remember what value has to be bound to what placeholder
  1532.                             $bindValues[$type][$key] = array(
  1533.                                 'percStringPerc' $key => '%' $string '%'
  1534.                             );
  1535.                             break;
  1536.                         case 'Citations include':
  1537.                             $joinsInd .= " LEFT JOIN indiv_meta im ON im.indiv_id = i.id_ind ";
  1538.                             $whereInd .= ' ' $operationInd " (
  1539.                                                         (
  1540.                                                             im.meta_option = 'researcharea'
  1541.                                                             AND im.meta_value LIKE  :percStringPerc$key
  1542.                                                         )
  1543.                                                         OR (
  1544.                                                             im.meta_option = 'other-citation'
  1545.                                                             AND im.meta_value LIKE  :percStringPerc$key
  1546.                                                         )
  1547.                                                         OR (
  1548.                                                             im.meta_option = 'researchgate'
  1549.                                                             AND im.meta_value LIKE  :percStringPerc$key
  1550.                                                         )
  1551.                                                     ) ";
  1552.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1553.                             $messagePart .= "in $type ";
  1554.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1555.                             //remember what value has to be bound to what placeholder
  1556.                             $bindValues[$type][$key] = array(
  1557.                                 'percStringPerc' $key => '%' $string '%'
  1558.                             );
  1559.                             break;
  1560.                         case 'Working languages includes':
  1561.                             $whereInd .= ' ' $operationInd " (
  1562.                                                        FIND_IN_SET ('$string', i.languages)
  1563.                                                     ) ";
  1564.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1565.                             $messagePart .= "in $type ";
  1566.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1567.                             break;
  1568.                         case 'Degree contains':
  1569.                             $whereInd .= ' ' $operationInd " (
  1570.                                                        i.degree LIKE  :percStringPerc$key
  1571.                                                     ) ";
  1572.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1573.                             $messagePart .= "in $type ";
  1574.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1575.                             //remember what value has to be bound to what placeholder
  1576.                             $bindValues[$type][$key] = array(
  1577.                                 'percStringPerc' $key => '%' $string '%'
  1578.                             );
  1579.                             break;
  1580.                         case 'Is retired':
  1581.                             $whereInd .= ' ' $operationInd " (
  1582.                                                        i.retired = $string
  1583.                                                     ) ";
  1584.                             $messagePart .= "$operation experts who are \"<strong>Retired</strong>\" ";
  1585.                             break;
  1586.                         case 'Is deceased':
  1587.                             $whereInd .= ' ' $operationInd " (
  1588.                                                        i.deceased = $string
  1589.                                                     ) ";
  1590.                             $messagePart .= "$operation  experts who are \"<strong>Deceased</strong>\" ";
  1591.                             break;
  1592.                         case 'Is quality checked':
  1593.                             $whereInd .= ' ' $operationInd " (
  1594.                                                        i.quality_checked = $string
  1595.                                                     ) ";
  1596.                             $messagePart .= "$operation experts who are \"<strong>Quality checked</strong>\" ";
  1597.                             break;
  1598.                         case 'Comment contains':
  1599.                             $whereInd .= ' ' $operationInd " (
  1600.                                                        i.comments LIKE  :percStringPerc$key
  1601.                                                     ) ";
  1602.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1603.                             $messagePart .= "in $type ";
  1604.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1605.                             //remember what value has to be bound to what placeholder
  1606.                             $bindValues[$type][$key] = array(
  1607.                                 'percStringPerc' $key => '%' $string '%'
  1608.                             );
  1609.                             break;
  1610.                         case 'Is Active':
  1611.                             $whereInd .= ' ' $operationInd " (
  1612.                                                         i.status = $string
  1613.                                                 ) ";
  1614.                             if ($string == '1') {
  1615.                                 $messagePart .= "$operation expert is <strong>Active</strong> ";
  1616.                             } else {
  1617.                                 $messagePart .= "$operation expert is <strong>not active</strong> ";
  1618.                             }
  1619.                             break;
  1620.                         case 'Gender is':
  1621.                             // #734 we have different values for this 'gender' filter
  1622.                             // 'male' and 'female' are simple
  1623.                             // but we have 'na', 'other' and '' in the database
  1624.                             // '' and 'na' mean 'prefer not to say'
  1625.                             // 'other' means 'other'
  1626.                             $whereInd .= ' ' $operationInd " ( 
  1627.                                                         i.gender = '$string' ";
  1628.                             if ($string == 'na') {
  1629.                                 $whereInd .= ' OR i.gender = "" ';
  1630.                                 $string 'Prefer not to say';
  1631.                             } else {
  1632.                                 $string ucfirst($string);
  1633.                             }
  1634.                             $whereInd .= ' ) ';
  1635.                             $messagePart .= "$operation $type \"<strong>" self::readableFilter($value) . "</strong>\"  \"<strong>$string</strong>\" ";
  1636.                             break;
  1637.                         case 'Do Not Invite':
  1638.                             $whereInd .= ' ' $operationInd " (
  1639.                                                         i.do_not_invite = 1
  1640.                                                 ) ";
  1641.                             $messagePart .= "$operation $type using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1642.                             break;
  1643.                         case 'Unique Identifier':
  1644.                             $whereInd .= ' ' $operationInd " (
  1645.                                                 i.id_ind = '$string'
  1646.                                                 ) ";
  1647.                             $messagePart .= "$operation $type having unique identifier \"<strong>$string</strong>\" ";
  1648.                             break;
  1649.                         case 'Updated':
  1650.                             $startDate = isset($searchParams['startDate'][$key]) ? "l_date_upd >= '" self::cleanDate($searchParams['startDate'][$key]) . "' " "1=1 ";
  1651.                             $endDate = isset($searchParams['endDate'][$key]) ? "and l_date_upd <= '" self::cleanDate($searchParams['endDate'][$key]) . "' " " AND 1=1 ";
  1652.                             $whereInd .= ' ' $operationInd ' ' $startDate ' ' $endDate;
  1653.                             $messagePart .= "$operation $type updated ";
  1654.                             $messagePart .= "between \"<strong>" self::cleaned($searchParams['startDate'][$key]) . "</strong>\" ";
  1655.                             $messagePart .= "and \"<strong>" self::cleaned($searchParams['endDate'][$key]) . "</strong>\" ";
  1656.                             break;
  1657.                         case 'Created':
  1658.                             $startDate = isset($searchParams['startDate'][$key]) ? "f_date_ent >= '" self::cleanDate($searchParams['startDate'][$key]) . "' " "1=1 ";
  1659.                             $endDate = isset($searchParams['endDate'][$key]) ? "and f_date_ent <= '" self::cleanDate($searchParams['endDate'][$key]) . "' " " AND 1=1 ";
  1660.                             $whereInd .= ' ' $operationInd ' ' $startDate ' ' $endDate;
  1661.                             $messagePart .= "$operation $type \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1662.                             $messagePart .= "between \"<strong>" self::cleaned($searchParams['startDate'][$key]) . "</strong>\" ";
  1663.                             $messagePart .= "and \"<strong>" self::cleaned($searchParams['endDate'][$key]) . "</strong>\" ";
  1664.                             break;
  1665.                         case 'Quality last checked':
  1666.                             $startDate = isset($searchParams['startDate'][$key]) ? "quality_checked_date > '" self::cleanDate($searchParams['startDate'][$key]) . "' " "1=1 ";
  1667.                             $endDate = isset($searchParams['endDate'][$key]) ? "and quality_checked_date < '" self::cleanDate($searchParams['endDate'][$key]) . "' " " AND 1=1 ";
  1668.                             $whereInd .= ' ' $operationInd ' ' $startDate ' ' $endDate;
  1669.                             $messagePart .= "$operation $type \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1670.                             $messagePart .= "between \"<strong>" self::cleaned($searchParams['startDate'][$key]) . "</strong>\" ";
  1671.                             $messagePart .= "and \"<strong>" self::cleaned($searchParams['endDate'][$key]) . "</strong>\" ";
  1672.                             break;
  1673.                         default:
  1674.                             break;
  1675.                     }
  1676.                     $operationInd $searchParams['searchToggle'][$key] ?? " OR ";
  1677.                     $operation $searchParams['searchToggle'][$key] ?? " OR ";
  1678.                 } elseif ($type == 'institutions') {
  1679.                     if ($sortBy == '') {
  1680.                         $sortBy 'name';
  1681.                     }
  1682.                     $bindValues[$type][$key] = array();
  1683.                     $selectQryInst "
  1684.                             SELECT 
  1685.                                 'institutions' AS type, 
  1686.                                 i.activated, 
  1687.                                 i.id_inst, 
  1688.                                 it.insttype_name AS instType, 
  1689.                                 i.inst_name,
  1690.                                 i.inst_name_eng,
  1691.                                 i.inst_address,
  1692.                                 i.addr_2,
  1693.                                 i.city AS instCity,
  1694.                                 i.state AS instState,
  1695.                                 i.postcode AS instPostCode,
  1696.                                 c.country,
  1697.                                 i.activities,
  1698.                                 i.inst_logo,
  1699.                                 i.parent_id,   
  1700.                                 '' AS jobtitle, 
  1701.                                 '' AS eventtype,
  1702.                                 '' AS fname, 
  1703.                                 '' AS sname
  1704.                             FROM 
  1705.                                 institutions i
  1706.                         ";
  1707.                     $joinsInst ' LEFT JOIN countries c ON c.id_country =  i.country_code
  1708.                                         LEFT JOIN insttypes it ON it.id_insttype =  i.inst_type_id ';
  1709.                     switch ($value) {
  1710.                         case 'Name contains':
  1711.                             $whereInst .= ' ' $operationInst " ( 
  1712.                                                    i.inst_name LIKE  :percStringPerc$key
  1713.                                                 OR i.inst_name_eng LIKE  :percStringPerc$key
  1714.                                                 OR i.acronym LIKE  :percStringPerc$key
  1715.                                                         ) ";
  1716.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1717.                             $messagePart .= "in $type ";
  1718.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1719.                             //remember what value has to be bound to what placeholder
  1720.                             $bindValues[$type][$key] = array(
  1721.                                 'percStringPerc' $key => '%' $string '%'
  1722.                             );
  1723.                             break;
  1724.                         /**
  1725.                          * does not exist
  1726.                          *
  1727.                         case 'Worklocation contains':
  1728.                             $whereInst .= ' ' . $operationInst . " ( 
  1729.                                                           i.inst_address LIKE  :percStringPerc$key
  1730.                                                     OR i.addr_2 LIKE  :percStringPerc$key
  1731.                                                     OR i.city LIKE  :percStringPerc$key
  1732.                                                     OR i.state LIKE  :percStringPerc$key
  1733.                                                        ) ";
  1734.                             $messagePart .= "$operation \"<strong>" . self::cleaned($string) . "</strong>\" ";
  1735.                             $messagePart .= "in $type ";
  1736.                             $messagePart .= "using filter \"<strong>" . self::readableFilter($value) . "</strong>\" ";
  1737.                             //remember what value has to be bound to what placeholder
  1738.                             $bindValues[$type][$key] = array(
  1739.                                 'percStringPerc' . $key => '%' . $string . '%'
  1740.                             );
  1741.                             break;
  1742.                         */
  1743.                         /*
  1744.                          * #680
  1745.                          *
  1746.                         case 'Current/Previous addresses contain':
  1747.                             $whereInst .= ' ' . $operationInst . " (
  1748.                                                           i.inst_address LIKE  :percString$key
  1749.                                                     OR i.addr_2 LIKE  :percStringPerc$key
  1750.                                                     OR i.city LIKE  :percStringPerc$key
  1751.                                                     OR i.state LIKE  :percStringPerc$key
  1752.                                                        ) ";
  1753.                             $messagePart .= "$operation \"<strong>" . self::cleaned($string) . "</strong>\" ";
  1754.                             $messagePart .= "in $type ";
  1755.                             $messagePart .= "using filter \"<strong>" . self::readableFilter($value) . "</strong>\" ";
  1756.                             //remember what value has to be bound to what placeholder
  1757.                             $bindValues[$type][$key] = array(
  1758.                                 'percString' . $key => '%' . $string,
  1759.                                 'percStringPerc' . $key => '%' . $string . '%'
  1760.                             );
  1761.                             break;
  1762.                         */
  1763.                         case 'Country is':
  1764.                             $whereInst .= ' ' $operationInst " ( 
  1765.                                                           i.country_code = $string
  1766.                                                        ) ";
  1767.                             $messagePart .= "$operation $type ";
  1768.                             $messagePart .= "from  \"<strong>" self::getCountryById($string$doctrine) . "</strong>\" ";
  1769.                             break;
  1770.                         case 'Country in region':
  1771.                             $idRegion $string;
  1772.                             //reset $string, will be an array
  1773.                             $string = array();
  1774.                             //get the countries in that region
  1775.                             //and create an array with the ids of the countries
  1776.                             $countriesInRegion self::getCountriesInRegion($idRegion$doctrine);
  1777.                             foreach ($countriesInRegion as $country) {
  1778.                                 $string[] = $country->getIdCountry();
  1779.                             }
  1780.                             $string implode(','$string);
  1781.                             //this is identical to 'Worklocation in countries'
  1782.                             $whereInst .= ' ' $operationInd " ( 
  1783.                                                     i.country_code in ($string)
  1784.                                             ) ";
  1785.                             $messagePart .= "$operation $type from the region ";
  1786.                             $messagePart .= '"<strong>' self::getRegionById($idRegion$doctrine) . '</strong>" ';
  1787.                             $messagePart .= ' (' implode(', 'self::getMultipleCountriesById($string$doctrine)) . ') ';
  1788.                             break;
  1789.                         case 'Sea regions of study is':
  1790.                             $whereInst .= ' ' $operationInst " ( 
  1791.                                                           FIND_IN_SET ('$string', i.inst_region)
  1792.                                                        ) ";
  1793.                             $messagePart .= "$operation $type ";
  1794.                             $messagePart .= "having $value \"<strong>" self::getSeaRegionById($string$doctrine) . "</strong>\" ";
  1795.                             break;
  1796.                         case 'Type is':
  1797.                             $whereInst .= ' ' $operationInst " ( 
  1798.                                                           i.inst_type_id = $string
  1799.                                                        ) ";
  1800.                             $messagePart .= "$operation $type having " self::readableFilter($value) . " \"<strong>";
  1801.                             $messagePart .= SearchController::getInstituteTypeById($string$doctrine) . "</strong>\"";
  1802.                             break;
  1803.                         case 'Activities contains':
  1804.                             $whereInst .= ' ' $operationInst " (
  1805.                                                     i.activities LIKE  :percStringPerc$key
  1806.                                                     ) ";
  1807.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1808.                             $messagePart .= "in $type ";
  1809.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1810.                             //remember what value has to be bound to what placeholder
  1811.                             $bindValues[$type][$key] = array(
  1812.                                 'percStringPerc' $key => '%' $string '%'
  1813.                             );
  1814.                             break;
  1815.                         case 'Tel/Fax contains':
  1816.                             $whereInst .= ' ' $operationInst " ( 
  1817.                                                           i.inst_tel LIKE  :percStringPerc$key
  1818.                                                     OR i.inst_fax LIKE  :percStringPerc$key
  1819.                                                        ) ";
  1820.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1821.                             $messagePart .= "in $type ";
  1822.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1823.                             //remember what value has to be bound to what placeholder
  1824.                             $bindValues[$type][$key] = array(
  1825.                                 'percStringPerc' $key => '%' $string '%'
  1826.                             );
  1827.                             break;
  1828.                         case 'Website URL contains':
  1829.                             $whereInst .= ' ' $operationInst " ( 
  1830.                                                           i.inst_url LIKE  :percStringPerc$key
  1831.                                                        ) ";
  1832.                             $messagePart .= "$operation \"<strong" self::cleaned($string) . "</strong>\" ";
  1833.                             $messagePart .= "in $type ";
  1834.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1835.                             //remember what value has to be bound to what placeholder
  1836.                             $bindValues[$type][$key] = array(
  1837.                                 'percStringPerc' $key => '%' $string '%'
  1838.                             );
  1839.                             break;
  1840.                         case 'EDMO Code is':
  1841.                             $whereInst .= ' ' $operationInst " ( 
  1842.                                                           i.edmo_code = '$string'
  1843.                                                           AND edmo_code != 0
  1844.                                                           ) ";
  1845.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  1846.                             $messagePart .= "in $type ";
  1847.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1848.                             break;
  1849.                         case 'Updated':
  1850.                             $startDate = isset($searchParams['startDate'][$key]) ? "l_date_updated >= '" self::cleanDate($searchParams['startDate'][$key]) . "' " "1=1 ";
  1851.                             $endDate = isset($searchParams['endDate'][$key]) ? "AND l_date_updated <= '" self::cleanDate($searchParams['endDate'][$key]) . "' " " AND 1=1 ";
  1852.                             $whereInst .= ' ' $operationInst ' ' $startDate ' ' $endDate;
  1853.                             $messagePart .= "$operation $type \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1854.                             $messagePart .= "between \"<strong>" self::cleaned($searchParams['startDate'][$key]) . "</strong>\" ";
  1855.                             $messagePart .= "and \"<strong>" self::cleaned($searchParams['endDate'][$key]) . "</strong>\" ";
  1856.                             break;
  1857.                         case 'Created':
  1858.                             $startDate = isset($searchParams['startDate'][$key]) ? "f_date_entered >= '" self::cleanDate($searchParams['startDate'][$key]) . "' " "1=1 ";
  1859.                             $endDate = isset($searchParams['endDate'][$key]) ? "AND f_date_entered <= '" self::cleanDate($searchParams['endDate'][$key]) . "' " " AND 1=1 ";
  1860.                             $whereInst .= ' ' $operationInst ' ' $startDate ' ' $endDate;
  1861.                             $messagePart .= "$operation $type \"<strong>" self::readableFilter($value) . "</strong>\" ";
  1862.                             $messagePart .= "between \"<strong>" self::cleaned($searchParams['startDate'][$key]) . "</strong>\" ";
  1863.                             $messagePart .= "and \"<strong>" self::cleaned($searchParams['endDate'][$key]) . "</strong>\" ";
  1864.                             break;
  1865.                     }
  1866.                     $instCondCnt++;
  1867.                     $operationInst $searchParams['searchToggle'][$key] ?? " OR ";
  1868.                     $operation $searchParams['searchToggle'][$key] ?? " OR ";
  1869.                 } elseif ($type == 'all') {
  1870.                     $newString self::fulltext($string);
  1871.                     $stmtInd $connection->prepare("
  1872.                             SELECT 
  1873.                                 'experts' AS type, 
  1874.                                 i.status, 
  1875.                                 i.id_ind, 
  1876.                                 concat(i.fname,' ',i.sname) AS name, 
  1877.                                 i.fname,
  1878.                                 i.mname,
  1879.                                 i.sname, 
  1880.                                 inst_name,
  1881.                                 jobtitle,
  1882.                                 i.addr_1,
  1883.                                 i.addr_2,
  1884.                                 i.city,
  1885.                                 i.state,
  1886.                                 i.postcode,
  1887.                                 inst.inst_address,
  1888.                                 inst.addr_2 AS instAddr2,
  1889.                                 inst.city AS instCity,
  1890.                                 inst.state AS instState,
  1891.                                 inst.postcode AS instPostCode, 
  1892.                                 use_inst_addr, 
  1893.                                 deceased, 
  1894.                                 retired, 
  1895.                                 quality_checked, 
  1896.                                 (IF(use_inst_addr = 1, ic.country, c.country)) AS country, 
  1897.                                 MATCH (fname, sname) AGAINST (:newString IN BOOLEAN MODE) AS relevance, 
  1898.                                 'zz' AS instType, 
  1899.                                 'zz' AS eventtype, 
  1900.                                 '' AS inst_logo
  1901.                             FROM 
  1902.                                 indiv i
  1903.                                 LEFT JOIN countries c ON c.id_country =  i.country_code
  1904.                                 LEFT JOIN indiv_institution ii ON ii.id_ind = i.id_ind
  1905.                                 LEFT JOIN institutions inst ON inst.id_inst = ii.id_inst
  1906.                                 LEFT JOIN countries ic ON ic.id_country =  inst.country_code
  1907.                             WHERE 
  1908.                                 ( 
  1909.                                     MATCH (fname, mname, sname) AGAINST (:newString IN BOOLEAN MODE)
  1910.                                     OR fname LIKE :string
  1911.                                     OR fname LIKE :stringPerc
  1912.                                     OR fname LIKE :percString
  1913.                                     OR mname LIKE :stringPerc
  1914.                                     OR mname LIKE :percString
  1915.                                     OR sname LIKE :stringPerc
  1916.                                     OR sname LIKE :percString
  1917.                                 )
  1918.                                 " $searchParams['indivStatus'] . '
  1919.                             ORDER BY relevance DESC, i.sname ASC;
  1920.                         ');
  1921.                     $stmtInd->bindValue('newString'$newString);
  1922.                     $stmtInd->bindValue('string'$string);
  1923.                     $stmtInd->bindValue('percString''%' $string);
  1924.                     $stmtInd->bindValue('stringPerc'$string '%');
  1925.                     $stmtInd->bindValue('percStringPerc''%' $string '%');
  1926.                     $stmtInd->execute();
  1927.                     $dataResultInd $stmtInd->fetchAll();
  1928.                     $sortFields['jobtitle'] = 'Position';
  1929.                     $stmtInst $connection->prepare("
  1930.                             SELECT 
  1931.                                 'institutions' AS type, 
  1932.                                 i.activated, 
  1933.                                 i.id_inst, 
  1934.                                 insttype_name AS instType, 
  1935.                                 inst_name,
  1936.                                 inst_name_eng,
  1937.                                 inst_address,
  1938.                                 addr_2,
  1939.                                 city AS instCity,
  1940.                                 state AS instState,
  1941.                                 postcode AS instPostCode,
  1942.                                 country,
  1943.                                 activities,
  1944.                                 inst_logo,
  1945.                                 'zz' AS jobtitle, 
  1946.                                 MATCH (inst_name,inst_name_eng,acronym) AGAINST (:newString) AS relevance, 
  1947.                                 'zz' AS eventtype, 
  1948.                                 'zz' AS fname, 
  1949.                                 'zz' AS sname
  1950.                             FROM 
  1951.                                 institutions i
  1952.                                 LEFT JOIN countries c ON c.id_country =  i.country_code
  1953.                                 LEFT JOIN insttypes it ON it.id_insttype =  i.inst_type_id
  1954.                             WHERE 
  1955.                                 (
  1956.                                     MATCH (inst_name, inst_name_eng, acronym) AGAINST (:newString IN BOOLEAN MODE)
  1957.                                     OR inst_name LIKE :percStringPerc
  1958.                                     OR inst_name_eng LIKE :percStringPerc
  1959.                                     OR acronym LIKE :percStringPerc
  1960.                                     OR activities LIKE :percStringPerc
  1961.                                 )
  1962.                                  " $searchParams['instStatus'] . '
  1963.                             ORDER BY relevance DESC, i.inst_name ASC;
  1964.                         ');
  1965.                     $stmtInst->bindValue('newString'$newString);
  1966.                     $stmtInst->bindValue('percStringPerc''%' $string '%');
  1967.                     $stmtInst->execute();
  1968.                     $dataResultInst $stmtInst->fetchAll();
  1969.                     $sortFields['instType'] = 'Institution Type';
  1970.                     /**
  1971.                      *    Will be taken care when PPC
  1972.                      */
  1973.                     $stmtEvent $connection->prepare("
  1974.                             SELECT 
  1975.                                 'events' AS type, 
  1976.                                 et.eventtype_name AS eventtype, 
  1977.                                 e.status AS activated, 
  1978.                                 e.id_event, 
  1979.                                 e.title AS name, 
  1980.                                 e.start_on, 
  1981.                                 e.end_on, 
  1982.                                 e.address AS addr_1, 
  1983.                                 e.city, 
  1984.                                 e.state, 
  1985.                                 c.country AS country, 
  1986.                                 'zz' AS jobtitle, 
  1987.                                 'zz' AS instType, 
  1988.                                 'zz' AS fname, 
  1989.                                 'zz' AS sname, 
  1990.                                 'zz' AS inst_name
  1991.                             FROM 
  1992.                                 events e
  1993.                                 LEFT JOIN countries c on c.id_country =  e.id_country
  1994.                                 LEFT JOIN eventtypes et on et.id_eventtype =  e.id_eventtype
  1995.                             WHERE 
  1996.                                 (
  1997.                                     title LIKE  :percStringPerc
  1998.                                     OR shorttitle LIKE  :percStringPerc
  1999.                                     OR summary LIKE  :percStringPerc
  2000.                                     OR keywords LIKE  :percStringPerc
  2001.                                 )
  2002.                                 " $searchParams['eventStatus'] . '
  2003.                             ORDER BY start_on desc
  2004.                         ');
  2005.                     $stmtEvent->bindValue('percStringPerc''%' $string '%');
  2006.                     $stmtEvent->execute();
  2007.                     $dataResultEvent $stmtEvent->fetchAll();
  2008.                     $messagePart .= ' "<strong>' self::cleaned($string) . '</strong>" ';
  2009.                 } elseif ($type == 'events') {
  2010.                     $sortFields['name'] = 'Event Title';
  2011.                     if ($sortBy == '') {
  2012.                         $sortBy 'name';
  2013.                     }
  2014.                     $bindValues[$type][$key] = array();
  2015.                     $selectQryEvent "
  2016.                             SELECT 
  2017.                                 'events' AS type, 
  2018.                                 et.eventtype_name AS eventtype, 
  2019.                                 e.status AS activated, 
  2020.                                 e.id_event, 
  2021.                                 e.title AS name, 
  2022.                                 e.start_on, 
  2023.                                 e.end_on, 
  2024.                                 e.address AS addr_1, 
  2025.                                 e.city, 
  2026.                                 e.state, 
  2027.                                 c.country AS country, 
  2028.                                 'zz' AS jobtitle, 
  2029.                                 'zz' AS instType,
  2030.                                 'zz' AS fname, 
  2031.                                 'zz' AS sname
  2032.                             FROM 
  2033.                                  events e ";
  2034.                     $joinsEvent ' LEFT JOIN countries c ON c.id_country = e.id_country
  2035.                                        LEFT JOIN eventtypes et ON et.id_eventtype = e.id_eventtype ';
  2036.                     switch ($value) {
  2037.                         case 'Title contains':
  2038.                             $whereEvent .= ' ' $operationEvent " (
  2039.                                                   e.title LIKE  :percStringPerc$key
  2040.                                                        ) ";
  2041.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  2042.                             $messagePart .= "in $type ";
  2043.                             $messagePart .= "using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2044.                             //remember what value has to be bound to what placeholder
  2045.                             $bindValues[$type][$key] = array(
  2046.                                 'percStringPerc' $key => '%' $string '%'
  2047.                             );
  2048.                             break;
  2049.                         case 'eType is':
  2050.                             $whereEvent .= ' ' $operationEvent " (
  2051.                                                   e.id_eventtype = $string
  2052.                                                        ) ";
  2053.                             $messagePart .= "$operation $type ";
  2054.                             $messagePart .= "having Event Type \"<strong>" SearchController::getInstituteTypeById($string$doctrine) . "</strong>\" ";
  2055.                             break;
  2056.                         case 'Summary contains':
  2057.                             $whereEvent .= ' ' $operationEvent " (
  2058.                                                   e.summary LIKE  :percStringPerc$key
  2059.                                                        ) ";
  2060.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  2061.                             $messagePart .= "in $type using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2062.                             //remember what value has to be bound to what placeholder
  2063.                             $bindValues[$type][$key] = array(
  2064.                                 'percStringPerc' $key => '%' $string '%'
  2065.                             );
  2066.                             break;
  2067.                         case 'Keywords contain':
  2068.                             $whereEvent .= ' ' $operationEvent " (
  2069.                                                e.keywords LIKE  :percStringPerc$key
  2070.                                               ) ";
  2071.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  2072.                             $messagePart .= "in $type using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2073.                             //remember what value has to be bound to what placeholder
  2074.                             $bindValues[$type][$key] = array(
  2075.                                 'percStringPerc' $key => '%' $string '%'
  2076.                             );
  2077.                             break;
  2078.                         case 'Address contains':
  2079.                             $whereEvent .= ' ' $operationEvent " (
  2080.                                                e.address LIKE  :percStringPerc$key
  2081.                                                OR e.city LIKE  :percStringPerc$key
  2082.                                                OR e.state LIKE  :percStringPerc$key
  2083.                                               ) ";
  2084.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  2085.                             $messagePart .= "in $type using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2086.                             //remember what value has to be bound to what placeholder
  2087.                             $bindValues[$type][$key] = array(
  2088.                                 'percStringPerc' $key => '%' $string '%'
  2089.                             );
  2090.                             break;
  2091.                         case 'Country is':
  2092.                             dump($string);
  2093.                             $whereEvent .= ' ' $operationEvent " (
  2094.                                                e.id_country = $string
  2095.                                               ) ";
  2096.                             $messagePart .= "$operation $type ";
  2097.                             $messagePart .= "from  \"<strong>" self::getCountryById($string$doctrine) . "</strong>\" ";
  2098.                             break;
  2099.                         case 'Country in region':
  2100.                             $idRegion $string;
  2101.                             //reset $string, will be an array
  2102.                             $string = array();
  2103.                             //get the countries in that region
  2104.                             //and create an array with the ids of the countries
  2105.                             $countriesInRegion self::getCountriesInRegion($idRegion$doctrine);
  2106.                             foreach ($countriesInRegion as $country) {
  2107.                                 $string[] = $country->getIdCountry();
  2108.                             }
  2109.                             $string implode(','$string);
  2110.                             $whereEvent .= ' ' $operationInd " ( 
  2111.                                                     e.id_country in ($string)
  2112.                                              ) ";
  2113.                             $messagePart .= "$operation $type from the region ";
  2114.                             $messagePart .= '"<strong>' self::getRegionById($idRegion$doctrine) . '</strong>" ';
  2115.                             $messagePart .= ' (' implode(', 'self::getMultipleCountriesById($string$doctrine)) . ') ';
  2116.                             break;
  2117.                         case 'Date between':
  2118.                             $date '';
  2119.                             $messagePart .= "$operation $type with parameters '<strong>" self::readableFilter($value) . "</strong>': ";
  2120.                             if (isset($searchParams['startDate'][$key])
  2121.                                 && $searchParams['startDate'][$key] != ''
  2122.                                 && isset($searchParams['endDate'][$key])
  2123.                                 && $searchParams['endDate'][$key] != ''
  2124.                             ) {
  2125.                                 $startDate self::cleanDate($searchParams['startDate'][$key]);
  2126.                                 $endDate self::cleanDate($searchParams['endDate'][$key]);
  2127.                                 $date " start_on >= '$startDate
  2128.                                         AND end_on <= '$endDate' ";
  2129.                                 $messagePart .= "between '<strong>$startDate</strong>' ";
  2130.                                 $messagePart .= "and '<strong>$endDate</strong>' ";
  2131.                             } elseif (isset($searchParams['startDate'][$key])
  2132.                                 && (!$searchParams['endDate'][$key]
  2133.                                     || $searchParams['endDate'][$key] == '')
  2134.                             ) {
  2135.                                 $startDate self::cleanDate($searchParams['startDate'][$key]);
  2136.                                 $date " start_on >= '$startDate' ";
  2137.                                 $messagePart .= " -> after '<strong>$startDate</strong>' ";
  2138.                             } elseif (isset($searchParams['endDate'][$key])
  2139.                                 && (!$searchParams['startDate'][$key]
  2140.                                     || $searchParams['startDate'][$key] == '')
  2141.                             ) {
  2142.                                 $endDate self::cleanDate($searchParams['endDate'][$key]);
  2143.                                 $date " end_on <= '$endDate' ";
  2144.                                 $messagePart .= " -> before '<strong>$endDate</strong>' ";
  2145.                             } else {
  2146.                                 $whereEvent .= '';
  2147.                             }
  2148.                             $whereEvent .= ' ' $operationInst ' ' $date;
  2149.                             break;
  2150.                         case 'Updated':
  2151.                             $endDate = isset($searchParams['endDate'][$key]) ? "AND updated_at <= '" self::cleanDate($searchParams['endDate'][$key]) . "' " " AND 1=1 ";
  2152.                             $whereEvent .= ' ' $operationInst ' ' self::cleaned($searchParams['startDate'][$key]) . ' ' $endDate;
  2153.                             $messagePart .= "$operation $type \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2154.                             $messagePart .= "between \"<strong>" self::cleaned($searchParams['startDate'][$key]) . "</strong>\" ";
  2155.                             $messagePart .= "and \"<strong>" self::cleaned($searchParams['endDate'][$key]) . "</strong>\" ";
  2156.                             break;
  2157.                         case 'Created':
  2158.                             $startDate = isset($searchParams['startDate'][$key]) ? "created_at >= '" self::cleanDate($searchParams['startDate'][$key]) . "' " "1=1 ";
  2159.                             $endDate = isset($searchParams['endDate'][$key]) ? "AND created_at <= '" self::cleanDate($searchParams['endDate'][$key]) . "' " " AND 1=1 ";
  2160.                             $whereEvent .= ' ' $operationInst ' ' $startDate ' ' $endDate;
  2161.                             $messagePart .= "$operation $type \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2162.                             $messagePart .= "between \"<strong>" self::cleaned($searchParams['startDate'][$key]) . "</strong>\" ";
  2163.                             $messagePart .= "and \"<strong>" self::cleaned($searchParams['endDate'][$key]) . "</strong>\" ";
  2164.                             break;
  2165.                     }
  2166.                     $operationEvent $searchParams['searchToggle'][$key] ?? " OR ";
  2167.                 } elseif ($type == 'documents') {
  2168.                     $sortFields['name'] = 'Document Title';
  2169.                     if ($sortBy == '') {
  2170.                         $sortBy 'title';
  2171.                     }
  2172.                     $bindValues[$type][$key] = array();
  2173.                     $selectQryDocument "
  2174.                             SELECT 
  2175.                                 'documents' AS type, 
  2176.                                 d.id_doc,
  2177.                                 dt.id_doctype AS id_doctype, 
  2178.                                 dt.doctypename AS documenttype, 
  2179.                                 d.title, 
  2180.                                 d.created_at,
  2181.                                 d.doc_code,
  2182.                                 'undefined' AS country
  2183.                             FROM 
  2184.                                  documents d, 
  2185.                                  doctypes dt 
  2186.                             WHERE 
  2187.                                   dt.id_doctype = d.id_doctype ";
  2188.                     switch ($value) {
  2189.                         case 'Title contains':
  2190.                             $whereDocument .= ' ' $operationEvent " (
  2191.                                                   d.title LIKE  :percStringPerc$key
  2192.                                                        ) ";
  2193.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  2194.                             $messagePart .= "in $type using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2195.                             //remember what value has to be bound to what placeholder
  2196.                             $bindValues[$type][$key] = array(
  2197.                                 'percStringPerc' $key => '%' $string '%'
  2198.                             );
  2199.                             break;
  2200.                         case 'Document type is':
  2201.                             $whereDocument .= ' ' $operationEvent " (
  2202.                                                   dt.id_doctype = :idDoctype
  2203.                                                        ) ";
  2204.                             $messagePart .= "$operation $type having Document Type ";
  2205.                             $messagePart .= "\"<strong> " self::readableFilter($value) . "</strong>\" ";
  2206.                             //remember what value has to be bound to what placeholder
  2207.                             $bindValues[$type][$key] = array(
  2208.                                 'idDoctype' => $string
  2209.                             );
  2210.                             break;
  2211.                         case 'Document code is':
  2212.                             $whereDocument .= ' ' $operationEvent " (
  2213.                                                   d.doc_code LIKE  :percStringPerc$key
  2214.                                                        ) ";
  2215.                             $messagePart .= "$operation $type having Document Code ";
  2216.                             $messagePart .= "\"<strong> " self::readableFilter($value) . "</strong>\" ";
  2217.                             //remember what value has to be bound to what placeholder
  2218.                             $bindValues[$type][$key] = array(
  2219.                                 'percStringPerc' $key => '%' $string '%'
  2220.                             );
  2221.                             break;
  2222.                         case 'Summary contains':
  2223.                             $whereDocument .= ' ' $operationEvent " (
  2224.                                                   d.summary LIKE  :percStringPerc$key
  2225.                                                        ) ";
  2226.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  2227.                             $messagePart .= "in $type using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2228.                             //remember what value has to be bound to what placeholder
  2229.                             $bindValues[$type][$key] = array(
  2230.                                 'percStringPerc' $key => '%' $string '%'
  2231.                             );
  2232.                             break;
  2233.                         case 'Keywords contain':
  2234.                             $whereDocument .= ' ' $operationEvent " (
  2235.                                                d.keywords LIKE  :percStringPerc$key
  2236.                                               ) ";
  2237.                             $messagePart .= "$operation \"<strong>" self::cleaned($string) . "</strong>\" ";
  2238.                             $messagePart .= "in $type using filter \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2239.                             //remember what value has to be bound to what placeholder
  2240.                             $bindValues[$type][$key] = array(
  2241.                                 'percStringPerc' $key => '%' $string '%'
  2242.                             );
  2243.                             break;
  2244.                         case 'Updated':
  2245.                             if (isset($searchParams['endDate'][$key])) {
  2246.                                 $endDate self::cleanDate($searchParams['endDate'][$key]);
  2247.                                 $endDate "AND updated_at <= '$endDate' ";
  2248.                             } else {
  2249.                                 $endDate ' AND 1=1 ';
  2250.                             }
  2251.                             $whereDocument .= ' ' $operationInst ' ' self::cleaned($searchParams['startDate'][$key]) . ' ' $endDate;
  2252.                             $messagePart .= "$operation $type \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2253.                             $messagePart .= "between \"<strong>" self::cleaned($searchParams['startDate'][$key]) . "</strong>\" ";
  2254.                             $messagePart .= "and \"<strong>" self::cleaned($searchParams['endDate'][$key]) . "</strong>\" ";
  2255.                             break;
  2256.                         case 'Created':
  2257.                             if (isset($searchParams['startDate'][$key])) {
  2258.                                 $startDate self::cleanDate($searchParams['startDate'][$key]);
  2259.                                 $startDate "created_at >= '$startDate' ";
  2260.                             } else {
  2261.                                 $startDate '1=1 ';
  2262.                             }
  2263.                             if (isset($searchParams['endDate'][$key])) {
  2264.                                 $endDate self::cleanDate($searchParams['endDate'][$key]);
  2265.                                 $endDate "AND created_at <= '$endDate' ";
  2266.                             } else {
  2267.                                 $endDate ' AND 1=1 ';
  2268.                             }
  2269.                             $whereDocument .= ' ' $operationInst ' ' $startDate ' ' $endDate;
  2270.                             $messagePart .= "$operation $type \"<strong>" self::readableFilter($value) . "</strong>\" ";
  2271.                             $messagePart .= "between \"<strong>" self::cleaned($searchParams['startDate'][$key]) . "</strong>\" ";
  2272.                             $messagePart .= "and \"<strong>" self::cleaned($searchParams['endDate'][$key]) . "</strong>\" ";
  2273.                             break;
  2274.                     }
  2275.                     $operationEvent $searchParams['searchToggle'][$key] ?? " OR ";
  2276.                 }
  2277.             }
  2278.             if (isset($selectQryInd)) {
  2279.                 $selectQryInd .= " FROM indiv i ";
  2280.                 if ($endQueryInd == false) {
  2281.                     $whereInd .= ' ) ' $searchParams['indivStatus'] . 'GROUP BY i.id_ind';
  2282.                 }
  2283.                 $queryInd $selectQryInd ' ' $commonJoins ' ' $joinsInd ' ' $whereInd ' ' $matchOrder;
  2284.                 $stmtInd $connection->prepare($queryInd);
  2285.                 foreach($bindValues['experts'] as $bindValue) {
  2286.                     foreach($bindValue as $placeholder => $value) {
  2287.                         $stmtInd->bindValue($placeholder$value);
  2288.                     }
  2289.                 }
  2290.                 $stmtInd->execute();
  2291.                 $dataResultInd $stmtInd->fetchAll();
  2292.                 $sortFields['jobtitle'] = 'Position';
  2293.             }
  2294.             if (isset($selectQryInst)) {
  2295.                 if ($endQueryInst == false) {
  2296.                     $whereInst .= " ) " $searchParams['instStatus'] . " GROUP BY i.id_inst ";
  2297.                 }
  2298.                 $queryInst $selectQryInst ' ' $joinsInst ' ' $whereInst "  ORDER BY i.inst_name ASC";
  2299.                 $stmtInst $connection->prepare($queryInst);
  2300.                 foreach($bindValues['institutions'] as $bindValue) {
  2301.                     foreach($bindValue as $placeholder => $value) {
  2302.                         $stmtInst->bindValue($placeholder$value);
  2303.                     }
  2304.                 }
  2305.                 $stmtInst->execute();
  2306.                 $dataResultInst $stmtInst->fetchAll();
  2307.                 $sortFields["instType"] = "Institution Type";
  2308.             }
  2309.             if (isset($selectQryEvent)) {
  2310.                 if ($endQueryEvent == false) {
  2311.                     $whereEvent .= ' ) ' $searchParams['eventStatus'];
  2312.                     $whereEvent.= ' GROUP BY e.id_event ORDER BY start_on DESC ';
  2313.                 }
  2314.                 $queryEvent $selectQryEvent ' ' $joinsEvent ' ' $whereEvent;
  2315.                 $stmtEvent $connection->prepare($queryEvent);
  2316.                 foreach($bindValues['events'] as $bindValue) {
  2317.                     foreach($bindValue as $placeholder => $value) {
  2318.                         $stmtEvent->bindValue($placeholder$value);
  2319.                     }
  2320.                 }
  2321.                 $stmtEvent->execute();
  2322.                 $dataResultEvent $stmtEvent->fetchAll();
  2323.             }
  2324.             if (isset($selectQryDocument)) {
  2325.                 if ($endQueryDocument == false) {
  2326.                     $whereDocument .= ' ORDER BY created_at DESC';
  2327.                 }
  2328.                 $queryDocument $selectQryDocument ' ' $whereDocument;
  2329.                 $stmtDocument $connection->prepare($queryDocument);
  2330.                 foreach($bindValues['documents'] as $bindValue) {
  2331.                     foreach($bindValue as $placeholder => $value) {
  2332.                         $stmtDocument->bindValue($placeholder$value);
  2333.                     }
  2334.                 }
  2335.                 $stmtDocument->execute();
  2336.                 $dataResultDocument $stmtDocument->fetchAll();
  2337.             }
  2338.             $dataResult array_merge(
  2339.                 $dataResultInd,
  2340.                 $dataResultInst,
  2341.                 $dataResultEvent,
  2342.                 $dataResultDocument
  2343.             );
  2344.         }
  2345.         if ($messagePart == '') {
  2346.             $message 'no data found at all';
  2347.         } else {
  2348.             $messageEnd 'returned <strong>' count($dataResult) . '</strong> result(s).';
  2349.             $message $messageStart $messagePart $messageEnd;
  2350.         }
  2351.         //status 0 means there are no errors to be mentioned
  2352.         $return = array(
  2353.             'status' => 0,
  2354.             'dataResult' => $dataResult,
  2355.             'sortFields' => $sortFields,
  2356.             'sortby' => $sortBy,
  2357.             'message' => $message,
  2358.             'searchResultType' => $searchResultType
  2359.         );
  2360.         return $return;
  2361.     }
  2362.     /**
  2363.      * show the results of the advanced search
  2364.      *
  2365.      * @param Request $request
  2366.      *
  2367.      * @return Response
  2368.      */
  2369.     public function advancedSearchAction(Request $request): Response
  2370.     {
  2371.         //if we do a 'browse' search (from the homepage)
  2372.         //AND we try to filter the results (this can be the case after searching for a word in 'all')
  2373.         //we should redirect this to a more complex = advanced search type
  2374.         $searchParams $this::extractParams($request);
  2375.         //dump($searchParams);
  2376.         //we want to see inactive/unapproved/... results as a global editor
  2377.         //normal users should not see that
  2378.         if ($this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')) {
  2379.             $indivStatus ' ';
  2380.             $instStatus ' ';
  2381.             $eventStatus ' ';
  2382.         } else {
  2383.             $indivStatus ' AND status = 1 ';
  2384.             $instStatus ' AND activated = 1 ';
  2385.             $eventStatus ' AND status = 1 ';
  2386.         }
  2387.         $searchParams['indivStatus'] = $indivStatus;
  2388.         $searchParams['instStatus'] = $instStatus;
  2389.         $searchParams['eventStatus'] = $eventStatus;
  2390.         //remember the filters that we have applied
  2391.         //used to add action to the filter labels shown above the results
  2392.         $appliedFilters = array();
  2393.         $appliedCountryFilters = array();
  2394.         $doctrine $this->get('doctrine');
  2395.         //get the results depending on the defined action
  2396.         if ($searchParams['action'] == 'browse') {
  2397.             $results self::getBrowseSearchResults($searchParams$doctrine);
  2398.         } elseif ($searchParams['action'] == 'advSearch') {
  2399.             $results self::getAdvSearchResults($searchParams$doctrine);
  2400.         } else {
  2401.             $results = array(
  2402.                 'status' => 2,
  2403.                 'message' => 'we need at least the parameter "action" (browse or advSearch)'
  2404.             );
  2405.         }
  2406.         //this means we have an error somewhere, or we have no results (status == 4)
  2407.         if ($results['status']
  2408.             && $results['status'] != 3
  2409.         ) {
  2410.             return $this->render(
  2411.                 'Exception/error.html.twig',
  2412.                 array(
  2413.                     'message' => $results['message']
  2414.                 )
  2415.             );
  2416.         }
  2417.         $dataResult $results['dataResult'];
  2418.         $searchResultType $results['searchResultType'];
  2419.         //only keep the results that match one of the filtertypes (experts, institutions,....) we are asking
  2420.         if (isset($searchParams['searchFilterType'])
  2421.             && is_array($searchParams['searchFilterType'])
  2422.         ) {
  2423.             $filterData = array();
  2424.             foreach (array_unique($searchParams['searchFilterType']) as $type) {
  2425.                 $filterData array_merge(
  2426.                     $filterData,
  2427.                     $this->addFilter(
  2428.                       $type,
  2429.                         'type',
  2430.                         $dataResult
  2431.                     )
  2432.                 );
  2433.                 $appliedFilters[] = $type;
  2434.             }
  2435.             $dataResult $filterData;
  2436.         }
  2437.         //only show the results for the country we are filtering
  2438.         if (isset($searchParams['filterCountry'])
  2439.             && trim($searchParams['filterCountry']) != ''
  2440.         ) {
  2441.             $filterData = array();
  2442.             foreach (explode(','$searchParams['filterCountry']) as $countryValue) {
  2443.                 if (trim($countryValue) != '') {
  2444.                     $filterData array_merge(
  2445.                         $filterData,
  2446.                         $this->addFilter(
  2447.                             $countryValue,
  2448.                             'country',
  2449.                             $dataResult
  2450.                         )
  2451.                     );
  2452.                     $appliedCountryFilters[] = $countryValue;
  2453.                 }
  2454.             }
  2455.             $dataResult $filterData;
  2456.         }
  2457.         //if sortby is defined other than relevance, then manually sort by name;
  2458.         if (isset($results['sortby'])
  2459.             && $results['sortby'] != 'relevance'
  2460.         ) {
  2461.             $this->sortBy(
  2462.                 $results['sortby'],
  2463.                 $dataResult,
  2464.                 $searchParams['sortOrder']
  2465.             );
  2466.         } else {
  2467.             $results['sortby'] = 'relevance';
  2468.         }
  2469.         $data $this->get('knp_paginator')
  2470.             ->paginate(
  2471.                 $dataResult,
  2472.                 $request->query->getInt('page'1),
  2473.                 $searchParams['limit'],
  2474.                 array(
  2475.                     'pageParameterName' => 'page',
  2476.                     'sortDirectionParameterName' => 'dir'
  2477.                 )
  2478.             );
  2479.         //gather all the email address already
  2480.         //could be done at the receiving end also...
  2481.         //or are we the receiving end already?
  2482.         $emailusers = array();
  2483.         foreach ($dataResult as $expert) {
  2484.             if ($expert['type'] == 'experts') {
  2485.                 $emailusers[] = $expert['id_ind'];
  2486.             }
  2487.         }
  2488.         //who is making this query
  2489.         //this is used for searches where we want to send emails to the resulting experts
  2490.         $user self::getDoctrine()
  2491.             ->getRepository('OceanExpertBundle:Indiv')
  2492.             ->findOneBy(
  2493.                 array(
  2494.                     'idInd' => $this->get('security.token_storage')->getToken()->getUser()
  2495.                 )
  2496.             );
  2497.         //show what we have
  2498.         return $this->render(
  2499.             'Search/advancedSearch.html.twig',
  2500.             array(
  2501.                 'action' => $searchParams['action'],
  2502.                 'data' => $data,
  2503.                 'filters' => self::getFilters($dataResult),
  2504.                 'searchResultText' => $results['message'],
  2505.                 'appliedFilters' => $appliedFilters,
  2506.                 'appliedCountryFilters' => $appliedCountryFilters,
  2507.                 'searchResultType' => $searchResultType,
  2508.                 'searchConditions' => $searchParams['conditions'],
  2509.                 'sortfields' => $results['sortFields'],
  2510.                 'user' => $user,
  2511.                 'emailUsers' => $emailusers,
  2512.                 'sortby' => $results['sortby']
  2513.             )
  2514.         );
  2515.     }
  2516.     public static function sortBy($field, &$array$direction 'ASC'): bool
  2517.     {
  2518.         usort($array, function($a$b) use ($field$direction) {
  2519.             $a $a[$field] ?? '';
  2520.             $b $b[$field] ?? '';
  2521.             if ($a == $b) {
  2522.                 return 0;
  2523.             }
  2524.             if (strtolower($direction) == 'desc') {
  2525.                 return $a $b ? -1;
  2526.             } else {
  2527.                 return $a $b ? -1;
  2528.             }
  2529.         });
  2530.         return true;
  2531.     }
  2532.     /**
  2533.      * @param $dataArr
  2534.      * @param $type
  2535.      * @return array
  2536.      *
  2537.      */
  2538.     public static function getUnique($dataArr$type): array
  2539.     {
  2540.         SearchController::sortBy($type$dataArr'ASC');
  2541.         $fields = array();
  2542.         foreach ($dataArr as $value) {
  2543.             if (isset($value[$type])
  2544.                 && trim($value[$type]) != ''
  2545.             ) {
  2546.                 if (array_key_exists($value[$type], $fields)) {
  2547.                     $fields[$value[$type]] += 1;
  2548.                 } else {
  2549.                     $fields[$value[$type]] = 1;
  2550.                 }
  2551.             }
  2552.         }
  2553.         ksort($fields);
  2554.         return $fields;
  2555.     }
  2556.     public static function addFilter($filter$filterKey$dataArr): array
  2557.     {
  2558.         $filterData = array();
  2559.         foreach ($dataArr as $key => $value) {
  2560.             if ($filter == 'all'
  2561.                 || (isset($value[$filterKey])
  2562.                 && $value[$filterKey] == $filter)
  2563.             ) {
  2564.                 $filterData[$key] = $value;
  2565.             }
  2566.         }
  2567.         return $filterData;
  2568.     }
  2569.     /**
  2570.      * get the subject area name by its id
  2571.      *
  2572.      * @param int    $id id of the subject area
  2573.      * @param object $doctrine
  2574.      *
  2575.      * @return string
  2576.      */
  2577.     public static function getSubjectAreaById(int $idobject $doctrine): string
  2578.     {
  2579.         $subjectArea $doctrine
  2580.             ->getRepository('OceanExpertBundle:Subjects')
  2581.             ->findOneBy(array('idSub' => $id));
  2582.         return $subjectArea->getSubname();
  2583.     }
  2584.     /**
  2585.      * get the name of the sea region by its id
  2586.      * used to be getRegionById()
  2587.      *
  2588.      * @param int    $id       id of the sea area
  2589.      * @param object $doctrine doctrine
  2590.      *
  2591.      * @return string
  2592.      */
  2593.     public static function getSeaRegionById(int $idobject $doctrine): string
  2594.     {
  2595.         $seaRegion $doctrine
  2596.             ->getRepository('OceanExpertBundle:Searegions')
  2597.             ->findOneBy(array('idSearegion' => $id));
  2598.         return $seaRegion->getName();
  2599.     }
  2600.     /**
  2601.      * get the name of the institution type
  2602.      * replaced by getInstituteTypeNameById()
  2603.      *
  2604.      * @param int    $id       the id of the institution type
  2605.      * @param object $doctrine doctrine
  2606.      *
  2607.      * @return string
  2608.      */
  2609.     public static function getInstituteTypeById(int $idobject $doctrine): string
  2610.     {
  2611.         return self::getInstituteTypeNameById($id$doctrine);
  2612.     }
  2613.     /**
  2614.      * get the name of the institution type
  2615.      * used to be getInstituteTypeById()
  2616.      *
  2617.      * @param int    $id       the id of the institution type
  2618.      * @param object $doctrine doctrine
  2619.      *
  2620.      * @return string
  2621.      */
  2622.     public function getInstituteTypeNameById(int $idobject $doctrine): string
  2623.     {
  2624.         $instType $doctrine
  2625.             ->getRepository('OceanExpertBundle:Insttypes')
  2626.             ->findOneBy(
  2627.                 array(
  2628.                     'idInsttype' => $id
  2629.                 )
  2630.             );
  2631.         if ($instType) {
  2632.             return $instType->getInsttypeName();
  2633.         } else {
  2634.             return 'no institution found';
  2635.         }
  2636.     }
  2637.     public static function getJobTypesById($id$doctrine)
  2638.     {
  2639.         $jobType $doctrine
  2640.             ->getRepository('OceanExpertBundle:Jobtypes')
  2641.             ->findOneBy(array('idJob' => $id));
  2642.         return $jobType->getJobName();
  2643.     }
  2644.     /**
  2645.      * get the name of the country by its id
  2646.      * used to be getCountryById()
  2647.      *
  2648.      * @param int $id id of the country
  2649.      * @param object $doctrine
  2650.      *
  2651.      * @return string|bool
  2652.      */
  2653.     public static function getCountryById(int $idobject $doctrine): string
  2654.     {
  2655.         if ($id != 0) {
  2656.             $country $doctrine
  2657.                 ->getRepository('OceanExpertBundle:Countries')
  2658.                 ->findOneBy(array('idCountry' => $id));
  2659.             return $country->getCountry();
  2660.         } else {
  2661.             return '';
  2662.         }
  2663.     }
  2664.     public static function getMultipleCountriesById($id$doctrine): array
  2665.     {
  2666.         $id explode(','$id);
  2667.         $countries $doctrine
  2668.             ->getRepository('OceanExpertBundle:Countries')
  2669.             ->createQueryBuilder('c')
  2670.             ->select('c.country')
  2671.             ->where('c.idCountry in (:idCountries)')
  2672.             ->setParameter('idCountries'$id)
  2673.             ->orderBy('c.country')
  2674.             ->getQuery()
  2675.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2676.         return array_column($countries'country');
  2677.     }
  2678.     /**
  2679.      * get the name of the region by its id
  2680.      *
  2681.      * @param int    $id       id of the region
  2682.      * @param object $doctrine doctrine
  2683.      *
  2684.      * @return string
  2685.      */
  2686.     public static function getRegionById(int $idobject $doctrine): string
  2687.     {
  2688.         $region $doctrine
  2689.             ->getRepository('OceanExpertBundle:Regions')
  2690.             ->findOneBy(array('idRegion' => $id));
  2691.         return $region->getName();
  2692.     }
  2693.     /**
  2694.      * get all regions
  2695.      * can be used by the search to provide a dropdown menu
  2696.      *
  2697.      * @return JsonResponse
  2698.      */
  2699.     public function getRegionsAction()
  2700.     {
  2701.         $regions self::getDoctrine()
  2702.             ->getRepository('OceanExpertBundle:Regions')
  2703.             ->findAll();
  2704.         $regions array_map(function ($region)
  2705.             {
  2706.                 return array(
  2707.                     'id' => $region->getIdRegion(),
  2708.                     'name' => $region->getName()
  2709.                 );
  2710.             },
  2711.             $regions
  2712.         );
  2713.         return new JsonResponse($regions);
  2714.     }
  2715.     /**
  2716.      * get all all the country id's that are in this region
  2717.      *
  2718.      * @return array
  2719.      */
  2720.     public static function getCountriesInRegion($idRegion$doctrine): array
  2721.     {
  2722.         $countryIds $doctrine
  2723.             ->getRepository('OceanExpertBundle:RegionCountries')
  2724.             ->findBy(
  2725.                 array(
  2726.                     'idRegion' => $idRegion
  2727.                 )
  2728.             );
  2729.         return $countryIds;
  2730.     }
  2731.     public static function getGroupById($id$doctrine)
  2732.     {
  2733.         $group $doctrine
  2734.             ->getRepository('OceanExpertBundle:Groups')
  2735.             ->findOneBy(array('idGroup' => $id));
  2736.         return $group->getGroupName();
  2737.     }
  2738.     public static function readableFilter($filter): string
  2739.     {
  2740.         return ucfirst(preg_replace('/_/'' '$filter));
  2741.     }
  2742.     /**
  2743.      * get all sea regions
  2744.      * can be used by the search to provide a dropdown menu
  2745.      *
  2746.      * @return Response
  2747.      */
  2748.     public function getSeaRegionsAction(): Response
  2749.     {
  2750.         $regions self::getDoctrine()
  2751.             ->getRepository('OceanExpertBundle:Searegions')
  2752.             ->seaRegions();
  2753.         return new JsonResponse($regions);
  2754.     }
  2755.     public function getMemberGroupsAction(): Response
  2756.     {
  2757.         $groups self::getDoctrine()
  2758.             ->getRepository('OceanExpertBundle:Groups')
  2759.             ->createQueryBuilder('e')
  2760.             ->select('e.idGroup AS id,e.groupname AS name')
  2761.             ->orderBy('e.groupname')
  2762.             ->getQuery()
  2763.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2764.         return new JsonResponse($groups);
  2765.     }
  2766.     public static function getChildGroup($group$doctrine): array
  2767.     {
  2768.         $groupids = array();
  2769.         $allgroups = array($group);
  2770.         $groups $doctrine
  2771.             ->getRepository('OceanExpertBundle:Groups')
  2772.             ->createQueryBuilder('e')
  2773.             ->select('e.idGroup,e.groupname')
  2774.             ->orderBy('e.groupname')
  2775.             ->where('e.idParentgroup = :group')
  2776.             ->setParameter('group'$group)
  2777.             ->getQuery()
  2778.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2779.         foreach ($groups as $value) {
  2780.             $groupids[] = $value['idGroup'];
  2781.             $allgroups[] = $value['idGroup'];
  2782.         }
  2783.         if (count($groupids) > 0) {
  2784.             do {
  2785.                 $group2 $doctrine
  2786.                     ->getRepository('OceanExpertBundle:Groups')
  2787.                     ->createQueryBuilder('e')
  2788.                     ->select('e.idGroup AS id,e.groupname AS name')
  2789.                     ->orderBy('e.groupname')
  2790.                     ->where('e.idParentgroup in(:groupids)')
  2791.                     ->setParameter('groupids'$groupids)
  2792.                     ->getQuery()
  2793.                     ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2794.                 $groupids = array();
  2795.                 foreach ($group2 as $value) {
  2796.                     $groupids[] = $value['id'];
  2797.                     $allgroups[] = $value['id'];
  2798.                 }
  2799.             } while (count($group2) > 0);
  2800.         }
  2801.         return $allgroups;
  2802.     }
  2803.     public function getJobTypesAction(): Response
  2804.     {
  2805.         $jobTypes self::getDoctrine()
  2806.             ->getRepository('OceanExpertBundle:Jobtypes')
  2807.             ->createQueryBuilder('e')
  2808.             ->select('e.idJob AS id,e.jobname AS name')
  2809.             ->orderBy('e.jobname')
  2810.             ->getQuery()
  2811.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2812.         return new JsonResponse($jobTypes);
  2813.     }
  2814.     /**
  2815.      * get all countries
  2816.      * can be used by the search to provide a dropdown menu
  2817.      *
  2818.      * @return Response
  2819.      */
  2820.     public function getCountriesAction(): Response
  2821.     {
  2822.         $countries self::getDoctrine()
  2823.             ->getRepository('OceanExpertBundle:Countries')
  2824.             ->createQueryBuilder('e')
  2825.             ->select('e.idCountry AS id,e.country AS name')
  2826.             ->orderBy('e.country')
  2827.             ->getQuery()
  2828.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2829.         return new JsonResponse($countries);
  2830.     }
  2831.     public function getSubjectAreaAction(): Response
  2832.     {
  2833.         $subjectArea self::getDoctrine()
  2834.             ->getRepository('OceanExpertBundle:Subjects')
  2835.             ->createQueryBuilder('e')
  2836.             ->select('e.subname AS id,e.subname AS name')
  2837.             ->orderBy('e.subname')
  2838.             ->getQuery()
  2839.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2840.         return new JsonResponse($subjectArea);
  2841.     }
  2842.     public function getEventTypesAction(): Response
  2843.     {
  2844.         $eventTypes self::getDoctrine()
  2845.             ->getRepository('OceanExpertBundle:Eventtypes')
  2846.             ->createQueryBuilder('e')
  2847.             ->select('e.idEventtype AS id,e.eventtypeName AS name')
  2848.             ->orderBy('e.eventtypeName')
  2849.             ->getQuery()
  2850.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2851.         return new JsonResponse($eventTypes);
  2852.     }
  2853.     /**
  2854.      * here for backward compatibility
  2855.      *
  2856.      * @deprecated
  2857.      *
  2858.      * @return JsonResponse
  2859.      */
  2860.     function getInstitutionTypesAction(): JsonResponse
  2861.     {
  2862.         return $this->getInstituteTypesAction();
  2863.     }
  2864.     /**
  2865.      * @return JsonResponse
  2866.      */
  2867.     public function getInstituteTypesAction(): JsonResponse
  2868.     {
  2869.         $instTypes self::getDoctrine()
  2870.             ->getRepository('OceanExpertBundle:Insttypes')
  2871.             ->createQueryBuilder('i')
  2872.             ->select('i.idInsttype AS id,i.insttypeName AS name')
  2873.             ->orderBy('i.insttypeName')
  2874.             ->getQuery()
  2875.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2876.         return new JsonResponse($instTypes);
  2877.     }
  2878.     /**
  2879.      * get all possible document types
  2880.      * can be used by the search to provide a dropdown menu
  2881.      * @see #609
  2882.      *
  2883.      * @return Response
  2884.      */
  2885.     public function getDocumentTypesAction(): Response
  2886.     {
  2887.         $documentTypes self::getDoctrine()
  2888.             ->getRepository('OceanExpertBundle:Doctypes')
  2889.             ->createQueryBuilder('i')
  2890.             ->select('i.idDoctype AS id,i.doctypename AS name')
  2891.             ->orderBy('i.doctypename')
  2892.             ->getQuery()
  2893.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2894.         return new JsonResponse($documentTypes);
  2895.     }
  2896.     public function getMembersAction(Request $request): Response
  2897.     {
  2898.         $doctrine self::getDoctrine();
  2899.         $members = array();
  2900.         if (null !== $request->request->get('searchterm')) {
  2901.             $searchTerm $request->request->get('searchterm');
  2902.             $type $request->request->get('searchparam');
  2903.         } elseif (null !== $request->query->get('searchterm')) {
  2904.             $searchTerm $request->query->get('searchterm');
  2905.             $type $request->query->get('searchparam');
  2906.         } else {
  2907.             return new JsonResponse(
  2908.                 array(
  2909.                     'status' => 1,
  2910.                     'error' => 'please send "searchparam" and "searchterm"'
  2911.                 )
  2912.             );
  2913.         }
  2914.         $searchParams $this::extractParams($request);
  2915.         $searchParams['searchQuery'] = $searchTerm;
  2916.         $searchParams['searchType'] = $type;
  2917.         $searchParams['searchFilterType'] = ['experts'];
  2918.         $connection $doctrine->getManager()->getConnection();
  2919.         if ($type == 'name'
  2920.             || $type == 'all'
  2921.         ) {
  2922.             /*
  2923.             $statement = $connection->prepare("
  2924.                 SELECT
  2925.                     i.id_ind AS DT_RowId,
  2926.                     i.id_ind,
  2927.                     i.title,
  2928.                     i.fname,
  2929.                     i.mname,
  2930.                     i.sname,
  2931.                     inst.inst_name,
  2932.                     c.country,
  2933.                     i.status,
  2934.                     MATCH (i.fname,i.sname) AGAINST (:searchQuery IN BOOLEAN MODE) AS relevance
  2935.                 FROM
  2936.                     indiv i
  2937.                     LEFT JOIN countries c ON c.id_country =  i.country_code
  2938.                     LEFT JOIN indiv_institution ii ON ii.id_ind = i.id_ind
  2939.                     LEFT JOIN institutions inst ON inst.id_inst = ii.id_inst
  2940.                 WHERE
  2941.                     (
  2942.                          MATCH (i.fname,i.mname,i.sname) AGAINST (:searchQuery IN BOOLEAN MODE)
  2943.                         OR i.fname LIKE :percSearchQuery
  2944.                         OR i.fname LIKE :searchQueryPerc
  2945.                         OR i.mname LIKE :percSearchQuery
  2946.                         OR i.mname LIKE :searchQueryPerc
  2947.                         OR i.sname LIKE :percSearchQuery
  2948.                         OR i.sname LIKE :searchQueryPerc
  2949.                     )
  2950.                 ORDER BY relevance DESC, sname ASC;
  2951.             ");
  2952.             $statement->bindValue('searchQuery', $searchParams['searchQuery']);
  2953.             $statement->bindValue('searchQueryPerc', $searchParams['searchQuery'] . '%');
  2954.             $statement->bindValue('percSearchQuery', '%' . $searchParams['searchQuery']);
  2955.             $statement->execute();
  2956.             $members = array_merge($members, $statement->fetchAll());
  2957.             */
  2958.             //we only need the active ones
  2959.             $indivStatus ' AND status = 1 ';
  2960.             $instStatus ' AND activated = 1 ';
  2961.             $eventStatus ' AND status = 1 ';
  2962.             $searchParams['indivStatus'] = $indivStatus;
  2963.             $searchParams['instStatus'] = $instStatus;
  2964.             $searchParams['eventStatus'] = $eventStatus;
  2965.             $membersTmp self::getBrowseSearchResults($searchParams$doctrine);
  2966.             //recreate the array we expected here (see old code)
  2967.             foreach($membersTmp['dataResult'] as $dataResult) {
  2968.                 if (!isset($dataResult['id_ind'])) {
  2969.                     //this is not an expert, skip
  2970.                     continue;
  2971.                 }
  2972.                 $members[] = array(
  2973.                     "DT_RowId" => $dataResult['id_ind'],
  2974.                     "id_ind" => $dataResult['id_ind'],
  2975.                     "title" => $dataResult['title'],
  2976.                     "fname" => $dataResult['fname'],
  2977.                     "mname" => $dataResult['mname'],
  2978.                     "sname" => $dataResult['sname'],
  2979.                     "inst_name" => $dataResult['inst_name'],
  2980.                     "country" => $dataResult['country'],
  2981.                     "status" => $dataResult['status'],
  2982.                     "relevance" => $dataResult['relevance'],
  2983.                 );
  2984.             }
  2985.         } elseif ($type == 'email') {
  2986.             $statement $connection->prepare("
  2987.                 SELECT 
  2988.                     i.id_ind AS DT_RowId,
  2989.                     i.id_ind, 
  2990.                     i.title, 
  2991.                     i.fname, 
  2992.                     i.mname, 
  2993.                     i.sname,
  2994.                     inst.inst_name,
  2995.                     c.country, 
  2996.                     i.status, 
  2997.                     MATCH (i.email1) AGAINST (:searchQuery IN BOOLEAN MODE) AS relevance 
  2998.                 FROM 
  2999.                     indiv i
  3000.                     LEFT JOIN countries c ON c.id_country =  i.country_code
  3001.                     LEFT JOIN indiv_institution ii ON ii.id_ind = i.id_ind
  3002.                     LEFT JOIN institutions inst ON inst.id_inst = ii.id_inst
  3003.                 WHERE 
  3004.                     email1 = :searchQuery
  3005.                     OR email2 = :searchQuery
  3006.                     OR email3 = :searchQuery
  3007.                 ORDER BY relevance DESC;
  3008.             ");
  3009.             $statement->bindValue(':searchQuery'$searchParams['searchQuery']);
  3010.             $statement->execute();
  3011.             $members array_merge(
  3012.                 $members,
  3013.                 $statement->fetchAll()
  3014.             );
  3015.         } elseif ($type == 'group') {
  3016.             //we only need the active ones
  3017.             $indivStatus ' AND status = 1 ';
  3018.             $instStatus ' AND activated = 1 ';
  3019.             $eventStatus ' AND status = 1 ';
  3020.             $searchParams['indivStatus'] = $indivStatus;
  3021.             $searchParams['instStatus'] = $instStatus;
  3022.             $searchParams['eventStatus'] = $eventStatus;
  3023.             $membersTmp self::getBrowseSearchResults($searchParams$doctrine);
  3024.             //recreate the array we expected here (see old code)
  3025.             foreach($membersTmp['dataResult'] as $dataResult) {
  3026.                 if (!isset($dataResult['id_ind'])) {
  3027.                     //this is not an experts, skip
  3028.                     continue;
  3029.                 }
  3030.                 $members[] = array(
  3031.                     "DT_RowId" => $dataResult['id_ind'],
  3032.                     "id_ind" => $dataResult['id_ind'],
  3033.                     "title" => $dataResult['title'],
  3034.                     "fname" => $dataResult['fname'],
  3035.                     "mname" => $dataResult['mname'],
  3036.                     "sname" => $dataResult['sname'],
  3037.                     "inst_name" => $dataResult['inst_name'],
  3038.                     "country" => $dataResult['country'],
  3039.                     "status" => $dataResult['status'],
  3040.                     "relevance" => $dataResult['relevance'],
  3041.                     "groupName" => $dataResult['groupName'],
  3042.                     "groupId" => $dataResult['groupId']
  3043.                 );
  3044.             }
  3045.             /*
  3046.             $statement = $connection->prepare('
  3047.                 SELECT
  3048.                     i.id_ind AS DT_RowId,
  3049.                     i.id_ind,
  3050.                     i.title,
  3051.                     i.fname,
  3052.                     i.mname,
  3053.                     i.sname,
  3054.                     inst.inst_name,
  3055.                     c.country,
  3056.                     i.status,
  3057.                     1 AS relevance
  3058.                 FROM
  3059.                     indiv i
  3060.                     LEFT JOIN countries c ON c.id_country =  i.country_code
  3061.                     LEFT JOIN indiv_institution ii ON ii.id_ind = i.id_ind
  3062.                     LEFT JOIN institutions inst ON inst.id_inst = ii.id_inst
  3063.                     LEFT JOIN member_groups m ON i.id_ind = m.id_ind
  3064.                 WHERE
  3065.                     m.id_group like "%t%"
  3066.                 ORDER BY relevance DESC;
  3067.             ');
  3068.             $statement->bindValue('searchQuery', $searchParams['searchQuery']);
  3069.             $statement->execute();
  3070.             $members = array_merge($members, $statement->fetchAll());
  3071.             */
  3072.         }
  3073.         return new JsonResponse(
  3074.             array(
  3075.                 'data' => $members
  3076.             )
  3077.         );
  3078.     }
  3079.     /**
  3080.      * @param int $expert expert id
  3081.      *
  3082.      * @return int
  3083.      *
  3084.      * @todo is this used somewhere??? Arno 15/04/2022
  3085.      */
  3086.     function getExpertEvents(int $expert): int
  3087.     {
  3088.         $em self::getDoctrine()->getManager();
  3089.         $qb $em->createQueryBuilder();
  3090.         $qb->select('e.idEvent');
  3091.         $qb->from('OceanExpertBundle:EventParticipants''e');
  3092.         $qb->where('e.idInd = :idInd');
  3093.         $qb->setParameter('idInd'$expert);
  3094.         $participants $qb->getQuery()->getResult();
  3095.         $participants array_map('current'$participants);
  3096.         $qb $em->createQueryBuilder();
  3097.         $qb->select('e.idEvent');
  3098.         $qb->from('OceanExpertBundle:EventStaff''e');
  3099.         $qb->where('e.idInd = :idInd');
  3100.         $qb->setParameter('idInd'$expert);
  3101.         $staff $qb->getQuery()->getResult();
  3102.         $staff array_map('current'$staff);
  3103.         $qb $em->createQueryBuilder();
  3104.         $qb->select('e.idEvent');
  3105.         $qb->from('OceanExpertBundle:EventContacts''e');
  3106.         $qb->where('e.idInd = :idInd');
  3107.         $qb->setParameter('idInd'$expert);
  3108.         $contacts $qb->getQuery()->getResult();
  3109.         $contacts array_map('current'$contacts);
  3110.         $result array_merge($participants$staff$contacts);
  3111.         $results array_unique($resultSORT_REGULAR);
  3112.         return count($results);
  3113.     }
  3114.     /**
  3115.      * clean input strings to prevent XSS and other problems
  3116.      *
  3117.      * @param string $string input string
  3118.      *
  3119.      * @return string
  3120.      */
  3121.     public static function cleaned(string $string): string
  3122.     {
  3123.         $string nl2br(stripslashes($string));
  3124.         return preg_replace(
  3125.             '/[<>]/',
  3126.             '--*--',
  3127.             $string
  3128.         );
  3129.     }
  3130.     /**
  3131.      * in case we get the wrong format for the date
  3132.      * cleanup and return the correct format
  3133.      * we want a string like 'yyyy-mm-dd'
  3134.      *
  3135.      * @param string $string the date to be checked
  3136.      *
  3137.      * @return string
  3138.      */
  3139.     public static function cleanDate(string $string): string
  3140.     {
  3141.         if (strpos($string'/')) {
  3142.             $date explode('/'$string);
  3143.             if (strlen($date[0]) == 4) {
  3144.                 // this was something like yyyy/mm/dd I guess
  3145.                 return $date[0] . '-' $date[1] . '-' $date[2];
  3146.             } else {
  3147.                 // this was something like dd/mm/yyyy I guess
  3148.                 return $date[2] . '-' $date[1] . '-' $date[0];
  3149.             }
  3150.         } elseif (strpos($string'-')) {
  3151.             $date explode('-'$string);
  3152.             if (strlen($date[0]) == 4) {
  3153.                 // this was something like yyyy-mm-dd I guess
  3154.                 //that is the correct format already
  3155.                 return $string;
  3156.             } else {
  3157.                 // this was something like dd-mm-yyyy I guess
  3158.                 return $date[2] . '-' $date[1] . '-' $date[0];
  3159.             }
  3160.         } else {
  3161.             //no idea what to clean up
  3162.             return $string;
  3163.         }
  3164.     }
  3165.     public static function fulltext($string): string
  3166.     {
  3167.         $newString '';
  3168.         if (trim($string) != '') {
  3169.             $arrStr explode(' '$string);
  3170.             foreach ($arrStr as &$value) {
  3171.                 $value '+' $value;
  3172.             }
  3173.             $newString implode(' '$arrStr);
  3174.         }
  3175.         return $newString;
  3176.     }
  3177. }