1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-21 13:11:52 +02:00

Merge pull request #3257 from SimSync/fix_3065

Fixes #3065 Added a method to translate wildcards to mysql counterparts
This commit is contained in:
Cameron 2018-07-07 15:46:14 -07:00 committed by GitHub
commit 1b4e0af07a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3996,6 +3996,29 @@ class e_admin_controller_ui extends e_admin_controller
return $qry;
}
/**
* Fix search string by replacing the commonly used '*' wildcard
* with the mysql represenation of it '%' and '?' with '_' (single character)
*
* @param string $search
* @return string
*/
protected function fixSearchWildcards($search)
{
$search = trim($search);
if (empty($search))
{
return '';
}
// strip wildcard on the beginning and the end
while (substr($search, 0, 1) == '*') $search = substr($search, 1);
while (substr($search, -1) == '*') $search = substr($search, 0, -1);
// replace "*" wildcard with mysql wildcard "%"
return str_replace(array('*', '?'), array('%', '_'), $search);
}
// TODO - abstract, array return type, move to parent?
protected function _modifyListQry($raw = false, $isfilter = false, $forceFrom = false, $forceTo = false, $listQry = '')
@ -4011,7 +4034,7 @@ class e_admin_controller_ui extends e_admin_controller
$filter = array();
$searchQuery = $tp->toDB($request->getQuery('searchquery', ''));
$searchQuery = $this->fixSearchWildcards($tp->toDB($request->getQuery('searchquery', '')));
$searchFilter = $this->_parseFilterRequest($request->getQuery('filter_options', ''));
if(E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES)