explicitly specifying columns to search to contacts class and let contacts class deal with constructing AND query from that

This commit is contained in:
Ralf Becker 2014-03-03 11:59:18 +00:00
parent 8bb226ba6b
commit 8d3c1fabbd

View File

@ -2918,42 +2918,40 @@ class mail_compose
$_searchString = trim($_REQUEST['query']); $_searchString = trim($_REQUEST['query']);
$include_lists = (boolean)$_REQUEST['include_lists']; $include_lists = (boolean)$_REQUEST['include_lists'];
if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString)>=$_searchStringLength) { if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString)>=$_searchStringLength)
{
//error_log(__METHOD__.__LINE__.array2string($_searchString)); //error_log(__METHOD__.__LINE__.array2string($_searchString));
if (method_exists($GLOBALS['egw']->contacts,'search')) { $showAccounts = empty($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']);
// 1.3+ $search = explode(' ', $_searchString);
$showAccounts = empty($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']); foreach ($search as $k => $v)
//error_log(__METHOD__.__LINE__.$_searchString); {
$seStAr = explode(' ',$_searchString); if (mb_strlen($v) < 3) unset($search[$k]);
foreach ($seStAr as $k => $v) if (strlen($v)<3) unset($seStAr[$k]); }
$_searchString = trim(implode(' AND ',$seStAr)); $search_str = implode(' +', $search); // tell contacts/so_sql to AND search patterns
//error_log(__METHOD__.__LINE__.$_searchString); //error_log(__METHOD__.__LINE__.$_searchString);
$filter = ($showAccounts?array():array('account_id' => null)); $filter = $showAccounts ? array() : array('account_id' => null);
$filter['cols_to_search']=array('n_prefix','n_given','n_family','org_name','email','email_home'); $filter['cols_to_search'] = array('n_prefix','n_given','n_family','org_name','email','email_home');
$contacts = $GLOBALS['egw']->contacts->search(implode(' +',$seStAr),array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home'),'n_fn','','%',false,'OR',array(0,100),$filter); $cols = array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home');
// additionally search the accounts, if the contact storage is not the account storage $contacts = $GLOBALS['egw']->contacts->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0,100), $filter);
if ($showAccounts && $GLOBALS['egw']->contacts->so_accounts) // additionally search the accounts, if the contact storage is not the account storage
{ if ($showAccounts && $GLOBALS['egw']->contacts->so_accounts)
$accounts = $GLOBALS['egw']->contacts->search(array( {
'n_prefix' => $_searchString, $filter['owner'] = 0;
'n_given' => $_searchString, $accounts = $GLOBALS['egw']->contacts->search($search_str, $cols, 'n_fn', '', '%', false,'OR', array(0,100), $filter);
'n_family' => $_searchString,
'org_name' => $_searchString,
'email' => $_searchString,
'email_home' => $_searchString,
),array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home'),'n_fn','','%',false,'OR',array(0,100),array('owner' => 0));
if ($contacts && $accounts) if ($contacts && $accounts)
{
$contacts = array_merge($contacts,$accounts);
usort($contacts,function($a, $b)
{ {
$contacts = array_merge($contacts,$accounts); return strcasecmp($a['n_fn'], $b['n_fn']);
usort($contacts,create_function('$a,$b','return strcasecmp($a["n_fn"],$b["n_fn"]);')); });
}
elseif($accounts)
{
$contacts =& $accounts;
}
unset($accounts);
} }
elseif($accounts)
{
$contacts =& $accounts;
}
unset($accounts);
} }
} }
$results = array(); $results = array();