mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 00:13:35 +01:00
implemented search method in accounts sql backend, to no allways do a full query and limit in code
This commit is contained in:
parent
7c9df2fe1e
commit
a345f2c47e
@ -251,10 +251,10 @@ class accounts
|
||||
{
|
||||
$this->total = $account_search[$serial]['total'];
|
||||
}
|
||||
// no backend understands $param['app'] and sql does not understand group-parameters
|
||||
// no backend understands $param['app'], only sql understands type owngroups or groupmemember[+memberships]
|
||||
// --> do an full search first and then filter and limit that search
|
||||
elseif($param['app'] || $this->config['account_repository'] != 'ldap' &&
|
||||
(is_numeric($param['type']) || in_array($param['type'],array('owngroups','groupmembers','groupmembers+memberships'))))
|
||||
elseif($param['app'] || $this->config['account_repository'] != 'sql' &&
|
||||
in_array($param['type'], array('owngroups','groupmembers','groupmembers+memberships')))
|
||||
{
|
||||
$app = $param['app'];
|
||||
unset($param['app']);
|
||||
@ -264,12 +264,7 @@ class accounts
|
||||
unset($param['offset']);
|
||||
$stop = $start + $offset;
|
||||
|
||||
if ($this->config['account_repository'] != 'ldap' && is_numeric($param['type']))
|
||||
{
|
||||
$members = $this->members($group=$param['type'], true);
|
||||
$param['type'] = 'accounts';
|
||||
}
|
||||
elseif ($param['type'] == 'owngroups')
|
||||
if ($param['type'] == 'owngroups')
|
||||
{
|
||||
$members = $this->memberships($GLOBALS['egw_info']['user']['account_id'],true);
|
||||
$param['type'] = 'groups';
|
||||
@ -319,22 +314,10 @@ class accounts
|
||||
}
|
||||
$account_search[$serial]['total'] = $this->total;
|
||||
}
|
||||
// search via ldap backend
|
||||
elseif (method_exists($this->backend, 'search')) // implements its on search function ==> use it
|
||||
{
|
||||
$account_search[$serial]['data'] = $this->backend->search($param);
|
||||
$account_search[$serial]['total'] = $this->total = $this->backend->total;
|
||||
}
|
||||
// search by old accounts_sql backend
|
||||
// direct search via backend
|
||||
else
|
||||
{
|
||||
$account_search[$serial]['data'] = array();
|
||||
$accounts = $this->backend->get_list($param['type'],$param['start'],$param['sort'],$param['order'],$param['query'],$param['offset'],$param['query_type'],$param['active']);
|
||||
if (!$accounts) $accounts = array();
|
||||
foreach($accounts as $data)
|
||||
{
|
||||
$account_search[$serial]['data'][$data['account_id']] = $data;
|
||||
}
|
||||
$account_search[$serial]['data'] = $this->backend->search($param);
|
||||
$account_search[$serial]['total'] = $this->total = $this->backend->total;
|
||||
}
|
||||
//echo "<p>accounts::search(".array2string(unserialize($serial)).")= returning ".count($account_search[$serial]['data'])." of $this->total entries<pre>".print_r($account_search[$serial]['data'],True)."</pre>\n";
|
||||
@ -730,9 +713,10 @@ class accounts
|
||||
}
|
||||
if ($account_id && ($data = self::cache_read($account_id)))
|
||||
{
|
||||
return $just_id && $data['memberships'] ? array_keys($data['memberships']) : $data['memberships'];
|
||||
$ret = $just_id && $data['memberships'] ? array_keys($data['memberships']) : $data['memberships'];
|
||||
}
|
||||
return null;
|
||||
//error_log(__METHOD__."($account_id, $just_id) data=".array2string($data)." returning ".array2string($ret));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,7 +138,9 @@ class accounts_sql
|
||||
$this->table.'.account_id='.abs($account_id),
|
||||
__LINE__, __FILE__, false, '', false, 0, $join);
|
||||
}
|
||||
catch (egw_exception_db $e) { }
|
||||
catch (egw_exception_db $e) {
|
||||
unset($e);
|
||||
}
|
||||
|
||||
if (!$rs) // handle not (yet) existing mailaccounts table
|
||||
{
|
||||
@ -246,7 +248,9 @@ class accounts_sql
|
||||
}
|
||||
}
|
||||
// ignore not (yet) existing mailaccounts table
|
||||
catch (egw_exception_db $e) {}
|
||||
catch (egw_exception_db $e) {
|
||||
unset($e);
|
||||
}
|
||||
}
|
||||
return $data['account_id'];
|
||||
}
|
||||
@ -412,11 +416,11 @@ class accounts_sql
|
||||
$filter['owner'] = 0;
|
||||
break;
|
||||
case 'groups':
|
||||
$filter['account_type'] = 'g';
|
||||
$filter[] = "account_type='g'";
|
||||
break;
|
||||
case 'owngroups':
|
||||
$filter['account_id'] = array_map('abs', $this->frontend->memberships($GLOBALS['egw_info']['user']['account_id'], true));
|
||||
$filter['account_type'] = 'g';
|
||||
$filter[] = "account_type='g'";
|
||||
break;
|
||||
case 'groupmembers':
|
||||
case 'groupmembers+memberships':
|
||||
@ -431,7 +435,8 @@ class accounts_sql
|
||||
default:
|
||||
if (is_numeric($param['type']))
|
||||
{
|
||||
$filter['account_id'] = $this->frontend->memberships($param['type'], true);
|
||||
$filter['account_id'] = $this->frontend->members($param['type'], true);
|
||||
$filter['owner'] = 0;
|
||||
break;
|
||||
}
|
||||
// fall-through
|
||||
@ -439,6 +444,19 @@ class accounts_sql
|
||||
$filter[] = "(egw_addressbook.contact_owner=0 OR egw_addressbook.contact_owner IS NULL)";
|
||||
break;
|
||||
}
|
||||
// fix ambigous account_id (used in accounts and contacts table)
|
||||
if (array_key_exists('account_id', $filter))
|
||||
{
|
||||
if (!$filter['account_id']) // eg. group without members (would give SQL error)
|
||||
{
|
||||
$this->total = 0;
|
||||
return array();
|
||||
}
|
||||
$filter[] = $this->db->expression($this->table, $this->table.'.', array(
|
||||
'account_id' => $filter['account_id'],
|
||||
));
|
||||
unset($filter['account_id']);
|
||||
}
|
||||
if ($param['active'])
|
||||
{
|
||||
$filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),addressbook_sql::ACOUNT_ACTIVE_FILTER);
|
||||
@ -509,7 +527,7 @@ class accounts_sql
|
||||
}
|
||||
}
|
||||
$this->total = $GLOBALS['egw']->contacts->total;
|
||||
//error_log(__METHOD__."('$_type', $start, '$sort', '$order', '$query', $offset, '$query_type') returning ".count($accounts).'/'.$this->total);
|
||||
//error_log(__METHOD__."(".array2string($param).") returning ".count($accounts).'/'.$this->total);
|
||||
return $accounts;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user