src/OceanExpertBundle/Controller/SearchController.php line 2684

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