- regular search method used by index is called now search

- search for (not yet working) extended search is called now ex_search (will be replaced by search)
- some parameter cleanups
- some changes for the new API contacts class, which just extends the bocontacts class of addressbook
This commit is contained in:
Ralf Becker 2006-04-24 20:52:14 +00:00
parent c170b9a047
commit 2315bfc199
4 changed files with 49 additions and 22 deletions

View File

@ -309,14 +309,12 @@ class bocontacts extends socontacts
/** /**
* reads contacts matched by key and puts all cols in the data array * reads contacts matched by key and puts all cols in the data array
* *
* @param array $keys array with keys in form internalName => value, may be a scalar value if only one key * @param int/string $contact_id
* @param string/array $extra_cols string or array of strings to be added to the SELECT, eg. "count(*) as num"
* @param string $join='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
* @return array/boolean contact data or false on error * @return array/boolean contact data or false on error
*/ */
function read($keys,$extra_cols='',$join='') function read($contact_id)
{ {
$data = parent::read($keys,$extra_cols,$join); $data = parent::read($contact_id);
if (!$data || !$this->check_perms(EGW_ACL_READ,$data)) if (!$data || !$this->check_perms(EGW_ACL_READ,$data))
{ {
return false; return false;

View File

@ -25,11 +25,6 @@
class socontacts class socontacts
{ {
/**
* @var string $links_table table name 'egw_links'
*/
var $links_table = 'egw_links';
/** /**
* @var string $extra_table name of customefields table * @var string $extra_table name of customefields table
*/ */
@ -93,6 +88,11 @@ class socontacts
*/ */
var $content_types = array(); var $content_types = array();
/**
* @var int $total total number of matches of last search
*/
var $total;
function socontacts($contact_app='addressbook') function socontacts($contact_app='addressbook')
{ {
$this->user = $GLOBALS['egw_info']['user']['account_id']; $this->user = $GLOBALS['egw_info']['user']['account_id'];
@ -124,7 +124,9 @@ class socontacts
$this->grants = $GLOBALS['egw']->acl->get_grants($contact_app,false); $this->grants = $GLOBALS['egw']->acl->get_grants($contact_app,false);
// remove some columns, absolutly not necessary to search in sql // remove some columns, absolutly not necessary to search in sql
$this->columns_to_search = array_diff(array_values($this->somain->db_cols),array('jpegphoto','owner','tid','private','id','cat_id','modified','modifier','creator','created')); $this->columns_to_search = array_diff(array_values($this->somain->db_cols),array('jpegphoto','owner','tid',
'private','id','cat_id','modified','modifier','creator','created','tz'));
$this->columns_to_search[] = $this->extra_value; // custome fields from extra_table
$this->account_extra_search = array('account_firstname','account_lastname','account_email','account_lid'); $this->account_extra_search = array('account_firstname','account_lastname','account_email','account_lid');
} }
// add grants for accounts: admin --> everything, everyone --> read // add grants for accounts: admin --> everything, everyone --> read
@ -259,7 +261,7 @@ class socontacts
/** /**
* reads contact data including custom fields * reads contact data including custom fields
* *
* @param interger/string $contact_id contact_id or 'a'.account_id * @param int/string $contact_id contact_id or 'a'.account_id
* @return array/boolean data if row could be retrived else False * @return array/boolean data if row could be retrived else False
*/ */
function read($contact_id) function read($contact_id)
@ -301,7 +303,7 @@ class socontacts
* @param boolean $need_full_no_count=false If true an unlimited query is run to determine the total number of rows, default false * @param boolean $need_full_no_count=false If true an unlimited query is run to determine the total number of rows, default false
* @return array of matching rows (the row is an array of the cols) or False * @return array of matching rows (the row is an array of the cols) or False
*/ */
function search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) function ex_search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
{ {
//echo 'socontacts::search->criteria:'; _debug_array($criteria); //echo 'socontacts::search->criteria:'; _debug_array($criteria);
// we can only deal with one category atm. // we can only deal with one category atm.
@ -498,7 +500,7 @@ class socontacts
* @param boolean $need_full_no_count=false If true an unlimited query is run to determine the total number of rows, default false * @param boolean $need_full_no_count=false If true an unlimited query is run to determine the total number of rows, default false
* @return array of matching rows (the row is an array of the cols) or False * @return array of matching rows (the row is an array of the cols) or False
*/ */
function &regular_search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
{ {
//echo "<p>socontacts::search(".print_r($criteria,true).",'$only_keys','$order_by','$extra_cols','$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n"; //echo "<p>socontacts::search(".print_r($criteria,true).",'$only_keys','$order_by','$extra_cols','$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";

View File

@ -37,7 +37,8 @@ class socontacts_sql extends so_sql
* For a union-query you call search for each query with $start=='UNION' and one more with only $order_by and $start set to run the union-query. * For a union-query you call search for each query with $start=='UNION' and one more with only $order_by and $start set to run the union-query.
* *
* @param array/string $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!) * @param array/string $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!)
* @param boolean/string $only_keys=true True returns only keys, False returns all cols. comma seperated list of keys to return * @param boolean/string/array $only_keys=true True returns only keys, False returns all cols. or
* comma seperated list or array of columns to return
* @param string $order_by='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY) * @param string $order_by='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY)
* @param string/array $extra_cols='' string or array of strings to be added to the SELECT, eg. "count(*) as num" * @param string/array $extra_cols='' string or array of strings to be added to the SELECT, eg. "count(*) as num"
* @param string $wildcard='' appended befor and after each criteria * @param string $wildcard='' appended befor and after each criteria
@ -52,7 +53,7 @@ class socontacts_sql extends so_sql
*/ */
function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
{ {
if ((int) $this->debug >= 4) echo "<p>socontacts_sql::search(".print_r($criteria,true).",'$only_keys','$order_by','$extra_cols','$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n"; if ((int) $this->debug >= 4) echo "<p>socontacts_sql::search(".print_r($criteria,true).",".print_r($only_keys,true).",'$order_by','$extra_cols','$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
$owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null);
@ -88,6 +89,8 @@ class socontacts_sql extends so_sql
$extra_cols = $extra_cols ? array_merge(is_array($extra_cols) ? $extra_cols : implode(',',$extra_cols),array_values($accounts2contacts)) : $extra_cols = $extra_cols ? array_merge(is_array($extra_cols) ? $extra_cols : implode(',',$extra_cols),array_values($accounts2contacts)) :
array_values($accounts2contacts); array_values($accounts2contacts);
// we need to remove the above columns from the select list, as they are added again via extra_cols and
// having them double is ambigues
if (!$only_keys) if (!$only_keys)
{ {
$account_table = $GLOBALS['egw']->db->get_table_definitions('phpgwapi',$this->accounts_table); // global db is on phpgwapi $account_table = $GLOBALS['egw']->db->get_table_definitions('phpgwapi',$this->accounts_table); // global db is on phpgwapi
@ -95,20 +98,39 @@ class socontacts_sql extends so_sql
$only_keys = implode(',',array_merge(array_diff(array_keys($this->db_cols),array_keys($accounts2contacts)), $only_keys = implode(',',array_merge(array_diff(array_keys($this->db_cols),array_keys($accounts2contacts)),
array_keys($account_table['fd']))); array_keys($account_table['fd'])));
} }
elseif($only_keys !== true)
{
if (!is_array($only_keys)) $only_keys = explode(',',$only_keys);
foreach(array_keys($accounts2contacts) as $col)
{
if (($key = array_search($col,$only_keys)) !== false ||
($key = array_search(str_replace('contact_','',$col),$only_keys)) !== false)
{
unset($only_keys[$key]);
}
}
}
foreach($filter as $col => $value) foreach($filter as $col => $value)
{ {
if (!is_int($col)) if (!is_int($col) && ($db_col = array_search($col,$this->db_cols)) !== false)
{ {
if (($db_col = array_search($col,$this->db_cols)) !== false && isset($accounts2contacts[$db_col])) if (isset($accounts2contacts[$db_col]))
{ {
unset($filter[$col]); unset($filter[$col]);
$filter[] = str_replace(' AS '.$db_col,'',$accounts2contacts[$db_col]).'='.$this->db->quote($value,$this->table_def['fd'][$db_col]['type']); $filter[] = str_replace(' AS '.$db_col,'',$accounts2contacts[$db_col]).
($value === "!''" ? "!=''" : '='.$this->db->quote($value,$this->table_def['fd'][$db_col]['type']));
}
elseif($value == "!''") // not empty query, will match all accounts, as their value is NULL not ''
{
$filter[] = "($db_col != '' AND $db_col IS NOT NULL)";
} }
} }
elseif (preg_match("/^([a-z0-9_]+) *(=|!=|LIKE|NOT LIKE) *'(.*)'\$/i",$value,$matches)) elseif (preg_match("/^([a-z0-9_]+) *(=|!=|LIKE|NOT LIKE|=!) *'(.*)'\$/i",$value,$matches))
{ {
if (($db_col = array_search($matches[1],$this->db_cols)) !== false && isset($accounts2contacts[$db_col])) if (($db_col = array_search($matches[1],$this->db_cols)) !== false && isset($accounts2contacts[$db_col]))
{ {
if ($matches[2] == '=!') $matches[2] = '!=';
$filter[$col] = str_replace(' AS '.$db_col,'',$accounts2contacts[$db_col]).' '.$matches[2].' \''.$matches[3].'\''; $filter[$col] = str_replace(' AS '.$db_col,'',$accounts2contacts[$db_col]).' '.$matches[2].' \''.$matches[3].'\'';
} }
} }

View File

@ -329,7 +329,7 @@ class uicontacts extends bocontacts
{ {
$query['col_filter'][] = $query['order']."!=''"; $query['col_filter'][] = $query['order']."!=''";
} }
$rows = (array) $this->regular_search($criteria,$id_only,$order,'','%',false,'OR',array((int)$query['start'],(int) $query['num_rows']),$query['col_filter']); $rows = (array) parent::search($criteria,$id_only,$order,'','%',false,'OR',array((int)$query['start'],(int) $query['num_rows']),$query['col_filter']);
//echo "<p style='margin-top: 100px;'>".$this->somain->db->Query_ID->sql."</p>\n"; //echo "<p style='margin-top: 100px;'>".$this->somain->db->Query_ID->sql."</p>\n";
if ($id_only) return $this->total; // no need to set other fields or $readonlys if ($id_only) return $this->total; // no need to set other fields or $readonlys
@ -878,7 +878,7 @@ class uicontacts extends bocontacts
$GLOBALS['egw_info']['flags']['app_header'] = lang('Addressbook'). ' - '. lang('Advanced search'); $GLOBALS['egw_info']['flags']['app_header'] = lang('Addressbook'). ' - '. lang('Advanced search');
if(!($GLOBALS['egw_info']['server']['contact_repository'] == 'sql' || !isset($GLOBALS['egw_info']['server']['contact_repository']))) if(!($GLOBALS['egw_info']['server']['contact_repository'] == 'sql' || !isset($GLOBALS['egw_info']['server']['contact_repository'])))
{ {
$GLOBALS['egw']->common->phpgw_header(); $GLOBALS['egw']->common->egw_header();
echo parse_navbar(); echo parse_navbar();
echo '<p> Advanced Search is not supported for ldap storage yet. Sorry! </p>'; echo '<p> Advanced Search is not supported for ldap storage yet. Sorry! </p>';
$GLOBALS['egw']->common->egw_exit(); $GLOBALS['egw']->common->egw_exit();
@ -956,6 +956,11 @@ class uicontacts extends bocontacts
$sel_options['tz'] = $tz + array('' => lang('doesn\'t matter')); $sel_options['tz'] = $tz + array('' => lang('doesn\'t matter'));
$sel_options['tid'][] = lang('all'); $sel_options['tid'][] = lang('all');
//foreach($this->content_types as $type => $data) $sel_options['tid'][$type] = $data['name']; //foreach($this->content_types as $type => $data) $sel_options['tid'][$type] = $data['name'];
// some changes for the new addressbook
$sel_options['owner'] = $this->get_addressbooks(EGW_ACL_READ,lang('all'));
$readonlys['change_photo'] = true;
$this->tmpl->read('addressbook.search'); $this->tmpl->read('addressbook.search');
return $this->tmpl->exec('addressbook.uicontacts.search',$content,$sel_options,$readonlys,$preserv); return $this->tmpl->exec('addressbook.uicontacts.search',$content,$sel_options,$readonlys,$preserv);
} }