Fix category search missing when result is a child, but parent does not match too

This commit is contained in:
Nathan Gray 2012-11-05 17:56:03 +00:00
parent 1e53272309
commit 2218fd8956
2 changed files with 31 additions and 22 deletions

View File

@ -338,7 +338,8 @@ class admin_categories
}
$cats = new categories($filter['owner'],$query['appname']);
$globalcat = isset($GLOBALS['egw_info']['user']['apps']['admin']) ? 'all_no_acl' : $globalcat; // ignore acl only for admins
$rows = $cats->return_sorted_array($query['start'],false,$query['search'],$query['sort'],$query['order'],$globalcat,$parent=0,true,$filter);
$parent = $query['search'] ? false : 0;
$rows = $cats->return_sorted_array($query['start'],false,$query['search'],$query['sort'],$query['order'],$globalcat,$parent,true,$filter);
$count = $cats->total_records;
foreach($rows as $key => &$row)
{

View File

@ -333,7 +333,10 @@ class categories
//error_log(__METHOD__."($start,$limit,$query,$sort,$order,globals=$globals,parent=$parent_id,$unserialize_data) account_id=$this->account_id, appname=$this->app_name: ".function_backtrace());
$parents = $cats = array();
if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,(array)$parent_id,-1,'',$filter,$unserialize_data)))
// Cast parent_id to array, but only if there is one
if($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id;
if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parent_id,-1,'',$filter,$unserialize_data)))
{
$cats = array();
}
@ -341,31 +344,36 @@ class categories
{
$parents[] = $cat['id'];
}
while (count($parents))
if($parent_id || !$cats) // Avoid wiping search results
{
if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data)))
// Go find the children
while (count($parents))
{
break;
}
$parents = $children = array();
foreach($subs as $cat)
{
$parents[] = $cat['id'];
$children[$cat['parent']][] = $cat;
}
// sort the cats into the mains
if (count($children))
{
$cats2 = $cats;
$cats = array();
foreach($cats2 as $cat)
if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data)))
{
$cats[] = $cat;
if (isset($children[$cat['id']]))
break;
}
$parents = $children = array();
foreach($subs as $cat)
{
$parents[] = $cat['id'];
$children[$cat['parent']][] = $cat;
}
// sort the cats into the mains
if (count($children))
{
$cats2 = $cats;
$cats = array();
foreach($cats2 as $cat)
{
foreach($children[$cat['id']] as $child)
$cats[] = $cat;
if (isset($children[$cat['id']]))
{
$cats[] = $child;
foreach($children[$cat['id']] as $child)
{
$cats[] = $child;
}
}
}
}