mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-27 09:09:04 +01:00
fixed sql error reported by Uwe Redecker on the German list and got cfs as orga fields working (including multiselections)
This commit is contained in:
parent
3d211e2cab
commit
b0da799ee7
@ -618,9 +618,54 @@ class bocontacts extends socontacts
|
||||
list($name,$value) = explode(':',$part);
|
||||
$org[$name] = $value;
|
||||
}
|
||||
|
||||
$contacts = parent::search('',$this->org_fields,'','','',false,'AND',false,$org);
|
||||
$csvs = array('cat_id'); // fields with comma-separated-values
|
||||
|
||||
// split regular fields and custom fields
|
||||
$custom_fields = $regular_fields = array();
|
||||
foreach($this->org_fields as $name)
|
||||
{
|
||||
if ($name[0] != '#')
|
||||
{
|
||||
$regular_fields[] = $name;
|
||||
}
|
||||
else
|
||||
{
|
||||
$custom_fields[] = $name = substr($name,1);
|
||||
$regular_fields['id'] = 'id';
|
||||
if (substr($this->customfields[$name]['type'],0,6)=='select' && $this->customfields[$name]['rows'] || // multiselection
|
||||
$this->customfields[$name]['type'] == 'radio')
|
||||
{
|
||||
$csvs[] = '#'.$name;
|
||||
}
|
||||
}
|
||||
}
|
||||
// read the regular fields
|
||||
$contacts = parent::search('',$regular_fields,'','','',false,'AND',false,$org);
|
||||
if (!$contacts) return false;
|
||||
|
||||
// if we have custom fields, read and merge them in
|
||||
if ($custom_fields)
|
||||
{
|
||||
foreach($contacts as $contact)
|
||||
{
|
||||
$ids[] = $contact['id'];
|
||||
}
|
||||
if (($cfs = $this->read_customfields($ids,$custom_fields)))
|
||||
{
|
||||
foreach ($contacts as &$contact)
|
||||
{
|
||||
$id = $contact['id'];
|
||||
if (isset($cfs[$id]))
|
||||
{
|
||||
foreach($cfs[$id] as $name => $value)
|
||||
{
|
||||
$contact['#'.$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($contact);
|
||||
}
|
||||
}
|
||||
|
||||
// create a statistic about the commonness of each fields values
|
||||
$fields = array();
|
||||
@ -628,12 +673,18 @@ class bocontacts extends socontacts
|
||||
{
|
||||
foreach($contact as $name => $value)
|
||||
{
|
||||
if ($name != 'cat_id') $fields[$name][$value]++;
|
||||
}
|
||||
foreach(explode(',',$contact['cat_id']) as $part)
|
||||
{
|
||||
list($name) = explode(',',$part);
|
||||
$fields['cat_id'][$name]++;
|
||||
if (!in_array($name,$csvs))
|
||||
{
|
||||
$fields[$name][$value]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// for comma separated fields, we have to use each single value
|
||||
foreach(explode(',',$value) as $val)
|
||||
{
|
||||
$fields[$name][$val]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($fields as $name => $values)
|
||||
@ -645,18 +696,18 @@ class bocontacts extends socontacts
|
||||
//echo "<p>$name: '$value' $num/".count($contacts)."=".($num / (double) count($contacts))." >= $this->org_common_factor = ".($num / (double) count($contacts) >= $this->org_common_factor ? 'true' : 'false')."</p>\n";
|
||||
if ($value && $num / (double) count($contacts) >= $this->org_common_factor)
|
||||
{
|
||||
if ($name != 'cat_id')
|
||||
if (!in_array($name,$csvs))
|
||||
{
|
||||
$org[$name] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$org[$name] = array();
|
||||
foreach ($values as $catid => $catvalue)
|
||||
foreach ($values as $value => $num)
|
||||
{
|
||||
if ($catid && $catvalue / (double) count($values) >= $this->org_common_factor)
|
||||
if ($value && $num / (double) count($contacts) >= $this->org_common_factor)
|
||||
{
|
||||
$org[$name][] = $catid;
|
||||
$org[$name][] = $value;
|
||||
}
|
||||
}
|
||||
$org[$name] = implode(',',$org[$name]);
|
||||
|
@ -314,24 +314,27 @@ class socontacts
|
||||
* Read all customfields of the given id's
|
||||
*
|
||||
* @param int/array $ids
|
||||
* @param array $field_names=null custom fields to read, default all
|
||||
* @return array id => name => value
|
||||
*/
|
||||
function read_customfields($ids)
|
||||
function read_customfields($ids,$field_names=null)
|
||||
{
|
||||
if ($this->contact_repository == 'ldap')
|
||||
{
|
||||
return array(); // ldap does not support custom-fields (non-nummeric uid)
|
||||
}
|
||||
if (is_null($fields)) $fields = array_keys($this->customfields);
|
||||
|
||||
foreach($ids as $key => $id)
|
||||
{
|
||||
if (!(int)$id) unset($ids[$key]);
|
||||
}
|
||||
if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap
|
||||
if (!$ids || !$field_names) return array(); // nothing to do, eg. all these contacts are in ldap
|
||||
|
||||
$fields = array();
|
||||
foreach((array)$this->soextra->search(array(
|
||||
$this->extra_id => $ids,
|
||||
$this->extra_key => array_keys($this->customfields),
|
||||
$this->extra_key => $field_names,
|
||||
),false) as $data)
|
||||
{
|
||||
if ($data) $fields[$data[$this->extra_id]][$data[$this->extra_key]] = $data[$this->extra_value];
|
||||
|
Loading…
Reference in New Issue
Block a user