Extend the patch to get_categories in infolog submitted by matthias to the other classes as well.

Added a hack that allows one to search for the categories' names prefixed by X-
Sony Ericsson phones (and possibly others) systematically prepend a X- to the 
category names, so with this patch we match X-CatName just like CatName

This is only done for SyncML obviously.
This commit is contained in:
Patrick Bihan-Faou 2007-12-11 09:29:50 +00:00
parent 810aa25ebd
commit d97f1eed5e
4 changed files with 95 additions and 85 deletions

View File

@ -516,6 +516,7 @@ class bocontacts extends socontacts
$GLOBALS['egw']->hooks->process($to_write,False,True); // called for every app now, not only enabled ones));
}
}
return $this->error ? false : $contact['id'];
}
@ -1115,40 +1116,40 @@ class bocontacts extends socontacts
return $adr_format;
}
var $app_cat;
var $glob_cat;
var $categories;
function find_or_add_categories($catname_list)
{
if (!is_object($this->glob_cat))
if (!is_object($this->categories))
{
if (!is_object($GLOBALS['egw']->categories))
{
$GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories',$this->owner,'phpgw');
}
$this->glob_cat =& $GLOBALS['egw']->categories;
}
if (!is_object($this->app_cat))
{
$this->app_cat =& CreateObject('phpgwapi.categories',$this->owner,'addressbook');
$this->categories =& CreateObject('phpgwapi.categories',$this->owner,'addressbook');
}
$cat_id_list = array();
foreach($catname_list as $cat_name)
{
$cat_name = trim($cat_name);
if (!($cat_id = $this->glob_cat->name2id($cat_name))
&& !($cat_id = $this->app_cat->name2id($cat_name)))
$cat_id = $this->categories->name2id($cat_name, 'X-');
if (!$cat_id)
{
$cat_id = $this->app_cat->add( array('name' => $cat_name,'descr' => $cat_name ));
// some SyncML clients (mostly phones add an X- to the category names
if (strncmp($cat_name, 'X-', 2) == 0)
{
$cat_name = substr($cat_name, 2);
}
$cat_id = $this->categories->add(array('name' => $cat_name,'descr' => $cat_name));
}
$cat_id_list[] = $cat_id;
if ($cat_id)
{
$cat_id_list[] = $cat_id;
}
}
if (count($cat_id_list) > 1)
{
$cat_id_list = array_unique($cat_id_list);
sort($cat_id_list, SORT_NUMERIC);
}
return $cat_id_list;
@ -1156,25 +1157,19 @@ class bocontacts extends socontacts
function get_categories($cat_id_list)
{
if (!is_object($this->glob_cat))
if (!is_object($this->categories))
{
if (!is_object($GLOBALS['egw']->categories))
{
$GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories',$this->owner,'phpgw');
}
$this->glob_cat =& $GLOBALS['egw']->categories;
$this->categories =& CreateObject('phpgwapi.categories',$this->owner,'addressbook');
}
if (!is_object($this->app_cat))
if (!is_array($cat_id_list))
{
$this->app_cat =& CreateObject('phpgwapi.categories',$this->owner,'addressbook');
$cat_id_list = explode(',',$cat_id_list);
}
$cat_list = array();
foreach(explode(',',$cat_id_list) as $cat_id)
foreach($cat_id_list as $cat_id)
{
if ( ($cat_data = $this->glob_cat->return_single($cat_id))
|| ($cat_data = $this->app_cat->return_single($cat_id)) )
if ($cat_data = $this->categories->return_single($cat_id))
{
$cat_list[] = $cat_data[0]['name'];
}

View File

@ -1042,36 +1042,38 @@ class bocalupdate extends bocal
return $this->so->delete_alarm($id);
}
var $app_cat;
var $glob_cat;
var $categories;
function find_or_add_categories($catname_list)
{
if (!is_object($this->glob_cat))
if (!is_object($this->categories))
{
$this->glob_cat =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'phpgw');
}
if (!is_object($this->app_cat))
{
$this->app_cat =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'calendar');
$this->categories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'calendar');
}
$cat_id_list = array();
foreach($catname_list as $cat_name)
{
$cat_name = trim($cat_name);
if (!($cat_id = $this->glob_cat->name2id($cat_name))
&& !($cat_id = $this->app_cat->name2id($cat_name)))
$cat_id = $this->categories->name2id($cat_name, 'X-');
if (!$cat_id)
{
$cat_id = $this->app_cat->add( array('name' => $cat_name,'descr' => $cat_name ));
if (strncmp($cat_name, "X-", 2) == 0)
{
$cat_name = substr($cat_name, 2);
}
$cat_id = $this->categories->add(array('name' => $cat_name,'descr' => $cat_name));
}
$cat_id_list[] = $cat_id;
if ($cat_id)
{
$cat_id_list[] = $cat_id;
}
}
if (count($cat_id_list) > 1)
{
$cat_id_list = array_unique($cat_id_list);
sort($cat_id_list, SORT_NUMERIC);
}
return $cat_id_list;
@ -1079,21 +1081,20 @@ class bocalupdate extends bocal
function get_categories($cat_id_list)
{
if (!is_object($this->glob_cat))
if (!is_object($this->categories))
{
$this->glob_cat =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'phpgw');
$this->categories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'calendar');
}
if (!is_object($this->app_cat))
if (!is_array($cat_id_list))
{
$this->app_cat =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'calendar');
$cat_id_list = explode(',',$cat_id_list);
}
$cat_list = array();
foreach(explode(',',$cat_id_list) as $cat_id)
foreach($cat_id_list as $cat_id)
{
if ( ($cat_data = $this->glob_cat->return_single($cat_id))
|| ($cat_data = $this->app_cat->return_single($cat_id)) )
if ($cat_data = $this->categories->return_single($cat_id))
{
$cat_list[] = $cat_data[0]['name'];
}

View File

@ -1279,40 +1279,34 @@ class boinfolog
return $icons;
}
var $app_cat;
var $glob_cat;
var $categories;
function find_or_add_categories($catname_list)
{
if (!is_object($this->glob_cat))
if (!is_object($this->categories))
{
if (!is_object($GLOBALS['egw']->categories))
{
$GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'phpgw');
}
$this->glob_cat =& $GLOBALS['egw']->categories;
}
if (!is_object($this->app_cat))
{
$this->app_cat =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'infolog');
$this->categories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'infolog');
}
$cat_id_list = array();
foreach($catname_list as $cat_name)
{
$cat_name = trim($cat_name);
if (!($cat_id = $this->glob_cat->name2id($cat_name))
&& !($cat_id = $this->app_cat->name2id($cat_name)))
$cat_id = $this->categories->name2id($cat_name, 'X-');
if (!$cat_id)
{
$cat_id = $this->app_cat->add( array('name' => $cat_name,'descr' => $cat_name ));
$cat_id = $this->categories->add(array('name' => $cat_name,'descr' => $cat_name));
}
$cat_id_list[] = $cat_id;
if ($cat_id)
{
$cat_id_list[] = $cat_id;
}
}
if (count($cat_id_list) > 1)
{
$cat_id_list = array_unique($cat_id_list);
sort($cat_id_list, SORT_NUMERIC);
}
return $cat_id_list;
@ -1326,25 +1320,19 @@ class boinfolog
*/
function get_categories($cat_id_list)
{
if (!is_object($this->glob_cat))
if (!is_object($this->categories))
{
if (!is_object($GLOBALS['egw']->categories))
{
$GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'phpgw');
}
$this->glob_cat =& $GLOBALS['egw']->categories;
$this->categories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'infolog');
}
if (!is_object($this->app_cat))
if (!is_array($cat_id_list))
{
$this->app_cat =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'infolog');
$cat_id_list = explode(',',$cat_id_list);
}
$cat_list = array();
foreach(is_array($cat_id_list) ? $cat_id_list : explode(',',$cat_id_list) as $cat_id)
foreach($cat_id_list as $cat_id)
{
if ( ($cat_data = $this->glob_cat->return_single($cat_id))
|| ($cat_data = $this->app_cat->return_single($cat_id)) )
if ($cat_data = $this->categories->return_single($cat_id))
{
$cat_list[] = $cat_data[0]['name'];
}

View File

@ -463,11 +463,19 @@
$values['level'] = $this->id2name($values['parent'],'level')+1;
$values['main'] = $this->id2name($values['parent'],'main');
}
$values = array_merge(
array(
'app_name' => $this->app_name,
'access' => 'public',
),
$values);
$this->db->insert($this->table,array(
'cat_parent' => $values['parent'],
'cat_owner' => $this->account_id,
'cat_access' => $values['access'],
'cat_appname' => $this->app_name,
'cat_appname' => $values['app_name'],
'cat_name' => $values['name'],
'cat_description' => $values['descr'],
'cat_data' => $values['data'],
@ -597,22 +605,40 @@
* @param string $cat_name cat-name
* @return int cat-id or 0 if not found
*/
function name2id($cat_name)
function name2id($cat_name,$strip)
{
static $cache = array(); // a litle bit of caching
if (isset($cache[$cat_name])) return $cache[$cat_name];
$this->db->select($this->table,'cat_id',array(
'cat_name' => $cat_name,
'(cat_appname='.$this->db->quote($this->app_name)." OR cat_appname='phpgw')",
if ($strip === true)
{
$strip = 'X-';
}
$cats = array($cat_name);
if (isset($strip) && strncmp($strip, $cat_name, strlen($strip)) == 0)
{
$stripped_cat_name = substr($cat_name, strlen($strip));
if (isset($cache[$stripped_cat_name]))
{
$cache[$cat_name] = $cache[$stripped_cat_name];
return $cache[$stripped_cat_name];
}
$cats[] = $stripped_cat_name;
}
$this->db->select($this->table,array('cat_name','cat_id'),array(
'cat_name' => $cats,
'cat_appname' => array($this->app_name, 'phpgw'),
),__LINE__,__FILE__,0,
"ORDER BY (CASE cat_owner WHEN ".(int)$this->account_id." THEN 1 WHEN -1 THEN 2 ELSE 3 END),cat_appname='phpgw'",
"ORDER BY cat_name!='$cat_name',(CASE cat_owner WHEN ".(int)$this->account_id." THEN 1 WHEN -1 THEN 2 ELSE 3 END),cat_appname='phpgw'",
false,1);
if (!$this->db->next_record()) return 0; // cat not found, dont cache it, as it might be created in this request
return $cache[$cat_name] = (int) $this->db->f('cat_id');
return $cache[$this->db->f('cat_name')] = (int) $this->db->f('cat_id');
}
/**