mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 01:28:19 +01:00
natural search in list pages
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
|
||||
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -4436,4 +4437,35 @@ if (! function_exists('getmypid'))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Natural search
|
||||
* @param array[string] $fields array filled with the fields names in the SQL query
|
||||
* @param string $value the value to look for
|
||||
* @return string $res the statement to append to the SQL query
|
||||
* */
|
||||
function natural_search($fields, $value)
|
||||
{
|
||||
global $db;
|
||||
$crits = explode(' ', $value);
|
||||
$res = "";
|
||||
$end = count($fields);
|
||||
$end2 = count($crits);
|
||||
$j = 0;
|
||||
foreach ($crits as $crit) {
|
||||
$i = 0;
|
||||
foreach ($fields as $field) {
|
||||
if ( $i > 0 && $i < $end){
|
||||
$res .= " OR ";
|
||||
}
|
||||
$res .= $field . " LIKE '%" . $db->escape(trim($crit)) . "%'";
|
||||
$i++;
|
||||
}
|
||||
if ($end > 1) $res .= ')';
|
||||
if ($j < $end2 - 1) $res .= " AND ";
|
||||
if ($end > 1 && $j < $end2 - 1) $res .= '(';
|
||||
$j++;
|
||||
}
|
||||
return " AND " . ($end > 1? '(' : '') . $res;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user