Merge custom fields when merging contacts

This commit is contained in:
Nathan Gray 2010-11-25 20:24:22 +00:00
parent e86c74ef5d
commit 92e1b0b75b

View File

@ -1525,6 +1525,8 @@ class addressbook_bo extends addressbook_so
{
$this->error = false;
$account = null;
$custom_fields = config::get_customfields('addressbook', true);
$custom_field_list = $this->read_customfields($ids);
foreach(parent::search(array('id'=>$ids),false) as $contact) // $this->search calls the extended search from ui!
{
if ($contact['account_id'])
@ -1537,6 +1539,9 @@ class addressbook_bo extends addressbook_so
$account = $contact;
continue;
}
// Add in custom fields
$contact = array_merge($contact, $custom_field_list[$contact['id']]);
$pos = array_search($contact['id'],$ids);
$contacts[$pos] = $contact;
}
@ -1576,6 +1581,14 @@ class addressbook_bo extends addressbook_so
break;
default:
// Multi-select custom fields can also be merged
if($name[0] == '#') {
$c_name = substr($name, 1);
if($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) {
if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',',$target[$name]) : array();
$target[$name] = implode(',',array_unique(array_merge($target[$name],is_array($value)?$value:explode(',',$value))));
}
}
if (!$target[$name]) $target[$name] = $value;
break;
}